Maurice 2025
Team 668's robot for Reefscape
Loading...
Searching...
No Matches
CommandSwerveDrivetrain Class Reference
Inheritance diagram for CommandSwerveDrivetrain:

Public Member Functions

None __init__ (self, type drive_motor_type, type steer_motor_type, type encoder_type, swerve.SwerveDrivetrainConstants drivetrain_constants, list[swerve.SwerveModuleConstants] modules)
 
Command apply_request (self, Callable[[], swerve.requests.SwerveRequest] request)
 
 periodic (self)
 
 slowly (self, bool do)
 
Command sys_id_dynamic (self, SysIdRoutine.Direction direction)
 
Command sys_id_quasistatic (self, SysIdRoutine.Direction direction)
 

Public Attributes

 autonpid
 
 reset_pose
 
bool slow = False
 

Protected Member Functions

 _configure_auto_builder (self)
 
 _start_sim_thread (self)
 

Protected Attributes

 _apply_robot_speeds = swerve.requests.ApplyRobotSpeeds()
 
bool _has_applied_operator_perspective = False
 
units.second _last_sim_time = 0.0
 
 _rotation_characterization = swerve.requests.SysIdSwerveRotation()
 
Notifier|None _sim_notifier = None
 
 _steer_characterization = swerve.requests.SysIdSwerveSteerGains()
 
 _sys_id_routine_rotation
 
 _sys_id_routine_steer
 
 _sys_id_routine_to_apply = self._sys_id_routine_translation
 
 _sys_id_routine_translation
 
 _translation_characterization = swerve.requests.SysIdSwerveTranslation()
 

Static Protected Attributes

 _BLUE_ALLIANCE_PERSPECTIVE_ROTATION = Rotation2d.fromDegrees(0)
 
 _RED_ALLIANCE_PERSPECTIVE_ROTATION = Rotation2d.fromDegrees(180)
 
units _SIM_LOOP_PERIOD = 0.005
 

Detailed Description

Class that extends the Phoenix 6 SwerveDrivetrain class and implements
Subsystem so it can easily be used in command-based projects.

Constructor & Destructor Documentation

◆ __init__()

None __init__ ( self,
type drive_motor_type,
type steer_motor_type,
type encoder_type,
swerve.SwerveDrivetrainConstants drivetrain_constants,
list[swerve.SwerveModuleConstants] modules )
Constructs a CTRE SwerveDrivetrain using the specified constants.

This constructs the underlying hardware devices, so users should not construct
the devices themselves. If they need the devices, they can access them through
getters in the classes.

:param drive_motor_type:     Type of the drive motor
:type drive_motor_type:      type
:param steer_motor_type:     Type of the steer motor
:type steer_motor_type:      type
:param encoder_type:         Type of the azimuth encoder
:type encoder_type:          type
:param drivetrain_constants: Drivetrain-wide constants for the swerve drive
:type drivetrain_constants:  swerve.SwerveDrivetrainConstants
:param modules:              Constants for each specific module
:type modules:               list[swerve.SwerveModuleConstants]

Member Function Documentation

◆ _configure_auto_builder()

_configure_auto_builder ( self)
protected

◆ _start_sim_thread()

_start_sim_thread ( self)
protected

◆ apply_request()

Command apply_request ( self,
Callable[[], swerve.requests.SwerveRequest] request )
Returns a command that applies the specified control request to this swerve drivetrain.

:param request: Lambda returning the request to apply
:type request: Callable[[], swerve.requests.SwerveRequest]
:returns: Command to run
:rtype: Command

◆ periodic()

periodic ( self)

◆ slowly()

slowly ( self,
bool do )

◆ sys_id_dynamic()

Command sys_id_dynamic ( self,
SysIdRoutine.Direction direction )
Runs the SysId Dynamic test in the given direction for the routine
specified by self.sys_id_routine_to_apply.

:param direction: Direction of the SysId Dynamic test
:type direction: SysIdRoutine.Direction
:returns: Command to run
:rtype: Command

◆ sys_id_quasistatic()

Command sys_id_quasistatic ( self,
SysIdRoutine.Direction direction )
Runs the SysId Quasistatic test in the given direction for the routine
specified by self.sys_id_routine_to_apply.

:param direction: Direction of the SysId Quasistatic test
:type direction: SysIdRoutine.Direction
:returns: Command to run
:rtype: Command

Member Data Documentation

◆ _apply_robot_speeds

_apply_robot_speeds = swerve.requests.ApplyRobotSpeeds()
protected

◆ _BLUE_ALLIANCE_PERSPECTIVE_ROTATION

_BLUE_ALLIANCE_PERSPECTIVE_ROTATION = Rotation2d.fromDegrees(0)
staticprotected

◆ _has_applied_operator_perspective

bool _has_applied_operator_perspective = False
protected

◆ _last_sim_time

units.second _last_sim_time = 0.0
protected

◆ _RED_ALLIANCE_PERSPECTIVE_ROTATION

_RED_ALLIANCE_PERSPECTIVE_ROTATION = Rotation2d.fromDegrees(180)
staticprotected

◆ _rotation_characterization

_rotation_characterization = swerve.requests.SysIdSwerveRotation()
protected

◆ _SIM_LOOP_PERIOD

_SIM_LOOP_PERIOD = 0.005
staticprotected

◆ _sim_notifier

Notifier | None _sim_notifier = None
protected

◆ _steer_characterization

_steer_characterization = swerve.requests.SysIdSwerveSteerGains()
protected

◆ _sys_id_routine_rotation

_sys_id_routine_rotation
protected
Initial value:
= SysIdRoutine(
SysIdRoutine.Config(
# This is in radians per second², but SysId only supports "volts per second"
rampRate=math.pi / 6,
# Use dynamic voltage of 7 V
stepVoltage=7.0,
# Use default timeout (10 s)
# Log state with SignalLogger class
recordState=lambda state: SignalLogger.write_string(
"SysIdSteer_State", SysIdRoutineLog.stateEnumToString(state)
),
),
SysIdRoutine.Mechanism(
lambda output: (
# output is actually radians per second, but SysId only supports "volts"
self.set_control(
self._rotation_characterization.with_rotational_rate(output)
),
# also log the requested output for SysId
# SignalLogger.write_double("Rotational_Rate", output),
),
lambda log: None,
self,
),
)

◆ _sys_id_routine_steer

_sys_id_routine_steer
protected
Initial value:
= SysIdRoutine(
SysIdRoutine.Config(
# Use default ramp rate (1 V/s) and timeout (10 s)
# Use dynamic voltage of 7 V
stepVoltage=7.0,
# Log state with SignalLogger class
recordState=lambda state: SignalLogger.write_string(
"SysIdSteer_State", SysIdRoutineLog.stateEnumToString(state)
),
),
SysIdRoutine.Mechanism(
lambda output: self.set_control(
self._steer_characterization.with_volts(output)
),
lambda log: None,
self,
),
)

◆ _sys_id_routine_to_apply

_sys_id_routine_to_apply = self._sys_id_routine_translation
protected

◆ _sys_id_routine_translation

_sys_id_routine_translation
protected
Initial value:
= SysIdRoutine(
SysIdRoutine.Config(
# Use default ramp rate (1 V/s) and timeout (10 s)
# Reduce dynamic voltage to 4 V to prevent brownout
stepVoltage=4.0,
# Log state with SignalLogger class
recordState=lambda state: SignalLogger.write_string(
"SysIdTranslation_State", SysIdRoutineLog.stateEnumToString(state)
),
),
SysIdRoutine.Mechanism(
lambda output: self.set_control(
self._translation_characterization.with_volts(output)
),
lambda log: None,
self,
),
)

◆ _translation_characterization

_translation_characterization = swerve.requests.SysIdSwerveTranslation()
protected

◆ autonpid

autonpid

◆ reset_pose

reset_pose

◆ slow

bool slow = False

The documentation for this class was generated from the following file: