Class WheelForceCalculator

java.lang.Object
com.ctre.phoenix6.swerve.utility.WheelForceCalculator

public class WheelForceCalculator extends Object
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.

  • Constructor Details

    • WheelForceCalculator

      public WheelForceCalculator(Translation2d[] moduleLocations, double mass_kg, double moi_kg_m_sq)
      Constructs a new wheel force feedforward calculator for the given drivetrain characteristics.
      Parameters:
      moduleLocations - The drivetrain swerve module locations
      mass_kg - The mass of the robot in kg
      moi_kg_m_sq - The moment of inertia of the robot in kg m^2
    • WheelForceCalculator

      public WheelForceCalculator(Translation2d[] moduleLocations, Mass mass, MomentOfInertia moi)
      Constructs a new wheel force feedforward calculator for the given drivetrain characteristics.
      Parameters:
      moduleLocations - The drivetrain swerve module locations
      mass - The mass of the robot
      moi - The moment of inertia of the robot
  • Method Details

    • calculate

      public final WheelForceCalculator.Feedforwards calculate(double ax, double ay, double 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^2
      ay - Acceleration in the Y direction (left) in m/s^2
      alpha - 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^2
      ay - Acceleration in the Y direction (left) in m/s^2
      alpha - Angular acceleration in rad/s^2
      centerOfRotation - Center of rotation
      Returns:
      Wheel force feedforwards to apply
    • 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^2
      ay - Acceleration in the Y direction (left) in m/s^2
      alpha - Angular acceleration in rad/s^2
      Returns:
      Wheel force feedforwards to apply
    • 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^2
      ay - Acceleration in the Y direction (left) in m/s^2
      alpha - Angular acceleration in rad/s^2
      centerOfRotation - 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 setpoints
      prev - The previous ChassisSpeeds setpoint of the path
      current - 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 setpoints
      prev - The previous ChassisSpeeds setpoint of the path
      current - The new ChassisSpeeds setpoint of the path
      centerOfRotation - Center of rotation
      Returns:
      Wheel force feedforwards to apply