|
|
|
![]() |
|
|||||||
|
||||||||
A complete routine, heavily commented, that implements a state machine to step through a sequence of steps to execute Autonomous mode.
I saw a number of questions on ChiefDelphi regarding how to implement Autonomous/Hybrid mode, in general as well as specific questions. This is a complete routine that can be called from function User_Autonomous_Code() in file user_routines_fast.c. It implements a state machine - a way of stepping through multiple steps to perform a sequence of actions. You can modify this template for your own needs. It's loaded with comments, and compiles and runs.
auton_state_machine1.zip
05-02-2008 10:47
David Bryan
Dear GaryK or anyone willing to hear.
I took this working section out of user_routines.c and renamed part of it and placed it into user_routines_fast.c. It will not compile. I cannot find my error. The same program will compile back in user_routines.c.
Here is the program:
/************************************************** *****************************
* FUNCTION NAME: Lim_Mix
* PURPOSE: Limits the mixed value for one joystick drive.
* CALLED FROM: Default_Routine, this file
* ARGUMENTS:
* Argument Type IO Description
* -------- ---- -- -----------
* intermediate_value int I
* RETURNS: unsigned char
************************************************** *****************************/
unsigned char Lim_Mix (int intermediate_valu)
{ // < I get a compile error here.
static int limited_valu;
if (intermediate_valu < 2000)
{
limited_valu = 2000;
}
else if (intermediate_valu > 2254)
{
limited_valu = 2254;
}
else
{
limited_valu = intermediate_valu;
}
return (unsigned char) (limited_valu - 2000);
}
// when i place the cursor over the variable, limited_valu
// i get the bubble [limited_valu = Out of Scope].
// please help
// thanks - David Bryan Team 818
05-02-2008 12:04
Alan Anderson
|
I took this working section out of user_routines.c and renamed part of it and placed it into user_routines_fast.c. It will not compile.
|
05-02-2008 12:43
Steve_AlanizDavid,
I did a cut and paste of the code and inserted it in My user_routines_fast
If I place the code in the autonomous section of the program I get the compile error.
If I place it above with the other function declarations it compiles fine.
Somebody with a greater knowledge of why C does what it does will have to explain why that happens. (I'm just a hacker..I like to stay on the hardware side of things...Instead of stupid compile errors we get blue smoke or sparks and that makes trouble shooting REAL easy!)
Anyway, I assume you can place the code outside the autonomous area and still call it. I may be wrong but that MIGHT solve the problem.
Steve
PS ...Oh you're placing a function within a function. User_Autonomous_Code . I don't think that's legal.
Steve
05-02-2008 13:11
garyk
Dear GaryK or anyone willing to hear. I took this working section out of user_routines.c and renamed part of it and placed it into user_routines_fast.c. It will not compile. I cannot find my error. The same program will compile back in user_routines.c. Here is the program: /************************************************** ***************************** * FUNCTION NAME: Lim_Mix * PURPOSE: Limits the mixed value for one joystick drive. * CALLED FROM: Default_Routine, this file * ARGUMENTS: * Argument Type IO Description * -------- ---- -- ----------- * intermediate_value int I * RETURNS: unsigned char ************************************************** *****************************/ unsigned char Lim_Mix (int intermediate_valu) { // < I get a compile error here. static int limited_valu; if (intermediate_valu < 2000) { limited_valu = 2000; } else if (intermediate_valu > 2254) { limited_valu = 2254; } else { limited_valu = intermediate_valu; } return (unsigned char) (limited_valu - 2000); } // when i place the cursor over the variable, limited_valu // i get the bubble [limited_valu = Out of Scope]. // please help // thanks - David Bryan Team 818 |
07-02-2008 10:19
David BryanHey Team
Thanks for your answers.
I set down with a C programmer Nathan and we solved the problem:
1) Added to IFI_utilities.h
2) char Limit_Mix (int); // ADDED 2/07/08 active in user_routines.c
Added to user_routines_fast.c and removed from user_routines.c
3)
/******************************** page 2.6 ***************************************
* FUNCTION NAME: Limit_Mix
* PURPOSE: Limits the mixed value for one joystick drive.
* CALLED FROM: Default_Routine, this file
* ARGUMENTS:
* Argument Type IO Description
* -------- ---- -- -----------
* intermediate_value int I
* RETURNS: unsigned char
************************************************** *****************************/
unsigned char Limit_Mix (int intermediate_value)
{
static int limited_value;
if (intermediate_value < 2000)
{
limited_value = 2000;
}
else if (intermediate_value > 2254)
{
limited_value = 2254;
}
else
{
limited_value = intermediate_value;
}
return (unsigned char) (limited_value - 2000);
}
4) pwm2_tiltup = Limit_Mix(2000 + pot_08 - pot_07 + 127);
5) When we do that all of it will compile!
Without lines 1, 2 above I could not make it work, but now it does thanks
to GM programmer Nathan Mackarewicz!
Problem I think is now solved!
Thanks!!