We have recently obtained a LCD display and were wondering how to use the LCD display to select various autonomous programs. We were unsure of how to load multiple programs onto the cortex. Do we need to use sensors, or is there a way to directly load more than one autonomous at a time? We are using easy C and it would be very nice if we could get some help. Thanks!
You do not need to load multiple programs onto the Cortex. The way that we have done what you have described is to have a menu setup on the LCD screen so that we can select which autonomous we would like the robot to run. Once we have selected it, a single variable will be set to a number based on which autonomous was selected. Then, we would have a bunch of if/else if statements in autonomous, to check what value the variable is set to, and then know which autonomous program to run.
Hopefully that helps.
~Jordan
I actually made a tutorial for this a while back. It uses a Potentiometer.
Hope it helps!
if you have some spare bumper/limit switches you could write a program that sets an int value to 1, then run a while loop
pseudo
if-digital1 == 1
{
int autonomous1 = 1
}
while(autonomous 1 == 1)
{
run autonomous code
}
you could do this as many times as you want (providing you have the bumper/limit sensors)
hope this helps
There are many posts on this subject a quick search pulled up the reference to the thread DPbaily mentions here.
It talks about implementation in robotC but the process is the same with easy C the implementation is different.
https://vexforum.com/t/potentiometer-autonomous-selector/20351/1&highlight=autonomous
If done right you can use the potentiometer to select the autonomous in your autonomous section of code you can also put a little section of code in your main routine to read the potentiometer and display the autonomous routine that will be selected when autonomous is entered. so you can dail the potentiometer to the appropriate setting for the autonomous you plan to run next while your robot is in manual control and then it will react to that setting when switched to autonomous.
A field control simulator is very useful for this part of your development.
[http://www.vexrobotics.com/276-2335.html
you could also build one, there are threads on how to do that as well. I found a thread describing how others have made competition switch simulators and was able to build one fairly easily, but I already had a crimper which can cost about as much as the simulator from Vex so it might not be cost effective to build your own unless you have the parts / tools on hand already.
Cheers Kb](http://www.vexrobotics.com/276-2335.html)
I realized I forgot to post the link to my video haha.
Here it is:
http://www.youtube.com/watch?v=4izLPYvJ1-0
I’m not sure about EasyC, but here is a snippet of my code for RobotC. Maybe you can translate it?
int count = 0;
int maxCount = 4;
bool picked = false;
while(!picked) {
displayLCDCenteredString(1,"< Enter >");
if(nLCDButtons == 1) {
waitForRelease();
count --;
if(count < 0) {
count = maxCount;
}
}
if(nLCDButtons == 4) {
waitForRelease();
count ++;
if(count > maxCount) {
count = 0;
}
}
if(nLCDButtons == 2) {
waitForRelease();
picked = true;
autonomousNumber = count;
}
switch(count) {
case 0: {
displayLCDCenteredString(0,"Autonomous 0");
break;
}
case 1: {
displayLCDCenteredString(0,"Autonomous 1");
break;
}
case 2: {
displayLCDCenteredString(0,"Autonomous 2");
break;
}
case 3: {
displayLCDCenteredString(0,"Autonomous 3");
break;
}
case 4: {
displayLCDCenteredString(0,"Programming");
break;
}
}
}
After the variable “picked” is set to true, then just depending on the value of “count”, run a certain autonomous program.
This code is a simple (as in there isn’t many “fancy” features") LCD selector program, with a timeout feature. It’s easyC, btw. The way the logic works is that you run a while() loop until a button has been pressed. Once the button has pressed, you can break the while() loop. The program also has a timeout function, which means that if you don’t press the button for a certain amount of time (10 seconds, in this example), you can default to a choice. If you don’t feel comfortable programming the timeout function, you can get rid of the StartTimer(), GetTimer(), and the if(timer >= 1000) loop.
int exit = 1;
unsigned char left_button;
unsigned char middle_button;
unsigned char right_button; // Do NOT place infinite loops inside of your Initialize Function. // If your Initialize Function never terminates, your program // will never progress to Autonomous and Operator Control. // See Help for more information about this function. InitLCD ( 1 ) ;
SetLCDLight ( 1 , 1 ) ;
SetLCDText ( 1 , 1 , "Maybe Some Text?" ) ;
SetLCDText ( 1 , 2 , "Second Line, too" ) ;
Wait ( 1000 ) ;
SetLCDText ( 1 , 1 , "Choices?" ) ;
SetLCDText ( 1 , 2 , "A B C" ) ;
StartLCDButtonsWatcher ( 1 ) ; // Tells LCD to start updating LCD buttons
StartTimer ( 1 ) ; // We'll use this for a timeout feature
while ( exit != -1 ) {
GetLCDButtonsWatcher ( 1 , &left_button , &middle_button , &right_button ) ; // Assigns 0 or 1 to the variables
if ( left_button == 1 ) { // left button has been pressed (note that this might be 0 instead of 1, I haven't used LCD buttons on easyC in a while)
SetLCDText ( 1 , 1 , "You've Selected" ) ;
SetLCDText ( 1 , 2 , " A " ) ;
choice = 1 ;
exit = -1 ; // while loop is now false, and will exit
break;
}
if ( middle_button == 1 ) {
SetLCDText ( 1 , 1 , "You've Selected" ) ;
SetLCDText ( 1 , 2 , " B " ) ;
choice = 2 ;
exit = -1 ; // while loop is now false, and will exit
break;
}
if ( right_button == 1 ) {
SetLCDText ( 1 , 1 , "You've Selected" ) ;
SetLCDText ( 1 , 2 , " C " ) ;
choice = 3 ;
exit = -1 ;// while loop is now false, and will exit
break;
}
timer = GetTimer ( 1 ) ;
if ( timer >= 10000 ) // If the timer has passed 1 sec (the selection has timed out)
{
SetLCDText ( 1 , 1 , "No button" ) ;
SetLCDText ( 1 , 2 , "pressed." ) ;
Wait ( 1000 ) ;
SetLCDText ( 1 , 1 , "Defaulting." ) ;
SetLCDText ( 1 , 2 , "" ) ;
choice = 0 ;
exit = -1 ;
break;
}
}
StopLCDButtonsWatcher ( 1 ) ;
}
I haven’t been able to test this, but you can customize the GetLCDButtonsWatcher() to be just left and right, etc. (it is logical left to right, so 1 to 3, respectively). Let me know if you have any questions.
Our club has not really done the LCD screens but relied on the various potentiometer switchers or jumpers. But it’s intriguing.
In robot C, do you put this in the pre-auton section of the code or the autonomous?
If in pre-auton and you got switched into autonomous prior to your LCD selection, do you typically set a default? Or is it still looping around in pre-auton?
If in autonomous section, how much time does hitting the buttons typically take away? With such a short auton this game that could be a factor to not finish what you want to do but on the flip side, you could also react to what the other robot does better.
I would start a task to handle the LCD in the pre-auton code.
pre-auton must not block or the autonomous task will not start.
Too long, make the selection before you enter autonomous.
If you want a full blown menu system I posted a pretty comprehensive example here, It was written back in August so may need fixes for the latest version of ROBOTC.
The way we do it it to use the while (! IsEnabled) statement in the initialise function. So if the robot is disabled then run the loop. BUT IF YOU DO NOT DO IT RIGHT YOUR ROBOT WILL NEVER GET TO THE OPERATOR CONTROL LOOP!!!
Here is some code to get the idea across,
while (! IsEnabled) {
if (button_1 == 1){
autonomous = 1;
break;
}
else if (button_2 == 1){
autonomous = 2;
break;
}
}
If you put a loop in the while loop it to must have the “! IsEnabled” condition on it too.
Make sure you test the code with a competition switch.
I learned this trick from the code 1103 posted.
Make it so that you have a variable unsigned char named something like program number.
if LCD-Button1 == on
{
Programnumber = 1;
}
if LCD-Button2 == on
{
Programnumber = 2;
}
if Programnumber == 1
{
Whatever you want your 1st program to do
}
if Programnumber == 2
{
Whatever you want your 2nd program to do
}