Logo

Westside Robotics FTC Java Programming Guide

Control Multiple Motors and Servos with a Game Pad

You now know everything you need to make your robot start doing something approximating driving!

Set up the other three motors in your drivetrain the same way you set up the first one. You will probably want to use a more descriptive name for your variables now that we have more than one thing to work with - driveRF or something like that might be a better choice.

All of our motors spin clockwise when given positive power. This creates a slight issue with most of our drivetrain designs. The motors on one side of the robot are mounted “upside-down,” so giving them the same power as the motors on the other side will have your robot spinning in circles instead of driving straight.

You’ll want to add something like this to your init method to explicitly set the directions for all 4 of your motors:

driveLF.setDirection(DcMotor.Direction.REVERSE);
driveRF.setDirection(DcMotor.Direction.FORWARD);

Make all of your drivetrain motors move with the same joystick axis, enabling you to drive your robot backward & forward, and make your servo position set based on one of the gamepad triggers. While you’re at it, go ahead and reset the encoder counts and have all motors run using encoders for all of your drive motors, too.