I’m the interim programmer for our team, and I’m trying to write some dead-reckoning code for the robot. I’ve currently got all my dead-reckoning strategies written in a .h file as an array of command type structures, much like the demo gyro code, but I need to be able to switch between them.
We’re using a DIP switch to choose the strategy we want, and I was wondering if I could use an array variable of command type structures in my functions that is aliased via a cascading-if in my code. (It would look something like this:)
command struct command_list];
if(dipswitch == 0)
command_list] = strat1_list]; //strat1_list] is defined in an included h file
else if(dipswitch == 1)
command_list] = strat2_list];
and so on and so forth, with a method calling it like this:
int move_forward(void)
{
end_time = command_list[current_command].parm_1;
if(curr_time > end_time)
rc = 1;
else
rc = 0;
}
(So that you can understand what’s going on, end_time would be the time at which you stop moving forward, and curr_time would count millisecs since the match began. You would grab the parameter that end_time is set to from a command type structure out of an array of those structs. command_list] is that array and current_command is a variable that increments as commands are completed.)
Our mentor wasn’t sure whether the aliasing of arrays was legal in C, though it seems like it should be, and I need to change a pretty sizeable chunk of code to find out. Anyone have any ideas?