Class SwerveRateLimiter
- All Implemented Interfaces:
Tunable
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
ConstructorsConstructorDescriptionCreates a newSwerveRateLimiterand publishes all acceleration limits to NetworkTables for live tuning. -
Method Summary
Modifier and TypeMethodDescriptionlimit(ChassisSpeeds wantedSpeedsRobotRelative, double customSkidLimit) Limits a desired robot-relative chassis velocity based on physical acceleration, tilt, and skid constraints, producing a safe and achievableChassisSpeeds.voidupdate(ChassisSpeeds robotRelative) Updates the current robot-relative chassis velocity used as the basis for acceleration limiting.
-
Constructor Details
-
SwerveRateLimiter
public SwerveRateLimiter()Creates a newSwerveRateLimiterand 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
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
Limits a desired robot-relative chassis velocity based on physical acceleration, tilt, and skid constraints, producing a safe and achievableChassisSpeeds.The limiting process operates in discrete time (20 ms) and applies several sequential constraints:
- Physical acceleration limit: Caps acceleration in the direction of current motion based on available traction and remaining headroom to max speed.
- Tilt prevention: Restricts directional acceleration components to prevent excessive forward, backward, or lateral tilting.
- 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
ChassisSpeedsrepresenting the limited, physically achievable robot-relative velocities for the next control step
-