Class SwerveRateLimiter

java.lang.Object
frc.robot.subsystems.swerve.util.SwerveRateLimiter
All Implemented Interfaces:
Tunable

@NullMarked public class SwerveRateLimiter extends Object implements Tunable
Applies rate limiting to robot-relative swerve chassis commands to ensure physically achievable, stable, and predictable motion.

This limiter constrains translational acceleration using a multi-stage process inspired by Team 1690's swerve control methodology:

  • Limits forward acceleration based on current speed and remaining headroom to maximum velocity
  • Clamps directional acceleration to prevent excessive robot tilt
  • Caps overall acceleration magnitude to avoid wheel slip and skidding

The limiter operates in discrete time (20 ms control loop) and should be called once per cycle. The current robot velocity must be provided via update(ChassisSpeeds) before calling limit(ChassisSpeeds, double).

All limits are exposed via NetworkTables under /SwerveRateLimiter/* and may be tuned at runtime. Diagnostic values are published to AdvantageKit logs for visualization and debugging.

Rotational velocity (omegaRadiansPerSecond) is passed through unchanged and is not subject to rate limiting.

Usage pattern:


 limiter.update(currentRobotRelativeSpeeds);
 ChassisSpeeds safeSpeeds = limiter.limit(desiredSpeeds);
 

Based on concepts presented by FRC Team 1690: https://www.youtube.com/watch?v=vUtVXz7ebEE

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new SwerveRateLimiter and publishes all acceleration limits to NetworkTables for live tuning.
  • Method Summary

    Modifier and Type
    Method
    Description
    limit(ChassisSpeeds wantedSpeedsRobotRelative, double customSkidLimit)
    Limits a desired robot-relative chassis velocity based on physical acceleration, tilt, and skid constraints, producing a safe and achievable ChassisSpeeds.
    void
    update(ChassisSpeeds robotRelative)
    Updates the current robot-relative chassis velocity used as the basis for acceleration limiting.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SwerveRateLimiter

      public SwerveRateLimiter()
      Creates a new SwerveRateLimiter and publishes all acceleration limits to NetworkTables for live tuning.

      Any updates received via NetworkTables will immediately modify the corresponding limit used by the rate limiter.

  • Method Details

    • update

      public void update(ChassisSpeeds robotRelative)
      Updates the current robot-relative chassis velocity used as the basis for acceleration limiting.

      This method should be called once per control loop using velocity data from odometry or state estimation before calling limit(ChassisSpeeds, double).

      Parameters:
      robotRelative - the current robot-relative chassis speeds
    • limit

      public ChassisSpeeds limit(ChassisSpeeds wantedSpeedsRobotRelative, double customSkidLimit)
      Limits a desired robot-relative chassis velocity based on physical acceleration, tilt, and skid constraints, producing a safe and achievable ChassisSpeeds.

      The limiting process operates in discrete time (20 ms) and applies several sequential constraints:

      1. Physical acceleration limit: Caps acceleration in the direction of current motion based on available traction and remaining headroom to max speed.
      2. Tilt prevention: Restricts directional acceleration components to prevent excessive forward, backward, or lateral tilting.
      3. Skid prevention: Limits the overall translational acceleration magnitude to avoid wheel slip.

      The resulting acceleration is integrated over one control loop period and added to the current velocity to produce the final commanded chassis speeds.

      Rotational velocity (omegaRadiansPerSecond) is passed through unchanged and is not subject to acceleration limiting.

      Parameters:
      wantedSpeedsRobotRelative - the desired robot-relative chassis speeds (vx, vy, omega)
      Returns:
      a new ChassisSpeeds representing the limited, physically achievable robot-relative velocities for the next control step