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(ChassisAccelerations acceleration)
      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:
      acceleration - Acceleration of the robot
      Returns:
      Wheel force feedforwards to apply
    • calculate

      public final WheelForceCalculator.Feedforwards calculate(ChassisAccelerations acceleration, 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:
      acceleration - Acceleration of the robot
      centerOfRotation - Center of rotation
      Returns:
      Wheel force feedforwards to apply
    • calculate

      public final WheelForceCalculator.Feedforwards calculate(double dt, ChassisVelocities prev, ChassisVelocities current)
      Calculates wheel force feedforwards for the desired change in velocity. This can be used with either robot-centric or field-centric velocities; the returned force feedforwards will match in being robot-/field-centric.
      Parameters:
      dt - The change in time between the path setpoints
      prev - The previous ChassisVelocities setpoint of the path
      current - The new ChassisVelocities setpoint of the path
      Returns:
      Wheel force feedforwards to apply
    • calculate

      public final WheelForceCalculator.Feedforwards calculate(double dt, ChassisVelocities prev, ChassisVelocities current, Translation2d centerOfRotation)
      Calculates wheel force feedforwards for the desired change in velocity. This can be used with either robot-centric or field-centric velocities; the returned force feedforwards will match in being robot-/field-centric.
      Parameters:
      dt - The change in time between the path setpoints
      prev - The previous ChassisVelocities setpoint of the path
      current - The new ChassisVelocities setpoint of the path
      centerOfRotation - Center of rotation
      Returns:
      Wheel force feedforwards to apply