There are many ways to split robot control across two gamepads. We recommend testing different combinations with your team to decide what feels the most comfortable to you!
This version of the program is intended to be just one example for using two gamepads. Arm and wrist control has been moved to a second gamepad while the main gamepad handles driving and the servos on the intake and claw.
In this example code, we changed our drive function to only be on the left stick!
Arcade Drive Code
When changing a function name this will automatically change throughout the entire code to reflect the new name.
Upgrading to a (REV-45-2470) allows for new kinds of movement giving the robot the ability to strafe side-to-side across the field.
For Mecanum Drive each wheel has an individual motor!
The FTC Starter Kit V3.1 can be
The following additional parts are needed:
- QTY 2
- QTY 4
- QTY 1 (set of 4)
How a Mecanum Drivetrain is programmed largely depends on the driver's preference for how the controller is configured.
In our provided example, the left joystick controls forward/back and strafe then the right joystick controls turning. This code is based on the sample provided by FIRST in Blocks (BasicOmniOpMode).
Port Type
Hub
Port Number
Device Type
Name
At the very beginning of our program the drivetrain motors are set to RUN_WITHOUT_ENCODER.
We need to create some new variables in order to use mecanum. Let's break those down first:
Variable
Purpose
At the beginning of the MECANUM_DRIVE function, our variables for each movement direction are being set to the value generated by the movement of the matching joystick axis.
Since we now have four motors in play, our equation for setting the appropriate power to each motor gets a little more complicated.
Our robot first needs to determine the combined movement of the left stick then calculate with the right stick's value. This allows for movement when the left joystick is at an angle, such as strafing along a diagonal!
Next, similar to our original drivetrain code, there's a chance a value may fall outside the range of the motor's power (-1 to 1). Therefore, we want our robot to check and bring those values back into range so we don't miss any inputs.
For our last step, our robot sets the power of each pair of motors based on all our calculations!
- QTY 1
(QTY 1) OR (QTY 2)
Motor
Control Hub
0
REV Robotics Ultraplanetary HD Hex Motor
frontLeft
FB
Moving forward and backwards
Strafe
Strafing side to side
Turn
Turning left and right
Mecanum Drive
Upgrading from the FTC Starter Kit V3.1 to Mecanum Drivetrain V2:
Example Mecanum Drive Program
Mecanum Demo Blocks Code:
Mecanum Configuration File:
Mecanum Configuration - Control Hub and Expansion Hub
Mecanum Code Breakdown
Before diving into mecanum, double check the direction your motors and wheels are turning. They may need to be reversed if you're experiencing jittering or inverted controls!
Add a block to change the set direction during initialization.