When an elevator is commanded to step from 0 inches to 40 inches instantaneously, an unprofiled PID controller responds to the large step error by commanding maximum output voltage (12V). This causes wheel slip, mechanical shock, and potential mechanism damage.
Motion Profiling replaces instantaneous setpoint jumps with a physically achievable continuous trajectory of position , velocity , and acceleration .
Trapezoidal Velocity Profiles
Section titled “Trapezoidal Velocity Profiles”A trapezoidal profile divides movement into three phases:
- Constant Acceleration Phase: Accelerates at maximum acceleration a_max until reaching cruise velocity v_cruise.
- Cruise Velocity Phase: Travels at steady speed v_cruise.
- Constant Deceleration Phase: Decelerates at -a_max to bring velocity to exactly 0 at the destination.
Velocity ^ | ___________________ (Cruise Velocity) | / \ | / \ | / \ | / \ +---+---------------------------+---> Time | Accel | Cruise | Decel |CTRE Motion Magic vs. WPILib ProfiledPIDController
Section titled “CTRE Motion Magic vs. WPILib ProfiledPIDController”| Feature | CTRE Phoenix 6 Motion Magic | WPILib ProfiledPIDController |
|---|---|---|
| Execution Rate | 1,000 Hz (1 kHz onboard Talon FX) | 50 Hz (roboRIO loop cycle) |
| Latency | Zero CAN bus communication latency | 20 ms roboRIO cycle latency |
| Jerk Limiting | Built-in S-Curve Jerk parameter (j_max) | Standard Trapezoid only |
| Setup in Code | MotionMagicVoltage control request | Java ProfiledPIDController object |
Configuring Motion Magic in Phoenix 6
Section titled “Configuring Motion Magic in Phoenix 6”TalonFXConfiguration config = new TalonFXConfiguration();
// Motion Magic parametersconfig.MotionMagic.MotionMagicCruiseVelocity = 80.0; // rotations/secconfig.MotionMagic.MotionMagicAcceleration = 160.0; // rotations/sec²config.MotionMagic.MotionMagicJerk = 1600.0; // rotations/sec³ (smooth S-curve)
// Closed-loop Slot 0 gainsconfig.Slot0.kP = 4.8;config.Slot0.kD = 0.15;config.Slot0.kV = 0.12;config.Slot0.kS = 0.20;
m_motor.getConfigurator().apply(config);Jerk is the derivative of acceleration (da/dt). Limiting jerk smooths the sharp transitions at the corners of trapezoidal velocity curves, preventing chain lash and gearbox shock.
Verified Sources & Standards
- WPILib TrapezoidProfile & S-Curve Motion Profilingdocs.wpilib.orgWPILib Standard