Class CANcoderSimState
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
deviceCoreCANcoderDevice to which this simulation state is attached
orientationChassisReferenceOrientation 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
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
Methods
AddPosition(double)
Adds to the simulated position of the CANcoder.
public StatusCode AddPosition(double dRotations)
Parameters
dRotationsdoubleThe 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
valueMagnetHealthValueThe 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 readonlyposition 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
rotationsdoubleThe 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
voltsdoubleThe supply voltage in Volts
Returns
- StatusCode
Status code
SetVelocity(double)
Sets the simulated velocity of the CANcoder.
public StatusCode SetVelocity(double rps)
Parameters
rpsdoubleThe new velocity in rotations per second
Returns
- StatusCode
Status code