Package frc.robot.lib.BLine
Class ChassisRateLimiter
java.lang.Object
frc.robot.lib.BLine.ChassisRateLimiter
A utility class that limits the rate of change of chassis speeds for smooth motion control.
This class provides acceleration limiting for both translational and rotational velocities in field-relative coordinates. It ensures that the robot's movement remains within physical constraints and prevents sudden changes in velocity that could cause wheel slip or mechanical stress.
The limiter operates in two phases:
- Velocity limiting: Clamps the desired speeds to maximum allowed velocities
- Acceleration limiting: Limits the rate of change from the previous velocity state
Example usage:
ChassisSpeeds limited = ChassisRateLimiter.limit(
desiredSpeeds,
lastSpeeds,
0.02, // 20ms loop time
4.0, // max translational acceleration (m/s²)
8.0, // max angular acceleration (rad/s²)
5.0, // max translational velocity (m/s)
Math.PI * 2 // max angular velocity (rad/s)
);
- See Also:
-
ChassisSpeeds
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic edu.wpi.first.math.kinematics.ChassisSpeedslimit(edu.wpi.first.math.kinematics.ChassisSpeeds desiredSpeeds, edu.wpi.first.math.kinematics.ChassisSpeeds lastSpeeds, double dt, double maxTranslationalAccelerationMetersPerSec2, double maxAngularAccelerationRadiansPerSec2, double maxTranslationalVelocityMetersPerSec, double maxAngularVelocityRadiansPerSec) Limits the chassis speeds to respect both velocity and acceleration constraints.
-
Constructor Details
-
ChassisRateLimiter
public ChassisRateLimiter()
-
-
Method Details
-
limit
public static edu.wpi.first.math.kinematics.ChassisSpeeds limit(edu.wpi.first.math.kinematics.ChassisSpeeds desiredSpeeds, edu.wpi.first.math.kinematics.ChassisSpeeds lastSpeeds, double dt, double maxTranslationalAccelerationMetersPerSec2, double maxAngularAccelerationRadiansPerSec2, double maxTranslationalVelocityMetersPerSec, double maxAngularVelocityRadiansPerSec) Limits the chassis speeds to respect both velocity and acceleration constraints.This method first applies velocity limits to clamp the desired speeds, then applies acceleration limits based on the time delta and previous speeds. The acceleration limiting preserves the direction of the desired velocity change while constraining its magnitude.
If
dt <= 0, only velocity limiting is applied and acceleration limiting is skipped.- Parameters:
desiredSpeeds- The target chassis speeds to achieve. This object may be modified if velocity limiting is applied.lastSpeeds- The chassis speeds from the previous control loop iteration.dt- The time delta since the last call, in seconds. Used for acceleration calculations. If zero or negative, only velocity limiting is applied.maxTranslationalAccelerationMetersPerSec2- The maximum allowed translational acceleration in meters per second squared. Must be positive.maxAngularAccelerationRadiansPerSec2- The maximum allowed angular acceleration in radians per second squared. Must be positive.maxTranslationalVelocityMetersPerSec- The maximum allowed translational velocity in meters per second. Set to 0 or negative to disable velocity limiting.maxAngularVelocityRadiansPerSec- The maximum allowed angular velocity in radians per second. Set to 0 or negative to disable velocity limiting.- Returns:
- A new
ChassisSpeedsobject with velocities constrained to the specified limits. The returned speeds will not exceed the maximum velocities and the change fromlastSpeedswill not exceed the maximum accelerations.
-