Hello,
I just wrote a program that allows our driver to reverse the front and back directions on the robot. However, when I have the code put into the rest of my program, the robot jitters whenever I try to drive. The drive section works when it is isolated. Int the attachment, i just deleted some of the unnecessary things (preauton, auton, etc…) so you get just the user control code.
Here is my user control code:
int drivermode=1;
task drive()
{
while (true)
{
if(vexrt[Btn7D] && vexrt[Btn8D] && drivermode==1)
{Drivermode=2;
wait1Msec(1000);
}
if(vexrt[Btn7D] && vexrt[Btn8D] && drivermode==2)
{
drivermode=1;
wait1Msec(1000);
}
if(drivermode==2);
{
////Create “deadzone” variables. Adjust threshold value to increase/decrease deadzone
int X2 = 0, Y1 = 0, X1 = 0, threshold = 15;
//Loop Forever
//Create “deadzone” for Y1/Ch3
if(abs(vexRT[Ch3]) > threshold)
Y1 = vexRT[Ch3];
else
Y1 = 0;
//Create “deadzone” for X1/Ch4
if(abs(vexRT[Ch4]) > threshold)
X1 = vexRT[Ch4];
else
X1 = 0;
//Create “deadzone” for X2/Ch1
if(abs(vexRT[Ch1]) > threshold)
X2 = vexRT[Ch1];
else
X2 = 0;
motor[port3] = Y1 - X2 - X1;//rightfront
motor[port2] = Y1 - X2 + X1; //rightback
motor[port5] = Y1 + X2 + X1; //leftfront
motor[port4] = Y1 + X2 - X1; //left back
wait1Msec(1);
}
if(drivermode==1);
{
////Create “deadzone” variables. Adjust threshold value to increase/decrease deadzone
int X2 = 0, Y1 = 0, X1 = 0, threshold = 15;
//Loop Forever
//Create “deadzone” for Y1/Ch3
if(abs(vexRT[Ch3]) > threshold)
Y1 = vexRT[Ch3];
else
Y1 = 0;
//Create “deadzone” for X1/Ch4
if(abs(vexRT[Ch4]) > threshold)
X1 = vexRT[Ch4];
else
X1 = 0;
//Create “deadzone” for X2/Ch1
if(abs(vexRT[Ch1]) > threshold)
X2 = vexRT[Ch1];
else
X2 = 0;
motor[port3] = -Y1 - X2 + X1;//rightfront
motor[port2] = -Y1 - X2 - X1; //rightback
motor[port5] = -Y1 + X2 - X1; //leftfront
motor[port4] = -Y1 + X2 + X1; //left back
wait1Msec(1);
}
}
}
task Flipper()
{
while(true){//claw code
if(vexRT[Btn5U])
{
motor[port6] = 60;
}
else if (vexRT[Btn5D])
{motor[port6] = -60;
}
else
{
motor[port6] = 0;
}
}}
task Claw(){
while(true){
if(vexRT[Btn8U])
{
motor[port8] = 60;
}
else if (vexRT[Btn8D])
{
motor[port8] = -30;
}
else
{
motor[port8] = 0;
}
}
}
task Arm(){ // arm code
while(true) {
if(vexRT[Btn6U] == 1)
{
motor[port1] = motor[port9] = motor[port7] = motor[port10] = 110;
}
else if(vexRT[Btn6D] ==1)
{
motor[port1] = motor[port9] = motor[port7] = motor[port10] = -100;
}
else
{
motor[port1] = motor[port9] = motor[port7] = motor[port10] = 0;
}
}
}
task usercontrol() //This is the code that runs all of the tasks.
{
startTask(Arm);
wait1Msec(1);
startTask(drive);
wait1Msec(1);
startTask(Flipper);
wait1Msec(1);
startTask(Claw);
wait1Msec(1);
}
Thanks for the help!
Forum.c (4.43 KB)