Quote:
Originally Posted by ShotgunNinja
Well, my team has shown that they wanted to go with the IR sensor controller, maybe using a TV/VCR remote. But I am in charge of the programming, and I was wondering...
Would something like this (Using ROBOTC) be usable?
Code:
task Autonomous() { // Note: Just pseudocode, but whatever
while (bIfiAutonomousMode) /* Just in case... */
{
switch(GetIRInputState()) /* Get the state of the IR sensor, in a different subroutine */
{
case Button1:
Action1; // Something like "Move forward, stop"...
case Button2:
Action2; // Maybe "Turn Left"
case Button3:
Action3; // Maybe "Turn Right"
case Button4:
Action4; /* Something along the lines of: "Grab ball off overpass, however possible" */
default:
TakeNoAction; // Just "Stop Motors" or something
}
BetweenActions; // Something like "Stop Motors, Wait XX MS"
}
EndingAction; /* Play a sound or something. Reset motors for Human Control. Etc. */
}
Any comments?
|
You should look into using pointers to functions...it makes what your trying to do real simple...When you press a button, change the pointer to a function to the new behavior function..In your autonomous_routine just call the pointer as if it were the function. I
first decalre a couple of simple functions like: (fill in the code)
void drive_fwd(void);
void drive_bwd(void);
void turn_left(void);
void turn_right(void);
then declare a function pointer:
void (*auto_function)(void); the splat in the parens make a function pointer.
Note the format of the prototype and the fucntion pointer is the same, for the pointer replace the function name with the (*pointer_name)
Now use your code to read the IR board
but the action would assign a fucntion to the pointer.
switch(GetIRInputState()) /* Get the state of the IR sensor, in a different subroutine */
{
case Button1:
auto_function = drive_fwd;; // Something like "Move forward, stop"...
case Button2:
auto_function = drive_bwd;; // Maybe "backwards"
case Button3:
auto_function = turn_left; // Maybe "Turn left"
case Button4:
auto_fucntion = turn_right; /* Something along the lines of: "Grab ball off overpass, however possible" */
default:
TakeNoAction; // Just "Stop Motors" or something
}
then by calling auto_function just as if it were a function it will perform the function you assigned to it.
auto_function(); // do what it assigned to the pointer. call this in the autonomous loop.
The function pointer will stay the same until you change it with the IR board.
BC