Table of Contents

Class TalonFXSSimState

Namespace
CTRE.Phoenix6.Sim
Assembly
Phoenix6.Hardware.dll

Class to control the state of a simulated TalonFXS.

For simulated PID control and current limits to behave correctly, SetRawRotorPosition(double) and SetRotorVelocity(double) must be updated periodically. This is typically done by sending the motor output from MotorVoltage or TorqueCurrent to a physics simulator (such as WPILib's DCMotorSim), which then calculates the new motor position and velocity.
public class TalonFXSSimState
Inheritance
TalonFXSSimState
Inherited Members

Constructors

TalonFXSSimState(CoreTalonFXS, ChassisReference, ChassisReference)

Creates an object to control the state of the given TalonFXS.

Note the recommended method of accessing simulation features is to use SimState.
public TalonFXSSimState(CoreTalonFXS device, ChassisReference motorOrientation = ChassisReference.CounterClockwise_Positive, ChassisReference extSensorOrientation = ChassisReference.CounterClockwise_Positive)

Parameters

device CoreTalonFXS

Device to which this simulation state is attached

motorOrientation ChassisReference

Orientation of the motor (and commutation sensor) relative to the robot chassis

extSensorOrientation ChassisReference

Orientation of the external sensor relative to the robot chassis

Fields

ExtSensorOrientation

The orientation of an external sensor attached to the TalonFXS relative to the robot chassis. This does NOT include the Commutation sensor source.

This value should not be changed based on the TalonFXS invert. Rather, this value should be changed when the mechanical linkage between the external sensor and the robot changes.
public ChassisReference ExtSensorOrientation

Field Value

ChassisReference

MotorOrientation

The orientation of the motor attached to the TalonFXS relative to the robot chassis. This include the Commutation sensor source.

This value should not be changed based on the TalonFXS invert. Rather, this value should be changed when the mechanical linkage between the motor and the robot changes.
public ChassisReference MotorOrientation

Field Value

ChassisReference

PulseWidthSensorOffset

The offset of an absolute external sensor attached to the Talon FXS relative to the robot chassis, in rotations. This offset is subtracted from the Pulse Width position, allowing for a non-zero sensor offset config to behave correctly in simulation.

This value should not be changed after initialization unless the mechanical linkage between the external sensor and the robot changes.
public double PulseWidthSensorOffset

Field Value

double

QuadratureEdgesPerRotation

The number of quadrature edges per sensor rotation for an external quadrature sensor attached to the TalonFXS.

public int QuadratureEdgesPerRotation

Field Value

int

Properties

AnalogVoltage

Gets the simulated analog voltage of the TalonFXS.

public double AnalogVoltage { get; }

Property Value

double

LastStatusCode

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.
public StatusCode LastStatusCode { get; }

Property Value

StatusCode

MotorVoltage

Gets the simulated output voltage of the motor.

public double MotorVoltage { get; }

Property Value

double

SupplyCurrent

Gets the simulated supply current of the TalonFXS.

Phoenix 6 simulation automatically calculates current.
public double SupplyCurrent { get; }

Property Value

double

TorqueCurrent

Gets the simulated output torque current of the motor.

Phoenix 6 simulation automatically calculates current.
public double TorqueCurrent { get; }

Property Value

double

Methods

AddQuadraturePosition(double)

Adds to the simulated quadrature position of the TalonFXS. This adds to the position of an external quadrature encoder after any gear ratio between the rotor and the sensor.

public StatusCode AddQuadraturePosition(double dRotations)

Parameters

dRotations double

The change in position in rotations

Returns

StatusCode

Status code

AddRotorPosition(double)

Adds to the simulated rotor position of the TalonFXS. This adds to the position of the rotor (before gear ratio) used for the Commutation feedback source.

public StatusCode AddRotorPosition(double dRotations)

Parameters

dRotations double

The change in position in rotations

Returns

StatusCode

Status code

SetAnalogVoltage(double)

Sets the simulated voltage of the analog input pin on the TalonFXS data port.

public StatusCode SetAnalogVoltage(double voltage)

Parameters

voltage double

Voltage of the pin

Returns

StatusCode

Status code

SetForwardLimit(bool)

Sets the simulated forward limit switch of the TalonFXS.

public StatusCode SetForwardLimit(bool closed)

Parameters

closed bool

Whether the limit switch is closed

Returns

StatusCode

Status code

SetPulseWidthPosition(double)

Sets the simulated pulse width position of the TalonFXS. This is the position of an external PWM encoder after any gear ratio between the rotor and the sensor.

public StatusCode SetPulseWidthPosition(double rotations)

Parameters

rotations double

The new position in rotations

Returns

StatusCode

Status code

SetPulseWidthVelocity(double)

Sets the simulated pulse width velocity of the TalonFXS. This is the position of an external PWM encoder after any gear ratio between the rotor and the sensor.

public StatusCode SetPulseWidthVelocity(double rps)

Parameters

rps double

The new velocity in rotations per second

Returns

StatusCode

Status code

SetQuadratureAcceleration(double)

Sets the simulated quadrature acceleration of the TalonFXS. This is the acceleration of an external quadrature encoder after any gear ratio between the rotor and the sensor.

public StatusCode SetQuadratureAcceleration(double rpss)

Parameters

rpss double

The new acceleration in rotations per second²

Returns

StatusCode

Status code

SetQuadratureVelocity(double)

Sets the simulated quadrature velocity of the TalonFXS. This is the velocity of an external quadrature encoder after any gear ratio between the rotor and the sensor.

public StatusCode SetQuadratureVelocity(double rps)

Parameters

rps double

The new velocity in rotations per second

Returns

StatusCode

Status code

SetRawQuadraturePosition(double)

Sets the simulated raw quadrature position of the TalonFXS. This is the position of an external quadrature encoder after any gear ratio between the rotor and the sensor.

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

The TalonFXS integrates this to calculate the true reported quadrature 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.
public StatusCode SetRawQuadraturePosition(double rotations)

Parameters

rotations double

The raw position in rotations

Returns

StatusCode

Status code

SetRawRotorPosition(double)

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

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

The TalonFXS 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.
public StatusCode SetRawRotorPosition(double rotations)

Parameters

rotations double

The raw position in rotations

Returns

StatusCode

Status code

SetReverseLimit(bool)

Sets the simulated reverse limit switch of the TalonFXS.

public StatusCode SetReverseLimit(bool closed)

Parameters

closed bool

Whether the limit switch is closed

Returns

StatusCode

Status code

SetRotorAcceleration(double)

Sets the simulated rotor acceleration of the TalonFXS. This is the acceleration of the rotor (before gear ratio) used for the Commutation feedback source.

public StatusCode SetRotorAcceleration(double rpss)

Parameters

rpss double

The new acceleration in rotations per second²

Returns

StatusCode

Status code

SetRotorVelocity(double)

Sets the simulated rotor velocity of the TalonFXS. This is the velocity of the rotor (before gear ratio) used for the Commutation feedback source.

public StatusCode SetRotorVelocity(double rps)

Parameters

rps double

The new velocity in rotations per second

Returns

StatusCode

Status code

SetSupplyVoltage(double)

Sets the simulated supply voltage of the TalonFXS.

The minimum allowed supply voltage is 4 V - values below this will be promoted to 4 V.
public StatusCode SetSupplyVoltage(double volts)

Parameters

volts double

The supply voltage in Volts

Returns

StatusCode

Status code