-
Notifications
You must be signed in to change notification settings - Fork 1
Motion Profile Tuning
This page describes the process for tuning Rio-based motion profiles.
The goal is to achieve suitable settings for the following values:
- Motion Profile velocity (V) and acceleration (A) feed forward
- Motion Profile distance-tracking P and D values (for PID; I is not supported by Pathfinder, which our follower code is based on). Note that in practice D is rarely, if ever, nonzero.
- Motion Profile gyro-correction P value
- Wheelbase (experimentally determined, may differ from physical wheelbase measurement)
The robot must be operational and have its velocity closed-loop speed control PIDs properly tuned. That is, the tuning described here is only for the motion-profile following and assumes that the basic drivetrain is already operational.
This procedure uses Shuffleboard to graph system responses. Shuffleboard must be installed (it comes with WPILib and should be available on the development PC). You need the Shuffleboard layout file, which can be found in our RobotCode2018 repository in the "Dashboard Layouts"/"Rio Profiling.json" file. Open this with Shuffleboard (File -> Load Layout).
The Shuffleboard layout has two tabs: "Motion Profile Tuning" and "Error & Parameter Output". The first is used to set operational (tuning) values and also graphs target-vs-actual position and heading, and shows average errors. The second tab shows position error over time, and what the parameter outputs are producing (e.g., how the parameters are contributing to the behavior).
Note: Because data flows through Network Tables, graph updates occur at 100ms intervals. Thus graphs may be somewhat "blocky". This is to be expected!
The robot code must be operating in "tuning mode" (set Tuning Mode flag in RobotMap) in order for the sending and receiving of Network Tables tuning data to operate. This avoids the possibility of accidentally changing tuning parameters during competition and also improves competition performance (less load). It also avoids cluttering the competition dashboard with irrelevant information.
Interaction between the robot and Shuffleboard (for graphing) is via Network Tables. A set of Network Tables variables are written to from within the motion profile follower (RunMotionProfileOnRio.java). Tuning parameters are set via a separate set of Network Tables variables. These are "TunableNumbers", a wrapper class that sets up a variable with a default value (if not in tuning mode or Network Tables is not providing that value) or reads it from Network Tables (in tuning mode and when the value is available).
The procedure is as follows:
- Disable gyro correction (RunMotionProfileOnRio.java: Boolean flag EnableGyroCorrection - set to false)
- Generate a straight-line motion profile (currently defined as a tuning auto "8 foot straight profile").
- Set distance-following P, D, and A values to zero. Set V value to 1 (== follow values in profile).
- Run the profile.
- Observe the graph. The goal is to minimize overall error, such that observed error tracks with acceleration. For a straight-line profile, this equates to a small positive error for the first half, and a small negative error for the second half, with the magnitudes of the two halves comparable to one another. (The crossover point should be at, or somewhat after, the middle of the profile.)
- When the conditions described in the previous step are met, move on to tuning the A (acceleration feed forward) value. Start with a low default value (say 0.1). Without changing the previously determined V value, adjust A to try to further reduce observed error.
- It will likely be necessary to iterate between adjusting V and A to achieve an overall minimum, as-flat-as-possible error curve. Pay attention to the overall magnitude of error and its general shape to determine which to adjust and in what direction. Properly tuned feed forward values should produce a nearly error free curve, with the error nearly random. The goal is that the P (and possibly D) adjustment applies only a very small amount of additional correction.
- When V and A have been tuned, move on to distance-P. Start with a value around 1 (this may well be on the small side). Adjust, observing its effect on the graph. If oscillation is observed, the value is too large. If there is still significant remaining error, the value is too small. In addition to the graphs, it may be useful to consult the average positive and negative, right and left side errors reported on the Motion Profile Tuning tab to get an idea of overall accuracy.
- D is often not required. Pathfinder notes that D may be required "if you are unhappy with the tracking of the trajectory".
- Wheelbase tuning is next. The idea here is to experimentally determine a wheelbase value to be used with Pathfinder's Tank Modifier class to translate the center-line profile to that of the individual wheels. Although the machine's actual wheelbase is a logical starting point, in practice this constant may be adjusted (similar to a feed-forward) to improve curve tracking. Note that gyro correction is still disabled at this point, so that we are relying on wheel tracking to produce the desired angle. The optimal wheelbase value may be a number of inches different than actual wheelbase. The procedure here is to create a motion profile that travels approximately 10' forward and 5' to the right , ending at 90 degrees from starting position. The wheelbase is set initially to actual wheelbase, and then adjusted so that the final angle is close to 90 degrees and average error is minimized. Without gyro correction, it should be possible to reach a small single-digit average error (say ~3 degrees) and a single digit or less final angle error.
- Finally, re-enable gyro correction and tune the P value to further reduce yaw error. Start with a value around 1 to 3. Tune until average error is minimized (<2 degrees or better), final error is acceptable (<1 degree), and there is no observable yaw oscillation.