LCD Screen Autonomous Code Programming


#1

Hey guys. My team and I just finished our first competition and we had many things to change. One of the relevations that we had was trying to use an LCD screen to our advantage so we could run multiple autonomous codes, so I was wondering if anyone could help me out in the programming aspect of it.


#2

v5 or v4 and what are you using to program it with.


#3

I am using v4 motors and using RobotC.


#4

Hi avl,
Our team utilizes a switch statement to choose between different autonomouses. We use the right and left buttons to select an autonomous and the center button to select. Is this what you are looking for?


#5

Kind of. One of the other teams at our school recommended the idea to us. They had said based on the circumstances of where you started your match on the field and the contrast between the other team and us you could change which autonomous you wanted through the LCD screen.


#6

search the forum, there are literally dozens of threads showing how to do this. Here is one, not the most simple, there are many others.
https://vexforum.com/t/robotc-lcd-autonomous-selection/24818/1


#7

Our girls used the one from Renegade Robotics.

It works well and they have adapted it for use in the actual code so they have pages of information - battery voltages, encoder positions, etc so there is feedback when driving and such.


#8

Thanks so much guys!


#9

Update: Our autonomous code selector works wonderfully.


#10

Good to hear!

As I mentioned, our girls adapted this to create a driver control screen that shows many items like encoder positions, ultrasonic sensor readings, battery voltage. One of the screens shows the encoder position on one line and the second has a conversion from encoder pulses to inches, with a button to reset the measurement. This allows them to reset the measurement, drive a distance in driver control, then take the actual measurement and place it in their autonomous code so programming is quicker.

Its a separate task that runs during driver. If I can find a copy, I’ll attach it. It could come in handy.


#11

Here is the driver menu the girls used. This is the first year we really got serious about programming and doing software better. As it stands now, our driver control uses the multitasking features of the cortex and it has lent itself to a much cleaner, easier to understand code. This is a separate task that runs the screen when the robot is in driver control to show multiple pieces of info the girls can use to make things quicker.

// start drivermenu example

task driverscreen()//  display items on the screen to allow for diagnosis
{
	// Leave this value alone; counting starts at 1
	int driverScreenMin = 1;

	//  IMPORTANT!!!
	// Total # menu items ***** Note Adjust this to match your number of screens!!!
	int driverScreenMax = 6;

	// Counter for what to display on the screen
	int driverScreen = 1;

	//Turns on the Backlight
	bLCDBacklight = true;

	// Leave these values alone
	// In RobotC:
	// when the left button is pressed, nLCDButtons = 1
	// when middle button is pressed, nLCDButtons = 2
	// when right button is pressed, nLCDButtons = 4
	const short leftButton = 1;
	const short centerButton = 2;
	const short rightButton = 4;

	string mainBattery, expBattery, lencdist, fusonic, rusonic, lusonic;


	// This section checks whether left & right buttons are
	// pressed, and either increments or decrements the
	// lcdScreen counter; if the counter is at the max or min
	// it will loop around to the other end
	while(1==1)
	{
		// left button
		if (nLCDButtons == leftButton) {
			if (driverScreenMin == driverScreen) {
				driverScreen = driverScreenMax;
				wait1Msec(250);
			}
			else {
				driverScreen= driverScreen-1;
				wait1Msec(250);
			}
		}

		// right button
		if (nLCDButtons == rightButton) {
			if (driverScreenMax == driverScreen) {
				driverScreen = driverScreenMin;
				wait1Msec(250);
			}
			else {
				driverScreen=driverScreen+1;
				wait1Msec(250);
			}
		}

		//------------------------------------------------------------
		if (driverScreen == 1) {
			clearLCDLine(0);
			clearLCDLine(1);
			displayLCDString (0, 0, "LEnc: ");
			displayNextLCDNumber(SensorValue(encoderL));
			displayLCDString (1, 0, "REnc: ");
			displayNextLCDNumber(SensorValue(encoderR));
		}
		//------------------------------------------------------------
		else if (driverScreen == 2 ) {
			clearLCDLine(0);
			clearLCDLine(1);

			//Display the Primary Robot battery voltage
			displayLCDString(0, 0, "MBat: ");
			sprintf(mainBattery, "%1.2f%c", nImmediateBatteryLevel/1000.0,'V'); //Build the value to be displayed
			displayNextLCDString(mainBattery);

			//Display the Backup battery voltage
			displayLCDString(1, 0, "EBat: ");
			sprintf(expBattery, "%1.2f%c", SensorValue(expBatt)/280.0, 'V');	//Build the value to be displayed
			displayNextLCDString(expBattery);

			//Short delay for the LCD refresh rate
			wait1Msec(100);
		}
		//------------------------------------------------------------
		else if (driverScreen == 3) {
			clearLCDLine(0);
			clearLCDLine(1);
			displayLCDString (0, 0, "LEnc: ");
			displayNextLCDNumber(SensorValue(encoderL));
			displayLCDString (1, 0, "Dist: ");
			sprintf(lencdist, "%3.2f", SensorValue(encoderL)*cir/360);
			displayNextLCDString(lencdist);

			if (nLCDButtons == centerButton) {
				SensorValue(encoderL) = 0;
				SensorValue(encoderR) = 0;
			}
			//------------------------------------------------------------
			else if (driverScreen == 4) {
				clearLCDLine(0);
				clearLCDLine(1);
				displayLCDCenteredString (0, "Front Ultrasonic");
				sprintf(fusonic, "3.2f", SensorValue(front));
				displayLCDCenteredString (1, fusonic);
			}
			//------------------------------------------------------------
			else if (driverScreen == 5) {
				clearLCDLine(0);
				clearLCDLine(1);
				displayLCDCenteredString (0, "Left Ultrasonic");
				sprintf(lusonic, "3.2f", SensorValue(left));
				displayLCDCenteredString (1, lusonic);
			}

			//------------------------------------------------------------
			else if (driverScreen == 6) {
				clearLCDLine(0);
				clearLCDLine(1);
				displayLCDCenteredString (0, "Right Ultrasonic");
				sprintf(rusonic, "3.2f", SensorValue(right));
				displayLCDCenteredString (1, rusonic);
			}



		}

		//------------------------------------------------------------

	}// end while loop for screen

} // end driver screen
// end driver menu example

Cortex LCD Autonomous selection