Code for Auton Selection

Im trying to do a code where I just select autonomous with 1 button. For example, when 1 press once, the auton is 1, and if I press again it’s 2.

Are you in ROBOTC or easyC? The general principles are the same but it’s a little different how you go about them.

Robot c I know how to make a loop but does not know how to Select it do I put the code during driver control or pre auton

I would put it in driver mode. That way you can change autonomous without the robot waiting on startup. Something like:

  if (Sensorvalue[Button] ==1)

I have something similar for my robot, but I use an LCD to confirm. I did all this because I had issues with teams (including myself) losing sync and hanging in the middle of a match because autonomous wanted to select.

A single button for auton gets you two choices on or off. The joystick is not allowed for auton for competitions as you can’t use them in auton mode.

I have seen the following for autonomous selectors:

  • Potentiometer dial across a bunch of settings. Use with a rubber link and tank sprocket to hold it in place.
  • Multiple Limit switches with rubber bands. each switch corresponds to a setting (red/blue, starting tile, then a optional program per each)
  • use jumpers - not a single button - much like the limit switches with rubber bands. Series of binary settings
  • LCD screen selector

Run these in pre auton routine to set the right values up front. You can call again from the start of auton mode too so it sets the right modes there if you change things after you turn the robot on.

Potentiometer example:

81J auton selector and wire curling

Most of my teams use the LCD to select their autonomous routine. It is easy for them to cycle through the options and select the one they want. It defaults to no autonomous if they don’t make a selection within 1 minute so they don’t get stuck with it waiting for a selection.

I’d be happy to post the code if anyone is interested.

We built this simple mechanism and just used some “if statements”, it can’t be unselected so there’s no problem with that.

Worlds most boring video. But it shows what it does anyway.

I would be quite interested in seeing this.

Thanks. This is only 2 autons though. We have a ridiculous amount of autons right now depends on strategy. For example, one of the autons picks up 2 orange balls and shoots them. Some of them are just pure defense depend on the other bot.

How do you use the jumper on the cortex? I can only find instructions for use on the PIC.

You plug it into a digital port, and it acts just like a limit or bumper switch.

So, would you program the code for Auton selector like this?

if (dgtl[port1] == 1) Auton1()
else if (dgtl[port2] == 1) Auton2()

Yes, that is correct.

Click on my signature and you can check out some of the LCD auton selection tutorials I did. Hope you find it somewhat helpful!

Edit: Look into the LCD playlist

Here is the LCD menu code I mentioned a couple weeks ago. I grabbed this from one of my teams and most of the others use something very similar. I found the basics of what is in AutoSelectLCD.c here on the forums several years ago and would love to give credit to whoever originally posted it, but can’t find any indication of where I found it. I don’t think my teams have changed the core code significantly.

My teams break up their code into multiple files, so below are excerpts from the files relevant to the LCD menu. I have removed code from some of the functions that did not relate to the LCD menu. Also note that if nothing is selected from the LCD within 1 minute then the NONE autonomous mode is selected by default.

Nothing But Net Main.c
Files to include:

//Include files
#include "Vex_Competition_Includes2.c"  //Main competition background not modify!
#include "AutonomousRuns.c"             //Autonomous runs code.
#include "AutoSelectLCD.c"              //LCD menu code

pre_auton: Run the code to display the menu on the LCD

void pre_auton()
	//During testing, comment out the SelectAutonomous(); call and uncomment the line
	//for the routine you want to test to bypass having to select from the LCD menu.

	//autoMode = AutoMode_CloseShoot;
	//autoMode = AutoMode_MidShoot;
	//autoMode = AutoMode_CloseNoShoot;
	//autoMode = AutoMode_LongShoot;
	//autoMode = AutoMode_ProgrammingSkills;

autonomous task: Determine which autonomous mode was selected and call the appropriate function

task autonomous()
	switch (autoMode)
	case AutoMode_None:

	case AutoMode_CloseShoot:

	case AutoMode_MidShoot:

	case AutoMode_CloseNoShoot:

	case AutoMode_LongShoot:

	case AutoMode_ProgrammingSkills:


// Autonomous Routines
void Auto_CloseShoot();
void Auto_MidShoot();
void Auto_CloseNoShoot();
void Auto_LongShoot();

// Programming Skills Functions
void Auto_ProgrammingSkills();

//========================== Auto_CloseShoot ==========================
void Auto_CloseShoot()

//========================== Auto_MidShoot ==========================
void Auto_MidShoot()

//========================== Auto_CloseNoShoot==========================
void Auto_CloseNoShoot()

//========================== Auto_LongShoot==========================
void Auto_LongShoot()

//========================== AutoMode_ProgrammingSkills ==========================
void Auto_ProgrammingSkills()


const short leftButton = 1;
const short centerButton = 2;
const short rightButton = 4;
// Add an entry in the AutoModes enum and a corresponding entry in autoNames to add an item to the menu.
// Add code in the autonomous task to handle what should happen when the new item is selected.
// AutoMode_Count should always be the last item int the enum and autoNames should NOT include an item
// that corresponds to AutoMode_Count.
typedef enum
  AutoMode_None = 0,
  AutoMode_CloseShoot = 1,
  AutoMode_MidShoot = 2,
  AutoMode_CloseNoShoot = 3,
  AutoMode_LongShoot = 4,
  AutoMode_ProgrammingSkills = 5,
} AutoModes;
const int autoSelectTimeout = 60000;
string autoNames[AutoMode_Count] = {"NONE", "Close Shoot", "Mid Shoot", "Close No Shoot", "Long Shoot", "PROG. SKILLS"};
int autoMode = 0;

void SelectAutonomous()
	SelectingAutonomous = true;
	time1[T3]= 0;
	autoMode = 0;

	bLCDBacklight = true;
	// Display first entry by default
	displayLCDCenteredString(0, autoNames[0]);
	displayLCDCenteredString(1, "<     Enter    >");

	// Loop until the center button is pushed
	while ((nLCDButtons != centerButton) && (time1[T3] < autoSelectTimeout) && bIfiRobotDisabled)
	  // If no buttons pushed keep waiting
	  if (nLCDButtons == 0)
	    // If left button pushed
	    if (nLCDButtons == leftButton)
	      // Show the previous autoMode, with wrap
	      if (autoMode > 0)
	        autoMode = AutoMode_Count - 1;
	    // If right button pushed
	    else if(nLCDButtons == rightButton)
	      // Show the next autoMode, with wrap
	      if (autoMode < (int)(AutoMode_Count - 1))
	        autoMode = 0;

	    //Update display
	    displayLCDCenteredString(0, autoNames[autoMode]);

	    // Wait until the button is released before continuing
	    while ((nLCDButtons != 0) && (time1[T3] < autoSelectTimeout))

	// If timed out, then select no autonomous
	if (time1[T3] >= autoSelectTimeout)
	  autoMode = 0;

 	//Clear LCD
	displayLCDCenteredString(0, autoNames[autoMode]);
	displayLCDCenteredString(1, "Selected!");
	//bLCDBacklight = false;
	SelectingAutonomous = false;