|
Re: Older FRC autonomous code
mark i tried the following code from one of my students and it does not seem to work, i will try your code above.
any help is greatly appreciated.
by the way i am opening up the user-routine_fast.c to modify the autonomous code is that correct?
thanks
// Drive forward, turn, return, and stop
void Autonomous()
{
static int counter=0; //keep track of loops to use as a crude timer - static keeps it around from call to call
static int autostate=1; //keep track of what step we're supposed to be doing
switch (autostate)
{
case 1: // Drive forward
pwm01 = pwm02 = 200;
pwm03 = pwm04 = 54; //motor is reversed
if (counter>38) //1 second
{
autostate = 2; // move on to the next step
counter = 0; // reset our timer for the next step
}
case 2: // Turnaround
pwm01 = pwm02 = 200;
pwm03 = pwm04 = 200; //motor is reversed
if (counter>76) //2 seconds
{
autostate = 3;
counter = 0;
}
case 3: // Drive forward (returning now)
pwm01 = pwm02 = 200;
pwm03 = pwm04 = 54; //motor is reversed
if (counter>38) //1 second
{
autostate = 4;
counter = 0;
}
case 4: // Stop - What to do when everything else is done
default: // also what to do if an invalid autostate occurs
pwm01 = pwm02 = pwm03 = pwm04 = 127; // Make sure the last thing you do is always stop
}
counter++;
}
|