![]() |
Multiple command_lists
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! Jon Mittelman Team 236 Mentor |
Re: Multiple command_lists
Quote:
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: Code:
if (thumb_wheel = 1) |
Re: Multiple command_lists
Quote:
|
Re: Multiple command_lists
Quote:
|
Re: Multiple command_lists
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.
|
Re: Multiple command_lists
Quote:
Quote:
-Kevin |
Re: Multiple command_lists
I would suggest making a two dimentional array.
Code:
Example commands.h file:Code:
Example robot.c code: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. -Tony K |
Re: Multiple command_lists
What I did was redid the code so that it accessed a pointer to the array, than made that pointer an argument:
Code:
struct commands *command_list;Code:
#define GET_COMMAND(index) command_list[(index)]Code:
robot_control(default_script); |
Re: Multiple command_lists
[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. |
| All times are GMT -5. The time now is 02:49. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi