phoenix6.hardware¶
Subpackages¶
phoenix6.hardware.corephoenix6.hardware.traitsphoenix6.hardware.traits.common_devicephoenix6.hardware.traits.common_talonphoenix6.hardware.traits.common_talon_with_external_motorphoenix6.hardware.traits.common_talon_with_focphoenix6.hardware.traits.has_external_motorphoenix6.hardware.traits.has_talon_controlsphoenix6.hardware.traits.has_talon_signalsphoenix6.hardware.traits.supports_focphoenix6.hardware.traits.supports_music
Submodules¶
Package Contents¶
- class phoenix6.hardware.ParentDevice(device_id: int, model: str, canbus: phoenix6.canbus.CANBus)¶
Bases:
phoenix6.hardware.traits.common_device.CommonDeviceParent class for all devices.
Constructor for a device
- Parameters:
deviceId (int) – ID of the device
model (str) – Model of the device
canbus (CANBus) – CANbus the device is on
- property device_id: int¶
Gets the ID of this device.
- Returns:
ID of this device
- Return type:
int
- property network: phoenix6.canbus.CANBus¶
Gets the network this device is on.
- Returns:
The network this device is on
- Return type:
- property device_hash: int¶
Gets a number unique for this device’s hardware type and ID. This number is not unique across networks.
This can be used to easily reference hardware devices on the same network in collections such as maps.
- Returns:
Hash of this device
- Return type:
int
- property control_request: SupportsSendRequest¶
Get the latest applied control.
- Returns:
Latest applied control
- Return type:
- property has_reset_occurred: bool¶
Check if the device has reset since the previous call to this routine
- Returns:
True if device has reset
- Return type:
bool
- property is_connected: bool¶
Returns whether the device is still connected to the robot. This is equivalent to refreshing and checking the latency of the Version status signal.
- Parameters:
max_latency_seconds (float) – The maximum latency of the Version status signal before the device is reported as disconnected
- Returns:
True if the device is connected
- Return type:
bool
- get_reset_occurred_checker() Callable[[], bool]¶
Get a lambda that checks for device resets.
- Returns:
A lambda that checks for device resets
- Return type:
Callable[[], bool]
- optimize_bus_utilization(optimized_freq_hz: phoenix6.units.hertz = 4.0, timeout_seconds: phoenix6.units.second = 0.1) phoenix6.status_code.StatusCode¶
Optimizes the device’s bus utilization by reducing the update frequencies of its status signals.
All status signals that have not been explicitly gven an update frequency using BaseStatusSignal.set_update_frequency will be slowed down. Note that if other status signals in the same frame have been given an update frequency, the update frequency will be honored for the entire frame.
This function only needs to be called once on this device in the robot program. Additionally, this method does not necessarily need to be called after setting the update frequencies of other signals.
To restore the default status update frequencies, call reset_signal_frequencies. Alternatively, remove this method call, redeploy the robot application, and power-cycle the device on the bus. The user can also override individual status update frequencies using BaseStatusSignal.set_update_frequency.
- Parameters:
optimized_freq_hz (hertz, optional) – The update frequency to apply to the optimized status signals. A frequency of 0 Hz will turn off the signals. Otherwise, the minimum supported signal frequency is 4 Hz (default).
timeout_seconds (second, optional) – Maximum amount of time to wait for each status frame when performing the action
- Returns:
Status code of the first failed update frequency set call, or OK if all succeeded.
- Return type:
- static optimize_bus_utilization_for_all(*devices: phoenix6.hardware.traits.common_device.CommonDevice | list[phoenix6.hardware.traits.common_device.CommonDevice], optimized_freq_hz: phoenix6.units.hertz = 4.0) phoenix6.status_code.StatusCode¶
Optimizes the bus utilization of the provided devices by reducing the update frequencies of their status signals.
All status signals that have not been explicitly given an update frequency using BaseStatusSignal.set_update_frequency will be slowed down. Note that if other status signals in the same status frame have been given an update frequency, the update frequency will be honored for the entire frame.
This function only needs to be called once in the robot program for the provided devices. Additionally, this method does not necessarily need to be called after setting the update frequencies of other signals.
To restore the default status update frequencies, call reset_signal_frequencies_for_all. Alternatively, remove this method call, redeploy the robot application, and power-cycle the devices on the bus. The user can also override individual status update frequencies using BaseStatusSignal.set_update_frequency.
This will wait up to 0.100 seconds (100ms) for each status frame.
- Parameters:
devices (tuple[CommonDevice | list[CommonDevice], ...]) – Devices for which to optimize bus utilization.
optimized_freq_hz (hertz, optional) – The update frequency to apply to the optimized status signals. A frequency of 0 Hz will turn off the signals. Otherwise, the minimum supported signal frequency is 4 Hz (default). This must be specified using a named parameter at the end of the parameter list.
- Returns:
Status code of the first failed optimize call, or OK if all succeeded
- Return type:
- reset_signal_frequencies(timeout_seconds: phoenix6.units.second = 0.1) phoenix6.status_code.StatusCode¶
Resets the update frequencies of all the device’s status signals to the defaults.
This restores the default update frequency of all status signals, including status signals explicitly given an update frequency using BaseStatusSignal.set_update_frequency and status signals optimized out using optimize_bus_utilization.
- Parameters:
timeout_seconds (second, optional) – Maximum amount of time to wait for each status frame when performing the action
- Returns:
Status code of the first failed update frequency set call, or OK if all succeeded.
- Return type:
- static reset_signal_frequencies_for_all(*devices: phoenix6.hardware.traits.common_device.CommonDevice | list[phoenix6.hardware.traits.common_device.CommonDevice]) phoenix6.status_code.StatusCode¶
Resets the update frequencies of all the devices’ status signals to the defaults.
This restores the default update frequency of all status signals, including status signals explicitly given an update frequency using BaseStatusSignal.set_update_frequency and status signals optimized out using optimize_bus_utilization_for_all.
This will wait up to 0.100 seconds (100ms) for each status frame.
- Parameters:
devices (tuple[CommonDevice | list[CommonDevice], ...]) – Devices for which to restore default update frequencies.
- Returns:
Status code of the first failed restore call, or OK if all succeeded
- Return type:
- class phoenix6.hardware.TalonFX(device_id: int, canbus: phoenix6.canbus.CANBus)¶
Bases:
phoenix6.hardware.core.core_talon_fx.CoreTalonFXClass description for the Talon FX integrated motor controller.
Constructs a new Talon FX motor controller object.
- Parameters:
device_id (int) – ID of the device, as configured in Phoenix Tuner
canbus (CANBus) – The CAN bus this device is on
- classmethod none() Self¶
Constructs a stubbed-out TalonFX, where all status signals, controls, configs, etc. perform no action and immediately return OK. This can be used to silence error messages for devices that have been completely removed from the robot.
- Returns:
Stubbed-out TalonFX
- Return type:
- close()¶
- setThrottle(throttle: float)¶
Sets the throttle of the motor controller.
- Parameters:
throttle (float) – The throttle where -1 indicates full reverse and 1 indicates full forward.
- setVoltage(voltage: wpimath.units.volts)¶
Sets the direct voltage output of the motor controller.
Compensates for the current bus voltage to ensure that the desired voltage is output even if the battery voltage is below 12V - highly useful when the voltage outputs are “meaningful” (e.g. they come from a feedforward calculation).
- Parameters:
voltage (units.volts) – The voltage.
- getThrottle() float¶
Gets the throttle of the motor controller.
- Returns:
The throttle where -1 represents full reverse and 1 represents full forward.
- Return type:
float
- disable()¶
Disables the motor controller.
- configNeutralMode(neutralMode: phoenix6.signals.NeutralModeValue, timeout_seconds: wpimath.units.seconds = 0.1) phoenix6.status_code.StatusCode¶
Sets the mode of operation when output is neutral or disabled. This is equivalent to setting the MotorOutputConfigs.neutral_mode when applying a TalonFXConfiguration to the motor.
Since neutral mode is a config, this API is blocking. We recommend that users avoid calling this API periodically.
- Parameters:
neutralMode (signals.NeutralModeValue) – The state of the motor controller bridge when output is neutral or disabled
timeout_seconds (units.seconds) – Maximum amount of time to wait when performing configuration
- Returns:
Status of refreshing and applying the neutral mode config
- Return type:
- feed()¶
- setExpiration(expirationTime: wpimath.units.seconds)¶
Set the expiration time for the corresponding motor safety object.
- Parameters:
expirationTime (units.seconds) – The timeout value in seconds.
- getExpiration() wpimath.units.seconds¶
Retrieve the timeout value for the corresponding motor safety object.
- Returns:
the timeout value in seconds.
- Return type:
units.seconds
- isAlive() bool¶
Determine of the motor is still operating or has timed out.
- Returns:
a True value if the motor is still operating normally and hasn’t timed out
- Return type:
bool
- setSafetyEnabled(enabled: bool)¶
Enable/disable motor safety for this device.
Turn on and off the motor safety option for this object.
- Parameters:
enabled (bool) – True if motor safety is enforced for this object.
- isSafetyEnabled() bool¶
Return the state of the motor safety enabled flag.
Return if the motor safety is currently enabled for this device.
- Returns:
True if motor safety is enforced for this device
- Return type:
bool
- stopMotor()¶
Called to stop the motor when the timeout expires.
- getDescription() str¶
- Returns:
Description of the motor controller
- Return type:
str
- class phoenix6.hardware.CANcoder(device_id: int, canbus: phoenix6.canbus.CANBus)¶
Bases:
phoenix6.hardware.core.core_cancoder.CoreCANcoderClass for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along with filtered velocity.
Constructs a new CANcoder object.
- Parameters:
device_id (int) – ID of the device, as configured in Phoenix Tuner
canbus (CANBus) – The CAN bus this device is on
- classmethod none() Self¶
Constructs a stubbed-out CANcoder, where all status signals, controls, configs, etc. perform no action and immediately return OK. This can be used to silence error messages for devices that have been completely removed from the robot.
- Returns:
Stubbed-out CANcoder
- Return type:
- close()¶
- class phoenix6.hardware.Pigeon2(device_id: int, canbus: phoenix6.canbus.CANBus)¶
Bases:
phoenix6.hardware.core.core_pigeon2.CorePigeon2Class description for the Pigeon 2 IMU sensor that measures orientation.
Constructs a new Pigeon 2 sensor object.
- Parameters:
device_id (int) – ID of the device, as configured in Phoenix Tuner
canbus (CANBus) – The CAN bus this device is on
- classmethod none() Self¶
Constructs a stubbed-out Pigeon2, where all status signals, controls, configs, etc. perform no action and immediately return OK. This can be used to silence error messages for devices that have been completely removed from the robot.
- Returns:
Stubbed-out Pigeon2
- Return type:
- close()¶
- reset()¶
Resets the Pigeon 2 to a heading of zero.
This can be used if there is significant drift in the gyro, and it needs to be recalibrated after it has been running.
- getRotation2d() wpimath.Rotation2d¶
Returns the heading of the Pigeon 2 as a Rotation2d.
The angle increases as the Pigeon 2 turns counterclockwise when looked at from the top. This follows the NWU axis convention.
The angle is continuous; that is, it will continue from 360 to 361 degrees. This allows for algorithms that wouldn’t want to see a discontinuity in the gyro output as it sweeps past from 360 to 0 on the second time around.
- Returns:
The current heading of the Pigeon 2 as a Rotation2d
- Return type:
- getRotation3d() wpimath.Rotation3d¶
Returns the orientation of the Pigeon 2 as a Rotation3d created from the quaternion signals.
- Returns:
The current orientation of the Pigeon 2 as a Rotation3d
- Return type:
Rotation3d
- getQuaternion() wpimath.Quaternion¶
Returns the orientation of the Pigeon 2 as a Quaternion.
- Returns:
The current orientation of the Pigeon 2 as a Quaternion
- Return type:
Quaternion
- class phoenix6.hardware.TalonFXS(device_id: int, canbus: phoenix6.canbus.CANBus)¶
Bases:
phoenix6.hardware.core.core_talon_fxs.CoreTalonFXSClass description for the Talon FXS motor controller.
Constructs a new Talon FXS motor controller object.
- Parameters:
device_id (int) – ID of the device, as configured in Phoenix Tuner
canbus (CANBus) – The CAN bus this device is on
- classmethod none() Self¶
Constructs a stubbed-out TalonFXS, where all status signals, controls, configs, etc. perform no action and immediately return OK. This can be used to silence error messages for devices that have been completely removed from the robot.
- Returns:
Stubbed-out TalonFXS
- Return type:
- close()¶
- setThrottle(throttle: float)¶
Sets the throttle of the motor controller.
- Parameters:
throttle (float) – The throttle where -1 indicates full reverse and 1 indicates full forward.
- setVoltage(voltage: wpimath.units.volts)¶
Sets the direct voltage output of the motor controller.
Compensates for the current bus voltage to ensure that the desired voltage is output even if the battery voltage is below 12V - highly useful when the voltage outputs are “meaningful” (e.g. they come from a feedforward calculation).
- Parameters:
voltage (units.volts) – The voltage.
- getThrottle() float¶
Gets the throttle of the motor controller.
- Returns:
The throttle where -1 represents full reverse and 1 represents full forward.
- Return type:
float
- disable()¶
Disables the motor controller.
- configNeutralMode(neutralMode: phoenix6.signals.NeutralModeValue, timeout_seconds: wpimath.units.seconds = 0.1) phoenix6.status_code.StatusCode¶
Sets the mode of operation when output is neutral or disabled. This is equivalent to setting the MotorOutputConfigs.neutral_mode when applying a TalonFXSConfiguration to the motor.
Since neutral mode is a config, this API is blocking. We recommend that users avoid calling this API periodically.
- Parameters:
neutralMode (signals.NeutralModeValue) – The state of the motor controller bridge when output is neutral or disabled
timeout_seconds (units.seconds) – Maximum amount of time to wait when performing configuration
- Returns:
Status of refreshing and applying the neutral mode config
- Return type:
- feed()¶
- setExpiration(expirationTime: wpimath.units.seconds)¶
Set the expiration time for the corresponding motor safety object.
- Parameters:
expirationTime (units.seconds) – The timeout value in seconds.
- getExpiration() wpimath.units.seconds¶
Retrieve the timeout value for the corresponding motor safety object.
- Returns:
the timeout value in seconds.
- Return type:
units.seconds
- isAlive() bool¶
Determine of the motor is still operating or has timed out.
- Returns:
a True value if the motor is still operating normally and hasn’t timed out
- Return type:
bool
- setSafetyEnabled(enabled: bool)¶
Enable/disable motor safety for this device.
Turn on and off the motor safety option for this object.
- Parameters:
enabled (bool) – True if motor safety is enforced for this object.
- isSafetyEnabled() bool¶
Return the state of the motor safety enabled flag.
Return if the motor safety is currently enabled for this device.
- Returns:
True if motor safety is enforced for this device
- Return type:
bool
- stopMotor()¶
Called to stop the motor when the timeout expires.
- getDescription() str¶
- Returns:
Description of the motor controller
- Return type:
str
- class phoenix6.hardware.CANrange(device_id: int, canbus: phoenix6.canbus.CANBus)¶
Bases:
phoenix6.hardware.core.core_canrange.CoreCANrangeClass for CANrange, a CAN based Time of Flight (ToF) sensor that measures the distance to the front of the device.
Constructs a new CANrange object.
- Parameters:
device_id (int) – ID of the device, as configured in Phoenix Tuner
canbus (CANBus) – The CAN bus this device is on
- classmethod none() Self¶
Constructs a stubbed-out CANrange, where all status signals, controls, configs, etc. perform no action and immediately return OK. This can be used to silence error messages for devices that have been completely removed from the robot.
- Returns:
Stubbed-out CANrange
- Return type:
- close()¶
- class phoenix6.hardware.CANdi(device_id: int, canbus: phoenix6.canbus.CANBus)¶
Bases:
phoenix6.hardware.core.core_candi.CoreCANdiClass for CTR Electronics’ CANdi™ branded device, a device that integrates digital signals into the existing CAN bus network.
Constructs a new CANdi object.
- Parameters:
device_id (int) – ID of the device, as configured in Phoenix Tuner
canbus (CANBus) – The CAN bus this device is on
- classmethod none() Self¶
Constructs a stubbed-out CANdi, where all status signals, controls, configs, etc. perform no action and immediately return OK. This can be used to silence error messages for devices that have been completely removed from the robot.
- Returns:
Stubbed-out CANdi
- Return type:
- close()¶
- class phoenix6.hardware.CANdle(device_id: int, canbus: phoenix6.canbus.CANBus)¶
Bases:
phoenix6.hardware.core.core_candle.CoreCANdleClass for CTR Electronics’ CANdle® branded device, a device that controls LEDs over the CAN bus.
Constructs a new CANdle object.
- Parameters:
device_id (int) – ID of the device, as configured in Phoenix Tuner
canbus (CANBus) – The CAN bus this device is on
- ANIM_SLOT_COUNT: int = '8'¶
The number of animation slots.
- classmethod none() Self¶
Constructs a stubbed-out CANdle, where all status signals, controls, configs, etc. perform no action and immediately return OK. This can be used to silence error messages for devices that have been completely removed from the robot.
- Returns:
Stubbed-out CANdle
- Return type:
- close()¶
- clear_all_animations() phoenix6.status_code.StatusCode¶
Clears all animations on the CANdle. This is equivalent to applying an EmptyAnimation to all the animation slots on the CANdle.
- Returns:
Status code of the first failed control call, or OK if all succeeded
- Return type: