Hi. First post here. I have a national competition tomorrow and we are DEFINITELY not going well. Our robot is somehow not moving anymore. When we first connect the robot to the joystick via VEX NET keys, then plugged in the competition control switch to the joystick, (program already downloaded to robot) it first moves when I flick it to usercontrol, then when I flick disable and then autonomous and then enable, it does not work. Same goes for the opposite, if started with autonomous, usercontrol won’t work. After it doesn’t work, even if I flick it back and forth, it does not work. Then when I powercycle, it works once and then stops again. Please help.
Here is our code, maybe its our codes’ problem.
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1, , sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Sensor, I2C_2, , sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Sensor, I2C_3, , sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Motor, port1, RightgoalMtr, tmotorVex393_HBridge, openLoop, reversed)
#pragma config(Motor, port3, ArmMtrLeft, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, ClawMtr, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, ArmMtrRight, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port6, RightbackMtr, tmotorVex393_MC29, openLoop, encoderPort, I2C_3)
#pragma config(Motor, port8, RightfrontMtr, tmotorVex393_MC29, openLoop, reversed, encoderPort, I2C_2)
#pragma config(Motor, port9, LeftfrontMtr, tmotorVex393_MC29, openLoop, encoderPort, I2C_1)
#pragma config(Motor, port10, LeftgoalMtr, tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
// This code is for the VEX cortex platform
#pragma platform(VEX2)
// Select Download method as "competition"
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(60)
//Main competition background code...do not modify!
#include "Vex_Competition_Includes.c"
/*---------------------------------------------------------------------------*/
/* Pre-Autonomous Functions */
/* */
/* You may want to perform some actions before the competition starts. */
/* Do them in the following function. You must return from this function */
/* or the autonomous and usercontrol tasks will not be started. This */
/* function is only called once after the cortex has been powered on and */
/* not every time that the robot is disabled. */
/*---------------------------------------------------------------------------*/
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 = true;
// Set bDisplayCompetitionStatusOnLcd to false if you don't want the LCD
// used by the competition include file, for example, you might want
// to display your team name on the LCD in this function.
// bDisplayCompetitionStatusOnLcd = false;
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, ...LeftfrontMtr
}
/*---------------------------------------------------------------------------*/
/* */
/* 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. */
/*---------------------------------------------------------------------------*/
void waitforencoders()
{
waitUntilMotorStop(LeftfrontMtr);
waitUntilMotorStop(RightfrontMtr);
waitUntilMotorStop(RightbackMtr);
}
void resetencoder()
{
resetMotorEncoder(RightbackMtr);
resetMotorEncoder(LeftfrontMtr);
resetMotorEncoder(RightfrontMtr);
}
void left90()
{
resetencoder();
setMotorTarget(LeftfrontMtr,369, -127, true);
setMotorTarget(RightfrontMtr,738, 127, true);
setMotorTarget(RightbackMtr,738, 127, true);
waitforencoders();
}
void right90()
{
resetencoder();
setMotorTarget(LeftfrontMtr,738, 127, true);
setMotorTarget(RightfrontMtr,369, -127, true);
setMotorTarget(RightbackMtr,369, -127, true);
waitforencoders();
}
task autonomous()
{
int straight1;
straight1 = 2220;
int straight2;
straight2 = 550;
int straight3;
straight3 = 825;
int straight4;
straight4 = 1660;
resetencoder();
setMotorTarget(LeftfrontMtr,straight1, 127, true);
setMotorTarget(RightfrontMtr,straight1, 127, true);
setMotorTarget(RightbackMtr,straight1, 127, true);
waitforencoders();
left90();
resetencoder();
setMotorTarget(LeftfrontMtr,straight2, 127, true);
setMotorTarget(RightfrontMtr,550, straight2, true);
setMotorTarget(RightbackMtr,550, straight2, true);
waitforencoders();
right90();
resetencoder();
setMotorTarget(LeftfrontMtr,825, straight3, true);
setMotorTarget(RightfrontMtr,825, straight3, true);
setMotorTarget(RightbackMtr,825, straight3, true);
waitforencoders();
left90();
resetencoder();
setMotorTarget(LeftfrontMtr,straight4, 127, true);
setMotorTarget(RightfrontMtr,straight4, 127, true);
setMotorTarget(RightbackMtr,straight4, 127, true);
waitforencoders();
left90();
motor(RightgoalMtr) = 20;
motor(LeftgoalMtr) = 20;
left90();
resetencoder();
setMotorTarget(LeftfrontMtr,straight4, 127, true);
setMotorTarget(RightfrontMtr,straight4, 127, true);
setMotorTarget(RightbackMtr,straight4, 127, true);
waitforencoders();
right90();
resetencoder();
setMotorTarget(LeftfrontMtr,straight3, 127, true);
setMotorTarget(RightfrontMtr,straight3, 127, true);
setMotorTarget(RightbackMtr,straight3, 127, true);
waitforencoders();
left90();
resetencoder();
setMotorTarget(LeftfrontMtr,straight2, 127, true);
setMotorTarget(RightfrontMtr,straight2, 127, true);
setMotorTarget(RightbackMtr,straight2, 127, true);
waitforencoders();
right90();
resetencoder();
setMotorTarget(LeftfrontMtr,straight1, 127, true);
setMotorTarget(RightfrontMtr,straight1, 127, true);
setMotorTarget(RightbackMtr,straight1, 127, true);
waitforencoders();
motor(RightgoalMtr) = -20;
motor(LeftgoalMtr) = -20;
wait10Msec(700);
resetencoder();
setMotorTarget(LeftfrontMtr,straight1, 127, true);
setMotorTarget(RightfrontMtr,straight1, 127, true);
setMotorTarget(RightbackMtr,straight1, 127, true);
waitforencoders();
}
/*---------------------------------------------------------------------------*/
/* */
/* 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 ClawTask()
{
while(true)
{
if (vexRT[Btn7R] == 1)
{
motor(ClawMtr) = 25;
wait1Msec(600);
motor(ClawMtr) = 0;
}
else if(vexRT[Btn7L] == 1)
{
motor(ClawMtr) = -25;
wait1Msec(600);
motor(ClawMtr) = 0;
}
else
{
motor(ClawMtr) = 0;
}
}
}
task usercontrol()
{
// User control code here, inside the loop
while (true)
{
startTask(ClawTask);
resetencoder();
if (abs(vexRT[Ch2]) > 20)
{
motor[RightbackMtr] = vexRT[Ch2];
motor[RightfrontMtr] = vexRT[Ch2];
}
else if (abs(vexRT[Ch2]) <= 20)
{
motor[RightbackMtr] = 0;
motor[RightfrontMtr] = 0;
}
if (abs(vexRT[Ch3]) > 20)
{
motor[LeftfrontMtr] = vexRT[Ch3];
}
else if (abs(vexRT[Ch3]) <= 20)
{
motor[LeftfrontMtr] = 0;
}
if (vexRT[Btn6U] == 1)
{
motor(ArmMtrLeft) = 80;
motor(ArmMtrRight) = 80;
}
else if (vexRT[Btn6D] == 1)
{
motor(ArmMtrLeft) = -80;
motor(ArmMtrRight) = -80;
}
else
{
motor(ArmMtrLeft) = 0;
motor(ArmMtrRight) = 0;
}
if (vexRT[Btn5U] == 1)
{
motor(LeftgoalMtr) = 127; //This speed will change as it is the speed of the mobile goal holder move.
motor(RightgoalMtr) = 127; //Same here.
}
else if (vexRT[Btn5D] == 1)
{
motor(LeftgoalMtr) = -127;
motor(RightgoalMtr) = -127;
}
else
{
motor(LeftgoalMtr) = 0;
motor(RightgoalMtr) = 0;
}
}
}
]
Thanks in Advance,
Rougescales