![]() |
C: Cascading for Aliases?
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:) Code:
command struct command_list[];Code:
int move_forward(void)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? |
Re: C: Cascading for Aliases?
You probably want to use either an array or arrays, an array and an index array or else pointers:
array or array method: Code:
struct comands cmd_list[][20] = {Another method: Code:
// It may be easier to understand if you know assembly and you have an array of function pointers.The advantage of this is that it's one long list of stuff. And it's already compatible with kevin's code! just add anywhere you want in the pre-autonomous routine (disabled mode), some code that sets: Code:
extern int current_command; // To interface with robot.c from another file.Kevin's function will just think that it somehow ended up past the NULL statement and will keep going until the next NULL. |
Re: C: Cascading for Aliases?
Your idea should work. My team is doing it in basically the same way. Here's what I'd do.
commands.h Code:
extern struct commands *command_list;Code:
#include "commands.h"Code:
#include "commands.h"Code:
if(dipswitch == 0)So yeah, your idea works. |
Re: C: Cascading for Aliases?
Just be aware that the multiple structs and multidimensional arrays are memory hogs. The most I was able to do with two different methods that I tried were 3 unique autonomous modes, while our strategy team has identified at least 5 that they would like to have available. As such, we are not going to use the scripting, although we are still going to use the same functions with some modifications.
|
| All times are GMT -5. The time now is 20:29. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi