Drivetrain Programming

From Team 449 Wiki

Every FRC robot uses a drive to get around, and every team needs to program theirs to drive well. We have some of the best drive code, but as a result it's a bit complicated. This is a guide on how to program and tune a drive.

Picking An Interface

All drive objects implement the DriveSubsystem interface, which has the ability to do things common to every type of drive- stopping, enabling, and resetting the encoders. No drive should directly implement DriveSubsystem, but should instead implement one or more of the sub-interfaces that extend it. As of the start of 2018 there are two: DriveShiftable, for drives that can shift, and DriveUnidirectional, for non-omnidirectional drivetrains like West Coast, 4-wheel, 2+2, 2+4, etc. If we decide to use an omindirectional drivetrain, a new interface will be needed for it.

Picking An Implementation

Currently, this is a very easy choice- if you’re not using a NavX and Talon SRXs for some reason, use DriveUnidirectionalSimple. If you are, use DriveUnidirectionalWithGyro for drives that can’t shift and DriveUnidirectionalWithGyroShiftable for ones that can.

Characterization

After picking which class to use, it’s time to characterize the drive train. The following only applies if the drive is using Talon SRXs, but it always should be.

White paper stuff

The following tests give you the numbers from our white paper, which you should read before doing this. All of these tests and the way the drive behaves when using the characterization numbers are based of voltage, so voltage compensation mode must be turned on for these tests, so that you get a consistent voltage. For each gear, run a forwards and backwards quasi-static voltage test, increasing the voltage a maximum of .25 volts/sec. The slower you can go, the better, just make sure you can get up to about 5 volts before you run out of carpet. Then do the step voltage test, picking a voltage high enough to get lots of acceleration but not so high that the battery can’t steadily supply it to all the motors. 6 volts seems to work pretty well for this. Although not directly related to the white paper, for shifting drives it’s helpful to know the max speed of each gear for joystick scaling purposes. We test this by just giving 12 volts to each side of the drive. Due to voltage sag, the actual voltage won’t be very close 12, but the point of this is just to see how fast the drive can go. To do the tests as fast possible, with the least robot pushing and rotating, and to get the most power for the test that needs it most (acceleration), do the tests in this order:

  1. forwards 12v acceleration in high gear
  2. forwards 6v acceleration in high gear
  3. reverse 6v acceleration in high gear
  4. forwards quasi-static in high gear
  5. reverse quasi-static in high gear
  6. forwards 12v acceleration in low gear
  7. forwards 6v acceleration in low gear
  8. reverse 6v acceleration in low gear
  9. forwards quasi-static in low gear
  10. reverse quasi-static in low gear

If the drive only has one gear, don’t bother with the 12v tests. After doing the tests, copy the logs off of the RoboRIO and plug them into this script, then put the values it spits out into the yaml file.

Effective Diameters

In order to be able to measure speeds in feet per second and distances in feet, we need to determine the effective circumference of the wheels. This is often significantly different than what you’d get from just measuring the wheel diameter with some calipers and multiplying by pi because of wheel slip and compression due to the weight of the robot. The best way to measure the wheel diameter is to have the robot run a motion profile to drive forwards 100 inches or 8.33333 feet, which the code will interpret as 8.33333 rotations because feetPerRotation defaults to 1. Pick a high value for P to make sure that the robot actually travels 8.33333 rotations. Measure how far the robot actually travels, and set feetPerRotation to that distance in inches over 100. After measuring this, go back to the characterization terms and divide kV and kA by feetPerRotation to convert them from volts/RPS and volts/RPS^2 to volts/FPS and volts/FPS^2 respectively. Next, measure the effective diameter of the robot itself by running one of the sides backwards on the 100 inch profile. Use the NavX to compare the angle before and after, then you know that that angle/360 = 100/diameter, so diameter = 36000/angle in inches.

PID tuning

After characterizing and finding the effective wheel and turning diameters, tune the PID terms. See PID Tuning for details.