In the Navigation code I downloaded, it is apparent that the command_list data structure contained in commands.h provides a list of actions for the robot to accomplish. Using robot_command(), one can call this from either the autonomous or the manual mode. But how can we create multiple lists of commands to be used from various autonomous programs? Can we re-create the data structure in different iterations in a .c file?
Kevin, I would feel a lot better if you moved a little farther from the cliff!
If it was me, we have used thumb wheels in the form of binary input to some digital I/O. So we work out which program we are going to run before the match starts, set the thumb wheel to select the program we want to run. In code it sort of looks like this:
if (thumb_wheel = 1)
{
do these commands;
do these commands;
do these commands;
do these commands;
}
if (thumb_wheel = 2)
{
do these commands;
do these commands;
do these commands;
do these commands;
}
if (thumb_wheel = 3)
{
do these commands;
do these commands;
do these commands;
do these commands;
}
That depends. Multiple header files will work, if you call each array in them a different name, then you can use code similar to above, and call the correct command on each array.
Actually, Rich Petras, another JPL engineer wrote this code. I talked with Rich tonight and he said that when he gets a chance, he wants to add conditional branching to the code, which will make it easier to do what you want. If he doesn’t get to it in the next few days, I’ll start working on it.
Example commands.h file:
#define AUTO_MODE 1
struct commands command_list]] =
{
{Set 0 of autonomous commands;}
},
{
{set 1 of autonomous commands;}
},
{
{set 2 of autonomous commands;}
}
Example robot.c code:
switch (command_list[AUTO_MODE][current_command].command)
{
case NULL:
{
rc = 0; // We don't want to increment to the next command
break;
}
case CMD_SHOW_STATE:
{
rc = cmd_show_state();
break;
}
...so on and so forth
Anyways, this allows for multiple programs that change with one macro definition. If you’re worried about space, just have multiple codes in you commands.h file, and comment them all out except for the one you want.
This array decliration can also be used if you have multiple programs and want to change between them with a switch on the robot without recompiling and downloading. Just replace the macro definition with the input source.
[quote=Jon236]In the Navigation code I downloaded, it is apparent that the command_list data structure contained in commands.h provides a list of actions for the robot to accomplish. Using robot_command(), one can call this from either the autonomous or the manual mode. But how can we create multiple lists of commands to be used from various autonomous programs? Can we re-create the data structure in different iterations in a .c file?
Kevin suggested that I jump in and answer this one. (He doesn’t want to take the blame if you find any errors in my part of the code.)
There are a couple of ways to do what you want. A trivial one is to write a version
of CMD_JUMP that jumps within the existing command list based on a DIO signal.
If you want to get fancy, you could write a command that rewrites the whole command list. It is a variable after all, and not a constant. Just remember to allocate an array big
enough to hold your largest sequence. You would probably want to reset your command number to zero before the next pass through the loop too.
I looked at a few of the suggestions others have made. Any of them will work, but it can make it hard to share commands if you change the underlying operation. I tried to avoid pointers, this is the elegant solution, but so many people get screwed up by pointers that we thought it might be better to not do that.[/quote]