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;
}
}
}
}