|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Rewriting main loop
I want to rewrite the main loop so that the program enters one of the two possible 26.2ms loop functions (User_Autonomous_Code() and Process_Data_From_Master_uP()) from the same place in the code. As it is, when the code enters autonomous mode, it stays in User_Autonomous_Code() until autonomous mode is unset. The main reason I'd like to change this is so that I can have a single counter counting 26.2ms cycles, rather than one in each function. Secondly, its much more logical to do it this way.
I tried to implement my method, but I get some inexplicable problem where User_Initialization() (which should be called prior to any of my changes) is not getting called, and consequently, the rest of the program cannot run. Does the master processor detect my changes and decide they are illegal or something? Why is the code written like this in the first place? The changes I made: in main.c replace Code:
while (1) /* This loop will repeat indefinitely. */
{
#ifdef _SIMULATOR
statusflag.NEW_SPI_DATA = 1;
#endif
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{ /* I'm slow! I only execute every 26.2ms because */
/* that's how fast the Master uP gives me data. */
Process_Data_From_Master_uP(); /* You edit this in user_routines.c */
if (autonomous_mode) /* DO NOT CHANGE! */
{
User_Autonomous_Code(); /* You edit this in user_routines_fast.c */
}
}
Process_Data_From_Local_IO(); /* You edit this in user_routines_fast.c */
/* I'm fast! I execute during every loop.*/
} /* while (1) */
} /* END of Main */
Code:
while (1) /* This loop will repeat indefinitely. */
{
#ifdef _SIMULATOR
statusflag.NEW_SPI_DATA = 1;
#endif
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{ /* I'm slow! I only execute every 26.2ms because */
/* that's how fast the Master uP gives me data. */
/* You edit this in user_routines.c */
if (autonomous_mode) /* DO NOT CHANGE! */
{
User_Autonomous_Code(); /* You edit this in user_routines_fast.c */
}
else
{
Process_Data_From_Master_uP();
}
/*counter++; can go here*/
}
Process_Data_From_Local_IO(); /* You edit this in user_routines_fast.c */
/* I'm fast! I execute during every loop.*/
} /* while (1) */
} /* END of Main */
Code:
while (autonomous_mode) /* DO NOT CHANGE! */
{
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{
Getdata(&rxdata); /* DO NOT DELETE, or you will be stuck here forever! */
/* Add your own autonomous code here. */
Generate_Pwms(pwm13,pwm14,pwm15,pwm16);
Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}
}
Code:
Getdata(&rxdata); /* DO NOT DELETE, or you will be stuck here forever! */ Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */ Last edited by Max Lobovsky : 04-01-2005 at 13:55. |
|
#2
|
|||||
|
|||||
|
Re: Rewriting main loop
Your code looks fine. There is no magic check to see if you've changed anything in main.c. Lots of teams have rewritten main.c without issues. All the teams I mentor modify main.c for this and a variety of other reasons as well.
I'll see if I can find some past threads on this topic. [edit]http://www.chiefdelphi.com/forums/sh...ad.php?t=24590 Since the call to User_Initialization comes before the loop you posted I suspect other problems. Here's one stripped down version. For clarity I removed some lines that delayed all action until the sensors stabilize after power-up, resets autonomous upon disable, and a couple of other specialized routine calls like conversion from 0->254 to -127->127. The Put/Getdata calls are also brought into main.c instead of being repeated elsewhere, so User_Autonomous() is a normal routine. 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) /* This loop will repeat indefinitely. */
{
#ifdef _SIMULATOR
statusflag.NEW_SPI_DATA = 1;
#endif
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{
Getdata(&rxdata); /* Get fresh data from the master microprocessor. */
Process_Data_From_Master_uP(); // Modified to only handle slow loop sensor stuff
if (competition_mode) // Robot is disabled
{
Gyro(); // Initialize gyro assumes FRC is powered up only when robot is in position
}
else if (autonomous_mode) // Robot is in autonomous
{
User_Autonomous_Code();
}
else // Robot is in normal human driver mode
{
User_Driver(); // Joystick driving
}
Putdata(&txdata); /* DO NOT CHANGE! */
}
Process_Data_From_Local_IO();
} /* while (1) */
} /* END of Main */
Last edited by Mark McLeod : 05-01-2005 at 08:23. |
|
#3
|
||||
|
||||
|
Re: Rewriting main loop
I guess I'll look for some typo or something somewhere. I think I will also move put and getdata() there, too.
|
|
#4
|
||||
|
||||
|
Re: Rewriting main loop
What exactly are the errors you get? It looks like this code is fine to me. If you do get it working, post it back up here (or on the code repository!
). I'd like to use it. (And I don't want to have to figure this out as well...) |
|
#5
|
||||
|
||||
|
Re: Rewriting main loop
That wasn't an actual copy of the code I tried to compile, so I imagine there was some small error somewhere in my code.. I just quickly rewrote the changes for the post (it's really just deleting some stuff and moving a single line).
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Rules for hanging, using a loop over the end of the bar | caffel | Rules/Strategy | 10 | 04-06-2004 15:04 |
| What is going to be your team's main strategy? | Matt Attallah | Chit-Chat | 5 | 06-04-2004 22:34 |
| Actual execution time measurement | Dan | Technical Discussion | 5 | 24-03-2003 11:36 |
| NEED HELP with Delay loop for compressor relay switch | archiver | 2001 | 10 | 24-06-2002 02:11 |
| main driver | Kaitlin Palmer | Off-Season Events | 0 | 09-04-2002 21:26 |