I just wrote a code last night for driving with mecanum wheels that has a toggle button that reverses the drive. It worked fine when it was isolated, but as soon as I incorporated it into the main code, the drive wouldn’t work and it would jitter. I know that it’s a programming error, and I need a second person’s opinion on this because I am the only programmer on my team.
Here is the user control portion of my code:
[PHP]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);
{
int X2 = 0, Y1 = 0, X1 = 0, threshold = 15;
//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);
{
int X2 = 0, Y1 = 0, X1 = 0, threshold = 15;
//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);
}[/PHP]
Thanks!