jgraber
Here is a tested working  C example from EasyC.   
Features Triggering 2 different Autonomous routines,  you may need up to 4?
Features Timed Driving with  SafeWait   methodology that allows Emergency STOP;  
If you don't have E-STOP feature,  if something goes wrong.....
   The only way to stop your rogue robot is to turn off the Joystick,  or pull out the Vexnet USB Key.

int STOP = 0;
int WaitTime = 0;
// MAIN Function ****************************************************************
void MyMain ( void ) {
while ( 1 ) { // repeat forever MAIN WHILE
// DRIVER CONTROL MODE, just 3 lines in this example
Arcade2 ( 1 , 2 , 1 , 9 , 2 , 0 , 0 ) ;
JoystickToServo ( 1 , 3 , 5 , 0 ) ;
JoystickToServo ( 1 , 4 , 6 , 0 ) ;

// Example Autonomous "Timed Driving" with abort function
// ********** Auto #1 ****** Use button B8 Up to STOP ********
if ( GetJoystickDigital (1, 8, 1) ) { // STARTING AUTON #1 with button B8-Down

SetMotor(2,100); // Right Wheel START Auton #1, segment 1
SetMotor(9, 00); // Left Wheel
// SafeWait( 4000 ); // could put in function if you know how
WaitTime = 4000;
while( ( (WaitTime -= 10) > 0) && STOP == 0 )
{ Wait( 10 ); if (GetJoystickDigital (1, 8, 2)) { STOP = 1; } }
SetMotor(2,0); SetMotor(9,0); // Stop Wheels at END OF SEGMENT

SetMotor(2,00); // Right Wheel START Auton #1, segment 2
SetMotor(9,00); // Left Wheel
WaitTime = 1000;
while( ( (WaitTime -= 10) > 0) && STOP == 0 )
{ Wait( 10 ); if (GetJoystickDigital (1, 8, 2)) { STOP = 1; } }
SetMotor(2,0); SetMotor(9,0); // Stop Wheels at END OF SEGMENT

STOP = 0; // Reset; Auton #1 LAST Segment
SetMotor(2,0); SetMotor(9,0); // Safety stop wheels
} // End of AUTONOMOUS Routine #1

// ********** Auto #2 ****** Use button B8 Up to STOP ********
if ( GetJoystickDigital (1, 8, 4) ) { // STARTING AUTON Routine B8-Right
SetMotor(2, -50); // Right Wheel Segment 1 start
SetMotor(9, -50); // Left Wheel
WaitTime = 2000;
while( ( (WaitTime -= 10) > 0) && STOP == 0 )
{ Wait( 10 ); if (GetJoystickDigital (1, 8, 2)) { STOP = 1; } }
SetMotor(2,0); SetMotor(9,0); // Stop Wheels at end of segment

STOP = 0; // Reset; Auton #1 LAST Segment
SetMotor(2,0); SetMotor(9,0); // Safety stop wheels
} // End of AUTONOMOUS Routine #2

} // end main WHILE
} // END BLOCK MYMain
 
Quote 0 0