RobotC Competition Template Question

How can I only run a gyro setup routine only if the robot is disabled or if it is in autonomous mode. The gyro takes about 2 seconds to setup and if I lose connection during tele-op mode, it takes the time to recalibrate.

Here is my code for calibrating the gyro:

//Completely clear out any previous sensor readings by setting the port to "sensorNone"
SensorType[in2] = sensorNone;
//Reconfigure Analog Port 2 as a Gyro sensor and allow time for ROBOTC to calibrate it
SensorType[in2] = sensorGyro;

This is similar to the code the RobotC example had. I am using RobotC 3.04. (I know it isn’t the most recent but we have a competition in 3 days and I didn’t want there to be a problem with the firmware.)

I’m not sure I completely understand your question. Put the gyro init in the pre_auton function and you should be OK. There’s nothing magic about the competition template, it’s really just like any other program, this is how the code starts.

task main()
	// Master CPU will not let competition start until powered on for at least 2-seconds
	displayLCDPos(0, 0);



	while (true)

You can see that the pre_auton function is called in the main task which then enters an infinite loop waiting for the competition control signals. If you wanted you could also init in the autonomous task but that would use up a couple of seconds of the autonomous time. You could also perhaps re-init every 30 seconds or so if that was a concern.

Good move, our teams will stay on 3.04 for the rest of the season unless we install the new motor encoders, I see no benefit to 3.05 at this stage.

What I really don’t want is the gyro setup happening whenever the robot loses connection and then regains.

I did a test for you. I downloaded some code in competition mode that displays useful information on the LCD while it is running, things like enabled/disabled. I ran and connected using WiFI and enabled driver operation using a competition switch. Then I turned off the joystick to simulate a lost connection, the driver code continued to run, when a connection was regained the driver code did not reset but continued to run, in other words the code did not reset and run the pre_auton routine again as far as I could tell.