Inverting controls in Java


Unfortunately, I’m not the programmer for my team, but I did pretty much all of our programming when we were using C. This means that I don’t know the Java lingo either. So please bare with me.

What we’re trying to do is invert our controls so that we can flip the forward and reverse directions on our robot. This is so that we dont need to turn the robot around to herd balls and stuff. Our programmer said that there is an “invert controls” option, but when she uses it, the axes of the joystick switch.

Has anyone found an easy way to invert the controls for their robot? We’re using the out of the box tankdrive routine.


RobotDrive myDrive = new RobotDrive(1,2,3,4);

if( invertMyDrive == true )
 myDrive.setInvertedMotor(kFrontLeft, true);
 myDrive.setInvertedMotor(kFrontRight, true);
 myDrive.setInvertedMotor(kRearLeft, true);
 myDrive.setInvertedMotor(kRearRight, true);

myDrive.tankDrive(leftStick, rightStick);

The above snippet will reverse the forward/backward direction of your bot if the “invertMyDrive” variable (a boolean) is set.

It sounds like if your axes got switched, you only inverted half of the drive.

really appreciate it Jared. I’ll pass this on to our programmer!

You might want an “else” portion in there too to set the back to normal. It’s nice to be able to change, but it’s nicer to be able to change back :slight_smile:

Details, details :slight_smile: