PID Tuning Practice - Motion Magic®
Overview
Motion Magic is CTRE’s trapezoidal profiler on Talon FX. This lesson uses Phoenix Tuner: find kG, tune kP with profile limits at zero, then set cruise velocity, acceleration, and optional jerk.
Video Tutorial
Motion Magic tuning in Phoenix Tuner:
Prerequisites
- Current limits configured
- Motor positive direction matches “up” or your convention
- Sensor-to-mechanism ratio correct
- Phoenix Tuner connected to the controller
Tuning Steps
- Enable the robot in Driver Station, then open Phoenix Tuner and navigate to the Config tab.
- Initialize all PID gains to 0 in the Config tab (if needed), then click the Download button on the motor controller to flash the configuration.
- Set the control mode to VoltageOut and enable the motor with 0 voltage initially.
- Set up plotting in Phoenix Tuner: plot position and velocity, then press Play to start monitoring the data.
- Set the gravity type appropriate for your mechanism in Phoenix Tuner.
- Find the highest voltage that doesn’t make the motor move (this will be your kG value):
- Start at 0.1 volts and keep doubling the voltage
- Watch the position and velocity plots
- Use zoom in/out to see small variations in movement
- The highest voltage before any movement occurs is your kG value
- Set kG to the value you found in the previous step.
- Set all Motion Magic® constants to 0 (cruise velocity, acceleration, and jerk) and set control mode to PositionVoltage.
- Tune kP (proportional gain):
- Start with a small value (e.g., 0.1)
- Keep doubling kP (0.1 → 0.2 → 0.4 → 0.8, etc.)
- Watch the position graph - it should become more rectangular/square as kP increases
- Continue until the graph is mostly square (sharp transitions, flat hold)
- Be careful not to break anything - stop if motion becomes unstable or dangerous
- (Optional) Tune kD (derivative gain):
- For more complex mechanisms, you may want to tune kD to reduce oscillation.
- Start with a small value (e.g., 0.01)
- Keep doubling kD (0.01 → 0.02 → 0.04, etc.)
- Watch the position graph - it should become more rectangular/square as kD increases, but not too much or it will cause jittering
- Continue until the graph is mostly square (sharp transitions, flat hold)
- Be careful not to break anything - stop if motion becomes unstable or dangerous
- If the mechanism is oscillating, you may need to reduce kD
- Set cruise velocity:
- Set the duty cycle to the maximum amount you want the mechanism to travel
- Quickly enable and disable the mechanism to get it to move as fast as possible
- Observe the maximum velocity achieved during this motion - it should be the flat part of the velocity graph
- Set that maximum velocity as your cruise velocity in Motion Magic® settings
- Configure acceleration and jerk based on mechanism constraints:
- Set acceleration (required) - this determines how quickly the mechanism accelerates to cruise velocity
- Consider how fast you want the mechanism to accelerate based on mechanical limits
- Set jerk (optional) - this smooths the acceleration profile
- Lower jerk values create smoother motion, higher values allow faster acceleration changes
- Test the motion profile. The position graph should be more rectangular than with PID alone - Motion Magic® creates smoother, trapezoidal motion profiles.
- Continue adjusting kP, cruise velocity, acceleration, and jerk until the motion is satisfactory. The goal is smooth, controlled motion with minimal overshoot and clear rectangular transitions in the position graph.
Motion Magic® Tuning Summary
Complete workflow:
- Enable robot, open Phoenix Tuner Config tab
- Set all gains to 0 and flash config
- Use VoltageOut mode, plot position and velocity
- Set gravity type and find kG (highest voltage with no movement)
- Set Motion Magic® constants to 0 initially
- Tune kP by doubling until position graph is rectangular
- Set cruise velocity from observed max velocity at desired duty cycle
- Configure acceleration (required) and jerk (optional) based on mechanism constraints
- Test and refine until motion is satisfactory
Important Notes
Motion Magic plans accel and cruise instead of asking PID alone to slam the mechanism to a setpoint. All steps here are in Phoenix Tuner: kG under voltage out, kP under position voltage, then Motion Magic cruise, acceleration, and jerk.