Quote:
Originally Posted by Shadow503
Code:
/**
* Call this method to drive
* @param speed a double describing the speed -15fps to +15fps
*/
void Autonomous::procTable(int AutoMode) {
// ........
if(cur_command + 1 < sizeof(currentCommand)) { //there is another command to run
cur_command++; //increment to next command
currentStateTime = 0; //move on to next state
}
// .........
}
|
This is at least part of the problem you are experiencing. "sizeof(currentCommand)" will not give the size of the commands array. sizeof evaluates at compile time to the size of a type, or, when used with a variable, the type of the variable. currentCommand's type is "struct Command *". So, the sizeof (regardless of which command table is chosen to have currentCommand point to) will always evaluate to the size of a struct Command
pointer (probably 4). This could be greater than the actual size of your command table, causing your program to potentially walk off the end of an array.
The easiest way to change this would be to add another command type that signifies the end of the command table. When your autonomous code sees that command as it processes the table, it knows it has reached the last entry.