Autonomous Code Help

Our robotc code in competition is not working sometimes when we connect to the tower is there a reason why?

#pragma config(Sensor, in8,    Gyro,           sensorGyro)
#pragma config(Sensor, dgtl1,  ,               sensorQuadEncoder)
#pragma config(Sensor, dgtl3,  ,               sensorQuadEncoder)
#pragma config(Sensor, dgtl9,  SolTM,          sensorDigitalOut)
#pragma config(Sensor, dgtl10, SolLM,          sensorDigitalOut)
#pragma config(Sensor, dgtl11, SolSR,          sensorDigitalOut)
#pragma config(Sensor, dgtl12, SolCE,          sensorDigitalOut)
#pragma config(Motor,  port1,           Motor1,        tmotorVex393_HBridge, openLoop)
#pragma config(Motor,  port2,           Motor2,        tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port3,           MotorA,        tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port4,           MotorB,        tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port5,           MotorC,        tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port6,           MotorD,        tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port7,           Filper,        tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port8,           Slider,        tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port9,           Motor9,        tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port10,          Motor10,       tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#pragma platform(VEX)

//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(145)

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

/////////////////////////////////////////////////////////////////////////////////////////
//
//                          Pre-Autonomous Functions
//
// You may want to perform some actions before the competition starts. Do them in the
// following function.
//
/////////////////////////////////////////////////////////////////////////////////////////

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;
SensorValue[SolCE] = 1;

	SensorType[in8] = sensorNone;
 	wait1Msec(100);
 //Reconfigure Analog Port 8 as a Gyro sensor and allow time for ROBOTC to calibrate it
	 SensorType[in8] = sensorGyro;
	 wait1Msec(200);

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

/////////////////////////////////////////////////////////////////////////////////////////
//
//                                 Autonomous Task
//
// This task is used to control your robot during the autonomous phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////

task autonomous()
{
SensorValue[SolCE] = 1;

motor[port1] = -127;
motor[port2] = -127;
motor[port9] = -127;
motor[port10] = -127;
wait1Msec(500);



motor[port1] = 0;
motor[port2] = 0;
motor[port9] = 0;
motor[port10] = 0;
wait1Msec(200);


}

/////////////////////////////////////////////////////////////////////////////////////////
//
//                                 User Control Task
//
// This task is used to control your robot during the user control phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////

task usercontrol()
{
	// User control code here, inside the loop

	while (true)
	{
		bLCDBacklight = true;                                    // Turn on LCD Backlight
		string mainBattery, backupBattery;

		clearLCDLine(0);                                            // Clear line 1 (0) of the LCD
		clearLCDLine(1);                                            // Clear line 2 (1) of the LCD

		//Display the Primary Robot battery voltage
		displayLCDString(0, 0, "Primary: ");
		sprintf(mainBattery, "%1.2f%c", nImmediateBatteryLevel/1000.0,'V'); //Build the value to be displayed
		displayNextLCDString(mainBattery);

		//Display the Backup battery voltage
		displayLCDString(1, 0, "Backup: ");
		sprintf(backupBattery, "%1.2f%c", BackupBatteryLevel/1000.0, 'V');    //Build the value to be displayed
		displayNextLCDString(backupBattery);

		//Short delay for the LCD refresh rate

		motor[port3] = vexRT[Ch1Xmtr2] - vexRT[Ch2];//lift
		motor[port4] = vexRT[Ch2] + vexRT[Ch1Xmtr2];
		motor[port5] = vexRT[Ch2] + vexRT[Ch1Xmtr2];
		motor[port6] = vexRT[Ch1Xmtr2] - vexRT[Ch2];

		bMotorFlippedMode[port1] = 1;
		bMotorFlippedMode[port9] = 1;

		motor[port1]  = vexRT[Ch3] - vexRT[Ch4];//drive
		motor[port2] = vexRT[Ch3] - vexRT[Ch4];
		motor[port10]  = vexRT[Ch3] + vexRT[Ch4];
		motor[port9] = vexRT[Ch3] + vexRT[Ch4];

	if(vexRT[Btn6D] == 1)
		{
			motor[port7] = -127;
		}
		else if(vexRT[Btn5D] == 1)// && eqaul AND
		{
			motor[port7] = 127;
		}
		else
		{
			motor[port7] = 0;
		}


		if(vexRT[Btn8U] == 1)
		{
			motor[port8] = 55;
		}
		else if(vexRT[Btn8D] == 1)// && eqaul AND
		{
			motor[port8] = -55;
		}
		else
		{
			motor[port8] = 0;
		}




			if(vexRT[Btn7D] == 1)           // If button  is pressed:
		{
			SensorValue[SolCE] = 0;  // …activate the solenoid.
		}
		else // If button 6U is NOT pressed:
		{
			SensorValue[SolCE] = 1;  // ..deactivate the solenoid.
		}

		if(vexRT[Btn6U] == 1)           // If button is pressed:
		{
			SensorValue[SolSR] = 1;  // …activate the solenoid.
	}
		if(vexRT[Btn5U] == 1)           // If button is pressed:
		{
			SensorValue[SolSR] = 0;  // …activate the solenoid.
		}

		if(vexRT[Btn7U] == 1)           // If button  is pressed:
		{
			SensorValue[SolLM] = 1;  // …activate the solenoid.
		}
		else // If button 6U is NOT pressed:
		{
			SensorValue[SolLM] = 0;  // ..deactivate the solenoid.
		}


		wait1Msec(30);

	}
}

Looking at the code, I don’t see anything in particular that could be causing the program to lock up, it seems to be pretty standard but very well-formatted code (which makes the debugging process easier for me, thank you for that).

When the program doesn’t work, what specifically is it doing/not doing? Does the robot simply not move, does it stop mid-match, does it run one portion of the program (such as autonomous or tele-op) but not the other?

The more detailed information you can provide on this one, the better we’ll be be able to debug the issue. Thanks in advance!

At the the beginning of the match when they start autonomous the robot just flinches and doesn’t run the program but then works in driver mode.

Which direction is the robot facing with the autonomous portion of the match starts? The only commands being given to the robot are a 1/2 second backwards movement, and a 200 millisecond stop command:

SensorValue[SolCE] = 1;

motor[port1] = -127;
motor[port2] = -127;
motor[port9] = -127;
motor[port10] = -127;
wait1Msec(500);



motor[port1] = 0;
motor[port2] = 0;
motor[port9] = 0;
motor[port10] = 0;
wait1Msec(200);

While this should move the robot backwards for 500 milliseconds, the robot may be running into the field wall instead. Try changing the starting orientation of the robot and increasing the movement time to a larger value (such as one second) to see if this resolves the issue.

Also, what do you have the ‘Robot -> VEX Cortex Communication Mode’ setting set to? You will need to make sure that it is set to ‘Competition (VEXNet)’ in order for the Competition settings to work properly; once you change this setting, you will need to compile the program to the robot and powercycle the Cortex (turn off and unplug USB cable, then turn it back on) in order for the changes to take affect.

The robot is facing away from the wall and I exstended the code andset the cortex to vexnet. So it is working for now I guess I will have to wait till wolrds for the real test.