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
1// In your subsystem constructor
2public ArmSubsystem() {
3    TalonFXConfiguration config = new TalonFXConfiguration();
4
5    // PID Configuration (same as before)
6    Slot0Configs slot0 = config.Slot0;
7    slot0.kP = 24.0;    // Proportional gain
8    slot0.kI = 0.0;     // Integral gain
9    slot0.kD = 0.1;     // Derivative gain
10
11    // Feedforward gains
12    slot0.kS = 0.25;    // Static friction compensation
13    slot0.kG = 0.12;    // Gravity compensation
14    slot0.kV = 0.12;    // Velocity feedforward
15    slot0.kA = 0.01;    // Acceleration feedforward
16
17    // Motion Magic Configuration
18    MotionMagicConfigs motionMagic = config.MotionMagic;
19    motionMagic.MotionMagicCruiseVelocity = 2.0;    // 2 rot/s max velocity
20    motionMagic.MotionMagicAcceleration = 8.0;      // 8 rot/s² acceleration
21    motionMagic.MotionMagicJerk = 80.0;             // 80 rot/s³ jerk limit
22
23    motor.getConfigurator().apply(config);
24}
25
26// Method to set target position with Motion Magic
27public void setTargetPosition(double positionRotations) {
28    motor.setControl(motionMagicRequest.withPosition(positionRotations));
29}
30
31

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

💡 Next Step: 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

We use PostHog analytics with user-identifying features disabled to improve our site. Data is aggregated and not used to identify you. You can accept or reject analytics.