Class SwerveModuleConstants
public class SwerveModuleConstants extends Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SwerveModuleConstants.SteerFeedbackType
Supported feedback sensors for the steer motors. -
Field Summary
Fields Modifier and Type Field Description int
CANcoderId
CAN ID of the CANcoder used for azimuth.CANcoderConfiguration
CANcoderInitialConfigs
The initial configs used to configure the CANcoder of the swerve module.double
CANcoderOffset
Offset of the CANcoder in rotations.double
CouplingGearRatio
Coupled gear ratio between the CANcoder and the drive motor.double
DriveFrictionVoltage
Simulated drive voltage required to overcome friction.double
DriveInertia
Simulated drive inertia in kilogram meters squared.SwerveModule.ClosedLoopOutputType
DriveMotorClosedLoopOutput
The closed-loop output type to use for the drive motors.Slot0Configs
DriveMotorGains
The drive motor closed-loop gains.double
DriveMotorGearRatio
Gear ratio between the drive motor and the wheel.int
DriveMotorId
CAN ID of the drive motor.TalonFXConfiguration
DriveMotorInitialConfigs
The initial configs used to configure the drive motor of the swerve module.boolean
DriveMotorInverted
True if the driving motor is reversed.SwerveModuleConstants.SteerFeedbackType
FeedbackSource
Choose how the feedback sensors should be configured.double
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.double
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.double
SlipCurrent
The maximum amount of stator current the drive motors can apply without slippage.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.double
SteerFrictionVoltage
Simulated steer voltage required to overcome friction.double
SteerInertia
Simulated azimuthal inertia in kilogram meters squared.SwerveModule.ClosedLoopOutputType
SteerMotorClosedLoopOutput
The closed-loop output type to use for the steer motors.Slot0Configs
SteerMotorGains
The steer motor closed-loop gains.double
SteerMotorGearRatio
Gear ratio between the steer motor and the CANcoder.int
SteerMotorId
CAN ID of the steer motor.TalonFXConfiguration
SteerMotorInitialConfigs
The initial configs used to configure the steer motor of the swerve module.boolean
SteerMotorInverted
True if the steering motor is reversed from the CANcoder.double
WheelRadius
Radius of the driving wheel in inches. -
Constructor Summary
Constructors Constructor Description SwerveModuleConstants()
-
Method Summary
Modifier and Type Method Description SwerveModuleConstants
withCANcoderId(int id)
Sets the CAN ID of the CANcoder used for azimuth.SwerveModuleConstants
withCANcoderInitialConfigs(CANcoderConfiguration configs)
The initial configs used to configure the CANcoder of the swerve module.SwerveModuleConstants
withCANcoderOffset(double offset)
Sets the offset of the CANcoder in rotations.SwerveModuleConstants
withCouplingGearRatio(double ratio)
Sets the coupled gear ratio between the CANcoder and the drive motor.SwerveModuleConstants
withDriveFrictionVoltage(double voltage)
Sets the simulated drive voltage required to overcome friction.SwerveModuleConstants
withDriveInertia(double driveInertia)
Sets the simulated drive inertia in kilogram meters squared.SwerveModuleConstants
withDriveMotorClosedLoopOutput(SwerveModule.ClosedLoopOutputType outputType)
Sets closed-loop output type to use for the drive motors.SwerveModuleConstants
withDriveMotorGains(Slot0Configs gains)
Sets the drive motor closed-loop gains.SwerveModuleConstants
withDriveMotorGearRatio(double ratio)
Sets the gear ratio between the drive motor and the wheel.SwerveModuleConstants
withDriveMotorId(int id)
Sets the CAN ID of the drive motor.SwerveModuleConstants
withDriveMotorInitialConfigs(TalonFXConfiguration configs)
The initial configs used to configure the drive motor of the swerve module.SwerveModuleConstants
withDriveMotorInverted(boolean driveMotorInverted)
Sets whether the driving motor is reversed.SwerveModuleConstants
withFeedbackSource(SwerveModuleConstants.SteerFeedbackType source)
Chooses how the feedback sensors should be configured.SwerveModuleConstants
withLocationX(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.SwerveModuleConstants
withLocationY(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.SwerveModuleConstants
withSlipCurrent(double slipCurrent)
Sets the maximum amount of stator current the drive motors can apply without slippage.SwerveModuleConstants
withSpeedAt12VoltsMps(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.SwerveModuleConstants
withSteerFrictionVoltage(double voltage)
Sets the simulated steer voltage required to overcome friction.SwerveModuleConstants
withSteerInertia(double steerInertia)
Sets the simulated azimuthal inertia in kilogram meters squared.SwerveModuleConstants
withSteerMotorClosedLoopOutput(SwerveModule.ClosedLoopOutputType outputType)
Sets closed-loop output type to use for the steer motors.SwerveModuleConstants
withSteerMotorGains(Slot0Configs gains)
Sets the steer motor closed-loop gains.SwerveModuleConstants
withSteerMotorGearRatio(double ratio)
Sets the gear ratio between the steer motor and the CANcoder.SwerveModuleConstants
withSteerMotorId(int id)
Sets the CAN ID of the steer motor.SwerveModuleConstants
withSteerMotorInitialConfigs(TalonFXConfiguration configs)
The initial configs used to configure the steer motor of the swerve module.SwerveModuleConstants
withSteerMotorInverted(boolean steerMotorInverted)
Sets whether the steering motor is reversed from the CANcoder.SwerveModuleConstants
withWheelRadius(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
SteerMotorClosedLoopOutput
and anySwerveModule.SteerRequestType
. -
DriveMotorGains
The drive motor closed-loop gains.When using closed-loop control, the drive motor uses the control output type specified by
DriveMotorClosedLoopOutput
and 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
SwerveModuleConstants
class 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
SwerveModuleConstants
class 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
SteerMotorClosedLoopOutput
and 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
DriveMotorClosedLoopOutput
and 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
SwerveModuleConstants
class 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
SwerveModuleConstants
class 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
-