Thread created automatically to discuss a document in CD-Media.
A programming template for Autonomous Mode by: garyk
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.
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.
The error you got seems like one that is actually caused by a problem with the code before it not being complete, with a missing semicolon or close brace. It looks like you might have put it in the middle of one of the existing functions, instead of between them. Double-check to make sure the preceding function in user_routines_fast.c didn’t get interfered with when you inserted your code.
David,
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.
I wonder also if you put this function inside another function. Did you put it where it says:
/* Add your own autonomous code here. */
?
If I put your code there I get an error on the “unsigned char” line.
Try removing all the code in question, and make sure you get a clean compile. Then, add your code at the very end of the file and I think it will compile.
The code you have is a complete function and it can’t be put in the middle of another function (and I apologize if you already know this.) If it works with your code at the end of user_routines_fast.c then you can call it where you need it.
BTW, if you just need a limit_mix function for your autonomous routine, you can call the one in user_routines.c - the significance of the function is determined by where you call it from, not which file it’s in. To do so, add this
line with the other function prototypes in user_routines.h:
unsigned char Limit_Mix (int);
Make sure it compiles after you remove your own Lim_Mix(), then you can
call Limit_Mix from your autonomous routine.