CTRE Phoenix 6 C++ 24.3.0
ctre::phoenix6::mechanisms::SimpleDifferentialMechanism Class Reference

Manages control of a simple two-axis differential mechanism. More...

#include <ctre/phoenix6/mechanisms/SimpleDifferentialMechanism.hpp>

Public Types

enum class  DifferentialPigeon2Source { Yaw , Pitch , Roll }
 Sensor sources for a differential Pigeon 2. More...
 
enum class  DisabledReason {
  None , MissingRemoteSensor , MissingDifferentialFX , RemoteSensorPosOverflow ,
  DeviceHasReset
}
 Possible reasons for the mechanism to disable. More...
 
enum class  RequiresUserReason { None , RemoteSensorPosOverflow , DeviceHasReset }
 Possible reasons for the mechanism to require user action to resume control. More...
 

Public Member Functions

 SimpleDifferentialMechanism (hardware::TalonFX &differentialAddFX, hardware::TalonFX &differentialSubFX, bool motorDirectionsAlign)
 Creates a new simple differential mechanism using the given two hardware::TalonFX devices. More...
 
 SimpleDifferentialMechanism (hardware::TalonFX &differentialAddFX, hardware::TalonFX &differentialSubFX, bool motorDirectionsAlign, hardware::Pigeon2 &pigeon2, DifferentialPigeon2Source pigeonSource)
 Creates a new simple differential mechanism using the given two hardware::TalonFX devices and a hardware::Pigeon2. More...
 
 SimpleDifferentialMechanism (hardware::TalonFX &differentialAddFX, hardware::TalonFX &differentialSubFX, bool motorDirectionsAlign, hardware::CANcoder &cancoder)
 Creates a new simple differential mechanism using the given two hardware::TalonFX devices and a hardware::CANcoder. More...
 
hardware::TalonFXGetDifferentialLeader ()
 Get the Talon FX that is differential leader. More...
 
hardware::TalonFX const & GetDifferentialLeader () const
 Get the Talon FX that is differential leader. More...
 
hardware::TalonFXGetDifferentialFollower ()
 Get the Talon FX that is differential follower. More...
 
hardware::TalonFX const & GetDifferentialFollower () const
 Get the Talon FX that is differential follower. More...
 
ctre::phoenix::StatusCode ApplyConfigs (int numRetries=kDefaultConfigRetries)
 Apply the mechanism configs to the devices. More...
 
void Periodic ()
 Call this method periodically to keep the mechanism state updated. More...
 
bool IsDisabled () const
 Get whether the mechanism is currently disabled due to an issue. More...
 
bool RequiresUserAction () const
 Get whether the mechanism is currently disabled and requires user action to re-enable mechanism control. More...
 
MechanismState GetMechanismState () const
 Gets the state of the mechanism. More...
 
void ClearUserRequirement ()
 Indicate to the mechanism that the user has performed the required action to resume mechanism control. More...
 
DisabledReason GetDisabledReason () const
 
RequiresUserReason GetRequiresUserReason () const
 
ctre::phoenix::StatusCode SetNeutralOut ()
 Request neutral output of mechanism. More...
 
ctre::phoenix::StatusCode SetCoastOut ()
 Request coast neutral output of mechanism. More...
 
ctre::phoenix::StatusCode SetStaticBrake ()
 Applies full neutral-brake on the mechanism by shorting motor leads together. More...
 
ctre::phoenix::StatusCode SetControl (controls::DifferentialDutyCycle _diffAddFXRequest)
 Sets the control request for this mechanism. More...
 
ctre::phoenix::StatusCode SetControl (controls::DifferentialVoltage _diffAddFXRequest)
 Sets the control request for this mechanism. More...
 
ctre::phoenix::StatusCode SetControl (controls::DifferentialPositionDutyCycle _diffAddFXRequest)
 Sets the control request for this mechanism. More...
 
ctre::phoenix::StatusCode SetControl (controls::DifferentialPositionVoltage _diffAddFXRequest)
 Sets the control request for this mechanism. More...
 
ctre::phoenix::StatusCode SetControl (controls::DifferentialVelocityDutyCycle _diffAddFXRequest)
 Sets the control request for this mechanism. More...
 
ctre::phoenix::StatusCode SetControl (controls::DifferentialVelocityVoltage _diffAddFXRequest)
 Sets the control request for this mechanism. More...
 
ctre::phoenix::StatusCode SetControl (controls::DifferentialMotionMagicDutyCycle _diffAddFXRequest)
 Sets the control request for this mechanism. More...
 
ctre::phoenix::StatusCode SetControl (controls::DifferentialMotionMagicVoltage _diffAddFXRequest)
 Sets the control request for this mechanism. More...
 

Static Public Attributes

static constexpr int kDefaultConfigRetries = 5
 The default number of retries for config applies. More...
 

Detailed Description

Manages control of a simple two-axis differential mechanism.

This mechanism provides limited differential functionality. Pro users on a CAN FD bus can use the DifferentialMechanism class instead for full functionality.

Member Enumeration Documentation

◆ DifferentialPigeon2Source

Sensor sources for a differential Pigeon 2.

Enumerator
Yaw 
Pitch 
Roll 

◆ DisabledReason

Possible reasons for the mechanism to disable.

Enumerator
None 

No reason given.

MissingRemoteSensor 

A remote sensor is not present on CAN Bus.

MissingDifferentialFX 

The remote Talon FX used for differential control is not present on CAN Bus.

RemoteSensorPosOverflow 

A remote sensor position has overflowed.

Because of the nature of remote sensors, it is possible for a remote sensor position to overflow beyond what is supported by the status signal frame. However, this is rare and cannot occur over the course of an FRC match under normal use.

DeviceHasReset 

A device or remote sensor has reset.

◆ RequiresUserReason

Possible reasons for the mechanism to require user action to resume control.

Enumerator
None 

No reason given.

RemoteSensorPosOverflow 

A remote sensor position has overflowed.

Because of the nature of remote sensors, it is possible for a remote sensor position to overflow beyond what is supported by the status signal frame. However, this is rare and cannot occur over the course of an FRC match under normal use.

DeviceHasReset 

A device or remote sensor has reset.

Constructor & Destructor Documentation

◆ SimpleDifferentialMechanism() [1/3]

ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::SimpleDifferentialMechanism ( hardware::TalonFX differentialAddFX,
hardware::TalonFX differentialSubFX,
bool  motorDirectionsAlign 
)
inline

Creates a new simple differential mechanism using the given two hardware::TalonFX devices.

The mechanism will use the average of the two Talon FX sensors on the primary axis, and the difference between the two Talon FX sensors on the differential axis.

This mechanism provides limited differential functionality. Pro users on a CAN FD bus can use the DifferentialMechanism class instead for full functionality.

Parameters
differentialAddFXThe Talon FX that will have the differential output added to its regular output.
differentialSubFXThe Talon FX that will have the differential output subtracted from its regular output.
motorDirectionsAlignWhether the differential motors' directions are aligned.

◆ SimpleDifferentialMechanism() [2/3]

ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::SimpleDifferentialMechanism ( hardware::TalonFX differentialAddFX,
hardware::TalonFX differentialSubFX,
bool  motorDirectionsAlign,
hardware::Pigeon2 pigeon2,
DifferentialPigeon2Source  pigeonSource 
)
inline

Creates a new simple differential mechanism using the given two hardware::TalonFX devices and a hardware::Pigeon2.

The mechanism will use the average of the two Talon FX sensors on the primary axis, and the selected Pigeon 2 sensor source on the differential axis.

This mechanism provides limited differential functionality. Pro users on a CAN FD bus can use the DifferentialMechanism class instead for full functionality.

Parameters
differentialAddFXThe Talon FX that will have the differential output added to its regular output.
differentialSubFXThe Talon FX that will have the differential output subtracted from its regular output.
motorDirectionsAlignWhether the differential motors' directions are aligned.
pigeon2The Pigeon 2 to use for the differential axis.
pigeonSourceThe sensor source to use for the Pigeon 2 (Yaw, Pitch, or Roll).

◆ SimpleDifferentialMechanism() [3/3]

ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::SimpleDifferentialMechanism ( hardware::TalonFX differentialAddFX,
hardware::TalonFX differentialSubFX,
bool  motorDirectionsAlign,
hardware::CANcoder cancoder 
)
inline

Creates a new simple differential mechanism using the given two hardware::TalonFX devices and a hardware::CANcoder.

The mechanism will use the average of the two Talon FX sensors on the primary axis, and the CANcoder position/velocity on the differential axis.

This mechanism provides limited differential functionality. Pro users on a CAN FD bus can use the DifferentialMechanism class instead for full functionality.

Parameters
differentialAddFXThe Talon FX that will have the differential output added to its regular output.
differentialSubFXThe Talon FX that will have the differential output subtracted from its regular output.
motorDirectionsAlignWhether the differential motors' directions are aligned.
cancoderThe CANcoder to use for the differential axis.

Member Function Documentation

◆ ApplyConfigs()

ctre::phoenix::StatusCode ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::ApplyConfigs ( int  numRetries = kDefaultConfigRetries)

Apply the mechanism configs to the devices.

This should be called after applying all other configs to the devices.

If the user does not call this function by the time SetControl is called, SetControl will apply the configs once.

Parameters
numRetriesNumber of retries when applying the configs
Returns
Status Code of the config applies.

◆ ClearUserRequirement()

void ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::ClearUserRequirement ( )

Indicate to the mechanism that the user has performed the required action to resume mechanism control.

◆ GetDifferentialFollower() [1/2]

hardware::TalonFX & ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::GetDifferentialFollower ( )
inline

Get the Talon FX that is differential follower.

The differential follower's position and velocity are used by the differential leader for the differential controller.

Returns
Differential follower Talon FX

◆ GetDifferentialFollower() [2/2]

hardware::TalonFX const & ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::GetDifferentialFollower ( ) const
inline

Get the Talon FX that is differential follower.

The differential follower's position and velocity are used by the differential leader for the differential controller.

Returns
Differential follower Talon FX

◆ GetDifferentialLeader() [1/2]

hardware::TalonFX & ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::GetDifferentialLeader ( )
inline

Get the Talon FX that is differential leader.

The differential leader calculates the output for the differential follower. The differential leader is also used for fault detection, and it reports status signals for the differential controller.

Returns
Differential leader Talon FX

◆ GetDifferentialLeader() [2/2]

hardware::TalonFX const & ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::GetDifferentialLeader ( ) const
inline

Get the Talon FX that is differential leader.

The differential leader calculates the output for the differential follower. The differential leader is also useful for fault detection, and it reports status signals for the differential controller.

Returns
Differential leader Talon FX

◆ GetDisabledReason()

DisabledReason ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::GetDisabledReason ( ) const
inline
Returns
The reason for the mechanism being disabled

◆ GetMechanismState()

MechanismState ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::GetMechanismState ( ) const
inline

Gets the state of the mechanism.

Returns
MechanismState representing the state of the mechanism

◆ GetRequiresUserReason()

RequiresUserReason ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::GetRequiresUserReason ( ) const
inline
Returns
The reason for the mechanism requiring user action to resume control

◆ IsDisabled()

bool ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::IsDisabled ( ) const
inline

Get whether the mechanism is currently disabled due to an issue.

Returns
true if the mechanism is temporarily disabled

◆ Periodic()

void ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::Periodic ( )

Call this method periodically to keep the mechanism state updated.

◆ RequiresUserAction()

bool ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::RequiresUserAction ( ) const
inline

Get whether the mechanism is currently disabled and requires user action to re-enable mechanism control.

Returns
true if the mechanism is disabled and the user must manually perform an action

◆ SetCoastOut()

ctre::phoenix::StatusCode ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::SetCoastOut ( )

Request coast neutral output of mechanism.

The bridge is disabled and the rotor is allowed to coast.

Returns
Status Code of the request.

◆ SetControl() [1/8]

ctre::phoenix::StatusCode ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::SetControl ( controls::DifferentialDutyCycle  _diffAddFXRequest)

Sets the control request for this mechanism.

Parameters
_diffAddFXRequestRequest a specified motor duty cycle with a differential position closed-loop.
Returns
Status Code of the request.

◆ SetControl() [2/8]

ctre::phoenix::StatusCode ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::SetControl ( controls::DifferentialMotionMagicDutyCycle  _diffAddFXRequest)

Sets the control request for this mechanism.

Parameters
_diffAddFXRequestRequests Motion MagicĀ® to target a final position using a motion profile, and PID to a differential position setpoint.
Returns
Status Code of the request.

◆ SetControl() [3/8]

ctre::phoenix::StatusCode ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::SetControl ( controls::DifferentialMotionMagicVoltage  _diffAddFXRequest)

Sets the control request for this mechanism.

Parameters
_diffAddFXRequestRequests Motion MagicĀ® to target a final position using a motion profile, and PID to a differential position setpoint.
Returns
Status Code of the request.

◆ SetControl() [4/8]

ctre::phoenix::StatusCode ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::SetControl ( controls::DifferentialPositionDutyCycle  _diffAddFXRequest)

Sets the control request for this mechanism.

Parameters
_diffAddFXRequestRequest PID to target position with a differential position setpoint.
Returns
Status Code of the request.

◆ SetControl() [5/8]

ctre::phoenix::StatusCode ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::SetControl ( controls::DifferentialPositionVoltage  _diffAddFXRequest)

Sets the control request for this mechanism.

Parameters
_diffAddFXRequestRequest PID to target position with a differential position setpoint
Returns
Status Code of the request.

◆ SetControl() [6/8]

ctre::phoenix::StatusCode ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::SetControl ( controls::DifferentialVelocityDutyCycle  _diffAddFXRequest)

Sets the control request for this mechanism.

Parameters
_diffAddFXRequestRequest PID to target velocity with a differential position setpoint.
Returns
Status Code of the request.

◆ SetControl() [7/8]

ctre::phoenix::StatusCode ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::SetControl ( controls::DifferentialVelocityVoltage  _diffAddFXRequest)

Sets the control request for this mechanism.

Parameters
_diffAddFXRequestRequest PID to target velocity with a differential position setpoint.
Returns
Status Code of the request.

◆ SetControl() [8/8]

ctre::phoenix::StatusCode ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::SetControl ( controls::DifferentialVoltage  _diffAddFXRequest)

Sets the control request for this mechanism.

Parameters
_diffAddFXRequestRequest a specified voltage with a differential position closed-loop.
Returns
Status Code of the request.

◆ SetNeutralOut()

ctre::phoenix::StatusCode ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::SetNeutralOut ( )

Request neutral output of mechanism.

The applied brake type is determined by the NeutralMode configuration of each device.

Since the NeutralMode configuration of devices may not align, users may prefer to use the SetCoastOut() or SetStaticBrake() method.

Returns
Status Code of the request.

◆ SetStaticBrake()

ctre::phoenix::StatusCode ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::SetStaticBrake ( )

Applies full neutral-brake on the mechanism by shorting motor leads together.

Returns
Status Code of the request.

Member Data Documentation

◆ kDefaultConfigRetries

constexpr int ctre::phoenix6::mechanisms::SimpleDifferentialMechanism::kDefaultConfigRetries = 5
staticconstexpr

The default number of retries for config applies.


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