Driving FRC Swerve Drive Base in TeleOp
Follow the instructions below to modify the FRC Template code for your swerve robot.
- In RobotParams.java, update the SWERVE_DRIVE_MOTOR_TYPE and SWERVE_STEER_MOTOR_TYPE to the motor types for your swerve modules.
- The Template code standardizes CAN IDs of the drive and steer motors on the swerve module so that the template code can be run on the drive base of any season. The left front, right front, left back and right back drive motors have their CAN IDs as 3, 4, 5 and 6 respectively. The left front, right front, left back and right back steer motors have their CAN IDs as 13, 14, 15 and 16 respectively. Please configure their CAN IDs accordingly.
- In RobotParams.java, update the SWERVE_STEER_ENCODER_TYPE to the encoder type for your swerve modules.
- If the steer encoders of your swerve module are CAN-based, the Template code also standardizes their CAN IDs. The left front, right front, left back and right back steer encoders have their CAN IDs as 23, 24, 25 and 26 respectively. Please configure their CAN IDs accordingly.
- If the steer encoders of your swerve module are Analog-based, the Template code standardizes the analog channels to be 0, 1, 2 and 3 for left front, right front, left back and right back encoders respectively. Please connect them to the correct input accordingly.
- Compile the code and deploy it to the robot.
- The next step is to zero calibrate the steer encoders. That depends on the type of encoders in use. If you are using Redux Helium Canandmag encoders, you can tip the robot on its side and physically align all four wheels pointing to the robot front. Then press the reset button on each encoder to zero it's position.
- For any other encoders, you need to tip the robot on its side and physically align all four wheels pointing to the robot front. Then run the Swerve Steer Calibration in Test Mode.
- In Shuffleboard, click the Test tab and select the Swerve Steer Calibration in the Tests drop-down menu.
- In the Driver Station app, enable Test Mode.
- In Shuffleboard, click the Dashboard tab and wait for a minute or two until the encoder values stabilize to the point where only the 3rd or 4th decimal places are changing. Then you can disable Test Mode in the FRC Driver Station app.
- Once the steer encoders are zero calibrated, the next step is to determine if the drive wheels are running in the correct direction. Tip the robot on its side and run the Drive Motors Test in Test Mode.
- In Shuffleboard, click the Test tab and select the Drive Motors Test in the Tests drop-down menu.
- In the Driver Station app, enable Test Mode. This test will run each of the four driving wheels one after the other for 5 seconds each in the sequence of Left Front, Right Front, Left Back and Right Back. Note the rotation direction of each wheel and make sure they would have run the robot in the forward direction if the robot were placed on the ground. If any of the wheels are rotating in the wrong direction, correct them in RobotParams.java. Change xxDRIVE_MOTOR_INVERTED from true to false or vice versa to reverse the corresponding driving wheels until the test shows all four wheels rotating in the correct direction.
- The next step is to tune the PID Coefficients for the steer motors. If the steer motors are CTRE motors, this can be done easily using the CTRE Phoenix Tuner X app. Please refer to the PID tuning section in later classes.
That's it. Your robot is now ready to be driven in TeleOp mode. On the FRC Driver Station, make sure the gamepad/joysticks are connected to the correct game ports corresponding to the code in RobotParams.java (JSPORT_*). Then enable TeleOp mode in the FRC Driver Station app. The default drive mode is Arcade Mode. It means the left stick on the driver gamepad controls the X and Y direction of the robot. The X-axis of the right stick controls the rotation. If you prefer, you can change the drive mode to Holonomic Mode. In this mode, the Y-axis of the left stick controls the Y direction of the robot. The X-axis of the right stick controls the X direction, the left trigger controls turning left and the right trigger controls turning right. To change to this mode, change ROBOT_DRIVE_MODE in RobotParams.java to DriveMode.HOLONOMIC_MODE.
In addition, there are a few more buttons on the driver gamepad that modify how the robot is driven. Click the right bumper on the driver gamepad will toggle between Robot and Field Oriented driving modes. Our library also supports Inverted driving mode allowing the robot to switch the front and back end. This is useful for a robot that has an end effector such as an intake at the back so that the drivers can drive the robot around as if the intake is in front. Press and hold the left bumper allows you to drive the robot at slow speed. This is useful for delicate movement of the robot.