![]() |
Editing Main.c
1 Attachment(s)
I have been thinking about this for a little while. Why not have 2 sets of initializations and loops? 1 for autonomous, 1 for regular. And while we're at it, include a HALT() routine. Here's my version. Where do I put the prototype for HALT()?
|
Re: Editing Main.c
Quote:
The second problem is that once your autonomous routine ends, there's no going back. This probably isn't such a big deal, but if somehow one packet from the OI comes down during autonomous mode with the autonomous flag cleared, your robot will stop autonomous mode and you won't be able to get back in. I highly doubt this would happen since IFI checksums the packets to ensure that they are valid before passing them to the user cpu, but still.. you never know what might happen. Finally, your idea of halting the robot is interesting, but I don't see the purpose for it. Why would you want your robot to ever shut down? And more importantly, why would you want code to do that in there when you compete? I know our drive team would be rather upset if we had code like that in our robot and then a bug or something caused that condition to occur... Also, if you really want to have this halt option, it would probably be a wise idea to turn off all your outputs beforehand (PWMs to 127, relay outputs off, etc). |
Re: Editing Main.c
there is also the fact that such could result in code duplication - you may use some of the same code for the Process_Data_from_Local as you would for autonomous.
|
Re: Editing Main.c
There really is no advantage to doing this. If you're worried about code readability, try splitting the actual code up into separate files like this:
Code:
if (autonomous_mode) { |
Re: Editing Main.c
Quote:
What? #include statements are pre-processor directives ... they are (quite necessarily) executed before compilation and definately before you upload the code to the robot. For conditional includes, you'd have to use the pre-processor directive #ifdef ... #endif -- but this isn't what you mean to do. Presumably, everytime you run the robot you'd want to execute *both* autonomous mode, and manual mode -- meaning you'd more than likely want both "auton.c" and "manual.c" to be included every time. Instead of #include "auton.c", perhaps you mean some sort of function call, where the function is defined in auton.c? *color me confused* Quote:
|
Re: Editing Main.c
Quote:
No, that *should* work as is.... since the preprocessor would stick both of the files in and then everything would compile. That being said, I do agree that making then relevant sections into functions (in seperate files if you insist), would make much more sense. |
Re: Editing Main.c
Quote:
I think what Random Dude meant was that you could use #includes so that you could be sure that the code you were writing would be executed for one mode or another, depending on what file you put it in. that way, you still have both autonomous mode and operator mode, but the code for each is in separate files. |
Re: Editing Main.c
Quote:
You get the conveinence of having the autonomous routine in 1 file and the main routine in the other file, and you save the CPU cycles necessary to jump to and from the function. |
Re: Editing Main.c
It is perfectly reasonable to rewrite main(). I did it. I don't understand why IFI put in such a baroque superstructure in the FRC default code. The EDU code was cleaner.
You can replace *everything* that IFI gave you, except for their library. All I saved was the printf (modified slightly) and the main library with the rxget and txput routines since those are "hidden" in a library. The important thing to keep the same is how the IFI stuff is initialized and how you go about getting and putting the packet from the master CPU. Every thing else is fair game. In short, my main looks like this: Code:
void main (void)Code:
Code:
void Process_Tasks(void)Just pay attention to those lines with /* DO NOT CHANGE */ appended to them. Not all, but most are important. Also, if you are interested in my tasking code, I put a zip called "sensors.zip" out on one of the programming forums (PID or Gyro, one of the two...) |
Re: Editing 'forbiden' areas
Thanx, Every one!
Unfortunately, I didn't even compile the code I posted. I would be surprised if thier weren't syntax errors or whatnot. Let's keep discussing about editing core areas for making code faster, more efficent, adding functionality, or just for the heck of it. A few challenges:
Still cracking, Astronouth7303 |
Re: Editing Main.c
If anyone really feels like abuse... would it be possible without messing with IFI stuff to actually write a full control with just ASM?
If so... anyone want to give it a try? |
Re: Editing Main.c
:yikes: Yikes, ouch, assembley language, yikes, ouch, wow. :SinksIn: You really took that to heart!
No, I don't know any asm's. But someone's got to do the first one. May be this will be an off-season thing. Again, Yikes, ouch, wow. |
Re: Editing Main.c
Quote:
|
Re: Editing Main.c
I just remembered: some of IFI's routines are written in ASM (or ASM and C). Check those!
|
Re: Editing Main.c
Hrm... editing main.c, sounds like a good idea. Only I can't. MPLAB won't let me change it -- it isn't accepting any input at all when I have that file in focus. Is there some sort of default protection to protect the unawares that I am unaware about? It was somewhat distressing when, during testing, I did actually want to put something there. Just another reason why MPLAB was getting me angry ... it has several, well "interesting" qualities.
|
Re: Editing Main.c
Check that the file isn't read-only, and doesn't have other protection. If that doesn't work, there's always notepad.
PS to other Main.c readers: In the Programming code Fix FRC thread, a recent post brings up something about PWMs 13, 14, 15, and 16. READ IT! |
Re: Editing Main.c
Quote:
and unclick the "Protect Read Only files" box. |
Re: Editing Main.c
Why did IF protect almost all the source files anyways?
|
Re: Editing Main.c
Quote:
|
Re: Editing Main.c
Quote:
|
Re: Editing Main.c
Quote:
|
Re: Editing Main.c
Too bad, that's what this is about! :) Don't you feel safer now?
|
Pause Function
copied from my other post.
Code:
#define PAUSE_SWITCH p4_trig //Change as necessary |
| All times are GMT -5. The time now is 00:01. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi