Package com.marslib.swerve
Class SwerveSetpointGenerator
java.lang.Object
com.marslib.swerve.SwerveSetpointGenerator
Takes a prior setpoint (ChassisSpeeds), a desired setpoint (from a driver, or from a path
follower), and outputs a new setpoint that respects all of the kinematic constraints on module
rotation speed and wheel velocity/acceleration. By generating a new setpoint every iteration, the
robot will converge to the desired setpoint quickly while avoiding any intermediate state that is
kinematically infeasible (and can result in wheel slip or robot heading drift as a result).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic class -
Constructor Summary
ConstructorsConstructorDescriptionSwerveSetpointGenerator(edu.wpi.first.math.kinematics.SwerveDriveKinematics kinematics) -
Method Summary
Modifier and TypeMethodDescriptionprotected doublefindDriveMaxS(double x0, double y0, double f0, double x1, double y1, double f1, double maxVelStep, int maxIterations) Computes the maximum linear acceleration scalar \( s_{max} \) for the driving vector wheel slip threshold.protected doublefindSteeringMaxS(double x0, double y0, double f0, double x1, double y1, double f1, double maxDeviation, int maxIterations) Computes the maximum positional scalar \( s_{max} \) for the steering rotation of a Swerve Module.generateSetpoint(SwerveSetpointGenerator.KinematicLimits limits, SwerveSetpointGenerator.SwerveSetpoint prevSetpoint, edu.wpi.first.math.kinematics.ChassisSpeeds desiredState, double dt)
-
Constructor Details
-
SwerveSetpointGenerator
public SwerveSetpointGenerator(edu.wpi.first.math.kinematics.SwerveDriveKinematics kinematics)
-
-
Method Details
-
findSteeringMaxS
protected double findSteeringMaxS(double x0, double y0, double f0, double x1, double y1, double f1, double maxDeviation, int maxIterations) Computes the maximum positional scalar \( s_{max} \) for the steering rotation of a Swerve Module.Utilizes
findRootto determine the exact timestamp bound where the change in module orientation \( d\theta \) precisely equals the physical limitmaxDeviation. The equation evaluates \( f(\theta) = \text{unwrap}(\theta) - \text{offset} = 0 \).- Parameters:
x0- Prior structural X (Cosine mapping vector)y0- Prior structural Y (Sine mapping vector)f0- Previous rotation radiansx1- Desired structural Xy1- Desired structural Yf1- Desired rotation radiansmaxDeviation- The structural Max Steering velocity * \( dt \)maxIterations- Bisection cut-off depth.- Returns:
- The maximum safe step multiplier scale.
-
findDriveMaxS
protected double findDriveMaxS(double x0, double y0, double f0, double x1, double y1, double f1, double maxVelStep, int maxIterations) Computes the maximum linear acceleration scalar \( s_{max} \) for the driving vector wheel slip threshold.Calculates the boundary threshold solving for: \( \sqrt{V_x^2 + V_y^2} - (\text{previous magnitude} + \text{max allowed acceleration step}) = 0 \).
- Parameters:
x0- Prior magnitude X velocityy0- Prior magnitude Y velocityf0- Previous hypotenuse sum velocityx1- Desired magnitude X velocityy1- Desired magnitude Y velocityf1- Desired hypotenuse sum velocitymaxVelStep- Absolute hardcap velocity slip threshold (\( \mu \cdot 9.81 \cdot dt \))maxIterations- Limits Newton iteration overloop.- Returns:
- A restricted translation scalar multiplier [0.0, 1.0].
-
generateSetpoint
public SwerveSetpointGenerator.SwerveSetpoint generateSetpoint(SwerveSetpointGenerator.KinematicLimits limits, SwerveSetpointGenerator.SwerveSetpoint prevSetpoint, edu.wpi.first.math.kinematics.ChassisSpeeds desiredState, double dt)
-