phoenix6.swerve

Subpackages

Submodules

Package Contents

Functions

lerp(startValue, endValue, t)

phoenix6.swerve.lerp(startValue, endValue, t: phoenix6.units.second)
class phoenix6.swerve.Rotation2d
class phoenix6.swerve.Rotation2d(value: phoenix6.units.radian)
class phoenix6.swerve.Rotation2d(x: float, y: float)
static fromDegrees(value: phoenix6.units.degree) Rotation2d
static fromRotations(value: phoenix6.units.rotation) Rotation2d
radians() phoenix6.units.radian
degrees() phoenix6.units.degree
rotations() phoenix6.units.rotation
cos() float
sin() float
tan() float
rotateBy(other: Rotation2d) Rotation2d
class phoenix6.swerve.SwerveModuleState(speed: phoenix6.swerve.utility.geometry.meters_per_second = 0, angle: phoenix6.swerve.utility.geometry.Rotation2d = Rotation2d())
static optimize(desiredState: SwerveModuleState, currentAngle: phoenix6.swerve.utility.geometry.Rotation2d) SwerveModuleState
class phoenix6.swerve.SwerveDrivetrainConstants

Common constants for a swerve drivetrain.

can_bus_name: str = 'rio'

Name of the CAN bus the swerve drive is on. Possible CAN bus strings are:

  • empty string or “rio” for the native roboRIO CAN bus

  • CANivore name or serial number

  • “*” for any CANivore seen by the program

Note that all devices must be on the same CAN bus.

pigeon2_id: int = 0

CAN ID of the Pigeon2 on the drivetrain.

pigeon2_configs: None | phoenix6.configs.Pigeon2Configuration

The configuration object to apply to the Pigeon2. This defaults to null. If this remains null, then the Pigeon2 will not be configured (and whatever configs are on it remain on it). If this is not null, the Pigeon2 will be overwritten with these configs.

with_can_bus_name(new_can_bus_name: str) SwerveDrivetrainConstants

Modifies the can_bus_name parameter and returns itself.

Name of the CAN bus the swerve drive is on. Possible CAN bus strings are:

  • empty string or “rio” for the native roboRIO CAN bus

  • CANivore name or serial number

  • “*” for any CANivore seen by the program

Note that all devices must be on the same CAN bus.

Parameters:

new_can_bus_name (str) – Parameter to modify

Returns:

this object

Return type:

SwerveDrivetrainConstants

with_pigeon2_id(new_pigeon2_id: int) SwerveDrivetrainConstants

Modifies the pigeon2_id parameter and returns itself.

CAN ID of the Pigeon2 on the drivetrain.

Parameters:

new_pigeon2_id (int) – Parameter to modify

Returns:

this object

Return type:

SwerveDrivetrainConstants

with_pigeon2_configs(new_pigeon2_configs: None | phoenix6.configs.Pigeon2Configuration) SwerveDrivetrainConstants

Modifies the pigeon2_configs parameter and returns itself.

The configuration object to apply to the Pigeon2. This defaults to null. If this remains null, then the Pigeon2 will not be configured (and whatever configs are on it remain on it). If this is not null, the Pigeon2 will be overwritten with these configs.

Parameters:

new_pigeon2_configs (None | Pigeon2Configuration) – Parameter to modify

Returns:

this object

Return type:

SwerveDrivetrainConstants

class phoenix6.swerve.ClosedLoopOutputType(*args, **kwds)

Bases: enum.Enum

Supported closed-loop output types.

VOLTAGE = 0
TORQUE_CURRENT_FOC = 1

Requires Pro

class phoenix6.swerve.DriveMotorArrangement(*args, **kwds)

Bases: enum.Enum

Supported motor arrangements for the drive motors.

TALON_FX_INTEGRATED = 0

Talon FX integrated brushless motor.

TALON_FXS_NEO_JST = 1

Third party NEO brushless motor connected to a Talon FXS over JST.

TALON_FXS_VORTEX_JST = 2

Third party VORTEX brushless motor connected to a Talon FXS over JST.

class phoenix6.swerve.SteerFeedbackType(*args, **kwds)

Bases: enum.Enum

Supported feedback sensors for the steer motors.

FUSED_CANCODER = 0

Requires Pro; Use FeedbackSensorSourceValue.FUSED_CANCODER for the steer motor.

SYNC_CANCODER = 1

Requires Pro; Use FeedbackSensorSourceValue.SYNC_CANCODER for the steer motor.

REMOTE_CANCODER = 2

Use FeedbackSensorSourceValue.REMOTE_CANCODER for the steer motor.

FUSED_CANDI_PWM1 = 3

Requires Pro; Use FeedbackSensorSourceValue.FUSED_CANDI_PWM1 for the steer motor.

FUSED_CANDI_PWM2 = 4

Requires Pro; Use FeedbackSensorSourceValue.FUSED_CANDI_PWM2 for the steer motor.

SYNC_CANDI_PWM1 = 5

Requires Pro; Use FeedbackSensorSourceValue.SYNC_CANDI_PWM1 for the steer motor.

SYNC_CANDI_PWM2 = 6

Requires Pro; Use FeedbackSensorSourceValue.SYNC_CANDI_PWM2 for the steer motor.

REMOTE_CANDI_PWM1 = 7

Use FeedbackSensorSourceValue.REMOTE_CANDI_PWM1 for the steer motor.

REMOTE_CANDI_PWM2 = 8

Use FeedbackSensorSourceValue.REMOTE_CANDI_PWM2 for the steer motor.

TALON_FXS_PULSE_WIDTH = 9

Use ExternalFeedbackSensorSourceValue.PULSE_WIDTH for the steer motor. This requires Talon FXS.

class phoenix6.swerve.SteerMotorArrangement(*args, **kwds)

Bases: enum.Enum

Supported motor arrangements for the steer motors.

TALON_FX_INTEGRATED = 0

Talon FX integrated brushless motor.

TALON_FXS_MINION_JST = 1

CTR Electronics Minion® brushless motor connected to a Talon FXS over JST.

TALON_FXS_NEO_JST = 2

Third party NEO brushless motor connected to a Talon FXS over JST.

TALON_FXS_VORTEX_JST = 3

Third party VORTEX brushless motor connected to a Talon FXS over JST.

TALON_FXS_NEO550_JST = 4

Third party NEO550 brushless motor connected to a Talon FXS over JST.

TALON_FXS_BRUSHED_AB = 5

Brushed motor connected to a Talon FXS on terminals A and B.

TALON_FXS_BRUSHED_AC = 6

Brushed motor connected to a Talon FXS on terminals A and C.

TALON_FXS_BRUSHED_BC = 7

Brushed motor connected to a Talon FXS on terminals B and C.

class phoenix6.swerve.SwerveModuleConstants

Bases: Generic[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

All constants for a swerve module.

steer_motor_id: int = 0

CAN ID of the steer motor.

drive_motor_id: int = 0

CAN ID of the drive motor.

encoder_id: int = 0

CAN ID of the absolute encoder used for azimuth.

encoder_offset: phoenix6.units.rotation = 0

Offset of the azimuth encoder.

location_x: phoenix6.units.meter = 0

The location of this module’s wheels relative to the physical center of the robot in meters along the X axis of the robot.

location_y: phoenix6.units.meter = 0

The location of this module’s wheels relative to the physical center of the robot in meters along the Y axis of the robot.

drive_motor_inverted: bool = False

True if the drive motor is inverted.

steer_motor_inverted: bool = False

True if the steer motor is inverted from the azimuth. The azimuth should rotate counter-clockwise (as seen from the top of the robot) for a positive motor output.

encoder_inverted: bool = False

True if the azimuth encoder is inverted from the azimuth. The encoder should report a positive velocity when the azimuth rotates counter-clockwise (as seen from the top of the robot).

drive_motor_gear_ratio: float = 0

Gear ratio between the drive motor and the wheel.

steer_motor_gear_ratio: float = 0

Gear ratio between the steer motor and the azimuth encoder. For example, the SDS Mk4 has a steering ratio of 12.8.

coupling_gear_ratio: float = 0

Coupled gear ratio between the azimuth encoder 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.

wheel_radius: phoenix6.units.meter = 0

Radius of the driving wheel in meters.

steer_motor_gains: phoenix6.configs.Slot0Configs

The steer motor closed-loop gains.

The steer motor uses the control ouput type specified by SteerMotorClosedLoopOutput and any SwerveModule.SteerRequestType. These gains operate on azimuth rotations (after the gear ratio).

drive_motor_gains: phoenix6.configs.Slot0Configs

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-loop SwerveModule.DriveRequestType. These gains operate on motor rotor rotations (before the gear ratio).

steer_motor_closed_loop_output: ClosedLoopOutputType

The closed-loop output type to use for the steer motors.

drive_motor_closed_loop_output: ClosedLoopOutputType

The closed-loop output type to use for the drive motors.

slip_current: phoenix6.units.ampere = 120

The maximum amount of stator current the drive motors can apply without slippage.

speed_at12_volts: phoenix6.units.meters_per_second = 0

When using open-loop drive control, this specifies the speed at which the robot travels when driven with 12 volts. This is used to approximate the output for a desired velocity. If using closed loop control, this value is ignored.

drive_motor_type: DriveMotorArrangement

Choose the motor used for the drive motor.

If using a Talon FX, this should be set to TalonFX_Integrated. If using a Talon FXS, this should be set to the motor attached to the Talon FXS.

steer_motor_type: SteerMotorArrangement

Choose the motor used for the steer motor.

If using a Talon FX, this should be set to TalonFX_Integrated. If using a Talon FXS, this should be set to the motor attached to the Talon FXS.

feedback_source: SteerFeedbackType

Choose how the feedback sensors should be configured.

If the robot does not support Pro, then this should be set to 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.

If this is set to FusedCANcoder or SyncCANcoder when the steer motor is not Pro-licensed, the device will automatically fall back to RemoteCANcoder and report a UsingProFeatureOnUnlicensedDevice status code.

drive_motor_initial_configs: DriveMotorConfigsT

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 with SwerveDrivetrain.config_neutral_mode)

  • MotorOutputConfigs.Inverted (SwerveModuleConstants.DriveMotorInverted)

  • Slot0Configs (SwerveModuleConstants.DriveMotorGains)

  • CurrentLimitsConfigs.StatorCurrentLimit / TorqueCurrentConfigs.PeakForwardTorqueCurrent / TorqueCurrentConfigs.PeakReverseTorqueCurrent (SwerveModuleConstants.SlipCurrent)

  • CurrentLimitsConfigs.StatorCurrentLimitEnable (Enabled)

steer_motor_initial_configs: SteerMotorConfigsT

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.EncoderId)

  • FeedbackConfigs.FeedbackSensorSource (SwerveModuleConstants.FeedbackSource)

  • FeedbackConfigs.RotorToSensorRatio (SwerveModuleConstants.SteerMotorGearRatio)

  • MotionMagicConfigs.MotionMagicExpo_kV / MotionMagicConfigs.MotionMagicExpo_kA (Calculated from gear ratios)

  • ClosedLoopGeneralConfigs.ContinuousWrap (true)

encoder_initial_configs: EncoderConfigsT

The initial configs used to configure the azimuth encoder 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.

For CANcoder, the list of configs that will be overwritten is as follows:

  • MagnetSensorConfigs.MagnetOffset (SwerveModuleConstants.EncoderOffset)

  • MagnetSensorConfigs.SensorDirection (SwerveModuleConstants.EncoderInverted)

steer_inertia: phoenix6.units.kilogram_square_meter = 1e-05

Simulated azimuthal inertia.

drive_inertia: phoenix6.units.kilogram_square_meter = 0.001

Simulated drive inertia.

steer_friction_voltage: phoenix6.units.volt = 0.25

Simulated steer voltage required to overcome friction.

drive_friction_voltage: phoenix6.units.volt = 0.25

Simulated drive voltage required to overcome friction.

with_steer_motor_id(new_steer_motor_id: int) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the steer_motor_id parameter and returns itself.

CAN ID of the steer motor.

Parameters:

new_steer_motor_id (int) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_drive_motor_id(new_drive_motor_id: int) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the drive_motor_id parameter and returns itself.

CAN ID of the drive motor.

Parameters:

new_drive_motor_id (int) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_encoder_id(new_encoder_id: int) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the encoder_id parameter and returns itself.

CAN ID of the absolute encoder used for azimuth.

Parameters:

new_encoder_id (int) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_encoder_offset(new_encoder_offset: phoenix6.units.rotation) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the encoder_offset parameter and returns itself.

Offset of the azimuth encoder.

Parameters:

new_encoder_offset (rotation) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_location_x(new_location_x: phoenix6.units.meter) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the location_x parameter and returns itself.

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:

new_location_x (meter) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_location_y(new_location_y: phoenix6.units.meter) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the location_y parameter and returns itself.

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:

new_location_y (meter) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_drive_motor_inverted(new_drive_motor_inverted: bool) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the drive_motor_inverted parameter and returns itself.

True if the drive motor is inverted.

Parameters:

new_drive_motor_inverted (bool) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_steer_motor_inverted(new_steer_motor_inverted: bool) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the steer_motor_inverted parameter and returns itself.

True if the steer motor is inverted from the azimuth. The azimuth should rotate counter-clockwise (as seen from the top of the robot) for a positive motor output.

Parameters:

new_steer_motor_inverted (bool) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_encoder_inverted(new_encoder_inverted: bool) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the encoder_inverted parameter and returns itself.

True if the azimuth encoder is inverted from the azimuth. The encoder should report a positive velocity when the azimuth rotates counter-clockwise (as seen from the top of the robot).

Parameters:

new_encoder_inverted (bool) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_drive_motor_gear_ratio(new_drive_motor_gear_ratio: float) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the drive_motor_gear_ratio parameter and returns itself.

Gear ratio between the drive motor and the wheel.

Parameters:

new_drive_motor_gear_ratio (float) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_steer_motor_gear_ratio(new_steer_motor_gear_ratio: float) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the steer_motor_gear_ratio parameter and returns itself.

Gear ratio between the steer motor and the azimuth encoder. For example, the SDS Mk4 has a steering ratio of 12.8.

Parameters:

new_steer_motor_gear_ratio (float) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_coupling_gear_ratio(new_coupling_gear_ratio: float) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the coupling_gear_ratio parameter and returns itself.

Coupled gear ratio between the azimuth encoder 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:

new_coupling_gear_ratio (float) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_wheel_radius(new_wheel_radius: phoenix6.units.meter) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the wheel_radius parameter and returns itself.

Radius of the driving wheel in meters.

Parameters:

new_wheel_radius (meter) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_steer_motor_gains(new_steer_motor_gains: phoenix6.configs.Slot0Configs) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the steer_motor_gains parameter and returns itself.

The steer motor closed-loop gains.

The steer motor uses the control ouput type specified by SteerMotorClosedLoopOutput and any SwerveModule.SteerRequestType. These gains operate on azimuth rotations (after the gear ratio).

Parameters:

new_steer_motor_gains (Slot0Configs) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_drive_motor_gains(new_drive_motor_gains: phoenix6.configs.Slot0Configs) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the drive_motor_gains parameter and returns itself.

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-loop SwerveModule.DriveRequestType. These gains operate on motor rotor rotations (before the gear ratio).

Parameters:

new_drive_motor_gains (Slot0Configs) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_steer_motor_closed_loop_output(new_steer_motor_closed_loop_output: ClosedLoopOutputType) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the steer_motor_closed_loop_output parameter and returns itself.

The closed-loop output type to use for the steer motors.

Parameters:

new_steer_motor_closed_loop_output (ClosedLoopOutputType) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_drive_motor_closed_loop_output(new_drive_motor_closed_loop_output: ClosedLoopOutputType) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the drive_motor_closed_loop_output parameter and returns itself.

The closed-loop output type to use for the drive motors.

Parameters:

new_drive_motor_closed_loop_output (ClosedLoopOutputType) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_slip_current(new_slip_current: phoenix6.units.ampere) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the slip_current parameter and returns itself.

The maximum amount of stator current the drive motors can apply without slippage.

Parameters:

new_slip_current (ampere) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_speed_at12_volts(new_speed_at12_volts: phoenix6.units.meters_per_second) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the speed_at12_volts parameter and returns itself.

When using open-loop drive control, this specifies the speed at which the robot travels when driven with 12 volts. This is used to approximate the output for a desired velocity. If using closed loop control, this value is ignored.

Parameters:

new_speed_at12_volts (meters_per_second) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_drive_motor_type(new_drive_motor_type: DriveMotorArrangement) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the drive_motor_type parameter and returns itself.

Choose the motor used for the drive motor.

If using a Talon FX, this should be set to TalonFX_Integrated. If using a Talon FXS, this should be set to the motor attached to the Talon FXS.

Parameters:

new_drive_motor_type (DriveMotorArrangement) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_steer_motor_type(new_steer_motor_type: SteerMotorArrangement) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the steer_motor_type parameter and returns itself.

Choose the motor used for the steer motor.

If using a Talon FX, this should be set to TalonFX_Integrated. If using a Talon FXS, this should be set to the motor attached to the Talon FXS.

Parameters:

new_steer_motor_type (SteerMotorArrangement) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_feedback_source(new_feedback_source: SteerFeedbackType) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the feedback_source parameter and returns itself.

Choose how the feedback sensors should be configured.

If the robot does not support Pro, then this should be set to 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.

If this is set to FusedCANcoder or SyncCANcoder when the steer motor is not Pro-licensed, the device will automatically fall back to RemoteCANcoder and report a UsingProFeatureOnUnlicensedDevice status code.

Parameters:

new_feedback_source (SteerFeedbackType) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_drive_motor_initial_configs(new_drive_motor_initial_configs: DriveMotorConfigsT) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the drive_motor_initial_configs parameter and returns itself.

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 with SwerveDrivetrain.config_neutral_mode)

  • MotorOutputConfigs.Inverted (SwerveModuleConstants.DriveMotorInverted)

  • Slot0Configs (SwerveModuleConstants.DriveMotorGains)

  • CurrentLimitsConfigs.StatorCurrentLimit / TorqueCurrentConfigs.PeakForwardTorqueCurrent / TorqueCurrentConfigs.PeakReverseTorqueCurrent (SwerveModuleConstants.SlipCurrent)

  • CurrentLimitsConfigs.StatorCurrentLimitEnable (Enabled)

Parameters:

new_drive_motor_initial_configs (DriveMotorConfigsT) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_steer_motor_initial_configs(new_steer_motor_initial_configs: SteerMotorConfigsT) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the steer_motor_initial_configs parameter and returns itself.

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.EncoderId)

  • FeedbackConfigs.FeedbackSensorSource (SwerveModuleConstants.FeedbackSource)

  • FeedbackConfigs.RotorToSensorRatio (SwerveModuleConstants.SteerMotorGearRatio)

  • MotionMagicConfigs.MotionMagicExpo_kV / MotionMagicConfigs.MotionMagicExpo_kA (Calculated from gear ratios)

  • ClosedLoopGeneralConfigs.ContinuousWrap (true)

Parameters:

new_steer_motor_initial_configs (SteerMotorConfigsT) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_encoder_initial_configs(new_encoder_initial_configs: EncoderConfigsT) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the encoder_initial_configs parameter and returns itself.

The initial configs used to configure the azimuth encoder 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.

For CANcoder, the list of configs that will be overwritten is as follows:

  • MagnetSensorConfigs.MagnetOffset (SwerveModuleConstants.EncoderOffset)

  • MagnetSensorConfigs.SensorDirection (SwerveModuleConstants.EncoderInverted)

Parameters:

new_encoder_initial_configs (EncoderConfigsT) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_steer_inertia(new_steer_inertia: phoenix6.units.kilogram_square_meter) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the steer_inertia parameter and returns itself.

Simulated azimuthal inertia.

Parameters:

new_steer_inertia (kilogram_square_meter) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_drive_inertia(new_drive_inertia: phoenix6.units.kilogram_square_meter) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the drive_inertia parameter and returns itself.

Simulated drive inertia.

Parameters:

new_drive_inertia (kilogram_square_meter) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_steer_friction_voltage(new_steer_friction_voltage: phoenix6.units.volt) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the steer_friction_voltage parameter and returns itself.

Simulated steer voltage required to overcome friction.

Parameters:

new_steer_friction_voltage (volt) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_drive_friction_voltage(new_drive_friction_voltage: phoenix6.units.volt) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the drive_friction_voltage parameter and returns itself.

Simulated drive voltage required to overcome friction.

Parameters:

new_drive_friction_voltage (volt) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

class phoenix6.swerve.SwerveModuleConstantsFactory

Bases: Generic[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Constants that are common across the swerve modules, used for creating instances of module-specific SwerveModuleConstants.

drive_motor_gear_ratio: float = 0

Gear ratio between the drive motor and the wheel.

steer_motor_gear_ratio: float = 0

Gear ratio between the steer motor and the azimuth encoder. For example, the SDS Mk4 has a steering ratio of 12.8.

coupling_gear_ratio: float = 0

Coupled gear ratio between the azimuth encoder 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.

wheel_radius: phoenix6.units.meter = 0

Radius of the driving wheel in meters.

steer_motor_gains: phoenix6.configs.Slot0Configs

The steer motor closed-loop gains.

The steer motor uses the control ouput type specified by SteerMotorClosedLoopOutput and any SwerveModule.SteerRequestType. These gains operate on azimuth rotations (after the gear ratio).

drive_motor_gains: phoenix6.configs.Slot0Configs

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-loop SwerveModule.DriveRequestType. These gains operate on motor rotor rotations (before the gear ratio).

steer_motor_closed_loop_output: ClosedLoopOutputType

The closed-loop output type to use for the steer motors.

drive_motor_closed_loop_output: ClosedLoopOutputType

The closed-loop output type to use for the drive motors.

slip_current: phoenix6.units.ampere = 120

The maximum amount of stator current the drive motors can apply without slippage.

speed_at12_volts: phoenix6.units.meters_per_second = 0

When using open-loop drive control, this specifies the speed at which the robot travels when driven with 12 volts. This is used to approximate the output for a desired velocity. If using closed loop control, this value is ignored.

drive_motor_type: DriveMotorArrangement

Choose the motor used for the drive motor.

If using a Talon FX, this should be set to TalonFX_Integrated. If using a Talon FXS, this should be set to the motor attached to the Talon FXS.

steer_motor_type: SteerMotorArrangement

Choose the motor used for the steer motor.

If using a Talon FX, this should be set to TalonFX_Integrated. If using a Talon FXS, this should be set to the motor attached to the Talon FXS.

feedback_source: SteerFeedbackType

Choose how the feedback sensors should be configured.

If the robot does not support Pro, then this should be set to 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.

If this is set to FusedCANcoder or SyncCANcoder when the steer motor is not Pro-licensed, the device will automatically fall back to RemoteCANcoder and report a UsingProFeatureOnUnlicensedDevice status code.

drive_motor_initial_configs: DriveMotorConfigsT

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 with SwerveDrivetrain.config_neutral_mode)

  • MotorOutputConfigs.Inverted (SwerveModuleConstants.DriveMotorInverted)

  • Slot0Configs (SwerveModuleConstants.DriveMotorGains)

  • CurrentLimitsConfigs.StatorCurrentLimit / TorqueCurrentConfigs.PeakForwardTorqueCurrent / TorqueCurrentConfigs.PeakReverseTorqueCurrent (SwerveModuleConstants.SlipCurrent)

  • CurrentLimitsConfigs.StatorCurrentLimitEnable (Enabled)

steer_motor_initial_configs: SteerMotorConfigsT

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.EncoderId)

  • FeedbackConfigs.FeedbackSensorSource (SwerveModuleConstants.FeedbackSource)

  • FeedbackConfigs.RotorToSensorRatio (SwerveModuleConstants.SteerMotorGearRatio)

  • MotionMagicConfigs.MotionMagicExpo_kV / MotionMagicConfigs.MotionMagicExpo_kA (Calculated from gear ratios)

  • ClosedLoopGeneralConfigs.ContinuousWrap (true)

encoder_initial_configs: EncoderConfigsT

The initial configs used to configure the azimuth encoder 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.

For CANcoder, the list of configs that will be overwritten is as follows:

  • MagnetSensorConfigs.MagnetOffset (SwerveModuleConstants.EncoderOffset)

  • MagnetSensorConfigs.SensorDirection (SwerveModuleConstants.EncoderInverted)

steer_inertia: phoenix6.units.kilogram_square_meter = 1e-05

Simulated azimuthal inertia.

drive_inertia: phoenix6.units.kilogram_square_meter = 0.001

Simulated drive inertia.

steer_friction_voltage: phoenix6.units.volt = 0.25

Simulated steer voltage required to overcome friction.

drive_friction_voltage: phoenix6.units.volt = 0.25

Simulated drive voltage required to overcome friction.

with_drive_motor_gear_ratio(new_drive_motor_gear_ratio: float) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the drive_motor_gear_ratio parameter and returns itself.

Gear ratio between the drive motor and the wheel.

Parameters:

new_drive_motor_gear_ratio (float) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_steer_motor_gear_ratio(new_steer_motor_gear_ratio: float) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the steer_motor_gear_ratio parameter and returns itself.

Gear ratio between the steer motor and the azimuth encoder. For example, the SDS Mk4 has a steering ratio of 12.8.

Parameters:

new_steer_motor_gear_ratio (float) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_coupling_gear_ratio(new_coupling_gear_ratio: float) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the coupling_gear_ratio parameter and returns itself.

Coupled gear ratio between the azimuth encoder 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:

new_coupling_gear_ratio (float) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_wheel_radius(new_wheel_radius: phoenix6.units.meter) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the wheel_radius parameter and returns itself.

Radius of the driving wheel in meters.

Parameters:

new_wheel_radius (meter) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_steer_motor_gains(new_steer_motor_gains: phoenix6.configs.Slot0Configs) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the steer_motor_gains parameter and returns itself.

The steer motor closed-loop gains.

The steer motor uses the control ouput type specified by SteerMotorClosedLoopOutput and any SwerveModule.SteerRequestType. These gains operate on azimuth rotations (after the gear ratio).

Parameters:

new_steer_motor_gains (Slot0Configs) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_drive_motor_gains(new_drive_motor_gains: phoenix6.configs.Slot0Configs) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the drive_motor_gains parameter and returns itself.

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-loop SwerveModule.DriveRequestType. These gains operate on motor rotor rotations (before the gear ratio).

Parameters:

new_drive_motor_gains (Slot0Configs) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_steer_motor_closed_loop_output(new_steer_motor_closed_loop_output: ClosedLoopOutputType) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the steer_motor_closed_loop_output parameter and returns itself.

The closed-loop output type to use for the steer motors.

Parameters:

new_steer_motor_closed_loop_output (ClosedLoopOutputType) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_drive_motor_closed_loop_output(new_drive_motor_closed_loop_output: ClosedLoopOutputType) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the drive_motor_closed_loop_output parameter and returns itself.

The closed-loop output type to use for the drive motors.

Parameters:

new_drive_motor_closed_loop_output (ClosedLoopOutputType) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_slip_current(new_slip_current: phoenix6.units.ampere) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the slip_current parameter and returns itself.

The maximum amount of stator current the drive motors can apply without slippage.

Parameters:

new_slip_current (ampere) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_speed_at12_volts(new_speed_at12_volts: phoenix6.units.meters_per_second) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the speed_at12_volts parameter and returns itself.

When using open-loop drive control, this specifies the speed at which the robot travels when driven with 12 volts. This is used to approximate the output for a desired velocity. If using closed loop control, this value is ignored.

Parameters:

new_speed_at12_volts (meters_per_second) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_drive_motor_type(new_drive_motor_type: DriveMotorArrangement) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the drive_motor_type parameter and returns itself.

Choose the motor used for the drive motor.

If using a Talon FX, this should be set to TalonFX_Integrated. If using a Talon FXS, this should be set to the motor attached to the Talon FXS.

Parameters:

new_drive_motor_type (DriveMotorArrangement) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_steer_motor_type(new_steer_motor_type: SteerMotorArrangement) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the steer_motor_type parameter and returns itself.

Choose the motor used for the steer motor.

If using a Talon FX, this should be set to TalonFX_Integrated. If using a Talon FXS, this should be set to the motor attached to the Talon FXS.

Parameters:

new_steer_motor_type (SteerMotorArrangement) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_feedback_source(new_feedback_source: SteerFeedbackType) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the feedback_source parameter and returns itself.

Choose how the feedback sensors should be configured.

If the robot does not support Pro, then this should be set to 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.

If this is set to FusedCANcoder or SyncCANcoder when the steer motor is not Pro-licensed, the device will automatically fall back to RemoteCANcoder and report a UsingProFeatureOnUnlicensedDevice status code.

Parameters:

new_feedback_source (SteerFeedbackType) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_drive_motor_initial_configs(new_drive_motor_initial_configs: DriveMotorConfigsT) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the drive_motor_initial_configs parameter and returns itself.

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 with SwerveDrivetrain.config_neutral_mode)

  • MotorOutputConfigs.Inverted (SwerveModuleConstants.DriveMotorInverted)

  • Slot0Configs (SwerveModuleConstants.DriveMotorGains)

  • CurrentLimitsConfigs.StatorCurrentLimit / TorqueCurrentConfigs.PeakForwardTorqueCurrent / TorqueCurrentConfigs.PeakReverseTorqueCurrent (SwerveModuleConstants.SlipCurrent)

  • CurrentLimitsConfigs.StatorCurrentLimitEnable (Enabled)

Parameters:

new_drive_motor_initial_configs (DriveMotorConfigsT) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_steer_motor_initial_configs(new_steer_motor_initial_configs: SteerMotorConfigsT) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the steer_motor_initial_configs parameter and returns itself.

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.EncoderId)

  • FeedbackConfigs.FeedbackSensorSource (SwerveModuleConstants.FeedbackSource)

  • FeedbackConfigs.RotorToSensorRatio (SwerveModuleConstants.SteerMotorGearRatio)

  • MotionMagicConfigs.MotionMagicExpo_kV / MotionMagicConfigs.MotionMagicExpo_kA (Calculated from gear ratios)

  • ClosedLoopGeneralConfigs.ContinuousWrap (true)

Parameters:

new_steer_motor_initial_configs (SteerMotorConfigsT) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_encoder_initial_configs(new_encoder_initial_configs: EncoderConfigsT) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the encoder_initial_configs parameter and returns itself.

The initial configs used to configure the azimuth encoder 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.

For CANcoder, the list of configs that will be overwritten is as follows:

  • MagnetSensorConfigs.MagnetOffset (SwerveModuleConstants.EncoderOffset)

  • MagnetSensorConfigs.SensorDirection (SwerveModuleConstants.EncoderInverted)

Parameters:

new_encoder_initial_configs (EncoderConfigsT) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_steer_inertia(new_steer_inertia: phoenix6.units.kilogram_square_meter) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the steer_inertia parameter and returns itself.

Simulated azimuthal inertia.

Parameters:

new_steer_inertia (kilogram_square_meter) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_drive_inertia(new_drive_inertia: phoenix6.units.kilogram_square_meter) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the drive_inertia parameter and returns itself.

Simulated drive inertia.

Parameters:

new_drive_inertia (kilogram_square_meter) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_steer_friction_voltage(new_steer_friction_voltage: phoenix6.units.volt) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the steer_friction_voltage parameter and returns itself.

Simulated steer voltage required to overcome friction.

Parameters:

new_steer_friction_voltage (volt) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

with_drive_friction_voltage(new_drive_friction_voltage: phoenix6.units.volt) SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Modifies the drive_friction_voltage parameter and returns itself.

Simulated drive voltage required to overcome friction.

Parameters:

new_drive_friction_voltage (volt) – Parameter to modify

Returns:

this object

Return type:

SwerveModuleConstantsFactory[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

create_module_constants(steer_motor_id: int, drive_motor_id: int, encoder_id: int, encoder_offset: phoenix6.units.rotation, location_x: phoenix6.units.meter, location_y: phoenix6.units.meter, drive_motor_inverted: bool, steer_motor_inverted: bool, encoder_inverted: bool) SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

Creates the constants for a swerve module with the given properties.

Parameters:
  • steer_motor_id (int) – CAN ID of the steer motor.

  • drive_motor_id (int) – CAN ID of the drive motor.

  • encoder_id (int) – CAN ID of the absolute encoder used for azimuth.

  • encoder_offset (rotation) – Offset of the azimuth encoder.

  • location_x (meter) – The location of this module’s wheels relative to the physical center of the robot in meters along the X axis of the robot.

  • location_y (meter) – The location of this module’s wheels relative to the physical center of the robot in meters along the Y axis of the robot.

  • drive_motor_inverted (bool) – True if the drive motor is inverted.

  • steer_motor_inverted (bool) – True if the steer motor is inverted from the azimuth. The azimuth should rotate counter-clockwise (as seen from the top of the robot) for a positive motor output.

  • encoder_inverted (bool) – True if the azimuth encoder is inverted from the azimuth. The encoder should report a positive velocity when the azimuth rotates counter-clockwise (as seen from the top of the robot).

Returns:

Constants for the swerve module

Return type:

SwerveModuleConstants[DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT]

class phoenix6.swerve.SwerveDrivetrain(drive_motor_type: type[DriveMotorT], steer_motor_type: type[SteerMotorT], encoder_type: type[EncoderT], drivetrain_constants: phoenix6.swerve.swerve_drivetrain_constants.SwerveDrivetrainConstants, modules: list[phoenix6.swerve.swerve_module_constants.SwerveModuleConstants])
class phoenix6.swerve.SwerveDrivetrain(drive_motor_type: type[DriveMotorT], steer_motor_type: type[SteerMotorT], encoder_type: type[EncoderT], drivetrain_constants: phoenix6.swerve.swerve_drivetrain_constants.SwerveDrivetrainConstants, odometry_update_frequency: phoenix6.units.hertz, modules: list[phoenix6.swerve.swerve_module_constants.SwerveModuleConstants])
class phoenix6.swerve.SwerveDrivetrain(drive_motor_type: type[DriveMotorT], steer_motor_type: type[SteerMotorT], encoder_type: type[EncoderT], drivetrain_constants: phoenix6.swerve.swerve_drivetrain_constants.SwerveDrivetrainConstants, odometry_update_frequency: phoenix6.units.hertz, odometry_standard_deviation: tuple[float, float, float], vision_standard_deviation: tuple[float, float, float], modules: list[phoenix6.swerve.swerve_module_constants.SwerveModuleConstants])

Bases: Generic[DriveMotorT, SteerMotorT, EncoderT]

Swerve Drive class utilizing CTR Electronics’ Phoenix 6 API.

This class handles the kinematics, configuration, and odometry of a swerve drive utilizing CTR Electronics devices. We recommend using the Swerve Project Generator in Tuner X to create a template project that demonstrates how to use this class.

This class performs pose estimation internally using a separate odometry thread. Vision measurements can be added using add_vision_measurement. Other odometry APIs such as reset_pose are also available. The resulting pose estimate can be retrieved along with module states and other information using get_state. Additionally, the odometry thread synchronously provides all new state updates to a telemetry function registered with register_telemetry.

This class will construct the hardware devices internally, so the user only specifies the constants (IDs, PID gains, gear ratios, etc). Getters for these hardware devices are available.

If using the generator, the order in which modules are constructed is Front Left, Front Right, Back Left, Back Right. This means if you need the Back Left module, call get_module(2) to get the third (0-indexed) module.

class SwerveDriveState

Plain-Old-Data class holding the state of the swerve drivetrain. This encapsulates most data that is relevant for telemetry or decision-making from the Swerve Drive.

pose

The current pose of the robot

speeds

The current velocity of the robot

module_states: list[SwerveModuleState]

The current module states

module_targets: list[SwerveModuleState]

The target module states

module_positions: list[SwerveModulePosition]

The current module positions

raw_heading

The raw heading of the robot, unaffected by vision updates and odometry resets

timestamp: phoenix6.units.second = 0.0

The timestamp of the state capture, in the timebase of utils.get_current_time_seconds()

odometry_period: phoenix6.units.second = 0.0

The measured odometry update period, in seconds

successful_daqs = 0

Number of successful data acquisitions

failed_daqs = 0

Number of failed data acquisitions

class OdometryThread(drivetrain: int)

Performs swerve module updates in a separate thread to minimize latency.

Parameters:

drivetrain (int) – ID of the swerve drivetrain

start()

Starts the odometry thread.

stop()

Stops the odometry thread.

is_odometry_valid() bool

Check if the odometry is currently valid.

Returns:

True if odometry is valid

Return type:

bool

set_thread_priority(priority: int)

Sets the odometry thread priority to a real time priority under the specified priority level

Parameters:

priority (int) – Priority level to set the odometry thread to. This is a value between 0 and 99, with 99 indicating higher priority and 0 indicating lower priority.

property odometry_thread: OdometryThread

Gets a reference to the odometry thread.

Returns:

Odometry thread

Return type:

OdometryThread

property kinematics: wpimath.kinematics.SwerveDrive2Kinematics | wpimath.kinematics.SwerveDrive3Kinematics | wpimath.kinematics.SwerveDrive4Kinematics | wpimath.kinematics.SwerveDrive6Kinematics

Gets a reference to the kinematics used for the drivetrain.

Returns:

Swerve kinematics

Return type:

SwerveDrive2Kinematics | SwerveDrive3Kinematics | SwerveDrive4Kinematics | SwerveDrive6Kinematics

property modules: list[phoenix6.swerve.swerve_module.SwerveModule[DriveMotorT, SteerMotorT, EncoderT]]

Get a reference to the full array of modules. The indexes correspond to the module described in the constructor.

Returns:

Reference to the SwerveModule array

Return type:

list[SwerveModule[DriveMotorT, SteerMotorT, EncoderT]]

property module_locations: list[Translation2d]

Gets the locations of the swerve modules.

Returns:

Reference to the array of swerve module locations

Return type:

list[Translation2d]

property pigeon2: phoenix6.hardware.pigeon2.Pigeon2

Gets this drivetrain’s Pigeon 2 reference.

This should be used only to access signals and change configurations that the swerve drivetrain does not configure itself.

Returns:

This drivetrain’s Pigeon 2 reference

Return type:

Pigeon2

close()

Closes this SwerveDrivetrain instance.

update_sim_state(dt: phoenix6.units.second, supply_voltage: phoenix6.units.volt)

Updates all the simulation state variables for this drivetrain class. User provides the update variables for the simulation.

Parameters:
  • dt (second) – time since last update call

  • supply_voltage (volt) – voltage as seen at the motor controllers

is_on_can_fd() bool

Gets whether the drivetrain is on a CAN FD bus.

Returns:

True if on CAN FD

Return type:

bool

get_odometry_frequency() phoenix6.units.hertz

Gets the target odometry update frequency.

Returns:

Target odometry update frequency

Return type:

hertz

is_odometry_valid() bool

Check if the odometry is currently valid.

Returns:

True if odometry is valid

Return type:

bool

set_control(request: phoenix6.swerve.requests.SwerveRequest)

Applies the specified control request to this swerve drivetrain.

Parameters:

request (requests.SwerveRequest) – Request to apply

get_state() SwerveDriveState

Gets the current state of the swerve drivetrain. This includes information such as the pose estimate, module states, and chassis speeds.

Returns:

Current state of the drivetrain

Return type:

SwerveDriveState

get_state_copy() SwerveDriveState

Gets a copy of the current state of the swerve drivetrain. This includes information such as the pose estimate, module states, and chassis speeds.

This can be used to get a thread-safe copy of the state object.

Returns:

Copy of the current state of the drivetrain

Return type:

SwerveDriveState

register_telemetry(telemetry_function: Callable[[SwerveDriveState], None])

Register the specified lambda to be executed whenever our SwerveDriveState function is updated in our odometry thread.

It is imperative that this function is cheap, as it will be executed along with the odometry call, and if this takes a long time, it may negatively impact the odometry of this stack.

This can also be used for logging data if the function performs logging instead of telemetry. Additionally, the SwerveDriveState object can be cloned and stored for later processing.

Parameters:

telemetry_function (Callable[[SwerveDriveState], None]) – Function to call for telemetry or logging

config_neutral_mode(neutral_mode: phoenix6.signals.spn_enums.NeutralModeValue) phoenix6.status_code.StatusCode

Configures the neutral mode to use for all modules’ drive motors.

Parameters:

neutral_mode (NeutralModeValue) – The drive motor neutral mode

Returns:

Status code of the first failed config call, or OK if all succeeded

Return type:

StatusCode

tare_everything()

Zero’s this swerve drive’s odometry entirely.

This will zero the entire odometry, and place the robot at 0,0

seed_field_centric()

Resets the rotation of the robot pose to 0 from the ForwardPerspectiveValue.OPERATOR_PERSPECTIVE perspective. This makes the current orientation of the robot X forward for field-centric maneuvers.

This is equivalent to calling reset_rotation with the operator perspective rotation.

reset_pose(pose: Pose2d)

Resets the pose of the robot. The pose should be from the ForwardPerspectiveValue.BLUE_ALLIANCE perspective.

Parameters:

pose (Pose2d) – Pose to make the current pose

reset_translation(translation: Translation2d)

Resets the translation of the robot pose without affecting rotation. The translation should be from the ForwardPerspectiveValue.BLUE_ALLIANCE perspective.

Parameters:

translation (Translation2d) – Translation to make the current translation

reset_rotation(rotation: Rotation2d)

Resets the rotation of the robot pose without affecting translation. The rotation should be from the ForwardPerspectiveValue.BLUE_ALLIANCE perspective.

Parameters:

rotation (Rotation2d) – Rotation to make the current rotation

set_operator_perspective_forward(field_direction: Rotation2d)

Takes the ForwardPerspectiveValue.BLUE_ALLIANCE perpective direction and treats it as the forward direction for ForwardPerspectiveValue.OPERATOR_PERSPECTIVE.

If the operator is in the Blue Alliance Station, this should be 0 degrees. If the operator is in the Red Alliance Station, this should be 180 degrees.

This does not change the robot pose, which is in the ForwardPerspectiveValue.BLUE_ALLIANCE perspective. As a result, the robot pose may need to be reset using reset_pose.

Parameters:

field_direction (Rotation2d) – Heading indicating which direction is forward from the ForwardPerspectiveValue.BLUE_ALLIANCE perspective

get_operator_forward_direction() Rotation2d

Returns the ForwardPerspectiveValue.BLUE_ALLIANCE perpective direction that is treated as the forward direction for ForwardPerspectiveValue.OPERATOR_PERSPECTIVE.

If the operator is in the Blue Alliance Station, this should be 0 degrees. If the operator is in the Red Alliance Station, this should be 180 degrees.

Returns:

Heading indicating which direction is forward from the ForwardPerspectiveValue.BLUE_ALLIANCE perspective

Return type:

Rotation2d

add_vision_measurement(vision_robot_pose: Pose2d, timestamp: phoenix6.units.second, vision_measurement_std_devs: tuple[float, float, float] | None = None)

Adds a vision measurement to the Kalman Filter. This will correct the odometry pose estimate while still accounting for measurement noise.

This method can be called as infrequently as you want, as long as you are calling SwerveDrivePoseEstimator.update every loop.

To promote stability of the pose estimate and make it robust to bad vision data, we recommend only adding vision measurements that are already within one meter or so of the current pose estimate.

Note that the vision measurement standard deviations passed into this method will continue to apply to future measurements until a subsequent call to SwerveDrivePoseEstimator.setVisionMeasurementStdDevs or this method.

Parameters:
  • vision_robot_pose (Pose2d) – The pose of the robot as measured by the vision camera.

  • timestamp (second) – The timestamp of the vision measurement in seconds. Note that you must use a timestamp with an epoch since system startup (i.e., the epoch of this timestamp is the same epoch as utils.get_current_time_seconds). This means that you should use utils.get_current_time_seconds as your time source or sync the epochs. An FPGA timestamp can be converted to the correct timebase using utils.fpga_to_current_time.

  • vision_measurement_std_devs (tuple[float, float, float] | None) – Standard deviations of the vision pose measurement (x position in meters, y position in meters, and heading in radians). Increase these numbers to trust the vision pose measurement less.

set_vision_measurement_std_devs(vision_measurement_std_devs: tuple[float, float, float])

Sets the pose estimator’s trust of global measurements. This might be used to change trust in vision measurements after the autonomous period, or to change trust as distance to a vision target increases.

Parameters:

vision_measurement_std_devs (tuple[float, float, float]) – Standard deviations of the vision measurements. Increase these numbers to trust global measurements from vision less. This matrix is in the form [x, y, theta]ᵀ, with units in meters and radians.

sample_pose_at(timestamp: phoenix6.units.second) Pose2d | None

Return the pose at a given timestamp, if the buffer is not empty.

Parameters:

timestamp (second) – The pose’s timestamp. Note that you must use a timestamp with an epoch since system startup (i.e., the epoch of this timestamp is the same epoch as utils.get_current_time_seconds). This means that you should use utils.get_current_time_seconds as your time source in this case. An FPGA timestamp can be converted to the correct timebase using utils.fpga_to_current_time.

Returns:

The pose at the given timestamp (or None if the buffer is empty).

Return type:

Pose2d | None

get_module(index: int) phoenix6.swerve.swerve_module.SwerveModule[DriveMotorT, SteerMotorT, EncoderT]

Get a reference to the module at the specified index. The index corresponds to the module described in the constructor.

Parameters:

index (int) – Which module to get

Returns:

Reference to SwerveModule

Return type:

SwerveModule[DriveMotorT, SteerMotorT, EncoderT]

get_rotation3d() wpimath.geometry.Rotation3d

Gets the current orientation of the robot as a Rotation3d from the Pigeon 2 quaternion values.

Returns:

The robot orientation as a Rotation3d

Return type:

Rotation3d

class phoenix6.swerve.SwerveControlParameters

Contains everything the control requests need to calculate the module state.

drivetrain_id = 0

ID of the native drivetrain instance, used for native calls

kinematics: wpimath.kinematics.SwerveDrive2Kinematics | wpimath.kinematics.SwerveDrive3Kinematics | wpimath.kinematics.SwerveDrive4Kinematics | wpimath.kinematics.SwerveDrive6Kinematics

The kinematics object used for control

module_locations: list[Translation2d]

The locations of the swerve modules

max_speed: phoenix6.units.meters_per_second = 0.0

The max speed of the robot at 12 V output, in m/s

operator_forward_direction

The forward direction from the operator perspective

current_chassis_speed

The current chassis speeds of the robot

current_pose

The current pose of the robot

timestamp: phoenix6.units.second = 0.0

The timestamp of the current control apply, in the timebase of utils.get_current_time_seconds()

update_period: phoenix6.units.second = 0.0

The update period of control apply

class phoenix6.swerve.SwerveModule(drive_motor_type: type[DriveMotorT], steer_motor_type: type[SteerMotorT], encoder_type: type[EncoderT], constants: phoenix6.swerve.swerve_module_constants.SwerveModuleConstants, canbus_name: str, drivetrain_id: int, index: int)

Bases: Generic[DriveMotorT, SteerMotorT, EncoderT]

Swerve Module class that encapsulates a swerve module powered by CTR Electronics devices.

This class handles the hardware devices and configures them for swerve module operation using the Phoenix 6 API.

This class constructs hardware devices internally, so the user only specifies the constants (IDs, PID gains, gear ratios, etc). Getters for these hardware devices are available.

Parameters:
  • drive_motor_type (type[DriveMotorT]) – Type of the drive motor

  • steer_motor_type (type[SteerMotorT]) – Type of the steer motor

  • encoder_type (type[EncoderT]) – Type of the azimuth encoder

  • constants (SwerveModuleConstants) – Constants used to construct the module

  • canbus_name (str) – The name of the CAN bus this module is on

  • drivetrain_id (int) – ID of the swerve drivetrain

  • index (int) – Index of this swerve module

class SteerRequestType(*args, **kwds)

Bases: enum.Enum

All possible control requests for the module steer motor.

MOTION_MAGIC_EXPO = 0

Control the drive motor using a Motion Magic® Expo request. The control output type is determined by SwerveModuleConstants.SteerMotorClosedLoopOutput

POSITION = 1

Control the drive motor using an unprofiled position request. The control output type is determined by SwerveModuleConstants.SteerMotorClosedLoopOutput

class DriveRequestType(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

OPEN_LOOP_VOLTAGE = 0

Control the drive motor using an open-loop voltage request.

VELOCITY = 1

Control the drive motor using a velocity closed-loop request. The control output type is determined by SwerveModuleConstants.DriveMotorClosedLoopOutput

class ModuleRequest

Contains everything the swerve module needs to apply a request.

state

Unoptimized speed and direction the module should target.

wheel_force_feedforward_x: phoenix6.units.newton = 0.0

Robot-centric wheel force feedforward to apply in the X direction. X is defined as forward according to WPILib convention, so this determines the forward force to apply.

This force should include friction applied to the ground.

wheel_force_feedforward_y: phoenix6.units.newton = 0.0

Robot-centric wheel force feedforward to apply in the Y direction. Y is defined as to the left according to WPILib convention, so this determines the force to apply to the left.

This force should include friction applied to the ground.

drive_request

The type of control request to use for the drive motor.

steer_request

The type of control request to use for the steer motor.

update_period: second = 0.0

The update period of the module request. Setting this to a non-zero value adds a velocity feedforward to the steer motor.

enable_foc = True

When using Voltage-based control, set to true (default) to use FOC commutation (requires Phoenix Pro), which increases peak power by ~15%. Set to false to use trapezoidal commutation. This is ignored when using Torque-based control, which always uses FOC.

FOC improves motor performance by leveraging torque (current) control. However, this may be inconvenient for applications that require specifying duty cycle or voltage. CTR-Electronics has developed a hybrid method that combines the performances gains of FOC while still allowing applications to provide duty cycle or voltage demand. This not to be confused with simple sinusoidal control or phase voltage control which lacks the performance gains.

with_state(new_state: SwerveModuleState) SwerveModule

Modifies the state parameter and returns itself.

Unoptimized speed and direction the module should target.

Parameters:

new_state (SwerveModuleState) – Parameter to modify

Returns:

Itself

Return type:

SwerveModule.ModuleRequest

with_wheel_force_feedforward_x(new_wheel_force_feedforward_x: phoenix6.units.newton) SwerveModule

Modifies the wheel_force_feedforward_x parameter and returns itself.

Robot-centric wheel force feedforward to apply in the X direction. X is defined as forward according to WPILib convention, so this determines the forward force to apply.

This force should include friction applied to the ground.

Parameters:

wheel_force_feedforward_x (newton) – Parameter to modify

Returns:

Itself

Return type:

SwerveModule.ModuleRequest

with_wheel_force_feedforward_y(new_wheel_force_feedforward_y: phoenix6.units.newton) SwerveModule

Modifies the wheel_force_feedforward_y parameter and returns itself.

Robot-centric wheel force feedforward to apply in the Y direction. Y is defined as to the left according to WPILib convention, so this determines the force to apply to the left.

This force should include friction applied to the ground.

Parameters:

wheel_force_feedforward_y (newton) – Parameter to modify

Returns:

Itself

Return type:

SwerveModule.ModuleRequest

with_drive_request(new_drive_request: SwerveModule) SwerveModule

Modifies the drive_request parameter and returns itself.

The type of control request to use for the drive motor.

Parameters:

new_drive_request (SwerveModule.DriveRequestType) – Parameter to modify

Returns:

Itself

Return type:

SwerveModule.ModuleRequest

with_steer_request(new_steer_request: SwerveModule) SwerveModule

Modifies the steer_request parameter and returns itself.

The type of control request to use for the steer motor.

Parameters:

new_steer_request (SwerveModule.SteerRequestType) – Parameter to modify

Returns:

Itself

Return type:

SwerveModule.ModuleRequest

with_update_period(new_update_period: second) SwerveModule

Modifies the update_period parameter and returns itself.

The update period of the module request. Setting this to a non-zero value adds a velocity feedforward to the steer motor.

Parameters:

new_update_period (second) – Parameter to modify

Returns:

Itself

Return type:

SwerveModule.ModuleRequest

with_enable_foc(new_enable_foc: bool) SwerveModule

Modifies the enable_foc parameter and returns itself.

When using Voltage-based control, set to true (default) to use FOC commutation (requires Phoenix Pro), which increases peak power by ~15%. Set to false to use trapezoidal commutation. This is ignored when using Torque-based control, which always uses FOC.

FOC improves motor performance by leveraging torque (current) control. However, this may be inconvenient for applications that require specifying duty cycle or voltage. CTR-Electronics has developed a hybrid method that combines the performances gains of FOC while still allowing applications to provide duty cycle or voltage demand. This not to be confused with simple sinusoidal control or phase voltage control which lacks the performance gains.

Parameters:

new_enable_foc (bool) – Parameter to modify

Returns:

Itself

Return type:

SwerveModule.ModuleRequest

property drive_closed_loop_output_type: phoenix6.swerve.swerve_module_constants.ClosedLoopOutputType

Gets the closed-loop output type to use for the drive motor.

Returns:

Drive motor closed-loop output type

Return type:

ClosedLoopOutputType

property steer_closed_loop_output_type: phoenix6.swerve.swerve_module_constants.ClosedLoopOutputType

Gets the closed-loop output type to use for the steer motor.

Returns:

Steer motor closed-loop output type

Return type:

ClosedLoopOutputType

property drive_motor: DriveMotorT

Gets this module’s Drive Motor reference.

This should be used only to access signals and change configurations that the swerve drivetrain does not configure itself.

Returns:

This module’s Drive Motor reference

Return type:

DriveMotorT

property steer_motor: SteerMotorT

Gets this module’s Steer Motor reference.

This should be used only to access signals and change configurations that the swerve drivetrain does not configure itself.

Returns:

This module’s Steer Motor reference

Return type:

SteerMotorT

property encoder: EncoderT

Gets this module’s azimuth encoder reference.

This should be used only to access signals and change configurations that the swerve drivetrain does not configure itself.

Returns:

This module’s azimuth encoder reference

Return type:

EncoderT

apply(module_request: ModuleRequest)
apply(drive_request: phoenix6.hardware.parent_device.SupportsSendRequest, steer_request: phoenix6.hardware.parent_device.SupportsSendRequest)
get_position(refresh: bool) SwerveModulePosition

Gets the state of this module and passes it back as a SwerveModulePosition object with latency compensated values.

This function is blocking when it performs a refresh.

Parameters:

refresh (bool) – True if the signals should be refreshed

Returns:

SwerveModulePosition containing this module’s state

Return type:

SwerveModulePosition

get_cached_position() SwerveModulePosition

Gets the last cached swerve module position. This differs from get_position in that it will not perform any latency compensation or refresh the signals.

Returns:

Last cached SwerveModulePosition

Return type:

SwerveModulePosition

get_current_state() SwerveModuleState

Get the current state of the module.

This is typically used for telemetry, as the SwerveModulePosition is used for odometry.

Returns:

Current state of the module

Return type:

SwerveModuleState

get_target_state() SwerveModuleState

Get the target state of the module.

This is typically used for telemetry.

Returns:

Target state of the module

Return type:

SwerveModuleState

reset_position()

Resets this module’s drive motor position to 0 rotations.