Table of Contents

Class TalonFXSimState

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

Class to control the state of a simulated TalonFX.

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 TalonFXSimState
Inheritance
TalonFXSimState
Inherited Members

Constructors

TalonFXSimState(CoreTalonFX, ChassisReference)

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

Note the recommended method of accessing simulation features is to use SimState.
public TalonFXSimState(CoreTalonFX device, ChassisReference orientation = ChassisReference.CounterClockwise_Positive)

Parameters

device CoreTalonFX

Device to which this simulation state is attached

orientation ChassisReference

Orientation of the device relative to the robot chassis

Fields

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.
public ChassisReference Orientation

Field Value

ChassisReference

Properties

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 TalonFX.

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

AddRotorPosition(double)

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.

public StatusCode AddRotorPosition(double dRotations)

Parameters

dRotations double

The change in position in rotations

Returns

StatusCode

Status code

SetForwardLimit(bool)

Sets the simulated forward limit switch of the TalonFX.

public StatusCode SetForwardLimit(bool closed)

Parameters

closed bool

Whether the limit switch is closed

Returns

StatusCode

Status code

SetMotorType(MotorType)

Sets the type of motor connected to the simulated Talon FX.

public StatusCode SetMotorType(TalonFXSimState.MotorType motorType)

Parameters

motorType TalonFXSimState.MotorType

The type of motor connected

Returns

StatusCode

Status code

SetRawRotorPosition(double)

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 SetPosition(double, 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.
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 TalonFX.

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 TalonFX. This is the acceleration of the rotor (before gear ratio) used for the RotorSensor 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 TalonFX. This is the velocity of the rotor (before gear ratio) used for the RotorSensor 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 TalonFX.

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