Autonomous Trigger

Is there a way to test autonomous (trigger autonomous) without having to use a control switch, just with the controller and Cortex (using RobotC for programming)?

You can just have a button that you don’t use for driving be used for running the autonomous.

How would I write that in the compiler?
Would it be in the autonomous task function itself?

It’s actually fairly simple!
Here’s what I put down, or close to what I put down for autonomous running via two buttons:


if(vexRT[Btn8U]==1&&vexRT[Btn8R]==1){
startTask(autonomous);
stopTask(usercontrol);
}

you can use the virtual competition control in robotC

A better way would be to say if the button is on then start task autonomous and put a 15 second wait time then stop task autonomous. That way you don’t need to restart your code every time you run it and its more accurate than the switch in that it stops at exactly 15 seconds. I do this with an LCD display.

One thing you may find interesting is how RobotC handles the starting of autonomous mode.
Go ahead and open up “VEX_Competition_Includes.h” by right clicking on the include in any competition template:

// Start the autonomous task
		  startTask(autonomous);

			// Waiting for autonomous phase to end
			while (bIfiAutonomousMode && !bIfiRobotDisabled)
			{
				if (!bVEXNETActive)
				{
				  if (nVexRCReceiveState == vrNoXmiters) // the transmitters are powered off!!
					  allMotorsOff();
				}
				wait1Msec(25);               // Waiting for autonomous phase to end
			}
		  allMotorsOff();
		  if(bStopTasksBetweenModes)
		  {
			  allTasksStop();
			}
		}

One thing that hasn’t been mentioned here is to make sure you terminate any tasks and stop any motors that are running once your ‘autonomous has stopped’. Nothing is worse than hitting the end of your autonomous and having your robot grind into the wall because you forgot to set the drive motors to 0.

So run:


allMotorsOff();
allTasksStop();

to clean things up.

Finally, don’t enable autonomous and disable driver control from the driver control task. It might seem simple, but you can’t control how long your autonomous will last for (and disable the motors and other tasks) if you disable the task controlling those things. If you need to, place your controller in a copy of the competition includes file (prehaps something like “auto_test_VEX_Competition_Includes.h”) inside the “task main()” (main task) as this task should never be disabled.

Oh and… don’t be like my team members and forget to restart the usercontrol task once your finished!

That’s what I mean, here’s what i do for my code to stop exactly what you’re talking about:
if(select==6)//which slide on the display its on.
{
if(nLCDButtons == 2)
{
SensorValue[dgtl1]=0;
SensorValue[dgtl3]=0;
motor[port1]=0;
motor[port2]=0;
motor[port3]=0;
motor[port4]=0;
motor[port5]=0;
motor[port6]=0;
motor[port7]=0;
motor[port8]=0;
motor[port9]=0;
motor[port10]=0;
clearLCDLine(0); // Clear line 1 (0) of the LCD
clearLCDLine(1); // Clear line 2 (1) of the LCD
displayLCDCenteredString(0,“starts in”);
displayLCDCenteredString(1,“3”);
wait1Msec(1000);
clearLCDLine(0); // Clear line 1 (0) of the LCD
clearLCDLine(1); // Clear line 2 (1) of the LCD
displayLCDCenteredString(0,“starts in”);
displayLCDCenteredString(1,“2”);
wait1Msec(1000);
clearLCDLine(0); // Clear line 1 (0) of the LCD
clearLCDLine(1); // Clear line 2 (1) of the LCD
displayLCDCenteredString(0,“starts in”);
displayLCDCenteredString(1,“1”);
wait1Msec(1000);
SensorValue[dgtl1]=0;
SensorValue[dgtl3]=0;
motor[port1]=0;
motor[port2]=0;
motor[port3]=0;
motor[port4]=0;
motor[port5]=0;
motor[port6]=0;
motor[port7]=0;
motor[port8]=0;
motor[port9]=0;
motor[port10]=0;
startTask(autonomous);
clearLCDLine(0); // Clear line 1 (0) of the LCD
clearLCDLine(1); // Clear line 2 (1) of the LCD
displayLCDCenteredString(0,“auton has”);
displayLCDCenteredString(1,“begun”);
wait1Msec(15000);
stopTask(autonomous);
s=0;//don’t mind this its just for stopping separate autonomous tasks with while loops
}

Yeah, something like that (though it paid to be mentioned to the OP). I would clean up and stop then start the userControl task again afterwards instead of being left powerless in the end, or being able to control the robot by accident otherwise. In your case, I would also consider using a for loop for the LCD output (3, 2, 1) and using the provided functions stopAllTasks(); and allMotorsOff(); instead of having to write out every motor name (and potentially running into issues if this ever gets ported to the PIC).

I just threw together something quickly (It probably wont compile or has some awful bug, but it gets the point across):

#define AUTO_TRIGGER Btn8L
#define AUTO_LENGTH_MS 15 * 1000 // RobotC removed the timing defines from comp template.

// Place this inside the task main in the
// Non-diabled, non-autonomous section that
// starts the usercontrol task.
// Returns true if has run auto, false otherwise.
bool autonomousStarter() {
	if( vexRT[AUTO_TRIGGER] ) {
		// This is where we clean up from any tasks
		// that might have been running before auto.
		// The intent here is to simulate a situation
		// like before an actual autonomous!
		allMotorsOff();
		if( bStopTasksBetweenModes ) { // Using the inbuilt variable.
			stopAllTasks(); // Will stop the usercontrol task!
		}
		
		// Start the autonomous period.
		startTask(autonomous);
		
		// Wait the specified time for the autonomous period
		wait1Msec(AUTO_LENGTH_MS);
		
		// Stop the autonomous task
		stopTask(autonomous);
		
		// Cleanup from the automouous
		allMotorsOff();
		if( bStopTasksBetweenModes ) {
			stopAllTasks();
		}
		
		// Start the usercontrol task
		startTask(userControl);
		return true; // Has run the autonomous
	}
	return false; // Has not run the autonomous
}

Yeah i could do all that but fact of the matter is i’m just too lazy.