CTRE Phoenix C++ 5.33.1
ctre::phoenix::CANifier Class Reference

CTRE CANifier. More...

#include <ctre/phoenix/CANifier.h>

Inheritance diagram for ctre::phoenix::CANifier:
ctre::phoenix::CANBusAddressable

Classes

struct  PinValues
 Structure to hold the pin values. More...
 

Public Types

enum  LEDChannel { LEDChannelA = 0 , LEDChannelB = 1 , LEDChannelC = 2 }
 Enum for the LED Output Channels. More...
 
enum  PWMChannel { PWMChannel0 = 0 , PWMChannel1 = 1 , PWMChannel2 = 2 , PWMChannel3 = 3 }
 Enum for the PWM Input Channels. More...
 
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
}
 General IO Pins on the CANifier. More...
 

Public Member Functions

 CANifier (int deviceNumber)
 Constructor. More...
 
 ~CANifier ()
 
ErrorCode SetLEDOutput (double percentOutput, LEDChannel ledChannel)
 Sets the LED Output. More...
 
ErrorCode SetGeneralOutput (GeneralPin outputPin, bool outputValue, bool outputEnable)
 Sets the output of a General Pin. More...
 
ErrorCode SetGeneralOutputs (int outputBits, int isOutputBits)
 Sets the output of all General Pins. More...
 
ErrorCode GetGeneralInputs (PinValues &allPins)
 Gets the state of all General Pins. More...
 
bool GetGeneralInput (GeneralPin inputPin)
 Gets the state of the specified pin. More...
 
int GetQuadraturePosition ()
 Gets the quadrature encoder's position. More...
 
int GetQuadratureVelocity ()
 Gets the quadrature encoder's velocity. More...
 
ErrorCode SetQuadraturePosition (int newPosition, int timeoutMs=0)
 Sets the quadrature encoder's position. More...
 
ErrorCode ConfigVelocityMeasurementPeriod (ctre::phoenix::sensors::SensorVelocityMeasPeriod period, int timeoutMs=0)
 Configures the period of each velocity sample. More...
 
ErrorCode ConfigVelocityMeasurementPeriod (CANifierVelocityMeasPeriod period, int timeoutMs=0)
 
ErrorCode ConfigVelocityMeasurementWindow (int windowSize, int timeoutMs=0)
 Sets the number of velocity samples used in the rolling average velocity measurement. More...
 
ErrorCode ConfigClearPositionOnLimitF (bool clearPositionOnLimitF, int timeoutMs=0)
 Enables clearing the position of the feedback sensor when the forward limit switch is triggered. More...
 
ErrorCode ConfigClearPositionOnLimitR (bool clearPositionOnLimitR, int timeoutMs=0)
 Enables clearing the position of the feedback sensor when the reverse limit switch is triggered. More...
 
ErrorCode ConfigClearPositionOnQuadIdx (bool clearPositionOnQuadIdx, int timeoutMs=0)
 Enables clearing the position of the feedback sensor when the quadrature index signal is detected. More...
 
double GetBusVoltage ()
 Gets the bus voltage seen by the device. More...
 
ErrorCode GetLastError ()
 Call GetLastError() generated by this object. More...
 
ErrorCode SetPWMOutput (int pwmChannel, double dutyCycle)
 Sets the PWM Output Currently supports PWM 0, PWM 1, and PWM 2. More...
 
ErrorCode EnablePWMOutput (int pwmChannel, bool bEnable)
 Enables PWM Outputs Currently supports PWM 0, PWM 1, and PWM 2. More...
 
ErrorCode GetPWMInput (PWMChannel pwmChannel, double pulseWidthAndPeriod[])
 Gets the PWM Input. More...
 
ErrorCode ConfigSetCustomParam (int newValue, int paramIndex, int timeoutMs=0)
 Sets the value of a custom parameter. More...
 
int ConfigGetCustomParam (int paramIndex, int timeoutMs=0)
 Gets the value of a custom parameter. More...
 
ErrorCode ConfigSetParameter (ParamEnum param, double value, uint8_t subValue, int ordinal, int timeoutMs=0)
 Sets a parameter. More...
 
double ConfigGetParameter (ParamEnum param, int ordinal, int timeoutMs=0)
 Gets a parameter. More...
 
ErrorCode 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. More...
 
ErrorCode SetStatusFramePeriod (CANifierStatusFrame statusFrame, uint8_t periodMs, int timeoutMs=0)
 Sets the period of the given status frame. More...
 
int GetStatusFramePeriod (CANifierStatusFrame frame, int timeoutMs=0)
 Gets the period of the given status frame. More...
 
ErrorCode SetControlFramePeriod (CANifierControlFrame frame, int periodMs)
 Sets the period of the given control frame. More...
 
int GetFirmwareVersion ()
 Gets the firmware version of the device. More...
 
bool HasResetOccurred ()
 Returns true if the device has reset since last call. More...
 
ErrorCode GetFaults (CANifierFaults &toFill)
 Gets the CANifier fault status. More...
 
ErrorCode GetStickyFaults (CANifierStickyFaults &toFill)
 Gets the CANifier sticky fault status. More...
 
ErrorCode ClearStickyFaults (int timeoutMs=0)
 Clears the Sticky Faults. More...
 
ctre::phoenix::ErrorCode ConfigAllSettings (const CANifierConfiguration &allConfigs, int timeoutMs=50)
 Configures all persistent settings. More...
 
void GetAllConfigs (CANifierConfiguration &allConfigs, int timeoutMs=50)
 Gets all persistant settings. More...
 
ErrorCode ConfigFactoryDefault (int timeoutMs=50)
 Configures all persistent settings to defaults (overloaded so timeoutMs is 50 ms). More...
 
- Public Member Functions inherited from ctre::phoenix::CANBusAddressable
 CANBusAddressable (int deviceNumber)
 Constructor for a CANBusAddressable device. More...
 
int GetDeviceNumber ()
 

Static Public Member Functions

static void DestroyAllCANifiers ()
 Destructs all CANifier objects. More...
 

Public Attributes

const int PWMChannelCount = 4
 Number of PWM channels available to CANifier. More...
 

Detailed Description

CTRE CANifier.

Device for interfacing common devices to the CAN bus.

Member Enumeration Documentation

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

Constructor & Destructor Documentation

◆ CANifier()

ctre::phoenix::CANifier::CANifier ( int  deviceNumber)

Constructor.

Parameters
deviceNumberThe CAN Device ID of the CANifier.

◆ ~CANifier()

ctre::phoenix::CANifier::~CANifier ( )

Member Function Documentation

◆ ClearStickyFaults()

ErrorCode ctre::phoenix::CANifier::ClearStickyFaults ( int  timeoutMs = 0)

Clears the Sticky Faults.

Parameters
timeoutMsTimeout 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()

ctre::phoenix::ErrorCode ctre::phoenix::CANifier::ConfigAllSettings ( const CANifierConfiguration allConfigs,
int  timeoutMs = 50 
)

Configures all persistent settings.

Parameters
allConfigsObject with all of the persistant settings
timeoutMsTimeout 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
clearPositionOnLimitFWhether clearing is enabled, defaults false
timeoutMsTimeout 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
clearPositionOnLimitRWhether clearing is enabled, defaults false
timeoutMsTimeout 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
clearPositionOnQuadIdxWhether clearing is enabled, defaults false
timeoutMsTimeout 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
timeoutMsTimeout 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
paramIndexIndex of custom parameter. [0-1]
timeoutMsTimeout 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
paramParameter enumeration.
ordinalOrdinal of parameter.
timeoutMsTimeout 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
paramParameter enumeration
valueToSendValue to send to parameter
valueReceivedReference to integer to receive
subValueSubValue of parameter
ordinalOrdinal of parameter
timeoutMsTimeout 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
newValueValue for custom parameter.
paramIndexIndex of custom parameter. [0-1]
timeoutMsTimeout 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
paramParameter enumeration.
valueValue of parameter.
subValueSubvalue for parameter. Maximum value of 255.
ordinalOrdinal of parameter.
timeoutMsTimeout 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() [1/2]

ErrorCode ctre::phoenix::CANifier::ConfigVelocityMeasurementPeriod ( CANifierVelocityMeasPeriod  period,
int  timeoutMs = 0 
)

◆ ConfigVelocityMeasurementPeriod() [2/2]

ErrorCode ctre::phoenix::CANifier::ConfigVelocityMeasurementPeriod ( ctre::phoenix::sensors::SensorVelocityMeasPeriod  period,
int  timeoutMs = 0 
)

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
periodDesired period for the velocity measurement.
timeoutMsTimeout 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
windowSizeNumber 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.
timeoutMsTimeout 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

Destructs all CANifier objects.

◆ EnablePWMOutput()

ErrorCode ctre::phoenix::CANifier::EnablePWMOutput ( int  pwmChannel,
bool  bEnable 
)

Enables PWM Outputs Currently supports PWM 0, PWM 1, and PWM 2.

Parameters
pwmChannelIndex of the PWM channel to enable.
bEnable"True" enables output on the pwm channel.

◆ GetAllConfigs()

void ctre::phoenix::CANifier::GetAllConfigs ( CANifierConfiguration allConfigs,
int  timeoutMs = 50 
)

Gets all persistant settings.

Parameters
allConfigsObject with all of the persistant settings
timeoutMsTimeout 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()

ErrorCode ctre::phoenix::CANifier::GetFaults ( CANifierFaults toFill)

Gets the CANifier fault status.

Parameters
toFillContainer 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
inputPinThe index of the pin.
Returns
The state of the pin.

◆ GetGeneralInputs()

ErrorCode ctre::phoenix::CANifier::GetGeneralInputs ( PinValues allPins)

Gets the state of all General Pins.

Parameters
allPinsA 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
pwmChannelPWM channel to get.
pulseWidthAndPeriodDouble 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
frameFrame to get the period of.
timeoutMsTimeout 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()

ErrorCode ctre::phoenix::CANifier::GetStickyFaults ( CANifierStickyFaults toFill)

Gets the CANifier sticky fault status.

Parameters
toFillContainer 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()

ErrorCode ctre::phoenix::CANifier::SetControlFramePeriod ( CANifierControlFrame  frame,
int  periodMs 
)

Sets the period of the given control frame.

Parameters
frameFrame whose period is to be changed.
periodMsPeriod 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
outputPinThe pin to use as output.
outputValueThe desired output state.
outputEnableWhether 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
outputBitsA bit mask of all the output states. LSB->MSB is in the order of the GeneralPin enum.
isOutputBitsA 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
percentOutputOutput duty cycle expressed as percentage.
ledChannelChannel 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
pwmChannelIndex of the PWM channel to output.
dutyCycleDuty 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
newPositionPosition 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()

ErrorCode ctre::phoenix::CANifier::SetStatusFramePeriod ( CANifierStatusFrame  statusFrame,
uint8_t  periodMs,
int  timeoutMs = 0 
)

Sets the period of the given status frame.

Parameters
statusFrameFrame whose period is to be changed.
periodMsPeriod in ms for the given frame.
timeoutMsTimeout 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.

Member Data Documentation

◆ 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: