Gray Matter
WorkshopMotion Magic in Tuner X
WPILib 2027 is still in alpha: these pages change as the APIs settle.
LESSON 07

Motion Magic in Tuner X

Plain position control asks for the whole move at once. Motion Magic hands the loop a moving target instead, so the mechanism accelerates, cruises, and stops smoothly. The Slot 0 gains you already saved carry over unchanged.

7 minutes
You’ll need
  • Slot 0 gains you trust, saved in PID Tuning in Tuner X.
  • The same Signal & Control plot, still showing target and measurement.

What mechanism are you working on?

The lesson below is written for the one you pick. Switch back any time to read it for the other.

The feedback loop from the last lesson does not change. Motion Magic sits in front of it and moves the target for it. It walks that target from where the mechanism is to where you asked it to go, one small step at a time.

Two numbers describe the route. Cruise velocity caps the speed. Acceleration caps how fast the speed may change. A third number, jerk, rounds the corner between them, and it stays at zero for now.

Arm
Position profile
The target is an angle. Both cruise velocity and acceleration apply, and the profile plans its own stop so the mechanism arrives with no speed left.
Flywheel
Velocity profile
The target is a speed. Only acceleration applies, because there is no arrival to plan. The profile ramps the speed target instead of stepping it.

Set the first limits

Start slow enough to watch. A two-second move across the range is easy to read on the plot, and easy to stop by hand. You can always speed it up later.

Motion Magic configuration
  1. Open Control and change the request type to MotionMagicVoltageMotionMagicVelocityVoltage.
  2. Under the Motion Magic config section, enter a cruise velocity of 0.5 rotations per second and an acceleration of 1 rotation per second squared. Both are in mechanism rotations, not motor rotations. Tune them far more aggressively on a competition robot.
  3. Under the Motion Magic config section, enter an acceleration of 20 rotations per second squared. That is the only profile number this mode reads, and it is in mechanism rotations, not motor rotations. Tune it far more aggressively on a competition robot.
  4. Ask for a speed of 100rotations per second on the request itself. A flywheel's speed is the target you send, not a config you save.
  5. Leave jerk at zero. Zero means no jerk limit, and the profile stays a plain trapezoid.
  6. Apply the configuration with the download button.
  7. Run it and see the magic!
IGNORED CONFIG

Cruise velocity does nothing here

Tuner X shows a cruise velocity box for every mechanism and lets you set it. Motion Magic Velocity never reads it. Phoenix says so in its own source, in two places. The control mode does not use the CruiseVelocity config, and that config is documented as unused by Motion Magic Velocity modes.

Cruise velocity is a speed ceiling for a mechanism travelling to a position. The arm sets one. A flywheel is not going anywhere, so the speed you request is the speed, and acceleration is the only thing shaping how it gets there.

Raise the limits

By now the conservative profile should track cleanly on every run. Now find out how much the mechanism will take before it stops behaving.

  1. Raise acceleration one step at a time and watch the ramp. Stop when the measurement falls behind, the current spikes, or the structure shakes.
  2. Raise cruise velocity the same way, watching the flat section instead of the ramp.
  3. Run the longest move you will ever ask for, in both directions. The long move is what exposes cruise tracking.
  4. Run the shortest useful move too. It never cruises, so it tests the stop instead.
  5. Spin up from a standstill to your full speed. That is the longest ramp the wheel will ever do, and it is where the loop falls behind first.
  6. Then step between two speeds without stopping. A small change should arrive almost at once, and the wheel should settle without hunting.

Then back off from the ceiling you found. A profile tuned to the last volt on a fresh battery falls behind on a tired one. A loaded mechanism is slower than an empty one, and a match gives you both at once.

Around 80% of the ceiling you found is a good starting point.

Check your work

Run the same move five times from a standstill, alternating direction. You are done when the five traces sit on top of each other.

Spin up from rest to the same speed five times, letting the wheel stop in between. You are done when the five traces sit on top of each other.

Check

You should see

  • The measurement follows the reference as it speeds up, holds, and slows to a stop.
  • The measurement follows the reference up the ramp and holds with it.
  • The mechanism arrives once and stays there, with no bounce.
  • The wheel reaches the speed once and holds it, with no hunting.
  • Current peaks during acceleration and settles once the profile stops asking for more.
  • The long move and the short move both stop cleanly.
  • A spin-up from rest and a small step between speeds both settle.

Check yourself

What does Motion Magic change about the feedback loop you tuned last lesson?

You leave jerk at zero in the Motion Magic configs. What does that do to the profile?

Which units does Tuner X expect for cruise velocity and acceleration?

Which units does Tuner X expect for the flywheel's Motion Magic acceleration?

A short move ramps up, turns around, and comes back down without ever holding a flat speed. What should you change?

You ask for a speed just above the one the wheel already holds, and it arrives with no visible ramp. What should you change?

The measurement tracks the reference through the ramp, then sags below it for the whole cruise section, while motor voltage still has headroom. What do you do?

The measurement follows the reference up the ramp, then settles below the speed you asked for and stays there. Motor voltage still has headroom. What do you do?

The measurement lags the reference from the first moment of the move and never catches up. What comes first?

Pick an answer for each.