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;
}
}