Class SimpleDifferentialMechanism
public class SimpleDifferentialMechanism extends Object
DifferentialMechanism
class instead
for full functionality.-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SimpleDifferentialMechanism.DifferentialPigeon2Source
Sensor sources for a differential Pigeon 2.static class
SimpleDifferentialMechanism.DisabledReason
Possible reasons for the mechanism to disable.static class
SimpleDifferentialMechanism.RequiresUserReason
Possible reasons for the mechanism to require user action to resume control. -
Field Summary
Fields Modifier and Type Field Description static int
kDefaultConfigRetries
The default number of retries for config applies. -
Constructor Summary
Constructors Constructor Description SimpleDifferentialMechanism(TalonFX differentialAddFX, TalonFX differentialSubFX, boolean motorDirectionsAlign)
Creates a new simple differential mechanism using the given twoTalonFX
devices.SimpleDifferentialMechanism(TalonFX differentialAddFX, TalonFX differentialSubFX, boolean motorDirectionsAlign, CANcoder cancoder)
SimpleDifferentialMechanism(TalonFX differentialAddFX, TalonFX differentialSubFX, boolean motorDirectionsAlign, Pigeon2 pigeon2, SimpleDifferentialMechanism.DifferentialPigeon2Source pigeonSource)
-
Method Summary
Modifier and Type Method Description StatusCode
applyConfigs()
Apply the mechanism configs to the devices.StatusCode
applyConfigs(int numRetries)
Apply the mechanism configs to the devices.void
clearUserRequirement()
Indicate to the mechanism that the user has performed the required action to resume mechanism control.TalonFX
getDifferentialFollower()
Get the Talon FX that is differential follower.TalonFX
getDifferentialLeader()
Get the Talon FX that is differential leader.SimpleDifferentialMechanism.DisabledReason
getDisabledReason()
MechanismState
getMechanismState()
Gets the state of the mechanism.SimpleDifferentialMechanism.RequiresUserReason
getRequiresUserReason()
boolean
isDisabled()
Get whether the mechanism is currently disabled due to an issue.void
periodic()
Call this method periodically to keep the mechanism state updated.boolean
requiresUserAction()
Get whether the mechanism is currently disabled and requires user action to re-enable mechanism control.StatusCode
setCoastOut()
Request coast neutral output of mechanism.StatusCode
setControl(DifferentialDutyCycle _diffAddFXRequest)
Sets the control request for this mechanism.StatusCode
setControl(DifferentialMotionMagicDutyCycle _diffAddFXRequest)
Sets the control request for this mechanism.StatusCode
setControl(DifferentialMotionMagicVoltage _diffAddFXRequest)
Sets the control request for this mechanism.StatusCode
setControl(DifferentialPositionDutyCycle _diffAddFXRequest)
Sets the control request for this mechanism.StatusCode
setControl(DifferentialPositionVoltage _diffAddFXRequest)
Sets the control request for this mechanism.StatusCode
setControl(DifferentialVelocityDutyCycle _diffAddFXRequest)
Sets the control request for this mechanism.StatusCode
setControl(DifferentialVelocityVoltage _diffAddFXRequest)
Sets the control request for this mechanism.StatusCode
setControl(DifferentialVoltage _diffAddFXRequest)
Sets the control request for this mechanism.StatusCode
setNeutralOut()
Request neutral output of mechanism.StatusCode
setStaticBrake()
Applies full neutral-brake on the mechanism by shorting motor leads together.
-
Field Details
-
kDefaultConfigRetries
The default number of retries for config applies.- See Also:
- Constant Field Values
-
-
Constructor Details
-
SimpleDifferentialMechanism
public SimpleDifferentialMechanism(TalonFX differentialAddFX, TalonFX differentialSubFX, boolean motorDirectionsAlign)Creates a new simple differential mechanism using the given twoTalonFX
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:
differentialAddFX
- The Talon FX that will have the differential output added to its regular output.differentialSubFX
- The Talon FX that will have the differential output subtracted from its regular output.motorDirectionsAlign
- Whether the differential motors' directions are aligned.
-
SimpleDifferentialMechanism
public SimpleDifferentialMechanism(TalonFX differentialAddFX, TalonFX differentialSubFX, boolean motorDirectionsAlign, Pigeon2 pigeon2, SimpleDifferentialMechanism.DifferentialPigeon2Source pigeonSource)Creates a new simple differential mechanism using the given twoTalonFX
devices and aPigeon2
. 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:
differentialAddFX
- The Talon FX that will have the differential output added to its regular output.differentialSubFX
- The Talon FX that will have the differential output subtracted from its regular output.motorDirectionsAlign
- Whether the differential motors' directions are aligned.pigeon2
- The Pigeon 2 to use for the differential axis.pigeonSource
- The sensor source to use for the Pigeon 2 (Yaw, Pitch, or Roll).
-
SimpleDifferentialMechanism
public SimpleDifferentialMechanism(TalonFX differentialAddFX, TalonFX differentialSubFX, boolean motorDirectionsAlign, CANcoder cancoder)Creates a new simple differential mechanism using the given twoTalonFX
devices and aCANcoder
. 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:
differentialAddFX
- The Talon FX that will have the differential output added to its regular output.differentialSubFX
- The Talon FX that will have the differential output subtracted from its regular output.motorDirectionsAlign
- Whether the differential motors' directions are aligned.cancoder
- The CANcoder to use for the differential axis.
-
-
Method Details
-
getDifferentialLeader
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
-
getDifferentialFollower
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
-
applyConfigs
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.
This function defaults to retrying up to
kDefaultConfigRetries
.- Returns:
- Status Code of the config applies.
-
applyConfigs
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:
numRetries
- Number of retries when applying the configs- Returns:
- Status Code of the config applies.
-
periodic
Call this method periodically to keep the mechanism state updated. -
isDisabled
Get whether the mechanism is currently disabled due to an issue.- Returns:
- true if the mechanism is temporarily disabled
-
requiresUserAction
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
-
getMechanismState
Gets the state of the mechanism.- Returns:
- MechanismState representing the state of the mechanism
-
clearUserRequirement
Indicate to the mechanism that the user has performed the required action to resume mechanism control. -
getDisabledReason
- Returns:
- The reason for the mechanism being disabled
-
getRequiresUserReason
- Returns:
- The reason for the mechanism requiring user action to resume control
-
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()
orsetStaticBrake()
method.- Returns:
- Status Code of the request.
-
setCoastOut
Request coast neutral output of mechanism. The bridge is disabled and the rotor is allowed to coast.- Returns:
- Status Code of the request.
-
setStaticBrake
Applies full neutral-brake on the mechanism by shorting motor leads together.- Returns:
- Status Code of the request.
-
setControl
Sets the control request for this mechanism.- Parameters:
_diffAddFXRequest
- Request a specified motor duty cycle with a differential position closed-loop.- Returns:
- Status Code of the request.
-
setControl
Sets the control request for this mechanism.- Parameters:
_diffAddFXRequest
- Request a specified voltage with a differential position closed-loop.- Returns:
- Status Code of the request.
-
setControl
Sets the control request for this mechanism.- Parameters:
_diffAddFXRequest
- Request PID to target position with a differential position setpoint.- Returns:
- Status Code of the request.
-
setControl
Sets the control request for this mechanism.- Parameters:
_diffAddFXRequest
- Request PID to target position with a differential position setpoint- Returns:
- Status Code of the request.
-
setControl
Sets the control request for this mechanism.- Parameters:
_diffAddFXRequest
- Request PID to target velocity with a differential position setpoint.- Returns:
- Status Code of the request.
-
setControl
Sets the control request for this mechanism.- Parameters:
_diffAddFXRequest
- Request PID to target velocity with a differential position setpoint.- Returns:
- Status Code of the request.
-
setControl
Sets the control request for this mechanism.- Parameters:
_diffAddFXRequest
- Requests 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
Sets the control request for this mechanism.- Parameters:
_diffAddFXRequest
- Requests Motion MagicĀ® to target a final position using a motion profile, and PID to a differential position setpoint.- Returns:
- Status Code of the request.
-