LCD for multiple autonomous

Yes another rookie issue :confused:

We picked up the VEX LCD so we could choose between autonomous routines, but we cannot figure out how to code for it in RobotC. We have looked at the sample code and tried to copy and paste into a competition template with no luck. The display is correctly connected and gives the default display, and our autonomous modes have been tested in regular program templates.

We are wanting to be able to choose from 3 autonomous modes with the possibility of 5 later. We just dont know what to put where as far as pre-autonomous, etc…

We are using RobotC 3.60

Also do we do multiple cometition templates and choose from them from another program or do all of the autonomous modes get seperated and put into the one template?

Some good references:

https://vexforum.com/t/lcd-module/19335/1
http://robodesigners.blogspot.com/2012/03/selecting-autonomous-with-lcd-robotc.html

I don’t know why but my searches brought up no results (I always look before I ask). But I think I found what I was doing wrong and may have a handle on it now. I will read these if I stumble again.

Thanks!

I thought I had this whooped, we have made some progress with the code but we are getting

“Error:Undefined variable ‘count’. ‘short’ assumed.” on line 163.

We have not copied and pasted the real autonomous out of our other templates yet, we are trying to master the LCD first.

#pragma config(UART_Usage, UART2, uartVEXLCD, baudRate19200, IOPins, None, None)
#pragma config(Sensor, in1,    arm,            sensorPotentiometer)
#pragma config(Sensor, dgtl1,  sonarRight,     sensorSONAR_inch)
#pragma config(Sensor, dgtl5,  encoderRight,   sensorQuadEncoder)
#pragma config(Sensor, dgtl8,  sonarLeft,      sensorSONAR_inch)
#pragma config(Sensor, dgtl10, encoderLeft,    sensorQuadEncoder)
#pragma config(Motor,  port2,           frontRight,    tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port3,           backRight,     tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port4,           liftRight,     tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port5,           intakeRight,   tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port6,           frontLeft,     tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port7,           backLeft,      tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port8,           liftLeft,      tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port9,           awod,          tmotorServoContinuousRotation, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#pragma platform(VEX)

//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)

#include "Vex_Competition_Includes.c"   //Main competition background code...do not modify!
const short leftButton = 1;
const short centerButton = 2;
const short rightButton = 4;

//Wait for Press--------------------------------------------------
void waitForPress()
{
	while(nLCDButtons == 0){}
	wait1Msec(5);
}
//----------------------------------------------------------------

//Wait for Release------------------------------------------------
void waitForRelease()
{
	while(nLCDButtons != 0){}
	wait1Msec(5);
}

//

/////////////////////////////////////////////////////////////////////////////////////////
//
//                          Pre-Autonomous Functions
//
// You may want to perform some actions before the competition starts. Do them in the
// following function.
//
/////////////////////////////////////////////////////////////////////////////////////////

void pre_auton()
{
  	//Declare count variable to keep track of our choice
	int count = 0;

	//------------- Beginning of User Interface Code ---------------
	//Clear LCD
	clearLCDLine(0);
	clearLCDLine(1);
	//Loop while center button is not pressed
	while(nLCDButtons != centerButton)
	{
		//Switch case that allows the user to choose from 4 different options
		switch(count){
		case 0:
			//Display first choice
			displayLCDCenteredString(0, "Autonomous 1");
			displayLCDCenteredString(1, "<		 Enter		>");
			waitForPress();
			//Increment or decrement "count" based on button press
			if(nLCDButtons == leftButton)
			{
				waitForRelease();
				count = 3;
			}
			else if(nLCDButtons == rightButton)
			{
				waitForRelease();
				count++;
			}
			break;
		case 1:
			//Display second choice
			displayLCDCenteredString(0, "Autonomous 2");
			displayLCDCenteredString(1, "<		 Enter		>");
			waitForPress();
			//Increment or decrement "count" based on button press
			if(nLCDButtons == leftButton)
			{
				waitForRelease();
				count--;
			}
			else if(nLCDButtons == rightButton)
			{
				waitForRelease();
				count++;
			}
			break;
		case 2:
			//Display third choice
			displayLCDCenteredString(0, "Autonomous 3");
			displayLCDCenteredString(1, "<		 Enter		>");
			waitForPress();
			//Increment or decrement "count" based on button press
			if(nLCDButtons == leftButton)
			{
				waitForRelease();
				count--;
			}
			else if(nLCDButtons == rightButton)
			{
				waitForRelease();
				count++;
			}
			break;
		case 3:
			//Display fourth choice
			displayLCDCenteredString(0, "Autonomous 4");
			displayLCDCenteredString(1, "<		 Enter		>");
			waitForPress();
			//Increment or decrement "count" based on button press
			if(nLCDButtons == leftButton)
			{
				waitForRelease();
				count--;
			}
			else if(nLCDButtons == rightButton)
			{
				waitForRelease();
				count = 0;
			}
			break;
		default:
		
			count = 0;
			
			break;
			
		}
	}
  
}

/////////////////////////////////////////////////////////////////////////////////////////
//
//                                 Autonomous Task
//
// This task is used to control your robot during the autonomous phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////

task autonomous()
{
 	//Clear LCD
	clearLCDLine(0);
	clearLCDLine(1);
	//Switch Case that actually runs the user choice
	switch(count){
	case 0:
		//If count = 0, run the code correspoinding with choice 1
		displayLCDCenteredString(0, "Autonomous 1");
		displayLCDCenteredString(1, "is running!");
		wait1Msec(2000);						// Robot waits for 2000 milliseconds

		// Move forward at full power for 3 seconds
		motor[frontRight] = 127;			// Motor on port2 is run at full (127) power forward
		motor[frontLeft]	= 127;			// Motor on port3 is run at full (127) power forward
		wait1Msec(300);							// Robot runs previous code for 3000 milliseconds before moving on
		break;
	case 1:
		//If count = 1, run the code correspoinding with choice 2
		displayLCDCenteredString(0, "Autonomous 2");
		displayLCDCenteredString(1, "is running!");
		wait1Msec(2000);						// Robot waits for 2000 milliseconds

		// Move reverse at full power for 3 seconds
		motor[frontRight] = -127;			// Motor on port2 is run at full (-127) power reverse
		motor[frontLeft]	= -127;			// Motor on port3 is run at full (-127) power reverse
		wait1Msec(300);							// Robot runs previous code for 3000 milliseconds before moving on
		break;
	case 2:
		//If count = 2, run the code correspoinding with choice 3
		displayLCDCenteredString(0, "Autonomous 3");
		displayLCDCenteredString(1, "is running!");
		wait1Msec(2000);						// Robot waits for 2000 milliseconds

		//Turn right for 3 seconds
		motor[frontLeft] = -63;			// Motor on port2 is run at half power reverse
		motor[frontRight]	= 63;				// Motor on port3 is run at half power forward
		wait1Msec(300);							// Robot runs previous code for 3000 milliseconds before moving on
		break;
	case 3:
		//If count = 3, run the code correspoinding with choice 4
		displayLCDCenteredString(0, "Autonomous 4");
		displayLCDCenteredString(1, "is running!");
		wait1Msec(2000);						// Robot waits for 2000 milliseconds

		//Turn left for 3 seconds
		motor[frontRight] = 63;				// Motor on port2 is run at half power forward
		motor[frontLeft]	= -63;			// Motor on port3 is run at half power reverse
		wait1Msec(300);							// Robot runs previous code for 3000 milliseconds before moving on
		break;
	default:
		displayLCDCenteredString(0, "No valid choice");
		displayLCDCenteredString(1, "was made!");
		break;
	}}

/////////////////////////////////////////////////////////////////////////////////////////
//
//                                 User Control Task
//
// This task is used to control your robot during the user control phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////

task usercontrol()
{
	// User control code here, inside the loop

	while (true)
	{
	  {
    //Remote Control Commands
    motor[frontRight] = vexRT[Ch2];
    motor[backRight] =  vexRT[Ch2];
    motor[frontLeft] = vexRT[Ch3];
    motor[backLeft] =  vexRT[Ch3];

    //Arm Control
    if(vexRT[Btn5U] == 1)
    {
      motor[liftLeft] = 127;
      motor[liftRight] = 127;
    }
    else if(vexRT[Btn5D] == 1)
    {
      motor[liftLeft] = -63;
      motor[liftRight] = -63;
    }
    else
    {
      motor[liftLeft] = 0;
      motor[liftRight] = 0;
    }

    //Intake Control
    if(vexRT[Btn6U] == 1)
    {
     
      motor[intakeRight] = 127;
    }
    else if(vexRT[Btn6D] == 1)
    {
     
      motor[intakeRight] = -127;
    }
    else
    {
   
      motor[intakeRight] = 0;
    }
  }
}	
}

We’ve used a variation of this code for the last few competitions. It works very well.

To fix your error, cut out the line “int count = 0;” from your pre_auton() function and move it to the top of the program, where you have all the “const short” stuff. You’re getting that error because the autonomous() function doesn’t get access to the count variable.

BINGO! Thank you!!!