Package org.team1126.lib.swerve.config
Class SwerveConfig
java.lang.Object
org.team1126.lib.swerve.config.SwerveConfig
Config builder for the
SwerveAPI.-
Field Summary
FieldsModifier and TypeFieldDescriptiondoubleThe maximum angular acceleration the robot is capable of in radians/second/second.doubleThe default frame period for unused CAN signals in seconds.doubleThe period to look ahead for discretizing chassis speeds in seconds.doubleThe maximum angular velocity for driver input in radians/second.doubleDeadband to apply to driver angular velocity input.doubleExponential power to apply to driver angular velocity input.doubleThe maximum velocity for driver input in meters/second.doubleDeadband to apply to driver velocity input.doubleExponential power to apply to driver velocity input.The IMU to use, generated by theSwerveIMUsclass.Configurations for swerve modules.booleanIf the move motors should have brake mode enabled.double[]Feed forward gains for move motors, as a tuple of[kS, kV].doubleThe move gear ratio, in motor rotations/wheel rotation.double[]PID gains for move motors, as a tuple of[kP, kI, kD].doubleThe stator current limit in amps for move motors.doubleThe supply current limit in amps for move motors.doubleThe period to update odometry in seconds.edu.wpi.first.math.Vector<edu.wpi.first.math.numbers.N3> Standard deviations for odometry.doubleThe robot's main loop period in seconds.com.ctre.phoenix6.CANBusThe CAN bus utilized by Phoenix devices.booleanIf move motors should enable FOC.booleantrueif Phoenix Pro is active on all devices used by the swerve API.booleanIf turn motors should enable FOC.doubleThe maximum acceleration the robot is capable of relevant to carpet slip in meters/second/second.doubleThe maximum acceleration the robot is capable of relevant to motor torque in meters/second/second.booleanIf the turn motors should have brake mode enabled.doubleThe turn gear ratio, in motor rotations/module rotation.double[]PID gains for turn motors, as a tuple of[kP, kI, kD].doubleThe stator current limit in amps for turn motors.doubleThe supply current limit in amps for turn motors.doubleThe minimum velocity required for a swerve module to accept a commanded output.doubleThe maximum forward velocity the robot is capable of in meters/second.doubleThe robot's nominal voltage.doubleThe wheel diameter in meters. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionsetBrakeMode(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.setModules(SwerveModuleConfig... modules) 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.voidverify()Verifies the config as well as the config's modules.
-
Field Details
-
period
public double periodThe robot's main loop period in seconds. -
odometryPeriod
public double odometryPeriodThe period to update odometry in seconds. -
discretizationPeriod
public double discretizationPeriodThe period to look ahead for discretizing chassis speeds in seconds. -
defaultFramePeriod
public double defaultFramePeriodThe default frame period for unused CAN signals in seconds. -
movePID
public double[] movePIDPID gains for move motors, as a tuple of[kP, kI, kD]. -
moveFF
public double[] moveFFFeed forward gains for move motors, as a tuple of[kS, kV]. -
turnPID
public double[] turnPIDPID gains for turn motors, as a tuple of[kP, kI, kD]. -
moveBrakeMode
public boolean moveBrakeModeIf the move motors should have brake mode enabled. -
turnBrakeMode
public boolean turnBrakeModeIf the turn motors should have brake mode enabled. -
velocity
public double velocityThe maximum forward velocity the robot is capable of in meters/second. -
velDeadband
public double velDeadbandThe minimum velocity required for a swerve module to accept a commanded output. -
slipAccel
public double slipAccelThe maximum acceleration the robot is capable of relevant to carpet slip in meters/second/second. -
torqueAccel
public double torqueAccelThe maximum acceleration the robot is capable of relevant to motor torque in meters/second/second. -
angularAccel
public double angularAccelThe maximum angular acceleration the robot is capable of in radians/second/second. -
driverVel
public double driverVelThe maximum velocity for driver input in meters/second. -
driverVelExp
public double driverVelExpExponential power to apply to driver velocity input. -
driverVelDeadband
public double driverVelDeadbandDeadband to apply to driver velocity input. -
driverAngularVel
public double driverAngularVelThe maximum angular velocity for driver input in radians/second. -
driverAngularVelExp
public double driverAngularVelExpExponential power to apply to driver angular velocity input. -
driverAngularVelDeadband
public double driverAngularVelDeadbandDeadband to apply to driver angular velocity input. -
voltage
public double voltageThe robot's nominal voltage. Typically12.0. -
moveStatorLimit
public double moveStatorLimitThe stator current limit in amps for move motors. -
moveSupplyLimit
public double moveSupplyLimitThe supply current limit in amps for move motors. -
turnStatorLimit
public double turnStatorLimitThe stator current limit in amps for turn motors. -
turnSupplyLimit
public double turnSupplyLimitThe supply current limit in amps for turn motors. -
moveGearRatio
public double moveGearRatioThe move gear ratio, in motor rotations/wheel rotation. -
turnGearRatio
public double turnGearRatioThe turn gear ratio, in motor rotations/module rotation. -
wheelDiameter
public double wheelDiameterThe wheel diameter in meters. -
odometryStdDevs
public edu.wpi.first.math.Vector<edu.wpi.first.math.numbers.N3> odometryStdDevsStandard deviations for odometry. -
imu
The IMU to use, generated by theSwerveIMUsclass. -
phoenixCanBus
public com.ctre.phoenix6.CANBus phoenixCanBusThe CAN bus utilized by Phoenix devices. -
phoenixPro
public boolean phoenixProtrueif Phoenix Pro is active on all devices used by the swerve API. -
phoenixMoveFOC
public boolean phoenixMoveFOCIf move motors should enable FOC. -
phoenixTurnFOC
public boolean phoenixTurnFOCIf turn motors should enable FOC. -
modules
Configurations for swerve modules.
-
-
Constructor Details
-
SwerveConfig
public SwerveConfig()
-
-
Method Details
-
setTimings
Sets all timings utilized by the drivetrain. Shorthand forsetTimings(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
Sets PID gains for move motors.- Parameters:
kP- Proportional gain constant.kI- Integral gain constant.kD- Derivative gain constant.
-
setMoveFF
Sets feed forward constants for move motors. A good starting point is akVvalue 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
Sets PID gains for turn motors.- Parameters:
kP- Proportional gain constant.kI- Integral gain constant.kD- Derivative gain constant.
-
setBrakeMode
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.0effectively disables.velDeadband- Deadband to apply to driver velocity input.0.0effectively disables.angularVel- The maximum angular velocity for driver input in radians/second.angularVelExp- Exponential power to apply to driver angular velocity input.1.0effectively disables.angularVelDeadband- Deadband to apply to driver angular velocity input.0.0effectively 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. Typically12.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
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 theSwerveIMUsclass.
-
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-trueif Phoenix Pro is active on all CTRE devices used by the swerve API.moveFOC- If move motors should enable FOC.procan still befalsewhile enabling FOC, provided all move motors are still licensed.turnFOC- If turn motors should enable FOC.procan still befalsewhile enabling FOC, provided all turn motors are still licensed.
-
setModules
Sets module configs. SeeSwerveModuleConfig.- 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.
-