PUBLIC: VEXRT Help [R]

@Dwiles08 posted in this thread about help with a program using vexRT].
Here is the original code for reference:


task main()
{
while(1==1)
{
	motor[rightMotor] = vexRT[Ch3];
		motor[leftMotor] = vexRT[Ch2];
		
		if(vexRT[Btn6U] == 1)
		{
			motor(rightMotor) = 127;
		}
		
		else if (vexRT[Btn6D] == 1)
		{
			motor(rightMotor) = -127;
		}
		
		else
		{
			motor(rightMotor) = 0;
		}

}

}

It looks like the series of if-else if-else statements might be messing up the motor on the right side. Try this to start with. We will add the button control back in later.


task main() {
while(true) {
motor[rightMotor] = vexRT[Ch2];
motor[leftMotor] = vexRT[Ch3];
wait1Msec(20);
}
}

See if this works; it should.

Yes the if else statement is the problem. When you put put it in there it says that if neither of those buttons are pressed then the motor equals zero. To fix this you need to put the 2 lines where it’s mapping the motors to the joystick inside that if else statement. :slight_smile:

I’m not sure why the left motor doesn’t work properly; it doesn’t appear in the if else section.
This is one way of adding the button control back in:


task main() {
  while(true) {
    if(vexRT[Btn6U])
      motor[rightMotor] =
        motor[leftMotor] =
        127;
    else if(vexRT[Btn6D])
      motor[rightMotor] =
        motor[leftMotor] =
        -127;
    else {
      motor[rightMotor] = vexRT[Ch2];
      motor[leftMotor] = vexRT[Ch3];
    }
    wait1Msec(20);
  }
}

Guys, as I stated in the original request, I don’t want button control; I want joystick controls.

Then just take a look at the 2nd code segment in my original post. Here it is again for reference.


task main() {
  while(true) {
    motor[rightMotor] = vexRT[Ch2];
    motor[leftMotor] = vexRT[Ch3];
    wait1Msec(20);
  }
}