Class SwerveConfig

java.lang.Object
org.team1126.lib.swerve.config.SwerveConfig

public class SwerveConfig extends Object
Config builder for the SwerveAPI.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    double
    The maximum angular acceleration the robot is capable of in radians/second/second.
    double
    The default frame period for unused CAN signals in seconds.
    double
    The period to look ahead for discretizing chassis speeds in seconds.
    double
    The maximum angular velocity for driver input in radians/second.
    double
    Deadband to apply to driver angular velocity input.
    double
    Exponential power to apply to driver angular velocity input.
    double
    The maximum velocity for driver input in meters/second.
    double
    Deadband to apply to driver velocity input.
    double
    Exponential power to apply to driver velocity input.
    The IMU to use, generated by the SwerveIMUs class.
    Configurations for swerve modules.
    boolean
    If the move motors should have brake mode enabled.
    double[]
    Feed forward gains for move motors, as a tuple of [kS, kV].
    double
    The move gear ratio, in motor rotations/wheel rotation.
    double[]
    PID gains for move motors, as a tuple of [kP, kI, kD].
    double
    The stator current limit in amps for move motors.
    double
    The supply current limit in amps for move motors.
    double
    The period to update odometry in seconds.
    edu.wpi.first.math.Vector<edu.wpi.first.math.numbers.N3>
    Standard deviations for odometry.
    double
    The robot's main loop period in seconds.
    com.ctre.phoenix6.CANBus
    The CAN bus utilized by Phoenix devices.
    boolean
    If move motors should enable FOC.
    boolean
    true if Phoenix Pro is active on all devices used by the swerve API.
    boolean
    If turn motors should enable FOC.
    double
    The maximum acceleration the robot is capable of relevant to carpet slip in meters/second/second.
    double
    The maximum acceleration the robot is capable of relevant to motor torque in meters/second/second.
    boolean
    If the turn motors should have brake mode enabled.
    double
    The turn gear ratio, in motor rotations/module rotation.
    double[]
    PID gains for turn motors, as a tuple of [kP, kI, kD].
    double
    The stator current limit in amps for turn motors.
    double
    The supply current limit in amps for turn motors.
    double
    The minimum velocity required for a swerve module to accept a commanded output.
    double
    The maximum forward velocity the robot is capable of in meters/second.
    double
    The robot's nominal voltage.
    double
    The wheel diameter in meters.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    setBrakeMode(boolean move, boolean turn)
    Sets motor brake modes.
    setDriverProfile(double vel, double velExp, double velDeadband, double angularVel, double angularVelExp, double angularVelDeadband)
    Configures the profile to apply to speeds calculated using the driver's controller input.
    Sets the IMU to use.
    setLimits(double velocity, double velDeadband, double slipAccel, double torqueAccel, double angularAccel)
    Sets limits for the drivetrain.
    setMechanicalProperties(double moveRatio, double turnRatio, double wheelDiameter)
    Sets swerve gearing properties.
    Sets module configs.
    setMoveFF(double kS, double kV)
    Sets feed forward constants for move motors.
    setMovePID(double kP, double kI, double kD)
    Sets PID gains for move motors.
    setOdometryStd(double x, double y, double angular)
    Sets the standard deviations for pose estimation from module odometry.
    setPhoenixFeatures(com.ctre.phoenix6.CANBus canBus, boolean pro, boolean moveFOC, boolean turnFOC)
    Sets available features for Phoenix devices.
    setPowerProperties(double voltage, double moveStatorLimit, double moveSupplyLimit, double turnStatorLimit, double turnSupplyLimit)
    Sets power properties.
    setTimings(double period)
    Sets all timings utilized by the drivetrain.
    setTimings(double period, double odometry, double discretization, double defaultFramePeriod)
    Sets various timings utilized by the drivetrain.
    setTurnPID(double kP, double kI, double kD)
    Sets PID gains for turn motors.
    void
    Verifies the config as well as the config's modules.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • period

      public double period
      The robot's main loop period in seconds.
    • odometryPeriod

      public double odometryPeriod
      The period to update odometry in seconds.
    • discretizationPeriod

      public double discretizationPeriod
      The period to look ahead for discretizing chassis speeds in seconds.
    • defaultFramePeriod

      public double defaultFramePeriod
      The default frame period for unused CAN signals in seconds.
    • movePID

      public double[] movePID
      PID gains for move motors, as a tuple of [kP, kI, kD].
    • moveFF

      public double[] moveFF
      Feed forward gains for move motors, as a tuple of [kS, kV].
    • turnPID

      public double[] turnPID
      PID gains for turn motors, as a tuple of [kP, kI, kD].
    • moveBrakeMode

      public boolean moveBrakeMode
      If the move motors should have brake mode enabled.
    • turnBrakeMode

      public boolean turnBrakeMode
      If the turn motors should have brake mode enabled.
    • velocity

      public double velocity
      The maximum forward velocity the robot is capable of in meters/second.
    • velDeadband

      public double velDeadband
      The minimum velocity required for a swerve module to accept a commanded output.
    • slipAccel

      public double slipAccel
      The maximum acceleration the robot is capable of relevant to carpet slip in meters/second/second.
    • torqueAccel

      public double torqueAccel
      The maximum acceleration the robot is capable of relevant to motor torque in meters/second/second.
    • angularAccel

      public double angularAccel
      The maximum angular acceleration the robot is capable of in radians/second/second.
    • driverVel

      public double driverVel
      The maximum velocity for driver input in meters/second.
    • driverVelExp

      public double driverVelExp
      Exponential power to apply to driver velocity input.
    • driverVelDeadband

      public double driverVelDeadband
      Deadband to apply to driver velocity input.
    • driverAngularVel

      public double driverAngularVel
      The maximum angular velocity for driver input in radians/second.
    • driverAngularVelExp

      public double driverAngularVelExp
      Exponential power to apply to driver angular velocity input.
    • driverAngularVelDeadband

      public double driverAngularVelDeadband
      Deadband to apply to driver angular velocity input.
    • voltage

      public double voltage
      The robot's nominal voltage. Typically 12.0.
    • moveStatorLimit

      public double moveStatorLimit
      The stator current limit in amps for move motors.
    • moveSupplyLimit

      public double moveSupplyLimit
      The supply current limit in amps for move motors.
    • turnStatorLimit

      public double turnStatorLimit
      The stator current limit in amps for turn motors.
    • turnSupplyLimit

      public double turnSupplyLimit
      The supply current limit in amps for turn motors.
    • moveGearRatio

      public double moveGearRatio
      The move gear ratio, in motor rotations/wheel rotation.
    • turnGearRatio

      public double turnGearRatio
      The turn gear ratio, in motor rotations/module rotation.
    • wheelDiameter

      public double wheelDiameter
      The wheel diameter in meters.
    • odometryStdDevs

      public edu.wpi.first.math.Vector<edu.wpi.first.math.numbers.N3> odometryStdDevs
      Standard deviations for odometry.
    • imu

      The IMU to use, generated by the SwerveIMUs class.
    • phoenixCanBus

      public com.ctre.phoenix6.CANBus phoenixCanBus
      The CAN bus utilized by Phoenix devices.
    • phoenixPro

      public boolean phoenixPro
      true if Phoenix Pro is active on all devices used by the swerve API.
    • phoenixMoveFOC

      public boolean phoenixMoveFOC
      If move motors should enable FOC.
    • phoenixTurnFOC

      public boolean phoenixTurnFOC
      If turn motors should enable FOC.
    • modules

      public SwerveModuleConfig[] modules
      Configurations for swerve modules.
  • Constructor Details

    • SwerveConfig

      public SwerveConfig()
  • Method Details

    • setTimings

      public SwerveConfig setTimings(double period)
      Sets all timings utilized by the drivetrain. Shorthand for setTimings(double, double, double, double).
      Parameters:
      period - The robot's main loop period in seconds.
    • setTimings

      public SwerveConfig setTimings(double period, double odometry, double discretization, double defaultFramePeriod)
      Sets various timings utilized by the drivetrain.
      Parameters:
      period - The robot's main loop period in seconds.
      odometry - The period to update odometry in seconds.
      discretization - The period to look ahead for discretizing chassis speeds in seconds.
      defaultFramePeriod - The default frame period for unused CAN signals in seconds.
    • setMovePID

      public SwerveConfig setMovePID(double kP, double kI, double kD)
      Sets PID gains for move motors.
      Parameters:
      kP - Proportional gain constant.
      kI - Integral gain constant.
      kD - Derivative gain constant.
    • setMoveFF

      public SwerveConfig setMoveFF(double kS, double kV)
      Sets feed forward constants for move motors. A good starting point is a kV value of <Optimal Voltage> / <Max Velocity>. These values can be obtained via characterization using sysID with a real robot.
      Parameters:
      kS - Static gain constant.
      kV - Velocity gain constant.
    • setTurnPID

      public SwerveConfig setTurnPID(double kP, double kI, double kD)
      Sets PID gains for turn motors.
      Parameters:
      kP - Proportional gain constant.
      kI - Integral gain constant.
      kD - Derivative gain constant.
    • setBrakeMode

      public SwerveConfig setBrakeMode(boolean move, boolean turn)
      Sets motor brake modes.
      Parameters:
      move - If the move motors should have brake mode enabled.
      turn - If the turn motors should have brake mode enabled.
    • setLimits

      public SwerveConfig setLimits(double velocity, double velDeadband, double slipAccel, double torqueAccel, double angularAccel)
      Sets limits for the drivetrain.

      You may find more predictable behavior by setting these values slightly lower than the actual maximum capabilities of your robot. It is recommended that these values are found empirically using an actual robot. An easy way to do so is to configure infeasible limits, then analyze telemetry.
      Parameters:
      velocity - The maximum forward velocity the robot is capable of in meters/second. More specifically, the maximum velocity a move motor is capable of.
      velDeadband - The minimum velocity required for a swerve module to accept a commanded output.
      slipAccel - The maximum acceleration the robot is capable of relevant to carpet slip in meters/second/second.
      torqueAccel - The maximum acceleration the robot is capable of relevant to motor torque in meters/second/second.
      angularAccel - The maximum angular acceleration the robot is capable of in radians/second/second.
    • setDriverProfile

      public SwerveConfig setDriverProfile(double vel, double velExp, double velDeadband, double angularVel, double angularVelExp, double angularVelDeadband)
      Configures the profile to apply to speeds calculated using the driver's controller input.
      Parameters:
      vel - The maximum velocity for driver input in meters/second.
      velExp - Exponential power to apply to driver velocity input. 1.0 effectively disables.
      velDeadband - Deadband to apply to driver velocity input. 0.0 effectively disables.
      angularVel - The maximum angular velocity for driver input in radians/second.
      angularVelExp - Exponential power to apply to driver angular velocity input. 1.0 effectively disables.
      angularVelDeadband - Deadband to apply to driver angular velocity input. 0.0 effectively disables.
    • setPowerProperties

      public SwerveConfig setPowerProperties(double voltage, double moveStatorLimit, double moveSupplyLimit, double turnStatorLimit, double turnSupplyLimit)
      Sets power properties.
      Parameters:
      voltage - The robot's nominal voltage. Typically 12.0.
      moveStatorLimit - The stator current limit in amps for move motors.
      moveSupplyLimit - The supply current limit in amps for move motors. Note that this value is ignored for REV devices.
      turnStatorLimit - The stator current limit in amps for turn motors.
      turnSupplyLimit - The supply current limit in amps for turn motors. Note that this value is ignored for REV devices.
    • setMechanicalProperties

      public SwerveConfig setMechanicalProperties(double moveRatio, double turnRatio, double wheelDiameter)
      Sets swerve gearing properties.
      Parameters:
      moveRatio - The move gear ratio, in motor rotations/wheel rotation.
      turnRatio - The turn gear ratio, in motor rotations/module rotation.
      wheelDiameter - The wheel diameter in meters.
    • setOdometryStd

      public SwerveConfig setOdometryStd(double x, double y, double angular)
      Sets the standard deviations for pose estimation from module odometry.
      Parameters:
      x - The X axis standard deviation in meters.
      y - The Y axis standard deviation in meters.
      angular - The angular standard deviation in radians.
    • setIMU

      Sets the IMU to use.
      Parameters:
      imu - The IMU to use, generated by the SwerveIMUs class.
    • setPhoenixFeatures

      public SwerveConfig setPhoenixFeatures(com.ctre.phoenix6.CANBus canBus, boolean pro, boolean moveFOC, boolean turnFOC)
      Sets available features for Phoenix devices. For Phoenix Pro features to be utilized by the Swerve API, all devices must be activated, and intrinsically must all be Phoenix devices (Pigeon2 + TalonFX + CANcoder). This configuration option can be omitted safely if its features are not needed.
      Parameters:
      canBus - The CAN bus utilized by Phoenix devices.
      pro - true if Phoenix Pro is active on all CTRE devices used by the swerve API.
      moveFOC - If move motors should enable FOC. pro can still be false while enabling FOC, provided all move motors are still licensed.
      turnFOC - If turn motors should enable FOC. pro can still be false while enabling FOC, provided all turn motors are still licensed.
    • setModules

      public SwerveConfig setModules(SwerveModuleConfig... modules)
      Sets module configs. See SwerveModuleConfig.
      Parameters:
      modules - The configs of the swerve modules.
    • verify

      public void verify()
      Verifies the config as well as the config's modules. Throws an error if an issue is found.