The code below works perfectly if the cortext is reset. However, if I only make an adjustment and re-download, selecting autonomous (on LCD then) on the competition control window skip the autonomous and invokes driver control. It might be more accurate to say it fails to stay in autonomous mode. It runs a couple commands and drops into driver control. Selecting autonomous again from the comp control dialog reruns autonomous…(somewhat faster than a power cycle) but still concerns as to what would cause this.
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1, BRIME, sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Sensor, I2C_2, BLIME, sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Motor, port2, FRWheel, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port3, BRWheel, tmotorVex393_MC29, openLoop, reversed, encoderPort, I2C_1)
#pragma config(Motor, port8, BLWheel, tmotorVex393_MC29, openLoop, encoderPort, I2C_2)
#pragma config(Motor, port9, FLWheel, tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
// This code is for the VEX cortex platform
#pragma platform(VEX)
// Select Download method as "competition"
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)
//Main competition background code...do not modify!
#include "Vex_Competition_Includes.c"
// Include the lcd button get utility function
#include "getlcdbuttons.c"
#define MAX_CHOICE 3
#define LW motor[FLWheel]=motor[BLWheel]
#define RW motor[FRWheel]=motor[BRWheel]
float TicksPerInch=49.94; //number of encoder ticks per inch driver
static int MyAutonomous = 0; // global hold the auton selection
static int L_TargetValue = 0;
static int Sv = 0;
static int IMESv = 0;
static int Mv = 0;
void
LcdAutonomousSet( int value, bool select = false )
{
// Cleat the lcd
clearLCDLine(0);
clearLCDLine(1);
// Display the selection arrows
displayLCDString(1, 0, l_arr_str);
displayLCDString(1, 13, r_arr_str);
// Save autonomous mode for later if selected
if(select)
MyAutonomous = value;
// If this choice is selected then display ACTIVE
if( MyAutonomous == value )
displayLCDString(1, 5, "ACTIVE");
else
displayLCDString(1, 5, "select");
// Show the autonomous names
switch(value) {
case 0:
displayLCDString(0, 0, "< No Autonomous>");
break;
case 1:
displayLCDString(0, 0, "< Red R >");
break;
default:
displayLCDString(0, 0, "Unknown");
break;
}
}
void LcdAutonomousSelection()
{
TControllerButtons button;
int choice = 0;
// Turn on backlight
bLCDBacklight = true;
// diaplay default choice
LcdAutonomousSet(0);
while( bIfiRobotDisabled )
{
// this function blocks until button is pressed
button = getLcdButtons();
// Display and select the autonomous routine
if( ( button == kButtonLeft ) || ( button == kButtonRight ) ) {
// previous choice
if( button == kButtonLeft )
if( --choice < 0 ) choice = MAX_CHOICE;
// next choice
if( button == kButtonRight )
if( ++choice > MAX_CHOICE ) choice = 0;
LcdAutonomousSet(choice);
}
// Select this choice
if( button == kButtonCenter )
// Don't hog the cpu !
wait1Msec(10);
}
}
void DriveFwd(int inches)
{
float PFwd=0.1;
L_TargetValue=TicksPerInch * inches + SensorValue(BLIME);
if(inches>0)
{
while(L_TargetValue>SensorValue(BLIME))
{
RW=LW=(L_TargetValue - SensorValue(BLIME)) * PFwd;
Sv=SensorValue(BLIME);
IMESv=nMotorEncoder(BLWheel);
Mv=(L_TargetValue - SensorValue(BLIME)) * PFwd;
}
RW=LW=-10;
sleep(150);
}else{
while(L_TargetValue<SensorValue(BLIME))
{
RW=LW=(L_TargetValue - SensorValue(BLIME)) * PFwd;
Sv=SensorValue(BLIME);
IMESv=nMotorEncoder(BLWheel);
Mv=(L_TargetValue - SensorValue(BLIME)) * PFwd;
}
RW=LW=10;
sleep(150);
}
RW=LW=0;
sleep(150);
}
//The auto functions
void R_Red()
{
DriveFwd(12);
}
void pre_auton()
{
bStopTasksBetweenModes = true;
string batteryString;
sprintf(batteryString, "M: %1.2f", (float)nImmediateBatteryLevel/1000.0);
displayLCDCenteredString(0, batteryString);
wait1Msec (3000);
LcdAutonomousSelection();
}
task autonomous()
{
switch( MyAutonomous ) {
case 0:
// No Auton
displayLCDCenteredString(1, "No Autonomous");
DriveFwd(-60);//added to test quickly
break;
case 1:
// cube dump over middle
displayLCDCenteredString(1, "R_Red");
R_Red ();
break;
default:
break;
}
}
/*---------------------------------------------------------------------------*/
/* */
/* 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)
{
}
}