Package com.ctre.phoenix6.swerve.utility
Class WheelForceCalculator
java.lang.Object
com.ctre.phoenix6.swerve.utility.WheelForceCalculator
Calculates wheel force feedforwards for a
SwerveDrivetrain.
Wheel force feedforwards can be used to improve accuracy of path
following in regions of acceleration.
Many path planning libraries (such as PathPlanner and Choreo) already provide per-module force feedforwards, which should be preferred over this class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classWheel force feedforwards to apply to a swerve drivetrain. -
Constructor Summary
ConstructorsConstructorDescriptionWheelForceCalculator(Translation2d[] moduleLocations, double mass_kg, double moi_kg_m_sq) Constructs a new wheel force feedforward calculator for the given drivetrain characteristics.WheelForceCalculator(Translation2d[] moduleLocations, Mass mass, MomentOfInertia moi) Constructs a new wheel force feedforward calculator for the given drivetrain characteristics. -
Method Summary
Modifier and TypeMethodDescriptioncalculate(double ax, double ay, double alpha) Calculates wheel force feedforwards for the desired robot acceleration.calculate(double ax, double ay, double alpha, Translation2d centerOfRotation) Calculates wheel force feedforwards for the desired robot acceleration.calculate(double dt, ChassisSpeeds prev, ChassisSpeeds current) Calculates wheel force feedforwards for the desired change in speeds.calculate(double dt, ChassisSpeeds prev, ChassisSpeeds current, Translation2d centerOfRotation) Calculates wheel force feedforwards for the desired change in speeds.calculate(LinearAcceleration ax, LinearAcceleration ay, AngularAcceleration alpha) Calculates wheel force feedforwards for the desired robot acceleration.calculate(LinearAcceleration ax, LinearAcceleration ay, AngularAcceleration alpha, Translation2d centerOfRotation) Calculates wheel force feedforwards for the desired robot acceleration.
-
Constructor Details
-
WheelForceCalculator
Constructs a new wheel force feedforward calculator for the given drivetrain characteristics.- Parameters:
moduleLocations- The drivetrain swerve module locationsmass_kg- The mass of the robot in kgmoi_kg_m_sq- The moment of inertia of the robot in kg m^2
-
WheelForceCalculator
Constructs a new wheel force feedforward calculator for the given drivetrain characteristics.- Parameters:
moduleLocations- The drivetrain swerve module locationsmass- The mass of the robotmoi- The moment of inertia of the robot
-
-
Method Details
-
calculate
Calculates wheel force feedforwards for the desired robot acceleration. This can be used with either robot-centric or field-centric accelerations; the returned force feedforwards will match in being robot-/field-centric.- Parameters:
ax- Acceleration in the X direction (forward) in m/s^2ay- Acceleration in the Y direction (left) in m/s^2alpha- Angular acceleration in rad/s^2- Returns:
- Wheel force feedforwards to apply
-
calculate
public final WheelForceCalculator.Feedforwards calculate(double ax, double ay, double alpha, Translation2d centerOfRotation) Calculates wheel force feedforwards for the desired robot acceleration. This can be used with either robot-centric or field-centric accelerations; the returned force feedforwards will match in being robot-/field-centric.- Parameters:
ax- Acceleration in the X direction (forward) in m/s^2ay- Acceleration in the Y direction (left) in m/s^2alpha- Angular acceleration in rad/s^2centerOfRotation- Center of rotation- Returns:
- Wheel force feedforwards to apply
-
calculate
public final WheelForceCalculator.Feedforwards calculate(LinearAcceleration ax, LinearAcceleration ay, AngularAcceleration alpha) Calculates wheel force feedforwards for the desired robot acceleration. This can be used with either robot-centric or field-centric accelerations; the returned force feedforwards will match in being robot-/field-centric.- Parameters:
ax- Acceleration in the X direction (forward) in m/s^2ay- Acceleration in the Y direction (left) in m/s^2alpha- Angular acceleration in rad/s^2- Returns:
- Wheel force feedforwards to apply
-
calculate
public final WheelForceCalculator.Feedforwards calculate(LinearAcceleration ax, LinearAcceleration ay, AngularAcceleration alpha, Translation2d centerOfRotation) Calculates wheel force feedforwards for the desired robot acceleration. This can be used with either robot-centric or field-centric accelerations; the returned force feedforwards will match in being robot-/field-centric.- Parameters:
ax- Acceleration in the X direction (forward) in m/s^2ay- Acceleration in the Y direction (left) in m/s^2alpha- Angular acceleration in rad/s^2centerOfRotation- Center of rotation- Returns:
- Wheel force feedforwards to apply
-
calculate
public final WheelForceCalculator.Feedforwards calculate(double dt, ChassisSpeeds prev, ChassisSpeeds current) Calculates wheel force feedforwards for the desired change in speeds. This can be used with either robot-centric or field-centric speeds; the returned force feedforwards will match in being robot-/field-centric.- Parameters:
dt- The change in time between the path setpointsprev- The previous ChassisSpeeds setpoint of the pathcurrent- The new ChassisSpeeds setpoint of the path- Returns:
- Wheel force feedforwards to apply
-
calculate
public final WheelForceCalculator.Feedforwards calculate(double dt, ChassisSpeeds prev, ChassisSpeeds current, Translation2d centerOfRotation) Calculates wheel force feedforwards for the desired change in speeds. This can be used with either robot-centric or field-centric speeds; the returned force feedforwards will match in being robot-/field-centric.- Parameters:
dt- The change in time between the path setpointsprev- The previous ChassisSpeeds setpoint of the pathcurrent- The new ChassisSpeeds setpoint of the pathcenterOfRotation- Center of rotation- Returns:
- Wheel force feedforwards to apply
-