Gray Matter LogoGray Matter Workshop

Advanced: Profiled Drive to Point

Profiled Path Following with Feedforward Control

The advanced DriveToPoint command combines motion profiling with feedforward control to achieve smooth, predictable autonomous movement. Instead of relying solely on PID feedback, this approach plans a velocity profile and proactively applies the forces needed to follow it.

Key Concept: Feedforward control anticipates what forces are needed based on the planned trajectory, while feedback (PID) handles small corrections for disturbances. Together, they create smooth, accurate autonomous navigation.

Motion Profiling Fundamentals

What is Motion Profiling?

Motion profiling generates smooth trajectories that respect your robot's physical capabilities. Instead of jerky movements from instant velocity changes, profiled paths smoothly accelerate, cruise at maximum speed, then decelerate to the target.

⚔ Acceleration Phase

Ramps up from current velocity to maximum velocity using controlled acceleration (4 m/s²)

šŸš€ Cruise Phase

Maintains maximum velocity (4.3 m/s) for the bulk of the journey when possible

šŸŽÆ Deceleration Phase

Smoothly brakes to reach the target position with zero velocity

Key Constraints

  • Max Velocity: 4.3 m/s (translation), Ļ€ rad/s (rotation)
  • Max Acceleration: 4 m/s² (translation), 2Ļ€ rad/s² (rotation)
  • Benefits: Prevents wheel slip, reduces mechanical stress, more predictable behavior

Tuning Max Velocity and Acceleration

Finding the Right Constraints

Setting appropriate velocity and acceleration constraints is crucial for reliable path following. These values need to be conservative enough that your robot can actually track them while still being fast enough for competitive performance.

šŸŽļø Maximum Velocity (kMaxV)

Set to ~90% of your robot's maximum speed

Why not 100%? This headroom allows your feedback controller to "catch up" if the robot falls behind the planned trajectory. Without this margin, you can't correct tracking errors.

Example: If max speed is 4.8 m/s
Set kMaxV = 4.3 m/s (90%)

⚔ Maximum Acceleration (kMaxAccel)

Set to a value that gets you close to max speed in ~1 second

Start with kMaxV as your initial guess, then tune by graphing actual velocity against target velocity. Reduce if your robot can't track the trajectory.

Example: kMaxV = 4.3 m/s
Start with kMaxAccel = 4.0 m/s²

šŸ“Š Validation Method: Graph Velocity Tracking

The best way to validate your constraints is to log and graph your robot's actual velocity against the planned trajectory velocity:

  1. Enable logging for both setpoint.speeds (planned) and actual chassis speeds
  2. Run your DriveToPoint command and capture data using AdvantageScope
  3. Graph both velocities over time - they should track closely
  4. If actual velocity lags significantly behind planned velocity, reduce kMaxAccel
  5. If actual velocity consistently exceeds planned velocity, you have headroom to increase constraints

Goal: Actual velocity should closely follow planned velocity with minimal lag

Feedforward vs Feedback Control

Understanding the Dual Control Strategy

The basic DriveToPoint command uses only feedback control (PID) - it measures error and reacts to it. The advanced version adds feedforward control - it anticipates what forces are needed before errors occur.

AspectBasic (Feedback Only)Advanced (Feedforward + Feedback)
Control TypeReactive - responds after error occursProactive + Reactive - anticipates needs and corrects disturbances
Path PlanningNone - direct to targetGenerates smooth trajectory with velocity profiles
PID TargetFinal target position (large errors)Moving setpoint on trajectory (small errors)
Force ApplicationOnly from PID correctionsPlanned forces + PID corrections
Motion QualityCan be jerky, oscillation proneSmooth, predictable, minimal oscillation

šŸš— Car Driving Analogy

Feedback Only: Like driving by only looking at lane lines and correcting when you drift. You're always reacting to errors after they happen.

Feedforward: Like knowing you need to turn the steering wheel before the curve based on the road ahead. You're anticipating what's needed.

Combined Approach: You plan your steering based on the road ahead (feedforward), but still make small corrections if wind pushes you off course (feedback).

Setpoint Tracking

Following a Trajectory vs Targeting an Endpoint

The key innovation in the advanced approach is using moving setpoints from the trajectory instead of just the final target position.

āŒ Basic Approach

āœ… Advanced Approach

Why This Matters

  • āœ… Smaller Errors: PID only needs to keep robot on the planned path, not correct for entire distance to target
  • āœ… Smoother Control: Setpoint moves gradually along trajectory, creating gentle corrections
  • āœ… Less Oscillation: Smaller errors mean less aggressive PID corrections and overshoot
  • āœ… Predictable Behavior: Robot follows a planned path instead of taking unpredictable routes

Wheel Force Feedforwards

Understanding Force-Based Control

The advanced DriveToPoint calculates specific forces to apply to each swerve module. This allows the robot to anticipate and execute the accelerations needed to follow the planned trajectory.

What are Wheel Forces?

When you command a swerve drivetrain to accelerate or turn, each individual wheel module needs to apply specific forces. The WheelForceCalculator determines exactly how much force each wheel should generate based on:

  • • The desired change in velocity (from trajectory)
  • • Robot's mass and moment of inertia (MOI)
  • • Each wheel's position relative to robot center
  • • Required acceleration to stay on trajectory

How It Works

  1. Calculate velocity change needed (current setpoint - previous setpoint)
  2. Divide by time step (dt) to get required acceleration
  3. Account for robot mass and moment of inertia (MOI parameter)
  4. Distribute forces across all wheel modules
  5. Return X and Y force arrays for each wheel

Phoenix 6 Integration

CTRE's Phoenix 6 API accepts force feedforwards directly:

šŸ’” Tuning: The MOI Parameter

The moment of inertia (MOI) parameter represents your robot's resistance to rotation. Higher MOI means more force is needed for rotational changes.

For guidance on estimating your robot's MOI, see Choreo's MOI estimation guide.

Workshop Implementation

Profiled DriveToPoint Code

View the complete implementation in the workshop code repository. The pull request shows the profiled path following with feedforward control.

Loading file...

šŸŽÆ When to Use Profiled Paths

āœ… Best Use Cases

  • • Autonomous Routines: Smooth, predictable movement without overshoot
  • • High-Speed Navigation: Safely reach maximum velocity without wheel slip
  • • Precise Positioning: Minimal oscillation when reaching scoring positions
  • • Teleop Assists: Drive-to-position helpers that feel smooth to drivers

āš ļø When Basic Might Be Enough

  • • Short Distances: Quick corrections where acceleration phase is minimal
  • • Learning/Testing: Understanding PID fundamentals before adding complexity
  • • Simple Teleop Assists: Driver-controlled movements with minimal autonomy