This example is a simplified form of a mecanum drivetrain code intended to review the basics of mecanum movement and is not recommended for a FTC robot.
Check out Programming Mecanum - Refined for a competition ready example!
Before getting started with programming we needed to create a configuration file. Below is an overview of how the robot is configured for the TeleOp code to function as expected:
Motor
0
REV Robotics Ultraplanetary HD Hex Motor
frontLeft
Motor
1
REV Robotics Ultraplanetary HD Hex Motor
frontRight
Motor
2
REV Robotics Ultraplanetary HD Hex Motor
backLeft
Motor
3
REV Robotics Ultraplanetary HD Hex Motor
backRight
Left Joystick - Left/Right on X-Axis
Strafe Left/Right
Left Joystick - Forward/Backward on Y-Axis
Forward/Backward
Right Joystick - Left/Right on X-Axis
Turn Counter-Clockwise/Clockwise
Before diving into mecanum, double check the direction your motors and wheels are spinning. They may need to be reversed if you're experiencing jittering or inverted controls!
For this program, we'll set the motors to RUN_WITHOUT_ENCODER along with their direction
For a mecanum drivetrain all 4 motors will be given a command to follow when the left joystick is moved along the Y-axis of the joystick. For moving forward and back all wheels must turn the same direction.
Recall that the Y-axis on the gamepad must be inverted.
For this example, strafing is controlled by the left stick's X-axis allowing the robot to slide left and right. In order to achieve this movement, the motors move in diagonal pairs, so frontLeft and backRight will move the opposit direction of backLeft and frontRight, similar to the X shape the wheels make.
Lastly, we have turning set by itself on the right joystick's X-axis. To turn our left and right pairs of wheels will spin in opposite directions.
This version of the mecanum program does not account for diagonal movements of the joystick. Check out Programing Mecanum - Refined to create a fully responsive mecanum drive!
Adjust the block to change the set direction during initialization.