Heads up: WPILib 2027 is still in alpha. These pages are changing quickly and aren't stable or finished yet — expect edits as the APIs settle.
Gray Matter LogoGray Matter Workshop

Motion Magic

KEY CONCEPT

Motion Magic: Profiled Motion Control

Motion Magic builds on PID control by adding smooth acceleration and deceleration profiles. This prevents jerky movements and reduces mechanical stress while maintaining precise positioning.

↳ TAKEAWAY

Motion Magic automatically generates smooth velocity profiles to reach target positions with controlled acceleration.

Understanding Motion Magic Profiles

Trapezoidal Profile

Motion Magic creates a trapezoidal velocity profile with three phases:

1. Acceleration: Ramp up to cruise velocity
2. Cruise: Maintain constant max velocity
3. Deceleration: Smoothly brake to target

Key Parameters

Motion Magic Cruise Velocity

Maximum velocity during cruise phase (rotations/second)

Motion Magic Acceleration

Rate of acceleration/deceleration (rotations/second²)

Motion Magic Jerk

Rate of change of acceleration (rotations/second³)

Official Motion Magic Documentation

For the full Motion Magic reference and configuration examples:

CTRE Motion Magic API Reference
Motion Magic Tuning Steps

Position Mechanisms (Arms, Elevators)

1. Calculate Maximum Velocity:
  • Motor Speed:The Kraken X44 runs about 125 RPS at maximum (CTRE's dyno measures ~129)
  • Efficiency: Best used around 80% efficiency
  • Gear Ratio: Our 25:1 arm gearing reduces speed
  • maxVel = (125 / 25) * 0.8 = 4.0 RPS
2. Set Motion Magic Parameters:
  • Cruise Velocity: Use calculated max velocity
  • cruiseVel = 2.0; // conservative start (calculated max is 4.0)
  • Acceleration: Start with 2x–4x cruise velocity for smooth motion (the workshop example uses 4x)
  • Competition: Typically end up with 4x to 10x cruise velocity
  • acceleration = cruiseVel * 4.0; // = 8.0, matches the example

Velocity Mechanisms (Flywheels, Shooters)

1. Calculate Maximum Velocity:
  • Motor Speed:The Kraken X44 runs about 125 RPS at maximum (CTRE's dyno measures ~129)
  • Efficiency: Best used around 80% efficiency
  • Direct Drive: Using Kraken encoder directly on flywheel
  • maxVel = 125 * 0.8 = 100 RPS
2. Set Motion Magic Parameters:
  • Target Velocity:Use calculated max velocity (for a flywheel, the setpoint IS the target speed; there's no separate cruise phase)
  • targetVel = 80.0; // comfortably under that ceiling
  • Acceleration: Start with 2x target velocity for smooth spin-up
  • Competition: Typically end up with 4x to 10x cruise velocity
  • acceleration = cruiseVel * 2.0; // smooth start

Why This Method Works:

Calculating cruise velocity from motor specs and efficiency gives you motion limits the mechanism can actually hit, so the profile stays smooth instead of oscillating. Start with 2x acceleration for smooth motion; competition robots often end up at 4x to 10x cruise velocity for faster response.

Motion Magic Tuning Tutorial

This video walks through Motion Magic tuning and how to pick each parameter:

Motion Magic Implementation in Code

Motion Magic Configuration Example

Workshop Implementation: Motion Magic

Before & After: Implementation

Before

  • • PID position control with PositionVoltage
  • • Instant acceleration to target
  • • Potential mechanical stress from jerky movements
  • • No velocity planning or profiling
  • • Abrupt start/stop motions

After

  • • Motion Magic profiled motion with MotionMagicVoltage
  • • Smooth acceleration and deceleration curves
  • • Reduced mechanical stress and wear
  • • Configurable cruise velocity and acceleration
  • • Smooth, predictable motion profiles

Loading file...

Code Walkthrough

Motion Magic Example Params for 25:1 Arm:

  • 25:1 Gearing: The Kraken X44 runs ~125 RPS, so 5 RPS theoretical max at output
  • Cruise Velocity (2.0): Conservative start: can reach 5 RPS but load may reduce performance
  • Acceleration (8.0): How quickly to reach cruise speed
  • Jerk (80.0): Smoothness of acceleration changes
  • MotionMagicVoltage: Replaces PositionVoltage for profiled control

Enhanced Features:

  • Setpoint Detection: Checks both position AND velocity
  • Smooth Motion: Eliminates jerky arm movements
  • Mechanical Safety: Reduces stress on gearboxes
  • Predictable Timing: Known motion duration

The arm now follows a smooth, profiled path to each target. Next, we cover tuning methods to get the best performance out of these controllers.

Motion Magic vs Basic PID

When to Use Basic PID:

  • Simple positioning tasks
  • Continuous control (like maintaining angle)
  • When speed of response is critical
  • Mechanisms with very low inertia

When to Use Motion Magic:

  • Large, heavy mechanisms (arms, elevators)
  • When smooth motion is important
  • Preventing mechanical stress
  • Predictable motion timing needed
NOTE · API STATUS

This is the WPILib 2027 alpha

The code on this page targets the WPILib 2027 alpha stack — Commands v3 + OpModes (GradleRIO 2027.0.0-alpha-6, Phoenix 6 26.50.0-alpha-1) on Java 25 and SystemCore — so exact APIs may still shift between alpha builds. This page was last verified against alpha-6 in July 2026.
CHECKPOINT · 6 ITEMS