Gray Matter LogoGray Matter Workshop

Motion Magic

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.

Key Concept: 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 complete Motion Magic reference, configuration examples, and advanced tuning techniques:

CTRE Motion Magic API Reference
⚙️ Motion Magic Tuning Steps

🦾 Position Mechanisms (Arms, Elevators)

1. Calculate Maximum Velocity:
  • Motor Speed: Krakens run around 100 RPS at maximum
  • Efficiency: Best used around 80% efficiency
  • Gear Ratio: Our 25:1 arm gearing reduces speed
  • maxVel = (100 / 25) * 0.8 = 3.2 RPS
2. Set Motion Magic Parameters:
  • Cruise Velocity: Use calculated max velocity
  • cruiseVel = 3.0; // conservative start
  • Acceleration: Start with 2x cruise velocity for smooth motion
  • Competition: Typically end up with 4x to 10x cruise velocity
  • acceleration = cruiseVel * 2.0; // smooth start

🌪️ Velocity Mechanisms (Flywheels, Shooters)

1. Calculate Maximum Velocity:
  • Motor Speed: Krakens run around 100 RPS at maximum
  • Efficiency: Best used around 80% efficiency
  • Direct Drive: Using Kraken encoder directly on flywheel
  • cruiseVel = 100 * 0.8 = 80 RPS
2. Set Motion Magic Parameters:
  • Cruise Velocity: Use calculated max velocity
  • cruiseVel = 80.0; // based on motor efficiency
  • Acceleration: Start with 2x cruise velocity for smooth motion
  • Competition: Typically end up with 4x to 10x cruise velocity
  • acceleration = cruiseVel * 2.0; // smooth start

💡 Why This Method Works:

By calculating cruise velocity based on motor specifications and efficiency, you set realistic motion limits that prevent oscillation and ensure smooth, achievable motion profiles. Starting with 2x acceleration provides smooth motion, while competition applications often require 4x to 10x cruise velocity for faster response.

📹 Motion Magic Tuning Tutorial

Watch this comprehensive tutorial on Motion Magic tuning techniques, parameter selection, and optimization strategies:

Motion Magic Implementation in Code

🔧 Motion Magic Configuration Example
Motion Magic Setup in Subsystem ConstructorJAVA

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
  • • Professional, smooth motion profiles

Loading file...

Code Walkthrough

Motion Magic Example Params for 25:1 Arm:

  • 25:1 Gearing: Krakens run ~100 RPS, so 4 RPS theoretical max at output
  • Cruise Velocity (2.0): Conservative start - can reach 4 RPS but load may reduces 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

Motion Magic gives us professional-grade position control! Next, we'll explore tuning methods to get optimal performance from our control algorithms.

⚖️ 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