|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
Editing Main.c
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()?
|
|
#2
|
||||
|
||||
|
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). |
|
#3
|
||||
|
||||
|
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.
|
|
#4
|
||||
|
||||
|
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) {
#include "auton.c"
} else {
#include "manual.c"
}
|
|
#5
|
||||
|
||||
|
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:
![]() |
|
#6
|
|||
|
|||
|
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. |
|
#7
|
||||
|
||||
|
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. |
|
#8
|
||||
|
||||
|
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. |
|
#9
|
|||
|
|||
|
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)
{
#ifdef UNCHANGEABLE_DEFINITION_AREA
IFI_Initialization (); /* DO NOT CHANGE! */
#endif
User_Initialization(); /* You edit this in user_routines.c */
statusflag.NEW_SPI_DATA = 0; /* DO NOT CHANGE! */
while (1)
{
#ifdef _SIMULATOR
statusflag.NEW_SPI_DATA = 1;
#endif
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{
Getdata(&rxdata);
ProcessPacket(); // User_routines.c
Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}
Process_Tasks(); // user_routines.c
} /* while (1) */
} /* END of Main */
Code:
void ProcessPacket(void)
{
int c;
// Put common stuff here
CheckSwitches(); // Mass examine digital input for change
if (autonomous_mode)
{
User_Autonomous_Code();
}
else
{
User_Normal_Code();
}
pwm01 = DoPid(&Left, &LeftEncoder);
pwm02 = DoPid(&Right, &RightEncoder);
//---------- Inputs to Relays--------------------------------------------
relay8_fwd = !rc_dig_in18; /* Power pump only if pressure switch is off. */
relay8_rev = 0;
...
Code:
void Process_Tasks(void)
{
static char GyroTimer = 0, PrintTimer = 0;
Poll_Rx1(); // The fast loop runs > 100khz
Poll_Tx1(); // Poll rather than interrupts
Poll_Rx2();
Poll_Tx2();
while (MsTimer) // Incremented by TimerInterrupt.
{
MsTimer--; // Section.
if (++GyroTimer == 10) // 100hz
{
GyroTimer = 0;
Gyro_Task();
} // END GyroTimer
if (++PrintTimer == 100) // 10hz
{
PrintTimer = 0;
TetherTask(STDIO);
} // END Print task
}// END Tasking
}
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...) Last edited by Larry Barello : 01-02-2004 at 11:23. |
|
#10
|
|||||
|
|||||
|
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 |
|
#11
|
||||
|
||||
|
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? |
|
#12
|
|||||
|
|||||
|
Re: Editing Main.c
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. |
|
#13
|
|||||
|
|||||
|
Re: Editing Main.c
Quote:
|
|
#14
|
|||||
|
|||||
|
Re: Editing Main.c
I just remembered: some of IFI's routines are written in ASM (or ASM and C). Check those!
|
|
#15
|
||||
|
||||
|
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.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Video Editing Software | SteveC116 | 3D Animation and Competition | 29 | 16-02-2004 23:16 |
| DHTML Menu Editing | sanddrag | Website Design/Showcase | 18 | 05-08-2003 17:34 |
| Video Editing Programs...share what you use and why... | Alexander McGee | 3D Animation and Competition | 25 | 09-01-2003 22:27 |
| Can we use editing tools? | Ydnar | 3D Animation and Competition | 2 | 11-03-2002 02:54 |