#include <CANifier.h>
Inherits ctre::phoenix::CANBusAddressable.
|
enum | LEDChannel { LEDChannelA = 0
, LEDChannelB = 1
, LEDChannelC = 2
} |
|
enum | PWMChannel { PWMChannel0 = 0
, PWMChannel1 = 1
, PWMChannel2 = 2
, PWMChannel3 = 3
} |
|
enum | GeneralPin {
QUAD_IDX = 0
, QUAD_B = 1
, QUAD_A = 2
, LIMR = 3
,
LIMF = 4
, SDA = 5
, SCL = 6
, SPI_CS = 7
,
SPI_MISO_PWM2P = 8
, SPI_MOSI_PWM1P = 9
, SPI_CLK_PWM0P = 10
} |
|
|
| CANifier (int deviceNumber) |
|
ErrorCode | SetLEDOutput (double percentOutput, LEDChannel ledChannel) |
|
ErrorCode | SetGeneralOutput (GeneralPin outputPin, bool outputValue, bool outputEnable) |
|
ErrorCode | SetGeneralOutputs (int outputBits, int isOutputBits) |
|
ErrorCode | GetGeneralInputs (PinValues &allPins) |
|
bool | GetGeneralInput (GeneralPin inputPin) |
|
int | GetQuadraturePosition () |
|
int | GetQuadratureVelocity () |
|
ErrorCode | SetQuadraturePosition (int newPosition, int timeoutMs=0) |
|
ErrorCode | ConfigVelocityMeasurementPeriod (ctre::phoenix::sensors::SensorVelocityMeasPeriod period, int timeoutMs=0) |
|
ErrorCode | ConfigVelocityMeasurementPeriod (CANifierVelocityMeasPeriod period, int timeoutMs=0) |
|
ErrorCode | ConfigVelocityMeasurementWindow (int windowSize, int timeoutMs=0) |
|
ErrorCode | ConfigClearPositionOnLimitF (bool clearPositionOnLimitF, int timeoutMs=0) |
|
ErrorCode | ConfigClearPositionOnLimitR (bool clearPositionOnLimitR, int timeoutMs=0) |
|
ErrorCode | ConfigClearPositionOnQuadIdx (bool clearPositionOnQuadIdx, int timeoutMs=0) |
|
double | GetBusVoltage () |
|
ErrorCode | GetLastError () |
|
ErrorCode | SetPWMOutput (int pwmChannel, double dutyCycle) |
|
ErrorCode | EnablePWMOutput (int pwmChannel, bool bEnable) |
|
ErrorCode | GetPWMInput (PWMChannel pwmChannel, double pulseWidthAndPeriod[]) |
|
ErrorCode | ConfigSetCustomParam (int newValue, int paramIndex, int timeoutMs=0) |
|
int | ConfigGetCustomParam (int paramIndex, int timeoutMs=0) |
|
ErrorCode | ConfigSetParameter (ParamEnum param, double value, uint8_t subValue, int ordinal, int timeoutMs=0) |
|
double | ConfigGetParameter (ParamEnum param, int ordinal, int timeoutMs=0) |
|
ErrorCode | ConfigGetParameter (ParamEnum param, int32_t valueToSend, int32_t &valueReceived, uint8_t &subValue, int32_t ordinal, int32_t timeoutMs) |
|
ErrorCode | SetStatusFramePeriod (CANifierStatusFrame statusFrame, uint8_t periodMs, int timeoutMs=0) |
|
int | GetStatusFramePeriod (CANifierStatusFrame frame, int timeoutMs=0) |
|
ErrorCode | SetControlFramePeriod (CANifierControlFrame frame, int periodMs) |
|
int | GetFirmwareVersion () |
|
bool | HasResetOccurred () |
|
ErrorCode | GetFaults (CANifierFaults &toFill) |
|
ErrorCode | GetStickyFaults (CANifierStickyFaults &toFill) |
|
ErrorCode | ClearStickyFaults (int timeoutMs=0) |
|
ctre::phoenix::ErrorCode | ConfigAllSettings (const CANifierConfiguration &allConfigs, int timeoutMs=50) |
|
void | GetAllConfigs (CANifierConfiguration &allConfigs, int timeoutMs=50) |
|
ErrorCode | ConfigFactoryDefault (int timeoutMs=50) |
|
| CANBusAddressable (int deviceNumber) |
|
int | GetDeviceNumber () |
|
CTRE CANifier
Device for interfacing common devices to the CAN bus.
◆ GeneralPin
General IO Pins on the CANifier
Enumerator |
---|
QUAD_IDX | Quadrature Idx pin
|
QUAD_B | Quadrature B pin
|
QUAD_A | Quadrature A pin
|
LIMR | Reverse limit pin
|
LIMF | Forward limit pin
|
SDA | SDA pin
|
SCL | SCL pin
|
SPI_CS | SPI_CS pin
|
SPI_MISO_PWM2P | SPI_MISO_PWM2 pin
|
SPI_MOSI_PWM1P | SPI_MOSI_PWM1 pin
|
SPI_CLK_PWM0P | SPI_CLK_PWM0 pin
|
◆ LEDChannel
Enum for the LED Output Channels
Enumerator |
---|
LEDChannelA | LED Channel A
|
LEDChannelB | LED Channel B
|
LEDChannelC | LED Channel C
|
◆ PWMChannel
Enum for the PWM Input Channels
Enumerator |
---|
PWMChannel0 | PWM Channel 0
|
PWMChannel1 | PWM Channel 1
|
PWMChannel2 | PWM Channel 2
|
PWMChannel3 | PWM Channel 3
|
◆ CANifier()
ctre::phoenix::CANifier::CANifier |
( |
int |
deviceNumber | ) |
|
Constructor.
- Parameters
-
deviceNumber | The CAN Device ID of the CANifier. |
◆ ClearStickyFaults()
ErrorCode ctre::phoenix::CANifier::ClearStickyFaults |
( |
int |
timeoutMs = 0 | ) |
|
Clears the Sticky Faults
- Parameters
-
timeoutMs | Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed. |
- Returns
- Error Code generated by function. 0 indicates no error.
◆ ConfigAllSettings()
Configures all persistent settings.
- Parameters
-
allConfigs | Object with all of the persistant settings |
timeoutMs | Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed. |
- Returns
- Error Code generated by function. 0 indicates no error.
◆ ConfigClearPositionOnLimitF()
ErrorCode ctre::phoenix::CANifier::ConfigClearPositionOnLimitF |
( |
bool |
clearPositionOnLimitF, |
|
|
int |
timeoutMs = 0 |
|
) |
| |
Enables clearing the position of the feedback sensor when the forward limit switch is triggered
- Parameters
-
clearPositionOnLimitF | Whether clearing is enabled, defaults false |
timeoutMs | Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed. |
- Returns
- Error Code generated by function. 0 indicates no error.
◆ ConfigClearPositionOnLimitR()
ErrorCode ctre::phoenix::CANifier::ConfigClearPositionOnLimitR |
( |
bool |
clearPositionOnLimitR, |
|
|
int |
timeoutMs = 0 |
|
) |
| |
Enables clearing the position of the feedback sensor when the reverse limit switch is triggered
- Parameters
-
clearPositionOnLimitR | Whether clearing is enabled, defaults false |
timeoutMs | Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed. |
- Returns
- Error Code generated by function. 0 indicates no error.
◆ ConfigClearPositionOnQuadIdx()
ErrorCode ctre::phoenix::CANifier::ConfigClearPositionOnQuadIdx |
( |
bool |
clearPositionOnQuadIdx, |
|
|
int |
timeoutMs = 0 |
|
) |
| |
Enables clearing the position of the feedback sensor when the quadrature index signal is detected
- Parameters
-
clearPositionOnQuadIdx | Whether clearing is enabled, defaults false |
timeoutMs | Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed. |
- Returns
- Error Code generated by function. 0 indicates no error.
◆ ConfigFactoryDefault()
ErrorCode ctre::phoenix::CANifier::ConfigFactoryDefault |
( |
int |
timeoutMs = 50 | ) |
|
Configures all persistent settings to defaults (overloaded so timeoutMs is 50 ms).
- Parameters
-
timeoutMs | Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed. |
- Returns
- Error Code generated by function. 0 indicates no error.
◆ ConfigGetCustomParam()
int ctre::phoenix::CANifier::ConfigGetCustomParam |
( |
int |
paramIndex, |
|
|
int |
timeoutMs = 0 |
|
) |
| |
Gets the value of a custom parameter. This is for arbitrary use.
Sometimes it is necessary to save calibration/duty cycle/output information in the device. Particularly if the device is part of a subsystem that can be replaced.
- Parameters
-
paramIndex | Index of custom parameter. [0-1] |
timeoutMs | Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed. |
- Returns
- Value of the custom param.
◆ ConfigGetParameter() [1/2]
double ctre::phoenix::CANifier::ConfigGetParameter |
( |
ParamEnum |
param, |
|
|
int |
ordinal, |
|
|
int |
timeoutMs = 0 |
|
) |
| |
Gets a parameter. Generally this is not used. This can be utilized in
- Using new features without updating API installation.
- Errata workarounds to circumvent API implementation.
- Allows for rapid testing / unit testing of firmware.
- Parameters
-
param | Parameter enumeration. |
ordinal | Ordinal of parameter. |
timeoutMs | Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed. |
- Returns
- Value of parameter.
◆ ConfigGetParameter() [2/2]
ErrorCode ctre::phoenix::CANifier::ConfigGetParameter |
( |
ParamEnum |
param, |
|
|
int32_t |
valueToSend, |
|
|
int32_t & |
valueReceived, |
|
|
uint8_t & |
subValue, |
|
|
int32_t |
ordinal, |
|
|
int32_t |
timeoutMs |
|
) |
| |
Gets a parameter by passing an int by reference
- Parameters
-
param | Parameter enumeration |
valueToSend | Value to send to parameter |
valueReceived | Reference to integer to receive |
subValue | SubValue of parameter |
ordinal | Ordinal of parameter |
timeoutMs | Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed. |
- Returns
- Error Code generated by function. 0 indicates no error.
◆ ConfigSetCustomParam()
ErrorCode ctre::phoenix::CANifier::ConfigSetCustomParam |
( |
int |
newValue, |
|
|
int |
paramIndex, |
|
|
int |
timeoutMs = 0 |
|
) |
| |
Sets the value of a custom parameter. This is for arbitrary use.
Sometimes it is necessary to save calibration/duty cycle/output information in the device. Particularly if the device is part of a subsystem that can be replaced.
- Parameters
-
newValue | Value for custom parameter. |
paramIndex | Index of custom parameter. [0-1] |
timeoutMs | Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed. |
- Returns
- Error Code generated by function. 0 indicates no error.
◆ ConfigSetParameter()
ErrorCode ctre::phoenix::CANifier::ConfigSetParameter |
( |
ParamEnum |
param, |
|
|
double |
value, |
|
|
uint8_t |
subValue, |
|
|
int |
ordinal, |
|
|
int |
timeoutMs = 0 |
|
) |
| |
Sets a parameter. Generally this is not used. This can be utilized in
- Using new features without updating API installation.
- Errata workarounds to circumvent API implementation.
- Allows for rapid testing / unit testing of firmware.
- Parameters
-
param | Parameter enumeration. |
value | Value of parameter. |
subValue | Subvalue for parameter. Maximum value of 255. |
ordinal | Ordinal of parameter. |
timeoutMs | Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed. |
- Returns
- Error Code generated by function. 0 indicates no error.
◆ ConfigVelocityMeasurementPeriod()
Configures the period of each velocity sample. Every 1ms a position value is sampled, and the delta between that sample and the position sampled kPeriod ms ago is inserted into a filter. kPeriod is configured with this function.
- Parameters
-
period | Desired period for the velocity measurement. |
timeoutMs | Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed. |
- Returns
- Error Code generated by function. 0 indicates no error.
◆ ConfigVelocityMeasurementWindow()
ErrorCode ctre::phoenix::CANifier::ConfigVelocityMeasurementWindow |
( |
int |
windowSize, |
|
|
int |
timeoutMs = 0 |
|
) |
| |
Sets the number of velocity samples used in the rolling average velocity measurement.
- Parameters
-
windowSize | Number of samples in the rolling average of velocity measurement. Valid values are 1,2,4,8,16,32. If another value is specified, it will truncate to nearest support value. |
timeoutMs | Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed. |
- Returns
- Error Code generated by function. 0 indicates no error.
◆ DestroyAllCANifiers()
static void ctre::phoenix::CANifier::DestroyAllCANifiers |
( |
| ) |
|
|
static |
◆ EnablePWMOutput()
ErrorCode ctre::phoenix::CANifier::EnablePWMOutput |
( |
int |
pwmChannel, |
|
|
bool |
bEnable |
|
) |
| |
Enables PWM Outputs Currently supports PWM 0, PWM 1, and PWM 2
- Parameters
-
pwmChannel | Index of the PWM channel to enable. |
bEnable | "True" enables output on the pwm channel. |
◆ GetAllConfigs()
Gets all persistant settings.
- Parameters
-
allConfigs | Object with all of the persistant settings |
timeoutMs | Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed. |
◆ GetBusVoltage()
double ctre::phoenix::CANifier::GetBusVoltage |
( |
| ) |
|
Gets the bus voltage seen by the device.
- Returns
- The bus voltage value (in volts).
◆ GetFaults()
Gets the CANifier fault status
- Parameters
-
toFill | Container for fault statuses. |
- Returns
- Error Code generated by function. 0 indicates no error.
◆ GetFirmwareVersion()
int ctre::phoenix::CANifier::GetFirmwareVersion |
( |
| ) |
|
Gets the firmware version of the device.
- Returns
- Firmware version of device.
◆ GetGeneralInput()
bool ctre::phoenix::CANifier::GetGeneralInput |
( |
GeneralPin |
inputPin | ) |
|
Gets the state of the specified pin
- Parameters
-
inputPin | The index of the pin. |
- Returns
- The state of the pin.
◆ GetGeneralInputs()
Gets the state of all General Pins
- Parameters
-
allPins | A structure to fill with the current state of all pins. |
◆ GetLastError()
ErrorCode ctre::phoenix::CANifier::GetLastError |
( |
| ) |
|
Call GetLastError() generated by this object. Not all functions return an error code but can potentially report errors.
This function can be used to retrieve those error codes.
- Returns
- The last ErrorCode generated.
◆ GetPWMInput()
ErrorCode ctre::phoenix::CANifier::GetPWMInput |
( |
PWMChannel |
pwmChannel, |
|
|
double |
pulseWidthAndPeriod[] |
|
) |
| |
Gets the PWM Input
- Parameters
-
pwmChannel | PWM channel to get. |
pulseWidthAndPeriod | Double array to hold Duty Cycle [0] and Period [1]. |
◆ GetQuadraturePosition()
int ctre::phoenix::CANifier::GetQuadraturePosition |
( |
| ) |
|
Gets the quadrature encoder's position
- Returns
- Position of encoder
◆ GetQuadratureVelocity()
int ctre::phoenix::CANifier::GetQuadratureVelocity |
( |
| ) |
|
Gets the quadrature encoder's velocity
- Returns
- Velocity of encoder
◆ GetStatusFramePeriod()
int ctre::phoenix::CANifier::GetStatusFramePeriod |
( |
CANifierStatusFrame |
frame, |
|
|
int |
timeoutMs = 0 |
|
) |
| |
Gets the period of the given status frame.
- Parameters
-
frame | Frame to get the period of. |
timeoutMs | Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed. |
- Returns
- Period of the given status frame.
◆ GetStickyFaults()
Gets the CANifier sticky fault status
- Parameters
-
toFill | Container for sticky fault statuses. |
- Returns
- Error Code generated by function. 0 indicates no error.
◆ HasResetOccurred()
bool ctre::phoenix::CANifier::HasResetOccurred |
( |
| ) |
|
Returns true if the device has reset since last call.
- Returns
- Has a Device Reset Occurred?
◆ SetControlFramePeriod()
Sets the period of the given control frame.
- Parameters
-
frame | Frame whose period is to be changed. |
periodMs | Period in ms for the given frame. |
- Returns
- Error Code generated by function. 0 indicates no error.
◆ SetGeneralOutput()
ErrorCode ctre::phoenix::CANifier::SetGeneralOutput |
( |
GeneralPin |
outputPin, |
|
|
bool |
outputValue, |
|
|
bool |
outputEnable |
|
) |
| |
Sets the output of a General Pin
- Parameters
-
outputPin | The pin to use as output. |
outputValue | The desired output state. |
outputEnable | Whether this pin is an output. "True" enables output. |
◆ SetGeneralOutputs()
ErrorCode ctre::phoenix::CANifier::SetGeneralOutputs |
( |
int |
outputBits, |
|
|
int |
isOutputBits |
|
) |
| |
Sets the output of all General Pins
- Parameters
-
outputBits | A bit mask of all the output states. LSB->MSB is in the order of the GeneralPin enum. |
isOutputBits | A boolean bit mask that sets the pins to be outputs or inputs. A bit of 1 enables output. |
◆ SetLEDOutput()
ErrorCode ctre::phoenix::CANifier::SetLEDOutput |
( |
double |
percentOutput, |
|
|
LEDChannel |
ledChannel |
|
) |
| |
Sets the LED Output
- Parameters
-
percentOutput | Output duty cycle expressed as percentage. |
ledChannel | Channel to set the output of. |
◆ SetPWMOutput()
ErrorCode ctre::phoenix::CANifier::SetPWMOutput |
( |
int |
pwmChannel, |
|
|
double |
dutyCycle |
|
) |
| |
Sets the PWM Output Currently supports PWM 0, PWM 1, and PWM 2
- Parameters
-
pwmChannel | Index of the PWM channel to output. |
dutyCycle | Duty Cycle (0 to 1) to output. Default period of the signal is 4.2 ms. |
◆ SetQuadraturePosition()
ErrorCode ctre::phoenix::CANifier::SetQuadraturePosition |
( |
int |
newPosition, |
|
|
int |
timeoutMs = 0 |
|
) |
| |
Sets the quadrature encoder's position
- Parameters
-
newPosition | Position to set |
timeoutMs |
Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed. |
- Returns
- Error Code generated by function. 0 indicates no error.
◆ SetStatusFramePeriod()
Sets the period of the given status frame.
- Parameters
-
statusFrame | Frame whose period is to be changed. |
periodMs | Period in ms for the given frame. |
timeoutMs | Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed. |
- Returns
- Error Code generated by function. 0 indicates no error.
◆ PWMChannelCount
const int ctre::phoenix::CANifier::PWMChannelCount = 4 |
Number of PWM channels available to CANifier
The documentation for this class was generated from the following file:
- Phoenix-api/cpp/src/main/native/include/ctre/phoenix/CANifier.h