I am a teacher at a high school in Ohio that is attempting to put on an in class robotics competition using VEX robots. I do not have the equipment to have a real field control system, however a colleague of mine mentioned I could design a template where pushing a bump switch will start autoanomus mode and then after the timer in the code runs out, the code would switch to a timed teleop mode. I have posted the code below, here are the current test results and error:
The first push does put it into autonomous mode but the assigned time does not cause the code to jump out of the while loop for the auto period, instead it continues to repeat the autonomous codes while loop. I was expecting the timer hitting 20 seconds to cause the while loop to become false and therefore move to the next line of code, which would cause it to move to the timed teleop while loop. Any help or guidance is deeply appreciated!
Beginning of Code:
task main()
{
int buttoncount; //create varible buttoncount to track number of times the auto bump switch is pressed.
buttoncount = 0; //set varible to zero
while(buttoncount==0) //Add loop for only buttoncount ==0
{
if(SensorValue(dgtl10)==1)
{
buttoncount = buttoncount + 1;//when the bump switch is pressed add 1 to “buttoncount”
}
}
//////////////////////////////////////////////////////////////////////////////////////////
//
// MODIFICATIONS ABOVE THIS LINE WILL CAUSE YOUR ROBOTS CODE TO BE RAN INCORRECTLY
//
// AUTOANOUMUS CODE
//
//////////////////////////////////////////////////////////////////////////////////////////
while(buttoncount == 1) //Autonamous starts when the bumpswitch is pressed once
{
clearTimer(T1);
while(time1[T1] < 20) //Autoanmous code will run for only 20 seconds. Modifications to this line will merit disqualification
{
while(1==1) //this is a students sample code I barrowedto test my template.
{
startMotor(port9, 127);
startMotor(port8, 127);
wait(6.5);
stopMotor(port9);
stopMotor(port8);
startMotor(port9, -127);
startMotor(port8, -127)
wait(2)
stopMotor(port9)
stopMotor(port8)
startMotor(port9, 127)
startMotor(port8, -127)
wait(1.5);
stopMotor(port9)
stopMotor(port8)
startMotor(port9, 127)
startMotor(port8, 127)
wait(5);
stopMotor(port9)
stopMotor(port8)
}
}
buttoncount = buttoncount + 1; //AFTER AUTOANMOUS ADD 1 TO THE VARIBLE. Modifications to this line will merit disqualification
}
/////////////////////////////////////////////////////////////////////////////////////////
//
// TELEOP CODE
//
/////////////////////////////////////////////////////////////////////////////////////////
while(buttoncount==2) //WHEN THE VARIBLE COUNT IS TWO RUN THE TELEOP CODE. Modifications to this line will merit disqualification
{
clearTimer(T2); //CLEAR THE SECOND TIMER. Modifications to this line will merit disqualification
while (time1[T2]<120) //RUN TEAM’S TELEOP CODE FOR 2 MINUTES. Modifications to this line will merit disqualification
{
while(1==1) //this is a students sample code I barrowedto test my template.
{
startMotor(port2,127);
startMotor(port3,127);
wait(15);
}}
}
buttoncount = buttoncount + 1; //AFTER TELEOP TIME EXPIRES ADD 1 TO THE VARIBLE. Modifications to this line will merit disqualification
}