Table of Contents

Class CANdiSimState

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

Class to control the state of a simulated CANdi.

public class CANdiSimState
Inheritance
CANdiSimState
Inherited Members

Constructors

CANdiSimState(CoreCANdi, ChassisReference, ChassisReference, ChassisReference)

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

Note the recommended method of accessing simulation features is to use SimState.
public CANdiSimState(CoreCANdi device, ChassisReference pwm1Orientation = ChassisReference.CounterClockwise_Positive, ChassisReference pwm2Orientation = ChassisReference.CounterClockwise_Positive, ChassisReference quadratureOrientation = ChassisReference.CounterClockwise_Positive)

Parameters

device CoreCANdi

Device to which this simulation state is attached

pwm1Orientation ChassisReference

Orientation of the PWM1 sensor relative to the robot chassis

pwm2Orientation ChassisReference

Orientation of the PWM2 sensor relative to the robot chassis

quadratureOrientation ChassisReference

Orientation of the Quadrature sensor relative to the robot chassis

Fields

Pwm1Orientation

The orientation of the PWM1 sensor relative to the robot chassis.

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

Field Value

ChassisReference

Pwm1SensorOffset

The offset of the PWM1 sensor position relative to the robot chassis, in rotations. This offset is subtracted from the PWM1 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 sensor and the robot changes.
public double Pwm1SensorOffset

Field Value

double

Pwm2Orientation

The orientation of the PWM2 sensor relative to the robot chassis.

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

Field Value

ChassisReference

Pwm2SensorOffset

The offset of the PWM2 sensor position relative to the robot chassis, in rotations. This offset is subtracted from the PWM2 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 sensor and the robot changes.
public double Pwm2SensorOffset

Field Value

double

QuadratureEdgesPerRotation

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

public int QuadratureEdgesPerRotation

Field Value

int

QuadratureOrientation

The orientation of the Quadrature sensor relative to the robot chassis.

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

Field Value

ChassisReference

Methods

SetOutputCurrent(double)

Sets the simulated output current of the CANdi.

public StatusCode SetOutputCurrent(double amps)

Parameters

amps double

The output current in amps

Returns

StatusCode

Status code

SetPwm1Connected(bool)

Sets whether a PWM sensor is connected to the S1 pin.

public StatusCode SetPwm1Connected(bool connected)

Parameters

connected bool

True if sensor is connected

Returns

StatusCode

Status code

SetPwm1Position(double)

Sets the simulated pulse width position of the CANdi. This is the position of an external PWM encoder connected to the S1 pin.

public StatusCode SetPwm1Position(double rotations)

Parameters

rotations double

The new position in rotations

Returns

StatusCode

Status code

SetPwm1RiseFall(double)

Sets the simulated PWM1 Rise to Fall timing of the CANdi.

public StatusCode SetPwm1RiseFall(double timeSeconds)

Parameters

timeSeconds double

The time between two Rise events in seconds

Returns

StatusCode

Status code

SetPwm1RiseRise(double)

Sets the simulated PWM1 Rise to Rise timing of the CANdi.

public StatusCode SetPwm1RiseRise(double timeSeconds)

Parameters

timeSeconds double

The time between two Rise events in seconds

Returns

StatusCode

Status code

SetPwm1Velocity(double)

Sets the simulated pulse width velocity of the CANdi. This is the velocity of an external PWM encoder connected to the S1 pin.

public StatusCode SetPwm1Velocity(double rps)

Parameters

rps double

The new velocity in rotations per second

Returns

StatusCode

Status code

SetPwm2Connected(bool)

Sets whether a PWM sensor is connected to the S2 pin.

public StatusCode SetPwm2Connected(bool connected)

Parameters

connected bool

True if sensor is connected

Returns

StatusCode

Status code

SetPwm2Position(double)

Sets the simulated pulse width position of the CANdi. This is the position of an external PWM encoder connected to the S2 pin.

public StatusCode SetPwm2Position(double rotations)

Parameters

rotations double

The new position in rotations

Returns

StatusCode

Status code

SetPwm2RiseFall(double)

Sets the simulated PWM2 Rise to Fall timing of the CANdi.

public StatusCode SetPwm2RiseFall(double timeSeconds)

Parameters

timeSeconds double

The time between the Rise and Fall events in seconds

Returns

StatusCode

Status code

SetPwm2RiseRise(double)

Sets the simulated PWM2 Rise to Rise timing of the CANdi.

public StatusCode SetPwm2RiseRise(double timeSeconds)

Parameters

timeSeconds double

The time between two Rise events in seconds

Returns

StatusCode

Status code

SetPwm2Velocity(double)

Sets the simulated pulse width velocity of the CANdi. This is the velocity of an external PWM encoder connected to the S2 pin.

public StatusCode SetPwm2Velocity(double rps)

Parameters

rps double

The new velocity in rotations per second

Returns

StatusCode

Status code

SetQuadratureVelocity(double)

Sets the simulated quadrature velocity of the CANdi.

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

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

The CANdi 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

SetS1State(S1StateValue)

Sets the state of the S1 pin

public StatusCode SetS1State(S1StateValue state)

Parameters

state S1StateValue

The state to set the S1 pin to

Returns

StatusCode

Status code

SetS2State(S2StateValue)

Sets the state of the S2 pin

public StatusCode SetS2State(S2StateValue state)

Parameters

state S2StateValue

The state to set the S2 pin to

Returns

StatusCode

Status code

SetSupplyVoltage(double)

Sets the simulated supply voltage of the CANdi.

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