Autonomous LCD Selector Issue

Hi everyone,
I have programmed an LCD autonomous chooser for our robot and it is working quite well, but there is one small issue. When we are plugged into the competition switch, the LCD only activates once autonomous is activated. It doesn’t work when the robot is disabled. We obviously cannot touch the robot during autonomous, so how can this be fixed?


int autonomousMode = 4;

void autonomousSelection() {
	bLCDBacklight = 1;
	while(nLCDButtons  != 2 && vexRT[Btn7R] != 1)
	{
		displayLCDCenteredString(0,"Autonomous: ");
		displayLCDNumber(0,14,autonomousMode,2);

		wait1Msec(10);
		if(nLCDButtons == 1) {
			autonomousMode--;
			while(nLCDButtons == 1) {
				wait1Msec(10);
			}
		}
		if(nLCDButtons == 4) {
			autonomousMode++;
			while(nLCDButtons == 4) {
				wait1Msec(10);
			}
		}
		if(autonomousMode < 1) {
			autonomousMode = 12;
		}
		else if(autonomousMode > 12) {
			autonomousMode = 1;
		}

		if(autonomousMode == 1) {
			displayLCDCenteredString(1,"Simple Backwards");
		}
		else if(autonomousMode == 2) {
			displayLCDCenteredString(1,"Star Knocker");
		}
		else if(autonomousMode == 3) {
			displayLCDCenteredString(1,"Red Left Corner");
		}
		else if(autonomousMode == 4) {
			displayLCDCenteredString(1,"Cube + Stars");
		}
		else if(autonomousMode == 5) {
			displayLCDCenteredString(1,"Red Left Center");
		}
		else if(autonomousMode == 6) {
			displayLCDCenteredString(1,"Red Right Center");
		}
		else if(autonomousMode == 7) {
			displayLCDCenteredString(1,"Blue Left Center");
		}
		else if(autonomousMode == 8) {
			displayLCDCenteredString(1,"Blue Right Center");
		}
		else if(autonomousMode == 9) {
			displayLCDCenteredString(1,"Red Left Cube");
		}
		else if(autonomousMode == 10) {
			displayLCDCenteredString(1,"Red Right Cube");
		}
		else if(autonomousMode == 11) {
			displayLCDCenteredString(1,"Blue Left Cube");
		}
		else if(autonomousMode == 12) {
			displayLCDCenteredString(1,"Blue Left Cube");
		}
		wait1Msec(10);
	}
	clearLCDScreen();
	bLCDBacklight = 0;
}


Also, ignore the several selections that are the same, those still need to be worked on since we don’t actually have the many different autonomous programs.
Here is the pre-auton section:


void pre_auton()
{
	if(bIfiRobotDisabled == true) {
		autonomousSelection();
		SensorType[gyroscope] = sensorNone;
		wait1Msec(500);
		SensorType[gyroscope] = sensorGyro;
		wait1Msec(2000);
	}

	
}

I’m going to preface this by saying that I code in PROS, not RobotC. However, this should be the same. Anyone who knows better should correct me.

You need to put your autonomous selection program in init.c, or the RobotC equivalent. Specifically, in PROS it goes in


void initialize(){ }

WHat does the init.c do? I don’t know the equivalent, but I may be able to figure it out if I know what it does.

It is where you initiate all of your encoders and the likes… It runs code before your robot starts into autonomous, so when it is turning on. If you put this code in there, you will be able to select autonomous when competitive control is disabled. So you’ll have to plug in a competitive switch and go to the “autonomous” and “disable” settings.

Yes, then pre_auton is the robotC equivalent of that. It is already in that but the LCD only says disabled with some sort of timer when it is disabled and set to autonomous from the competition control.

If you’re going to just use it for auton selection then you could make it so that it comes on during driver control to switch auton modes and then in the autonomous task you can have a bunch of if statements that say if auton mode = 1 then run this, if auton mode = 2 then run this, etc. By making different voids in your program. That way you can choose the auton mode before plugging in to the competition control.

I’m not sure what’s wrong with your code though. If i understand it right then it sounds like it’s doing the opposite of what you tell it to do. (It’s ok. We’ve all been there; when our robot decides that it hates us. :P).

This could be a legit way of doing this, but I want to solve this problem and get it to work in pre_auton anyway if I can, just to learn. However, thank you very much for the idea.

Make sure you plug into competition control before turning on the robot. If you don’t, then the LCD code will be bypassed, pre_auton is not run again after you plug into the field, only when the robot is first powered.

Uuuhhhh… We don’t do that… :confused:
We turn it all on and let it connect before plugging into the competition control and our lcd code works fine… we never use our backup battery either… Our robot’s messed up. :stuck_out_tongue:

Edit: i just realized why you said that :stuck_out_tongue:
I need to go to bed…

The problem I see is that if() statement in pre_auton() should be a while() loop. You would want to move your gyro stuff to before the while loop to prevent a 2.5 second delay once they enable you. Then do like @jpearman said and make sure you are plugged into a competition switch and disabled and it should work as expected.

EDIT: I see now you use the while loop in the function and check for those buttons. I would do like I mentioned, but eliminate that while loop inside of the function and let the pre_auton() while loop keep running that function. That’s how we do it, instead of having an exit button.

I see what you are saying, but the point of having the exit button on the controller is that if the robot disconnects in a match, we want to be able to exit the LCD display by pressing the button.

If you use the while loop like I described, as long as the robot isn’t disabled, it will bypass your LCD selector code if you suffer a disconnect.


int autonomousMode = 4;

void pre_auton()
{
	SensorType[gyroscope] = sensorNone;
	wait1Msec(500);
	SensorType[gyroscope] = sensorGyro;
	wait1Msec(2000);
	// keep running the autonomous function while we are disabled
	bLCDBacklight = 1;
	while(bIfiRobotDisabled == true) {
		autonomousSelection();
	}
	clearLCDScreen();
	bLCDBacklight = 0;
}

and

void autonomousSelection() {
	displayLCDCenteredString(0,"Autonomous: ");
	displayLCDNumber(0,14,autonomousMode,2);

	if(nLCDButtons == 1) {
		autonomousMode--;
		while(nLCDButtons == 1) {
			wait1Msec(10);
		}
	}
	else if(nLCDButtons == 4) {
		autonomousMode++;
		while(nLCDButtons == 4) {
			wait1Msec(10);
		}
	}

	if(autonomousMode < 1) {
		autonomousMode = 12;
	}
	else if(autonomousMode > 12) {
		autonomousMode = 1;
	}

	if(autonomousMode == 1) {
		displayLCDCenteredString(1,"Simple Backwards");
	}
	else if(autonomousMode == 2) {
		displayLCDCenteredString(1,"Star Knocker");
	}
	else if(autonomousMode == 3) {
		displayLCDCenteredString(1,"Red Left Corner");
	}
	else if(autonomousMode == 4) {
		displayLCDCenteredString(1,"Cube + Stars");
	}
	else if(autonomousMode == 5) {
		displayLCDCenteredString(1,"Red Left Center");
	}
	else if(autonomousMode == 6) {
		displayLCDCenteredString(1,"Red Right Center");
	}
	else if(autonomousMode == 7) {
		displayLCDCenteredString(1,"Blue Left Center");
	}
	else if(autonomousMode == 8) {
		displayLCDCenteredString(1,"Blue Right Center");
	}
	else if(autonomousMode == 9) {
		displayLCDCenteredString(1,"Red Left Cube");
	}
	else if(autonomousMode == 10) {
		displayLCDCenteredString(1,"Red Right Cube");
	}
	else if(autonomousMode == 11) {
		displayLCDCenteredString(1,"Blue Left Cube");
	}
	else if(autonomousMode == 12) {
		displayLCDCenteredString(1,"Blue Left Cube");
	}
}

I cleaned some stuff up, but tried not to make too many changes. And you might still need the autonomousSelection() function above the pre_auton() one, I don’t remember if RobotC complains about that or not at compile time. You might get some flicker on the LCD lines because you will be constantly updating the text strings instead of only on button presses.