Class DifferentialMechanism

java.lang.Object
com.ctre.phoenix6.mechanisms.DifferentialMechanism

public class DifferentialMechanism
extends Object
Manages control of a two-axis differential mechanism. This mechanism requires the devices to be Pro licensed and connected to a CAN FD bus. Unlicensed users and users on a CAN 2.0 bus can use the SimpleDifferentialMechanism instead with limited functionality.
  • Field Details

  • Constructor Details

    • DifferentialMechanism

      public DifferentialMechanism​(TalonFX differentialAddFX, TalonFX differentialSubFX, boolean motorDirectionsAlign)
      Creates a new differential mechanism using the given two 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 requires the devices to be Pro licensed and connected to a CAN FD bus. Unlicensed users and users on a CAN 2.0 bus can use the SimpleDifferentialMechanism instead with limited 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.
    • DifferentialMechanism

      public DifferentialMechanism​(TalonFX differentialAddFX, TalonFX differentialSubFX, boolean motorDirectionsAlign, Pigeon2 pigeon2, DifferentialMechanism.DifferentialPigeon2Source pigeonSource)
      Creates a new differential mechanism using the given two TalonFX devices and a 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 requires the devices to be Pro licensed and connected to a CAN FD bus. Unlicensed users and users on a CAN 2.0 bus can use the SimpleDifferentialMechanism instead with limited 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).
    • DifferentialMechanism

      public DifferentialMechanism​(TalonFX differentialAddFX, TalonFX differentialSubFX, boolean motorDirectionsAlign, CANcoder cancoder)
      Creates a new differential mechanism using the given two TalonFX devices and a 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 requires the devices to be Pro licensed and connected to a CAN FD bus. Unlicensed users and users on a CAN 2.0 bus can use the SimpleDifferentialMechanism instead with limited 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

      public StatusCode applyConfigs​(int numRetries)
      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

      public void periodic()
      Call this method periodically to keep the mechanism state updated.
    • isDisabled

      public boolean isDisabled()
      Get whether the mechanism is currently disabled due to an issue.
      Returns:
      true if the mechanism is temporarily disabled
    • requiresUserAction

      public boolean 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

      public void 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() or setStaticBrake() 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

      public StatusCode setControl​(DutyCycleOut AverageRequest, PositionDutyCycle DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average DutyCycleOut request of the mechanism.
      DifferentialRequest - Differential PositionDutyCycle request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(PositionDutyCycle AverageRequest, PositionDutyCycle DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average PositionDutyCycle request of the mechanism.
      DifferentialRequest - Differential PositionDutyCycle request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(VelocityDutyCycle AverageRequest, PositionDutyCycle DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average VelocityDutyCYcle request of the mechanism.
      DifferentialRequest - Differential PositionDutyCycle request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(MotionMagicDutyCycle AverageRequest, PositionDutyCycle DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average MotionMagicDutyCycle request of the mechanism.
      DifferentialRequest - Differential PositionDutyCycle request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(DutyCycleOut AverageRequest, VelocityDutyCycle DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average DutyCycleOut request of the mechanism.
      DifferentialRequest - Differential VelocityDutyCycle request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(PositionDutyCycle AverageRequest, VelocityDutyCycle DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average PositionDutyCycle request of the mechanism.
      DifferentialRequest - Differential VelocityDutyCycle request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(VelocityDutyCycle AverageRequest, VelocityDutyCycle DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average VelocityDutyCycle request of the mechanism.
      DifferentialRequest - Differential VelocityDutyCycle request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(MotionMagicDutyCycle AverageRequest, VelocityDutyCycle DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average MotionMagicDutyCycle request of the mechanism.
      DifferentialRequest - Differential VelocityDutyCycle request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(VoltageOut AverageRequest, PositionVoltage DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average VoltageOut request of the mechanism.
      DifferentialRequest - Differential PositionVoltage request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(PositionVoltage AverageRequest, PositionVoltage DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average PositionVoltage request of the mechanism.
      DifferentialRequest - Differential PositionVoltage request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(VelocityVoltage AverageRequest, PositionVoltage DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average VelocityVoltage request of the mechanism.
      DifferentialRequest - Differential PositionVoltage request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(MotionMagicVoltage AverageRequest, PositionVoltage DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average MotionMagicVoltage request of the mechanism.
      DifferentialRequest - Differential PositionVoltage request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(VoltageOut AverageRequest, VelocityVoltage DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average VoltageOut request of the mechanism.
      DifferentialRequest - Differential VelocityVoltage request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(PositionVoltage AverageRequest, VelocityVoltage DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average PositionVoltage request of the mechanism.
      DifferentialRequest - Differential VelocityVoltage request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(VelocityVoltage AverageRequest, VelocityVoltage DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average VelocityVoltage request of the mechanism.
      DifferentialRequest - Differential VelocityVoltage request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(MotionMagicVoltage AverageRequest, VelocityVoltage DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average MotionMagicVoltage request of the mechanism.
      DifferentialRequest - Differential VelocityVoltage request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(TorqueCurrentFOC AverageRequest, PositionTorqueCurrentFOC DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average TorqueCurrentFOC request of the mechanism.
      DifferentialRequest - Differential PositionTorqueCurrentFOC request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(PositionTorqueCurrentFOC AverageRequest, PositionTorqueCurrentFOC DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average PositionTorqueCurrentFOC request of the mechanism.
      DifferentialRequest - Differential PositionTorqueCurrentFOC request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(VelocityTorqueCurrentFOC AverageRequest, PositionTorqueCurrentFOC DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average VelocityTorqueCurrentFOC request of the mechanism.
      DifferentialRequest - Differential PositionTorqueCurrentFOC request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(MotionMagicTorqueCurrentFOC AverageRequest, PositionTorqueCurrentFOC DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average MotionMagicTorqueCurrentFOC request of the mechanism.
      DifferentialRequest - Differential PositionTorqueCurrentFOC request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(TorqueCurrentFOC AverageRequest, VelocityTorqueCurrentFOC DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average TorqueCurrentFOC request of the mechanism.
      DifferentialRequest - Differential VelocityTorqueCurrentFOC request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(PositionTorqueCurrentFOC AverageRequest, VelocityTorqueCurrentFOC DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average PositionTorqueCurrentFOC request of the mechanism.
      DifferentialRequest - Differential VelocityTorqueCurrentFOC request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(VelocityTorqueCurrentFOC AverageRequest, VelocityTorqueCurrentFOC DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average VelocityTorqueCurrentFOC request of the mechanism.
      DifferentialRequest - Differential VelocityTorqueCurrentFOC request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.
    • setControl

      public StatusCode setControl​(MotionMagicTorqueCurrentFOC AverageRequest, VelocityTorqueCurrentFOC DifferentialRequest)
      Sets the control request for this mechanism.
      Parameters:
      AverageRequest - Average MotionMagicTorqueCurrentFOC request of the mechanism.
      DifferentialRequest - Differential VelocityTorqueCurrentFOC request of the mechanism. Note: The UpdateFreqHz parameter for this control request will be ignored by the control frame.
      Returns:
      Status Code of the request.