Class SwerveModuleConstantsFactory
public class SwerveModuleConstantsFactory extends Object
SwerveModuleConstants
.-
Field Summary
Fields Modifier and Type Field Description CANcoderConfiguration
CANcoderInitialConfigs
The initial configs used to configure the CANcoder of the swerve module.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.TalonFXConfiguration
DriveMotorInitialConfigs
The initial configs used to configure the drive motor of the swerve module.SwerveModuleConstants.SteerFeedbackType
FeedbackSource
Choose how the feedback sensors should be configured.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.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 SwerveModuleConstantsFactory()
-
Method Summary
Modifier and Type Method Description SwerveModuleConstants
createModuleConstants(int steerId, int driveId, int cancoderId, double cancoderOffset, double locationX, double locationY, boolean driveMotorReversed)
Creates the constants for a swerve module with the given properties.SwerveModuleConstantsFactory
withCANcoderInitialConfigs(CANcoderConfiguration configs)
The initial configs used to configure the CANcoder of the swerve module.SwerveModuleConstantsFactory
withCouplingGearRatio(double ratio)
Sets the coupled gear ratio between the CANcoder and the drive motor.SwerveModuleConstantsFactory
withDriveFrictionVoltage(double voltage)
Sets the simulated drive voltage required to overcome friction.SwerveModuleConstantsFactory
withDriveInertia(double driveInertia)
Sets the simulated drive inertia in kilogram meters squared.SwerveModuleConstantsFactory
withDriveMotorClosedLoopOutput(SwerveModule.ClosedLoopOutputType outputType)
Sets closed-loop output type to use for the drive motors.SwerveModuleConstantsFactory
withDriveMotorGains(Slot0Configs gains)
Sets the drive motor closed-loop gains.SwerveModuleConstantsFactory
withDriveMotorGearRatio(double ratio)
Sets the gear ratio between the drive motor and the wheel.SwerveModuleConstantsFactory
withDriveMotorInitialConfigs(TalonFXConfiguration configs)
The initial configs used to configure the drive motor of the swerve module.SwerveModuleConstantsFactory
withFeedbackSource(SwerveModuleConstants.SteerFeedbackType source)
Chooses how the feedback sensors should be configured.SwerveModuleConstantsFactory
withSlipCurrent(double slipCurrent)
Sets the maximum amount of stator current the drive motors can apply without slippage.SwerveModuleConstantsFactory
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.SwerveModuleConstantsFactory
withSteerFrictionVoltage(double voltage)
Sets the simulated steer voltage required to overcome friction.SwerveModuleConstantsFactory
withSteerInertia(double steerInertia)
Sets the simulated azimuthal inertia in kilogram meters squared.SwerveModuleConstantsFactory
withSteerMotorClosedLoopOutput(SwerveModule.ClosedLoopOutputType outputType)
Sets closed-loop output type to use for the steer motors.SwerveModuleConstantsFactory
withSteerMotorGains(Slot0Configs gains)
Sets the steer motor closed-loop gains.SwerveModuleConstantsFactory
withSteerMotorGearRatio(double ratio)
Sets the gear ratio between the steer motor and the CANcoder.SwerveModuleConstantsFactory
withSteerMotorInitialConfigs(TalonFXConfiguration configs)
The initial configs used to configure the steer motor of the swerve module.SwerveModuleConstantsFactory
withSteerMotorInverted(boolean steerMotorInverted)
Sets whether the steering motor is reversed from the CANcoder.SwerveModuleConstantsFactory
withWheelRadius(double radius)
Sets the radius of the driving wheel in inches.
-
Field Details
-
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. -
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. -
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
(SwerveModuleConstants.DriveMotorInverted
) -
Slot0Configs
(SwerveModuleConstants.DriveMotorGains
) -
CurrentLimitsConfigs.StatorCurrentLimit
/TorqueCurrentConfigs.PeakForwardTorqueCurrent
/TorqueCurrentConfigs.PeakReverseTorqueCurrent
(SwerveModuleConstants.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
(SwerveModuleConstants.SteerMotorInverted
) -
Slot0Configs
(SwerveModuleConstants.SteerMotorGains
) -
FeedbackConfigs.FeedbackRemoteSensorID
(SwerveModuleConstants.CANcoderId
) -
FeedbackConfigs.FeedbackSensorSource
(SwerveModuleConstants.FeedbackSource
) -
FeedbackConfigs.RotorToSensorRatio
(SwerveModuleConstants.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
-
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
-
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 SwerveModuleConstantsFactory 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 SwerveModuleConstantsFactory 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
-
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
public SwerveModuleConstantsFactory withFeedbackSource(SwerveModuleConstants.SteerFeedbackType source)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
(SwerveModuleConstants.DriveMotorInverted
) -
Slot0Configs
(SwerveModuleConstants.DriveMotorGains
) -
CurrentLimitsConfigs.StatorCurrentLimit
/TorqueCurrentConfigs.PeakForwardTorqueCurrent
/TorqueCurrentConfigs.PeakReverseTorqueCurrent
(SwerveModuleConstants.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
(SwerveModuleConstants.SteerMotorInverted
) -
Slot0Configs
(SwerveModuleConstants.SteerMotorGains
) -
FeedbackConfigs.FeedbackRemoteSensorID
(SwerveModuleConstants.CANcoderId
) -
FeedbackConfigs.FeedbackSensorSource
(SwerveModuleConstants.FeedbackSource
) -
FeedbackConfigs.RotorToSensorRatio
(SwerveModuleConstants.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
-
createModuleConstants
public SwerveModuleConstants createModuleConstants(int steerId, int driveId, int cancoderId, double cancoderOffset, double locationX, double locationY, boolean driveMotorReversed)Creates the constants for a swerve module with the given properties.- Parameters:
steerId
- CAN ID of the steer motordriveId
- CAN ID of the drive motorcancoderId
- CAN ID of the CANcoder used for azimuthcancoderOffset
- Offset of the CANcoder in rotationslocationX
- The location of this module's wheels relative to the physical center of the robot in meters along the X axis of the robotlocationY
- The location of this module's wheels relative to the physical center of the robot in meters along the Y axis of the robotdriveMotorReversed
- True if the driving motor is reversed- Returns:
- Constants for the swerve module
-