Table of Contents

Class CANcoderSimState

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

Class to control the state of a simulated CANcoder.

public class CANcoderSimState
Inheritance
CANcoderSimState
Inherited Members

Constructors

CANcoderSimState(CoreCANcoder, ChassisReference)

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

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

Parameters

device CoreCANcoder

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 CANcoder relative to the robot chassis.

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

Field Value

ChassisReference

SensorOffset

The offset of the CANcoder position relative to the robot chassis, in rotations. This offset is subtracted from the raw position, allowing for a non-zero magnet offset config to behave correctly in simulation.

This value should not be changed after initialization unless the mechanical linkage between the CANcoder and the robot changes.
public double SensorOffset

Field Value

double

Methods

AddPosition(double)

Adds to the simulated position of the CANcoder.

public StatusCode AddPosition(double dRotations)

Parameters

dRotations double

The change in position in rotations

Returns

StatusCode

Status code

SetMagnetHealth(MagnetHealthValue)

Sets the simulated magnet health of the CANcoder.

public StatusCode SetMagnetHealth(MagnetHealthValue value)

Parameters

value MagnetHealthValue

The magnet health to simulate. This directly correlates to the red/green/orange state of the simulated LED.

Returns

StatusCode

Status code

SetRawPosition(double)

Sets the simulated raw position of the CANcoder.

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

The CANcoder integrates this to calculate the true reported 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 SetRawPosition(double rotations)

Parameters

rotations double

The raw position in rotations

Returns

StatusCode

Status code

SetSupplyVoltage(double)

Sets the simulated supply voltage of the CANcoder.

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

SetVelocity(double)

Sets the simulated velocity of the CANcoder.

public StatusCode SetVelocity(double rps)

Parameters

rps double

The new velocity in rotations per second

Returns

StatusCode

Status code