What did we do wrong?

Hello,
This weekend we went to a competition and ran into a probelm that we couldn’t get resolved and it cost us abunch of autonomous points.
Our code is below and it runs perfectly every time from the robotc debugger where you can toggle either ‘autonomous’ or ‘user control’, however it refused to run #1 or #2 from the arena. #3 would run though.
Any advise anyone could offer would be a big help.

Thanks!
Mike

// Include smart motor library
#include "SmartMotorLib.c"

// This code is for the VEX cortex platform
#pragma platform(VEX2)

// Select Download method as "competition"
#pragma competitionControl(Competition)

//Main competition background code...do not modify!
#include "Vex_Competition_Includes.c"


void pre_auton()
{
	// Set bStopTasksBetweenModes to false if you want to keep user created tasks
	// running between Autonomous and Driver controlled modes. You will need to
	// manage all user created tasks if set to false.
	bStopTasksBetweenModes = false;
	SmartMotorsInit();																						// Initialize the Smart Motor Library
	SmartMotorCurrentMonitorEnable();															// Limit current based on default motor current threshold
	SmartMotorRun();																							// Run smart motors
	SmartMotorsAddPowerExtender( port2, port9);										//Enable use of a power expander
	startTask( pidLiftController );
	startTask( pidArmController );
}

task autonomous()
{
		// ..........................................................................
		// Insert user code here.
		// ..........................................................................

		// Remove this function call once you have "real" code.
		//AutonomousCodePlaceholderForTesting();

		pidLiftRequestedValue = SensorValue lift_pot_1 ];
		pidArmRequestedValue = SensorValue arm_pot ];
/*********/
		if (SensorValue(select_pot) <= 500)
		{
			autonomousSelect = 1;
		}
		if (SensorValue(select_pot) >= 500 && SensorValue(select_pot) <= 1750)
		{
			autonomousSelect = 2;
		}
		if (SensorValue(select_pot) >= 1750)
		{
			autonomousSelect = 3;
		}
		
		switch( autonomousSelect )
		{
			/**************************************This code works for 20pt MG score***********************************/
		case 1:  //select pot all the way left
			clearTimer(T1);
			while (SensorValue[mobile_goal_lower_limit]==0&& time1(T1)<3500) // lower mobile goal
			{
				SetMotor(MG_Lift, -120);
			}
			SetMotor(MG_Lift, 0);
			pidArmRequestedValue = 1950;
			clearTimer(T1);
			while(SensorValue(arm_pot)<2050 && time1(T1)<1850)
			{																										// run this 'if' loop repeatedly and tell the lift to stop once it's inside the acceptable range.
				if (SensorValue(arm_pot)>2500 && SensorValue(arm_pot)<2400)
					//pidArmRequestedValue = SensorValue(arm_pot);
				wait1Msec(25);
			}
			SetMotor(Left_Drive, 90, true);
			SetMotor(Right_Drive, 90, true);
			wait1Msec(2750);
			SetMotor(Left_Drive, 0, true);
			SetMotor(Right_Drive, 0, true);
			wait1Msec(1);
			SetMotor(MG_Lift, 95, true);
			wait1Msec(2000);
			SetMotor(MG_Lift, 0, true);
			//mqotor(MG_Lift)= 0;
			clawMove(300, 90); //clawMove(int time, int power)						//open the claw
			wait1Msec(200);
			SetMotor(Left_Drive, -90, true);																		//back out with MG
			SetMotor(Right_Drive,-90, true);
			wait1Msec(2000);
			SetMotor(Left_Drive, -90, true);																		//Turn left
			SetMotor(Right_Drive, 90, true);
			wait1Msec(1500);
			SetMotor(Left_Drive, -90, true);																		//back straight
			SetMotor(Right_Drive, -90, true);
			wait1Msec(850);
			SetMotor(Left_Drive, -90, true);																		//turn left
			SetMotor(Right_Drive, 90, true);
			wait1Msec(1900);
			SetMotor(Left_Drive, 90, true);																			//forward straight
			SetMotor(Right_Drive, 90, true);
			wait1Msec(1600);
			SetMotor(Left_Drive, 90, true);																			//turn right
			SetMotor(Right_Drive, -90, true);
			wait1Msec(850);
			SetMotor(Left_Drive, 90, true);																			//forward straight
			SetMotor(Right_Drive, 90, true);
			wait1Msec(1100);
			SetMotor(Left_Drive, -90, true);																		//backward straight
			SetMotor(Right_Drive, -90, true);
			wait1Msec(1000);
			SetMotor(Left_Drive, 0, true);
			SetMotor(Right_Drive,0, true);
			break;

		case 2: 	//select pot in the center
			/********************************This code works for 10pt MG score**************************************/
			clearTimer(T1);
			while (SensorValue[mobile_goal_lower_limit]==0&& time1(T1)<3500) // lower mobile goal
			{
				SetMotor(MG_Lift, -120);
			}
			SetMotor(MG_Lift, 0);
			pidArmRequestedValue = 1950;
			clearTimer(T1);
			while(SensorValue(arm_pot)<2050 && time1(T1)<1850)
			{																										// run this 'if' loop repeatedly and tell the lift to stop once it's inside the acceptable range.
				if (SensorValue(arm_pot)>2500 && SensorValue(arm_pot)<2400)
					//pidArmRequestedValue = SensorValue(arm_pot);
				wait1Msec(25);
			}
			SetMotor(Left_Drive, 90, true);					//Drive to the MG
			SetMotor(Right_Drive, 90, true);					//Drive to the MG
			wait1Msec(3000);
			SetMotor(Left_Drive, 0, true);
			SetMotor(Right_Drive, 0, true);
			wait1Msec(1);
			SetMotor(MG_Lift, 95, true);
			wait1Msec(2000);
			SetMotor(MG_Lift, 0, true);
			wait1Msec(100);
			clawMove(300, 90); //clawMove(int time, int power)						//open the claw
			wait1Msec(200);
			SetMotor(Left_Drive, -90, true);
			SetMotor(Right_Drive, -90, true);
			wait1Msec(2000);
			SetMotor(Left_Drive, -90, true);
			SetMotor(Right_Drive, 90, true);
			wait1Msec(2000);
			SetMotor(Left_Drive, -90, true);
			SetMotor(Left_Drive, -90, true);
			wait1Msec(750);
			SetMotor(Left_Drive, -90, true);
			SetMotor(Right_Drive, 90, true);
			wait1Msec(1500);
			SetMotor(Left_Drive, 90, true);
			SetMotor(Right_Drive, 90, true);
			wait1Msec(1200);
			SetMotor(Left_Drive, 90, true);
			SetMotor(Right_Drive, -90, true);
			wait1Msec(1000);
			SetMotor(Left_Drive, 90, true);
			SetMotor(Right_Drive, 90, true);
			wait1Msec(1200);
			SetMotor(Left_Drive, -90, true);
			SetMotor(Right_Drive, -90, true);
			wait1Msec(1000);
			SetMotor(Left_Drive, 0, true);
			SetMotor(Right_Drive, 0, true);
			break;

		case 3: //select pot all the way right
			/***************************************code for the stationary goal****************************************/
			pidArmRequestedValue = 2800;
			clearTimer(T1);
			while(SensorValue(arm_pot)<2900 && time1(T1)<1500)
			{																										// run this 'if' loop repeatedly and tell the lift to stop once it's inside the acceptable range.
				if (SensorValue(arm_pot)>2900 && SensorValue(arm_pot)<2700)
					wait1Msec(25);
			}
			pidLiftRequestedValue = 2200;
			while(SensorValue(lift_pot_1) > 2300 || SensorValue(lift_pot_1) < 2100)
			{
				wait1Msec(25);
			}
			SetMotor(Left_Drive, 90);
			SetMotor(Right_Drive, 90);
			wait1Msec(900);
			SetMotor(Left_Drive, 0);
			SetMotor(Right_Drive, 0);
			clawMove(300, 90); //clawMove(int time, int power)						//open the claw
			wait1Msec(500);
			clawMove(300, -90);
			wait1Msec(500);
			SetMotor(Left_Drive, -90);
			SetMotor(Right_Drive, -90);
			wait1Msec(1000);
			SetMotor(Left_Drive, 0);
			SetMotor(Right_Drive, 0);
		//	break;

		//default:  // FAIL-SAFE FOR POTENTIOMETER FAILURE
			/***************************************code for the stationary goal****************************************/
			pidArmRequestedValue = 2800;
			clearTimer(T1);
			while(SensorValue(arm_pot)<2900 && time1(T1)<1500)
			{																										// run this 'if' loop repeatedly and tell the lift to stop once it's inside the acceptable range.
				if (SensorValue(arm_pot)>2900 && SensorValue(arm_pot)<2700)
					wait1Msec(25);
			}
			pidLiftRequestedValue = 2000;
			while(SensorValue(lift_pot_1) > 2100 || SensorValue(lift_pot_1) < 1900)
			{
				wait1Msec(25);
			}
			SetMotor(Left_Drive, 90);
			SetMotor(Right_Drive, 90);
			wait1Msec(1500);
			SetMotor(Left_Drive, 0);
			SetMotor(Right_Drive, 0);
			clawMove(500, 90); //clawMove(int time, int power)						//open the claw
			wait1Msec(500);
			clawMove(300, -90);
			break;
		}

}

When using a pot to select auton, you should average it a good bit. We had a large number of selections last year with the pot and the programmer found that he needed to average the pot value in pre-auton to make the selection. That way it was ready to go in auton.

Can you clarify a bit what you mean by ‘average the pot value in pre-auton’? Are you meaning to grab several readings during pre-auton to generate an average during autonomous or am I reading this wrong?

yes, read it like 50 times (delay 20ms between), add them up, divide by 50. Now you have a one second average. Don’t ever make decision on the pot for selection without an average, no telling what you can get if you hit a dead spot on the pot. Also, put some LEDs in on the digital ports to tell you what the pot thinks it sees.

Ok, thanks for the clarification we will definitely add an averaging function to our selection code.

On the note of the original question, do you happen to see anything that would explain why we consistently got successes with the ROBOTC debugger and failures with the actual field control hardware?

Like between matches I’ll bet we ran the autonomous 20+ times trying to figure out why it wouldn’t run during the match.

I have had very weird issues using cases in RobotC. What I prefer doing is making tasks with each auto then doing something like:

if(SensorValue[pot] < 500)
{
startTask(auton1); 
while(true)
{
wait1Msec(1);
}
else if(SensorValue[pot] > 500 && SensorValue[pot] <1000)
{
startTask(auton2); 
while(true)
{
wait1Msec(1);
}
else
{
startTask(auton3); 
while(true)
{
wait1Msec(1);
}
}
}