Question about pre_auton

Hi,
I am trying to design a program for my robot where I can use jumpers to tell the robot which autonomous to run. This is simple and I have been doing this for a while. Today I tried to add indicator LED’s to this system to tell me what autonomous I have chosen so I am less likely to make mistakes (jumper not plugged all the way in, jumper not in the right place, etc). I want to have one LED to indicate the color and one LED to indicate the side (skyrise or short post). I have been able to make the LED’s work to show what I have set it to, but it is necessary to plug in the jumpers before I turn on the robot for it to work. I put a piece of code in the pre_auton function that looks like this:

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;





		if(SensorValue[ColorJumper] == 0)
		{
			color = 1;
			SensorValue[redLight] = 1;
		}

		else
		{
			color = 0;
			SensorValue[redLight] = 0;
		}

		if(SensorValue[SideJumper] == 0)
		{
			side = 1;
			SensorValue[yellowLight] = 1;
		}

		else
		{
			side = 0;
			SensorValue[yellowLight] = 0;
		}


	SensorValue[Encoder] = 0;

	// All activities that occur before the competition starts
	// Example: clearing encoders, setting servo positions, ...
}

This piece of code turns on the LED’s when the robot first turns on and sets the side and color of the autonomous. The problem is that this code only updates the LED’s once, and I would like them to update continuously before the match starts. That way I can change the autonomous I want to run after I’ve turned on the robot and have the LED’s show me my choice. My first thought was to just put the set of if statements in an infinite loop, but when I tried this, the robot wouldn’t run “usercontrol.” (the robot wasn’t attached to the competition control so I don’t know what would happen in a real match). Can anyone help me with this?:confused: Sorry if this is a very simple question or if it has already been asked. I didn’t see any other posts about it, though.

Thanks
DCL

The competition template is nothing more than a pre-made “main” task, the flow (simplified) is like this in pseudo code.

task main()
{
    pre_auton();

    while(true )
        {
        while( the robot is disabled )
            wait

        if( driver control period )
            driver_control

        if( autonomous period )
            autonomous
        }
}

There’s a bit more to it but I left that out for simplicity.

Notice how the pre_auton is run before all the tests for driver control and autonomous. Your code in pre_auton should only run if the robot is disabled, once the robot is enabled it should return back to the main task and let the code there do its thing.

your pre_auton would be something like this.

void
pre_auton()
{
     while( the robot is disabled )
        {
        check jumpers and set leds.
        }
}

We use similar code when using the LCD, have a look at example 1 in this thread.

ROBOTC LCD autonomous selection

you can have your current autonomous program displayed on your lcd display also

Could you put the entire chunk of your code inside of a While loop and then have the condition of the while loop be satisfied when a button switch has been pressed? In other words, your code will kick out of its While loop after you have inserted all of your jumpers, verified all your LEDs, and then you press a button to finalize your selection.

This is somewhat how my kids do it with their LCD screen and buttons. EDIT: okay, so I just saw jpearman’s answer. Probably the reason my kids’ code looks like that is because they used jpearman’s LCD code.

Thanks so much for the great ideas.:slight_smile: I will try it out later today. I think I will try to use a button to tell the robot when I have finished choosing the autonomous. That way my new code will run even when I am not connected to competition control?

I would if I had one.:smiley:

It works!:slight_smile: At least when it is not attached to the competition control.

Can you test it by using the virtual competition switch in RobotC?

How does that work? I don’t have a programing hardware kit (http://www.vexrobotics.com/vex/products/accessories/logic/276-2186.html) so I might not be able to use it.

Oh, sorry. I think you need the programming kit to work that without being tethered. :o