Class TalonFXSimState

java.lang.Object
com.ctre.phoenix6.sim.TalonFXSimState

public class TalonFXSimState extends Object
Class to control the state of a simulated TalonFX.
  • Field Details

    • Orientation

      The orientation of the TalonFX relative to the robot chassis.

      This value should not be changed based on the TalonFX invert. Rather, this value should be changed when the mechanical linkage between the TalonFX and the robot changes.

  • Constructor Details

    • TalonFXSimState

      public TalonFXSimState(CoreTalonFX device)
      Creates an object to control the state of the given TalonFX.

      This constructor defaults to a counter-clockwise positive orientation relative to the robot chassis.

      Note the recommended method of accessing simulation features is to use CoreTalonFX.getSimState()

      Parameters:
      device - Device to which this simulation state is attached
    • TalonFXSimState

      public TalonFXSimState(CoreTalonFX device, ChassisReference orientation)
      Creates an object to control the state of the given TalonFX.

      Note the recommended method of accessing simulation features is to use CoreTalonFX.getSimState()

      Parameters:
      device - Device to which this simulation state is attached
      orientation - Orientation of the device relative to the robot chassis
  • Method Details

    • getLastStatusCode

      Gets the last status code generated by a simulation function.

      Not all functions return a status code but can potentially report errors. This function can be used to retrieve those status codes.

      Returns:
      Last status code generated by a simulation function
    • getMotorVoltage

      public double getMotorVoltage()
      Gets the simulated output voltage of the motor.
      Returns:
      Voltage applied to the motor in Volts
    • getMotorVoltageMeasure

      Gets the simulated output voltage of the motor as a unit type.
      Returns:
      Voltage applied to the motor
    • getTorqueCurrent

      public double getTorqueCurrent()
      Gets the simulated output torque current of the motor.

      Phoenix 6 simulation automatically calculates current.

      Returns:
      Torque current applied to the motor in Amperes
    • getTorqueCurrentMeasure

      Gets the simulated output torque current of the motor as a unit type.

      Phoenix 6 simulation automatically calculates current.

      Returns:
      Torque current applied to the motor
    • getSupplyCurrent

      public double getSupplyCurrent()
      Gets the simulated supply current of the TalonFX.

      Phoenix 6 simulation automatically calculates current.

      Returns:
      Supply current of the TalonFX in Amperes
    • getSupplyCurrentMeasure

      Gets the simulated supply current of the TalonFX as a unit type.

      Phoenix 6 simulation automatically calculates current.

      Returns:
      Supply current of the TalonFX
    • setSupplyVoltage

      public StatusCode setSupplyVoltage(double volts)
      Sets the simulated supply voltage of the TalonFX.

      The minimum allowed supply voltage is 4 V - values below this will be promoted to 4 V.

      Parameters:
      volts - The supply voltage in Volts
      Returns:
      Status code
    • setSupplyVoltage

      Sets the simulated supply voltage of the TalonFX.

      The minimum allowed supply voltage is 4 V - values below this will be promoted to 4 V.

      Parameters:
      voltage - The supply voltage
      Returns:
      Status code
    • setForwardLimit

      public StatusCode setForwardLimit(boolean closed)
      Sets the simulated forward limit switch of the TalonFX.
      Parameters:
      closed - Whether the limit switch is closed
      Returns:
      Status code
    • setReverseLimit

      public StatusCode setReverseLimit(boolean closed)
      Sets the simulated reverse limit switch of the TalonFX.
      Parameters:
      closed - Whether the limit switch is closed
      Returns:
      Status code
    • setRawRotorPosition

      public StatusCode setRawRotorPosition(double rotations)
      Sets the simulated raw rotor position of the TalonFX. This is the position of the rotor (before gear ratio) used for the RotorSensor feedback source.

      Inputs to this function over time should be continuous, as user calls of CoreTalonFX.setPosition(double) will be accounted for in the callee.

      The TalonFX integrates this to calculate the true reported rotor position.

      When using the WPI Sim GUI, you will notice a readonly position and settable rawPositionInput. The readonly signal is the emulated position which will match self-test in Tuner and the hardware API. Changes to rawPositionInput will be integrated into the emulated position. This way a simulator can modify the position without overriding hardware API calls for home-ing the sensor.

      Parameters:
      rotations - The raw position in rotations
      Returns:
      Status code
    • setRawRotorPosition

      Sets the simulated raw rotor position of the TalonFX. This is the position of the rotor (before gear ratio) used for the RotorSensor feedback source.

      Inputs to this function over time should be continuous, as user calls of CoreTalonFX.setPosition(double) will be accounted for in the callee.

      The TalonFX integrates this to calculate the true reported rotor position.

      When using the WPI Sim GUI, you will notice a readonly position and settable rawPositionInput. The readonly signal is the emulated position which will match self-test in Tuner and the hardware API. Changes to rawPositionInput will be integrated into the emulated position. This way a simulator can modify the position without overriding hardware API calls for home-ing the sensor.

      Parameters:
      position - The raw position
      Returns:
      Status code
    • addRotorPosition

      public StatusCode addRotorPosition(double dRotations)
      Adds to the simulated rotor position of the TalonFX. This adds to the position of the rotor (before gear ratio) used for the RotorSensor feedback source.
      Parameters:
      dRotations - The change in position in rotations
      Returns:
      Status code
    • addRotorPosition

      public StatusCode addRotorPosition(Angle dPosition)
      Adds to the simulated rotor position of the TalonFX. This adds to the position of the rotor (before gear ratio) used for the RotorSensor feedback source.
      Parameters:
      dPosition - The change in position
      Returns:
      Status code
    • setRotorVelocity

      public StatusCode setRotorVelocity(double rps)
      Sets the simulated rotor velocity of the TalonFX. This is the velocity of the rotor (before gear ratio) used for the RotorSensor feedback source.
      Parameters:
      rps - The new velocity in rotations per second
      Returns:
      Status code
    • setRotorVelocity

      Sets the simulated rotor velocity of the TalonFX. This is the velocity of the rotor (before gear ratio) used for the RotorSensor feedback source.
      Parameters:
      velocity - The new velocity
      Returns:
      Status code
    • setRotorAcceleration

      public StatusCode setRotorAcceleration(double rpss)
      Sets the simulated rotor acceleration of the TalonFX. This is the acceleration of the rotor (before gear ratio) used for the RotorSensor feedback source.
      Parameters:
      rpss - The new acceleration in rotations per second²
      Returns:
      Status code
    • setRotorAcceleration

      Sets the simulated rotor acceleration of the TalonFX. This is the acceleration of the rotor (before gear ratio) used for the RotorSensor feedback source.
      Parameters:
      acceleration - The new acceleration
      Returns:
      Status code