We are a second year team and this year with the new game we wanted to add an LCD screen so we could measure are batteries. We copied the sample program for it and changed it just enough so it would work for our bot. The LCD screen works and tells us the battery level for both, but in programming the LCD screen our robot’s user control portion is not responding and we can no longer drive the robot with the regular VEX controller. The LCD screen is still working and to test if it was the problem we commented out all the program for the LCD screen but the user control still wont work. We attached the code.
Batman (2).c (3.05 KB)
I don’t see the
bStopTasksBetweenModes = true;
in the pre_auton, so that might be an issue.
Having an empty autonomous might be confusing your robot too. I would insert
AutonomousCodePlaceholderForTesting();
in the auton task.
Also, I peeked in the competition template, and
//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(1500)
#pragma userControlDuration(10500)
should be
//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)
(I don’t know how much that affects things, but it’s just a thing I noticed.)
If that still does not fix it, open up a new competition template and paste in your code in the corresponding spots. Be careful not to change or delete things that are important.
The pre_auton function must return or autonomous and driver control will never be started.
This code has an infinite loop (the while loop), you need a way to detect competition start or, better still, run this diagnostics code as another task.
void pre_auton()
{
bLCDBacklight = true; // Turn on LCD Backlight
string mainBattery, PEB;
while (true)
{
clearLCDLine(0); // Clear line 1 (0) of the LCD
clearLCDLine(1); // Clear line 2 (1) of the LCD
//Display the Primary Robot battery voltage
displayLCDString(0, 0, "Primary: ");
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, "PEB: ");
sprintf(PEB, "%1.2f%c", sensorAnalog/6.5, 'V'); //Build the value to be displayed
displayNextLCDString(PEB);
//Short delay for the LCD refresh rate
wait1Msec(100);
}
}
Something like this perhaps
task showBattery()
{
bLCDBacklight = true; // Turn on LCD Backlight
string mainBattery, PEB;
while (true)
{
clearLCDLine(0); // Clear line 1 (0) of the LCD
clearLCDLine(1); // Clear line 2 (1) of the LCD
//Display the Primary Robot battery voltage
displayLCDString(0, 0, "Primary: ");
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, "PEB: ");
sprintf(PEB, "%1.2f%c", sensorAnalog/6.5, 'V'); //Build the value to be displayed
displayNextLCDString(PEB);
//Short delay for the LCD refresh rate
wait1Msec(100);
}
}
void pre_auton()
{
// Set bStopTasksBetweenModes to false if you want to keep user created tasks running between
// Autonomous and Tele-Op modes. You will need to manage all user created tasks if set to false.
bStopTasksBetweenModes = true;
startTask( showBattery );
}
task autonomous()
{
// This task may have been stopped so restart it
startTask( showBattery );
}
task usercontrol()
{
// This task may have been stopped so restart it
startTask( showBattery );
while (true)
{
// Driver code here
}
}
We tried these revisions and the robot is driving again but all that displays is the robot name. Here is the code.
Batman LCD.c (2.8 KB)
I think you posted the wrong code, all that’s there is a competition template.
Yes, LCD displays with programs in the pre-autonomous can be very complicated. I would say not to use them unless you are sure they will not fail on you at the last minute. I am hopeful that you won’t get to State and have it not be able to select a program and go to Driver-Control every other match like we experienced.