Motion Magic Expo
How the exponential profile is built from the motor model, and how to tune it.
1.4.1 Motion Magic Expo in Detail
Trapezoidal Motion Magic asks "how fast did the user say this may move?" Expo asks "how fast can this move?" A hand-picked trapezoidal acceleration is usually either too aggressive (the motor saturates and falls behind the profile) or too timid (time wasted on every move). Expo avoids the guess by building the profile from a model of the motor.
The short version. Expo uses two configs in MotionMagicConfigs:
| Config | Meaning | What it sets |
|---|---|---|
MotionMagicExpo_kV | Volts needed to hold 1 mechanism rotation/s | Top speed: |
MotionMagicExpo_kA | Volts needed to accelerate at 1 mechanism rotation/s², from rest | Starting acceleration: |
- Bigger values give a slower profile. This is backwards from kP intuition. A high kV means the motor needs a lot of voltage per rotation/s, so it tops out lower.
- The profile uses the measured supply voltage, so a sagging battery slows it down automatically.
- Both configs are always in Volts, even with TorqueCurrentFOC or DutyCycle requests. There is no FOC variant.
MotionMagicCruiseVelocityoptionally caps top speed below . Leave it at 0 for no cap.MotionMagicAccelerationandMotionMagicJerkare ignored.- The defaults (0.12 V/rps and 0.1 V/(rps/s)) are placeholders unrelated to your mechanism. Always set both.
Try it. Pick a motor, gear ratio, and inertia to see the configs to enter and the profile they produce. Then drag the trapezoidal acceleration to see where a hand-picked trapezoid asks for more than the motor can give.
From about 5.67 ms the trapezoid asks for more speed than the motor can reach even at full voltage. The mechanism falls behind and the PID has to absorb the error.
Assumes no friction, gravity, or current limits, and ignores the motor's own rotor inertia. Stator and torque-current limits cap acceleration further. The Expo configs are always in Volts, whatever request type you use.
The rest of this section shows where those formulas come from. If you just want to tune, skip to §1.4.2.
The motor model. A brushless motor at steady state obeys:
is the voltage at the motor, the (effective) winding resistance, the torque-producing current, the back-EMF constant (V·s/rad), and the rotor speed (rad/s). The first term is the resistive drop. The second is the back-EMF the spinning motor generates. (Inductance can be ignored: the electrical time constant is far shorter than the mechanical one.)
Torque is proportional to current, , so:
Torque is highest at rest and falls linearly with speed, reaching zero at the no-load speed , where back-EMF cancels the applied voltage.
Where the exponential comes from. Add Newton's second law. is the total inertia seen at the rotor (rotor plus mechanism, reflected through the gearbox), with no external load:
This is a first-order system with time constant:
Applying full voltage from rest gives the familiar exponential rise:
This is the curve Expo generates — what the motor would do on its own at full voltage. By construction, the profile never asks for more than the motor can deliver.
Linking the configs to the motor. With a gear reduction (), one mechanism rotation per second is rad/s at the rotor. Holding a speed takes only back-EMF voltage (), and accelerating from rest takes only resistive voltage (). Per mechanism unit:
In voltage mode these are the same quantities as the slot kV and kA that SysId identifies (in mechanism units).
Plugging full supply voltage into these gives the two limits from the table above: and . Their ratio is the profile's time constant, which is exactly the motor's:
The and cancel, so the time constant depends only on the motor and the inertia reflected to the rotor.
The generated trajectory. Starting from rest, the profile velocity and acceleration are:
(The acceleration follows by differentiating, using .)
Acceleration is highest at the start, when there is no back-EMF to fight, and decays toward zero as the mechanism approaches top speed. After one time constant, velocity is at of and acceleration has fallen to of its starting value. Deceleration mirrors this. Because acceleration jumps straight to its maximum at , Expo does not limit jerk.
Numerical check. A Kraken X60 (FOC) at 12 V, using constants from §1.6.2:
- V·s/rad, N·m/A, Ω
- A small turret: , total inertia at the rotor kg·m²
- V per (mechanism rotation/s)
- V per (mechanism rotation/s²)
- rotation/s ≈ 116 RPM at the turret
- rotation/s² at the instant the move starts
- ms
After 6.4 ms the turret is at ~73 RPM (63% of top speed). After ~19 ms (three time constants) it is at ~110 RPM (95%). Ten times the inertia gives a 64 ms time constant. Real FRC mechanisms often land around 30–100 ms.
Why this beats a trapezoid. With a trapezoid you guess . Guess low and every move is slower than it needs to be. Guess high and the motor saturates, and the mechanism falls further behind the profile as speed builds. Either way, the PID has to absorb the mismatch as error.
Expo's profile always asks for an acceleration the motor can produce at its current speed, because the profile is the motor model. The slot feedforwards (kS, kV, kA, kG) cancel the modeled behavior, and the PID only corrects disturbances and modeling error. Tracking error is much lower.
Slot kV/kA vs. Expo_kV/Expo_kA. They look alike but do different jobs:
| Parameter | Used by | Purpose |
|---|---|---|
Slot0Configs.kV | Closed-loop feedforward, every loop | Output per unit of commanded velocity |
Slot0Configs.kA | Closed-loop feedforward, every loop | Output per unit of commanded acceleration |
MotionMagicExpo_kV | Profile generator | Volts to hold a velocity. Sets top speed. |
MotionMagicExpo_kA | Profile generator | Volts to cause an acceleration. Sets starting acceleration and time constant. |
In voltage mode, slot kV/kA and Expo_kV/Expo_kA describe the same physics and should roughly match. In torque-current mode they come apart: slot kV is in Amps and usually near zero (the current loop has already removed back-EMF), while MotionMagicExpo_kV is still in Volts and still describes the motor's back-EMF. Set both independently.
1.4.2 Tuning Motion Magic Expo Parameters
Start from the kV and kA of a voltage-mode SysId run and refine on the robot. CTRE's advice is to start Expo_kV and Expo_kA higher than ideal. Too high only makes the profile slower, which is safe. Too low makes it ask for more than the motor can deliver, and the mechanism falls behind.
Tune the slot gains (kV, kA, kP, kD) first. Then:
-
Start values. Set
MotionMagicExpo_kV= slot kV andMotionMagicExpo_kA= slot kA (voltage mode). For a torque-current mechanism, use kV and kA from a voltage-mode SysId run on the same mechanism, or compute them with the formulas in §1.4.1. SetMotionMagicCruiseVelocity = 0(no cap). -
Add margin. Multiply both by 1.1–1.2. You give up a little speed, but the motor can always keep up. Trim it back later once you have data.
-
Log a long move in AdvantageScope or Tuner X:
ClosedLoopReference(profile position) andClosedLoopReferenceSlope(profile velocity)PositionandVelocityMotorVoltage(voltage mode) orTorqueCurrent(torque mode)
-
Check top speed (Expo_kV).
- Velocity falls further behind the reference as speed builds, with output saturated → Expo_kV is too low. The profile wants more speed than the motor has. Raise it until the traces line up.
- Velocity tracks, but motor voltage stays well below supply near top speed → Expo_kV is higher than needed. Lower it in ~5% steps to gain speed.
-
Check the start of the move (Expo_kA).
- Velocity lags the reference right from the start while output is saturated → Expo_kA is too low. Raise it.
- Velocity tracks and output stays well below saturation during the initial acceleration → Expo_kA is higher than needed. Lower it in small steps.
-
Cap top speed if needed. If the top speed is mechanically uncomfortable (vibration, chain whip), set
MotionMagicCruiseVelocitybelow . -
Test the worst cases:
- A tired battery (under 12.0 V resting). The profile slows down on its own. Confirm that tracking is still tight.
- The worst-case pose (arm horizontal, elevator fully extended). Gravity eats into the voltage available for motion.
- A short move, where the profile has to start slowing down almost as soon as it starts. This stresses deceleration. Errors here usually mean Expo_kA is too low.
1.4.3 Common Mistakes with Motion Magic Expo
-
Setting Expo_kV near zero in torque mode. Slot kV in torque mode is in Amps and often near zero, but
MotionMagicExpo_kVis still in Volts and still describes back-EMF. A tiny Expo_kV (the API minimum is 0.001) produces a profile far faster than the motor. The motor saturates immediately and you effectively get a step response. -
Leaving the defaults. 0.12 V/rps and 0.1 V/(rps/s) are generic placeholders. On a geared mechanism they describe a far faster motor than you have. Always set both.
-
Setting
MotionMagicAccelerationfor Expo. Expo silently ignores it. To limit acceleration, raise Expo_kA. Jerk cannot be limited at all, since the profile starts at full acceleration. If you need jerk limiting, use trapezoidal Motion Magic withMotionMagicJerk. -
Tuning the profile before the slot gains. If the closed loop can't track, you'll see error and wrongly blame Expo_kV. Tune the loop on slow setpoints first, then the profile.
-
Brownout surprises. The profile uses measured supply voltage, so if the bus sags to 10 V, top speed drops to for that moment. Usually harmless, but it can show up as velocity dips on power-hungry robots.
ClosedLoopReferenceshows the recomputed profile.