Robot only works with inputs from both sticks on controller

19122B

Hello,

We are having a very weird issue where our drive train works fine when both joysticks are being used. If I attempt to drive with only one stick at a time (we are using the tank control joystick settings), the motors start fidgeting and shaking. It makes no sense bc I can drive normally if I give input with both sticks.

Example.
Both sticks on controller are pushed forward. Works

Left stick pushed forward. Starts shaking.

Thanks for all of your help.
Cheers:)

Code:

    double leftVal = Controller1.Axis2.position(percent);

    double leftDriveVolts = rightVal * 0.8;
    double rightDriveVolts = leftVal * 0.8;
    
    //rightwheel.spin(forward,rightDriveVolts,voltageUnits::volt);
    //leftwheel.spin(forward,leftDriveVolts,voltageUnits::volt);
    
    if (abs(rightVal) > 20) {
      rightwheel.spin(forward,rightDriveVolts,voltageUnits::volt);
    } 
    else { 
      rightwheel.spin(forward,0.0,voltageUnits::volt);
    }

    if (abs(leftVal) > 20){
      leftwheel.spin(forward,leftDriveVolts,voltageUnits::volt);
    } 
    else {
      leftwheel.spin(forward,0.0,voltageUnits::volt);
    }
2 Likes

Okay, I would recommend not using voltage but using percent units directly from the controller input. For example:

if (abs(Controller1.Axis2.position(percent) > 20){
    leftWheel.spin(forward, Controller1.Axis2.position(percent), percent);
}

and so on and so forth for all cases.

1 Like

it has been updated:)

I just edited my original response.

I believe that is because you are using if statements, so the else for one side is the action for another and it tries to do both at once.

There is two ways you can tackle this, either you chain your if statements or you set the velocity of your motor to whichever the change of your joystick is.

Method 1:

if(abs(rightVal) > 20) {
}
else if(abs(rightVal) > 20){
}
else{
//stop motors
}

Method two:

leftwheel.spin(forward, Controller1.Axis2.position(percent), pct);

And then the same for the right wheel, but with the other joystick of course

VEXcode Pro V5 has a great example of a tank drive program that @Kes3003 should check out.

Correct me if I’m wrong, but I thought that abs only works on integers, not doubles, while fabs works on floats.

There are a few things I would change about this

  1. abs is only for int data types. I’d recommend replacing your abs() with fabs() for double
  2. Your if statements check leftVal for left speed but leftVal is used to assign rightDriveVolts. I think you need to assign leftDriveVolts as leftVal×0.8 and rightDriveVolts as rightVal×0.8

Other than that, it looks great

6 Likes

we changed the leftVal to leftSpeed and it’s working fine now :)! thank you so much

1 Like