Tank Drive Issues

Hello,
This year I have been switching my team over to Java and we have started to work with a Command Based control system. I built my drivetrain in RobotBuilder and then added code for the Tank Drive. Unfortunately, when I try to run the code, the left Joystick controls both sides of the robot instead of just the left side.

The Code:

DriveTrain subsystem:

public void tankDrive(double leftJoystickValue, double rightJoystickValue){
robotDrive.tankDrive(leftJoystickValue, rightJoystickValue);
}
public double deadZone (double val) {
return val > 0.25 || val < -0.25? val: 0;
}
public double adjustSpeed (double val){
return Robot.oi.leftJoystick.getRawButton(1)? val
.75: (Robot.oi.rightJoystick.getRawButton(1)? val*.75: val);

}*

DriveCommand:

protected void execute() {
Robot.drivetrain.tankDrive(Robot.drivetrain.adjustSpeed(Robot.drivetrain.deadZone(Robot.oi.getleftJoystick().getY())),
Robot.drivetrain.adjustSpeed(Robot.drivetrain.deadZone(Robot.oi.getrightJoystick().getY())));
}

Thanks

I don’t see anything in the code that you posted that would output the left joystick to both left and right. Are your joystick declarations correct?

I’m not entirely sure what is intended to be going on in the adjustSpeed method (chained ternary operators are pretty bad for that), but you’re using it for each side’s input into your tank drive and it seems to be depending on a specific combination of inputs.

EDIT: nevermind I get it now, my only remaining suspicions are the same as Joe’s.

To answer your question, I would take a look at the code in the OI class. getrightJoystick() and getleftJoystick() may not be returning what you’re expecting.

One suggestion to make your code a little easier to read/use (this isn’t goign to solve your problem)…

By changing what the tankDrive method does slightly you can clean up your “DriveCommand” code significantly, without changing how things work.


//DriveTrain subsystem:

public void tankDrive(double leftJoystickValue, double rightJoystickValue){
    robotDrive.tankDrive(
        Robot.drivetrain.adjustSpeed(Robot.drivetrain.deadZone(leftJoystickValue)),
        Robot.drivetrain.adjustSpeed(Robot.drivetrain.deadZone(rightJoystickValue)));
}

public double deadZone (double val) {
    return val > 0.25 || val < -0.25? val: 0;
}

public double adjustSpeed (double val){
    return Robot.oi.leftJoystick.getRawButton(1)? val*.75: (Robot.oi.rightJoystick.getRawButton(1)? val*.75: val);
}


//DriveCommand:

protected void execute() {
    Robot.drivetrain.tankDrive(
        Robot.oi.getleftJoystick().getY(),
        Robot.oi.getrightJoystick().getY());
}


Maybe it’s just my preference, but I prefer logic to be performed by the subsystem. That way if multiple commands call the exposed methods, they always perform in a consistent manner, and it reduces code duplication at the Command level.

Agreed that you probably have a problem in your OI. And tell us whether you are using 2 joysticks or a video game controller (ie XBox/PS3 controller).

Also, I am glad to see a team using robot builder. Such an amazing yet underused tool, especially for your first year using Java/C++.