Class SwerveModuleConstants
public class SwerveModuleConstants extends Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSwerveModuleConstants.SteerFeedbackTypeSupported feedback sensors for the steer motors. -
Field Summary
Fields Modifier and Type Field Description intCANcoderIdCAN ID of the CANcoder used for azimuth.CANcoderConfigurationCANcoderInitialConfigsThe initial configs used to configure the CANcoder of the swerve module.doubleCANcoderOffsetOffset of the CANcoder in rotations.doubleCouplingGearRatioCoupled gear ratio between the CANcoder and the drive motor.doubleDriveFrictionVoltageSimulated drive voltage required to overcome friction.doubleDriveInertiaSimulated drive inertia in kilogram meters squared.SwerveModule.ClosedLoopOutputTypeDriveMotorClosedLoopOutputThe closed-loop output type to use for the drive motors.Slot0ConfigsDriveMotorGainsThe drive motor closed-loop gains.doubleDriveMotorGearRatioGear ratio between the drive motor and the wheel.intDriveMotorIdCAN ID of the drive motor.TalonFXConfigurationDriveMotorInitialConfigsThe initial configs used to configure the drive motor of the swerve module.booleanDriveMotorInvertedTrue if the driving motor is reversed.SwerveModuleConstants.SteerFeedbackTypeFeedbackSourceChoose how the feedback sensors should be configured.doubleLocationXThe location of this module's wheels relative to the physical center of the robot in meters along the X axis of the robot.doubleLocationYThe location of this module's wheels relative to the physical center of the robot in meters along the Y axis of the robot.doubleSlipCurrentThe maximum amount of stator current the drive motors can apply without slippage.doubleSpeedAt12VoltsMpsWhen using open-loop drive control, this specifies the speed at which the robot travels when driven with 12 volts, in meters per second.doubleSteerFrictionVoltageSimulated steer voltage required to overcome friction.doubleSteerInertiaSimulated azimuthal inertia in kilogram meters squared.SwerveModule.ClosedLoopOutputTypeSteerMotorClosedLoopOutputThe closed-loop output type to use for the steer motors.Slot0ConfigsSteerMotorGainsThe steer motor closed-loop gains.doubleSteerMotorGearRatioGear ratio between the steer motor and the CANcoder.intSteerMotorIdCAN ID of the steer motor.TalonFXConfigurationSteerMotorInitialConfigsThe initial configs used to configure the steer motor of the swerve module.booleanSteerMotorInvertedTrue if the steering motor is reversed from the CANcoder.doubleWheelRadiusRadius of the driving wheel in inches. -
Constructor Summary
Constructors Constructor Description SwerveModuleConstants() -
Method Summary
Modifier and Type Method Description SwerveModuleConstantswithCANcoderId(int id)Sets the CAN ID of the CANcoder used for azimuth.SwerveModuleConstantswithCANcoderInitialConfigs(CANcoderConfiguration configs)The initial configs used to configure the CANcoder of the swerve module.SwerveModuleConstantswithCANcoderOffset(double offset)Sets the offset of the CANcoder in rotations.SwerveModuleConstantswithCouplingGearRatio(double ratio)Sets the coupled gear ratio between the CANcoder and the drive motor.SwerveModuleConstantswithDriveFrictionVoltage(double voltage)Sets the simulated drive voltage required to overcome friction.SwerveModuleConstantswithDriveInertia(double driveInertia)Sets the simulated drive inertia in kilogram meters squared.SwerveModuleConstantswithDriveMotorClosedLoopOutput(SwerveModule.ClosedLoopOutputType outputType)Sets closed-loop output type to use for the drive motors.SwerveModuleConstantswithDriveMotorGains(Slot0Configs gains)Sets the drive motor closed-loop gains.SwerveModuleConstantswithDriveMotorGearRatio(double ratio)Sets the gear ratio between the drive motor and the wheel.SwerveModuleConstantswithDriveMotorId(int id)Sets the CAN ID of the drive motor.SwerveModuleConstantswithDriveMotorInitialConfigs(TalonFXConfiguration configs)The initial configs used to configure the drive motor of the swerve module.SwerveModuleConstantswithDriveMotorInverted(boolean driveMotorInverted)Sets whether the driving motor is reversed.SwerveModuleConstantswithFeedbackSource(SwerveModuleConstants.SteerFeedbackType source)Chooses how the feedback sensors should be configured.SwerveModuleConstantswithLocationX(double locationXMeters)Sets the location of this module's wheels relative to the physical center of the robot in meters along the X axis of the robot.SwerveModuleConstantswithLocationY(double locationYMeters)Sets the location of this module's wheels relative to the physical center of the robot in meters along the Y axis of the robot.SwerveModuleConstantswithSlipCurrent(double slipCurrent)Sets the maximum amount of stator current the drive motors can apply without slippage.SwerveModuleConstantswithSpeedAt12VoltsMps(double speedAt12VoltsMps)When using open-loop drive control, this specifies the speed at which the robot travels when driven with 12 volts, in meters per second.SwerveModuleConstantswithSteerFrictionVoltage(double voltage)Sets the simulated steer voltage required to overcome friction.SwerveModuleConstantswithSteerInertia(double steerInertia)Sets the simulated azimuthal inertia in kilogram meters squared.SwerveModuleConstantswithSteerMotorClosedLoopOutput(SwerveModule.ClosedLoopOutputType outputType)Sets closed-loop output type to use for the steer motors.SwerveModuleConstantswithSteerMotorGains(Slot0Configs gains)Sets the steer motor closed-loop gains.SwerveModuleConstantswithSteerMotorGearRatio(double ratio)Sets the gear ratio between the steer motor and the CANcoder.SwerveModuleConstantswithSteerMotorId(int id)Sets the CAN ID of the steer motor.SwerveModuleConstantswithSteerMotorInitialConfigs(TalonFXConfiguration configs)The initial configs used to configure the steer motor of the swerve module.SwerveModuleConstantswithSteerMotorInverted(boolean steerMotorInverted)Sets whether the steering motor is reversed from the CANcoder.SwerveModuleConstantswithWheelRadius(double radius)Sets the radius of the driving wheel in inches.
-
Field Details
-
DriveMotorId
CAN ID of the drive motor. -
SteerMotorId
CAN ID of the steer motor. -
CANcoderId
CAN ID of the CANcoder used for azimuth. -
CANcoderOffset
Offset of the CANcoder in rotations. -
DriveMotorGearRatio
Gear ratio between the drive motor and the wheel. -
SteerMotorGearRatio
Gear ratio between the steer motor and the CANcoder. For example, the SDS Mk4 has a steering ratio of 12.8. -
CouplingGearRatio
Coupled gear ratio between the CANcoder and the drive motor.For a typical swerve module, the azimuth turn motor also drives the wheel a nontrivial amount, which affects the accuracy of odometry and control. This ratio represents the number of rotations of the drive motor caused by a rotation of the azimuth.
-
WheelRadius
Radius of the driving wheel in inches. -
LocationX
The location of this module's wheels relative to the physical center of the robot in meters along the X axis of the robot. -
LocationY
The location of this module's wheels relative to the physical center of the robot in meters along the Y axis of the robot. -
SteerMotorGains
The steer motor closed-loop gains.The steer motor uses the control ouput type specified by
SteerMotorClosedLoopOutputand anySwerveModule.SteerRequestType. -
DriveMotorGains
The drive motor closed-loop gains.When using closed-loop control, the drive motor uses the control output type specified by
DriveMotorClosedLoopOutputand any closed-loopSwerveModule.DriveRequestType. -
SteerMotorClosedLoopOutput
The closed-loop output type to use for the steer motors. -
DriveMotorClosedLoopOutput
The closed-loop output type to use for the drive motors. -
SlipCurrent
The maximum amount of stator current the drive motors can apply without slippage. -
SteerMotorInverted
True if the steering motor is reversed from the CANcoder. -
DriveMotorInverted
True if the driving motor is reversed. -
SpeedAt12VoltsMps
When using open-loop drive control, this specifies the speed at which the robot travels when driven with 12 volts, in meters per second. This is used to approximate the output for a desired velocity. If using closed loop control, this value is ignored. -
SteerInertia
Simulated azimuthal inertia in kilogram meters squared. -
DriveInertia
Simulated drive inertia in kilogram meters squared. -
SteerFrictionVoltage
Simulated steer voltage required to overcome friction. -
DriveFrictionVoltage
Simulated drive voltage required to overcome friction. -
FeedbackSource
Choose how the feedback sensors should be configured.If the robot does not support Pro, then this should remain as RemoteCANcoder. Otherwise, users have the option to use either FusedCANcoder or SyncCANcoder depending on if there is a risk that the CANcoder can fail in a way to provide "good" data.
-
DriveMotorInitialConfigs
The initial configs used to configure the drive motor of the swerve module. The default value is the factory-default.Users may change the initial configuration as they need. Any config that's not referenced in the
SwerveModuleConstantsclass is available to be changed.The list of configs that will be overwritten is as follows:
-
MotorOutputConfigs.NeutralMode(Brake mode, overwritten withSwerveModule.configNeutralMode(NeutralModeValue)) -
MotorOutputConfigs.Inverted(DriveMotorInverted) -
Slot0Configs(DriveMotorGains) -
CurrentLimitsConfigs.StatorCurrentLimit/TorqueCurrentConfigs.PeakForwardTorqueCurrent/TorqueCurrentConfigs.PeakReverseTorqueCurrent(SlipCurrent) -
CurrentLimitsConfigs.StatorCurrentLimitEnable(Enabled)
-
-
SteerMotorInitialConfigs
The initial configs used to configure the steer motor of the swerve module. The default value is the factory-default.Users may change the initial configuration as they need. Any config that's not referenced in the
SwerveModuleConstantsclass is available to be changed.The list of configs that will be overwritten is as follows:
-
MotorOutputConfigs.NeutralMode(Brake mode) -
MotorOutputConfigs.Inverted(SteerMotorInverted) -
Slot0Configs(SteerMotorGains) -
FeedbackConfigs.FeedbackRemoteSensorID(CANcoderId) -
FeedbackConfigs.FeedbackSensorSource(FeedbackSource) -
FeedbackConfigs.RotorToSensorRatio(SteerMotorGearRatio) -
MotionMagicConfigs(Calculated from gear ratios) -
ClosedLoopGeneralConfigs.ContinuousWrap(true)
-
-
CANcoderInitialConfigs
The initial configs used to configure the CANcoder of the swerve module. The default value is the factory-default.Users may change the initial configuration as they need. Any config that's not referenced in the
SwerveModuleConstants()class is available to be changed.The list of configs that will be overwritten is as follows:
-
-
Constructor Details
-
Method Details
-
withDriveMotorId
Sets the CAN ID of the drive motor.- Parameters:
id- CAN ID of the drive motor- Returns:
- this object
-
withSteerMotorId
Sets the CAN ID of the steer motor.- Parameters:
id- CAN ID of the steer motor- Returns:
- this object
-
withCANcoderId
Sets the CAN ID of the CANcoder used for azimuth.- Parameters:
id- CAN ID of the CANcoder used for azimuth- Returns:
- this object
-
withCANcoderOffset
Sets the offset of the CANcoder in rotations.- Parameters:
offset- Offset of the CANcoder in rotations- Returns:
- this object
-
withDriveMotorGearRatio
Sets the gear ratio between the drive motor and the wheel.- Parameters:
ratio- Gear ratio between the drive motor and the wheel- Returns:
- this object
-
withSteerMotorGearRatio
Sets the gear ratio between the steer motor and the CANcoder. For example, the SDS Mk4 has a steering ratio of 12.8.- Parameters:
ratio- Gear ratio between the steer motor and the CANcoder- Returns:
- this object
-
withCouplingGearRatio
Sets the coupled gear ratio between the CANcoder and the drive motor.For a typical swerve module, the azimuth turn motor also drives the wheel a nontrivial amount, which affects the accuracy of odometry and control. This ratio represents the number of rotations of the drive motor caused by a rotation of the azimuth.
- Parameters:
ratio- Coupled gear ratio between the CANcoder and the drive motor- Returns:
- this object
-
withWheelRadius
Sets the radius of the driving wheel in inches.- Parameters:
radius- Radius of the driving wheel in inches- Returns:
- this object
-
withLocationX
Sets the location of this module's wheels relative to the physical center of the robot in meters along the X axis of the robot.- Parameters:
locationXMeters- Location of this module's wheels- Returns:
- this object
-
withLocationY
Sets the location of this module's wheels relative to the physical center of the robot in meters along the Y axis of the robot.- Parameters:
locationYMeters- Location of this module's wheels- Returns:
- this object
-
withSteerMotorGains
Sets the steer motor closed-loop gains.The steer motor uses the control ouput type specified by
SteerMotorClosedLoopOutputand anySwerveModule.SteerRequestType.- Parameters:
gains- Steer motor closed-loop gains- Returns:
- this object
-
withDriveMotorGains
Sets the drive motor closed-loop gains.When using closed-loop control, the drive motor uses the control output type specified by
DriveMotorClosedLoopOutputand any closed-loopSwerveModule.DriveRequestType.- Parameters:
gains- Drive motor closed-loop gains- Returns:
- this object
-
withSteerMotorClosedLoopOutput
public SwerveModuleConstants withSteerMotorClosedLoopOutput(SwerveModule.ClosedLoopOutputType outputType)Sets closed-loop output type to use for the steer motors.- Parameters:
outputType- Closed-loop output type to use for the steer motors- Returns:
- this object
-
withDriveMotorClosedLoopOutput
public SwerveModuleConstants withDriveMotorClosedLoopOutput(SwerveModule.ClosedLoopOutputType outputType)Sets closed-loop output type to use for the drive motors.- Parameters:
outputType- Closed-loop output type to use for the drive motors- Returns:
- this object
-
withSlipCurrent
Sets the maximum amount of stator current the drive motors can apply without slippage.- Parameters:
slipCurrent- Maximum amount of stator current- Returns:
- this object
-
withSteerMotorInverted
Sets whether the steering motor is reversed from the CANcoder.- Parameters:
steerMotorInverted- True if the steering motor is reversed from the CANcoder- Returns:
- this object
-
withDriveMotorInverted
Sets whether the driving motor is reversed.- Parameters:
driveMotorInverted- True if the driving motor is reversed- Returns:
- this object
-
withSpeedAt12VoltsMps
When using open-loop drive control, this specifies the speed at which the robot travels when driven with 12 volts, in meters per second. This is used to approximate the output for a desired velocity. If using closed loop control, this value is ignored.- Parameters:
speedAt12VoltsMps- Speed at which the robot travels when driven with 12 volts, in meters per second- Returns:
- this object
-
withSteerInertia
Sets the simulated azimuthal inertia in kilogram meters squared.- Parameters:
steerInertia- Azimuthal inertia in kilogram meters squared- Returns:
- this object
-
withDriveInertia
Sets the simulated drive inertia in kilogram meters squared.- Parameters:
driveInertia- Drive inertia in kilogram meters squared- Returns:
- this object
-
withSteerFrictionVoltage
Sets the simulated steer voltage required to overcome friction.- Parameters:
voltage- Steer voltage required to overcome friction- Returns:
- this object
-
withDriveFrictionVoltage
Sets the simulated drive voltage required to overcome friction.- Parameters:
voltage- Drive voltage required to overcome friction- Returns:
- this object
-
withFeedbackSource
Chooses how the feedback sensors should be configured.If the robot does not support Pro, then this should remain as RemoteCANcoder. Otherwise, users have the option to use either FusedCANcoder or SyncCANcoder depending on if there is a risk that the CANcoder can fail in a way to provide "good" data.
- Parameters:
source- The feedback sensor source- Returns:
- this object
-
withDriveMotorInitialConfigs
The initial configs used to configure the drive motor of the swerve module. The default value is the factory-default.Users may change the initial configuration as they need. Any config that's not referenced in the
SwerveModuleConstantsclass is available to be changed.The list of configs that will be overwritten is as follows:
-
MotorOutputConfigs.NeutralMode(Brake mode, overwritten withSwerveModule.configNeutralMode(NeutralModeValue)) -
MotorOutputConfigs.Inverted(DriveMotorInverted) -
Slot0Configs(DriveMotorGains) -
CurrentLimitsConfigs.StatorCurrentLimit/TorqueCurrentConfigs.PeakForwardTorqueCurrent/TorqueCurrentConfigs.PeakReverseTorqueCurrent(SlipCurrent) -
CurrentLimitsConfigs.StatorCurrentLimitEnable(Enabled)
- Parameters:
configs- Configs to set as an initial set of configs- Returns:
- this object
-
-
withSteerMotorInitialConfigs
The initial configs used to configure the steer motor of the swerve module. The default value is the factory-default.Users may change the initial configuration as they need. Any config that's not referenced in the
SwerveModuleConstantsclass is available to be changed.The list of configs that will be overwritten is as follows:
-
MotorOutputConfigs.NeutralMode(Brake mode) -
MotorOutputConfigs.Inverted(SteerMotorInverted) -
Slot0Configs(SteerMotorGains) -
FeedbackConfigs.FeedbackRemoteSensorID(CANcoderId) -
FeedbackConfigs.FeedbackSensorSource(FeedbackSource) -
FeedbackConfigs.RotorToSensorRatio(SteerMotorGearRatio) -
MotionMagicConfigs(Calculated from gear ratios) -
ClosedLoopGeneralConfigs.ContinuousWrap(true)
- Parameters:
configs- Configs to set as an initial set of configs- Returns:
- this object
-
-
withCANcoderInitialConfigs
The initial configs used to configure the CANcoder of the swerve module. The default value is the factory-default.Users may change the initial configuration as they need. Any config that's not referenced in the
SwerveModuleConstants()class is available to be changed.The list of configs that will be overwritten is as follows:
- Parameters:
configs- Configs to set as an initial set of configs- Returns:
- this object
-