CTRE Phoenix C++ 5.33.0
ctre::phoenix::led::CANdle Class Reference

CTRE CANdle. More...

#include <ctre/phoenix/led/CANdle.h>

Public Member Functions

 CANdle (int deviceId, std::string const &canbus="")
 Constructor for a CANdle Device. More...
 
 ~CANdle ()
 
double GetBusVoltage ()
 Gets the Voltage of VBat as measured by CANdle. More...
 
double Get5VRailVoltage ()
 Gets the Voltage of the 5V line as measured by CANdle. More...
 
double GetCurrent ()
 Gets the low-side current as measured by CANdle. More...
 
double GetTemperature ()
 Gets the temperature of the CANdle in Celcius. More...
 
double GetVBatModulation ()
 Gets the applied vbat modulation in percent. More...
 
int GetMaxSimultaneousAnimationCount ()
 Gets the maximum number of simultaneous animations this version of CANdle firmware supports. More...
 
ctre::phoenix::ErrorCode Animate (Animation &animation, int animSlot=0)
 Animates the CANdle with the passed-in animation If the animation changes after calling this function, it must be passed into animate again for the changes to take effect. More...
 
ctre::phoenix::ErrorCode ClearAnimation (int animSlot)
 Clears the animation occurring in the selected selected animSlot. More...
 
ctre::phoenix::ErrorCode SetLEDs (int r, int g, int b, int w=0, int startIdx=0, int count=512)
 Sets a block of LEDs to the specified color. More...
 
ErrorCode ModulateVBatOutput (double dutyCyclePrcnt)
 Modulates the VBat output to the specified duty cycle percentage This function will only do something if the CANdle's VBatOutput is configured to Modulated. More...
 
ErrorCode ConfigLOSBehavior (bool disableWhenLOS, int timeoutMs=0)
 Configures what the CANdle should do if it loses communications to the Controller. More...
 
ErrorCode ConfigLEDType (LEDStripType type, int timeoutMs=0)
 Configures the type of LED the CANdle controls. More...
 
ErrorCode ConfigBrightnessScalar (double brightness, int timeoutMs=0)
 Configures the brightness scalar to be applied to every LED output. More...
 
ErrorCode ConfigStatusLedState (bool disableWhenRunning, int timeoutMs=0)
 Configures how the status led will behave when the CANdle is actively controlling LEDs If the CANdle is LOS or not actively commanded a value, it will always turn on its status LED. More...
 
ErrorCode ConfigVBatOutput (VBatOutputMode mode, int timeoutMs=0)
 Configures how the VBat Output will behave. More...
 
ErrorCode configV5Enabled (bool v5Enabled, int timeoutMs=0)
 Configures the enable state for the 5V rail. More...
 
double ConfigGetParameter (ParamEnum param, int ordinal, int timeoutMs=0)
 Gets a parameter. More...
 
ErrorCode ConfigSetParameter (ParamEnum param, double value, int subValue=0, int ordinal=0, int timeoutMs=0)
 Sets a parameter. More...
 
int ConfigGetCustomParam (int paramIndex, int timeoutMs=0)
 Gets the value of a custom parameter. More...
 
ErrorCode ConfigSetCustomParam (int paramIndex, int value, int timeoutMs=0)
 Sets the value of a custom parameter. More...
 
ErrorCode ConfigFactoryDefault (int timeoutMs=50)
 Configures all persistent settings to defaults. More...
 
ErrorCode GetFaults (CANdleFaults &toFill)
 Gets the CANdle fault status. More...
 
ErrorCode GetStickyFaults (CANdleStickyFaults &toFill)
 Gets the CANdle sticky fault status. More...
 
ErrorCode ClearStickyFaults (int timeoutMs=0)
 Clears the sticky faults. More...
 
bool HasResetOccurred ()
 Returns true if the device has reset since last call. More...
 
ErrorCode SetStatusFramePeriod (CANdleStatusFrame frame, int periodMs, int timeoutMs=0)
 Sets the period of the given status frame. More...
 
int GetStatusFramePeriod (CANdleStatusFrame frame, int timeoutMs=0)
 Gets the period of the given status frame. More...
 
ErrorCode SetControlFramePeriod (CANdleControlFrame frame, int periodMs)
 Sets the period of the given control frame. More...
 
ErrorCode ConfigAllSettings (CANdleConfiguration allConfigs, int timeoutMs=50)
 Configures all persistent settings. More...
 
void GetAllConfigs (CANdleConfiguration allConfigs, int timeoutMs=50)
 Gets all persistant settings. More...
 
ErrorCode GetLastError ()
 Call GetLastError() generated by this object. More...
 

Detailed Description

CTRE CANdle.

Device for controlling LEDs from the CAN bus.


// Example usage of a CANdle
CANdle candle{0}; // creates a new CANdle with ID 0

CANdleConfiguration config;
config.stripType = LEDStripType::RGB; // set the strip type to RGB
config.brightnessScalar = 0.5; // dim the LEDs to half brightness
candle.ConfigAllSettings(config);

candle.SetLEDs(255, 255, 255); // set the CANdle LEDs to white

// create a rainbow animation:
// - max brightness
// - half speed
// - 64 LEDs
RainbowAnimation rainbowAnim{1, 0.5, 64};
candle.Animate(rainbowAnim);

ErrorCode error = candle.GetLastError(); // gets the last error generated by the CANdle
CANdleFaults faults;
ErrorCode faultsError = candle.GetFaults(faults); // fills faults with the current CANdle faults; returns the last error generated

Constructor & Destructor Documentation

◆ CANdle()

ctre::phoenix::led::CANdle::CANdle ( int  deviceId,
std::string const &  canbus = "" 
)

Constructor for a CANdle Device.

Parameters
deviceIdThe Device ID of the CANdle
canbusName of the CANbus; can be a SocketCAN interface (on Linux), or a CANivore device name or serial number

◆ ~CANdle()

ctre::phoenix::led::CANdle::~CANdle ( )

Member Function Documentation

◆ Animate()

ctre::phoenix::ErrorCode ctre::phoenix::led::CANdle::Animate ( Animation animation,
int  animSlot = 0 
)

Animates the CANdle with the passed-in animation If the animation changes after calling this function, it must be passed into animate again for the changes to take effect.

Parameters
animationThe animation that CANdle will run. If this is null, it will clear the animation at the specified slot
animSlotThe animation slot to use for the animation, range is [0, getMaxSimultaneousAnimationCount()) exclusive
Returns
ErrorCode generated by function. OK indicates no error.

◆ ClearAnimation()

ctre::phoenix::ErrorCode ctre::phoenix::led::CANdle::ClearAnimation ( int  animSlot)

Clears the animation occurring in the selected selected animSlot.

Parameters
animSlotAnimation slot to clear
Returns
ErrorCode generated by function. OK indicates no error.

◆ ClearStickyFaults()

ErrorCode ctre::phoenix::led::CANdle::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()

ErrorCode ctre::phoenix::led::CANdle::ConfigAllSettings ( CANdleConfiguration  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.

◆ ConfigBrightnessScalar()

ErrorCode ctre::phoenix::led::CANdle::ConfigBrightnessScalar ( double  brightness,
int  timeoutMs = 0 
)

Configures the brightness scalar to be applied to every LED output.

This value is bounded to [0, 1].

Setting this to 1 will allow the LEDs to function at max brightness. Setting this to 0.5 will scale all values to half their applied value. Setting this to 0 will turn off the LEDs.

Forcing the LEDs off this way may be useful in certain testing circumstances but is generally not necessary. Self-test (Tuner) may be used to verify what the effective scalar is in case user forgot to restore the scalar to a non-zero value.

Parameters
brightnessValue from [0, 1] that will scale the LED output.
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::led::CANdle::ConfigFactoryDefault ( int  timeoutMs = 50)

Configures all persistent settings to defaults.

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::led::CANdle::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()

double ctre::phoenix::led::CANdle::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.

◆ ConfigLEDType()

ErrorCode ctre::phoenix::led::CANdle::ConfigLEDType ( LEDStripType  type,
int  timeoutMs = 0 
)

Configures the type of LED the CANdle controls.

Parameters
typeThe type of the LEDs the CANdle controls
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
ErrorCode generated by function. OK indicates no error.

◆ ConfigLOSBehavior()

ErrorCode ctre::phoenix::led::CANdle::ConfigLOSBehavior ( bool  disableWhenLOS,
int  timeoutMs = 0 
)

Configures what the CANdle should do if it loses communications to the Controller.

Parameters
disableWhenLOSSet to true to disable the LEDs on Loss of Signal.
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
ErrorCode generated by function. OK indicates no error.

◆ ConfigSetCustomParam()

ErrorCode ctre::phoenix::led::CANdle::ConfigSetCustomParam ( int  paramIndex,
int  value,
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::led::CANdle::ConfigSetParameter ( ParamEnum  param,
double  value,
int  subValue = 0,
int  ordinal = 0,
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.

◆ ConfigStatusLedState()

ErrorCode ctre::phoenix::led::CANdle::ConfigStatusLedState ( bool  disableWhenRunning,
int  timeoutMs = 0 
)

Configures how the status led will behave when the CANdle is actively controlling LEDs If the CANdle is LOS or not actively commanded a value, it will always turn on its status LED.

Parameters
disableWhenRunningDisables the status LED when the CANdle is running
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.

◆ configV5Enabled()

ErrorCode ctre::phoenix::led::CANdle::configV5Enabled ( bool  v5Enabled,
int  timeoutMs = 0 
)

Configures the enable state for the 5V rail.

This also affects the on-board LEDs.

Parameters
v5EnabledTrue to enable the 5V rail.
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
ErrorCode generated by function. OK indicates no error.

◆ ConfigVBatOutput()

ErrorCode ctre::phoenix::led::CANdle::ConfigVBatOutput ( VBatOutputMode  mode,
int  timeoutMs = 0 
)

Configures how the VBat Output will behave.

Parameters
modeVBat Output Behavior
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.

◆ Get5VRailVoltage()

double ctre::phoenix::led::CANdle::Get5VRailVoltage ( )

Gets the Voltage of the 5V line as measured by CANdle.

Returns
Voltage of the 5V line

◆ GetAllConfigs()

void ctre::phoenix::led::CANdle::GetAllConfigs ( CANdleConfiguration  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::led::CANdle::GetBusVoltage ( )

Gets the Voltage of VBat as measured by CANdle.

Returns
Voltage of VBat

◆ GetCurrent()

double ctre::phoenix::led::CANdle::GetCurrent ( )

Gets the low-side current as measured by CANdle.

Returns
Current in Amps

◆ GetFaults()

ErrorCode ctre::phoenix::led::CANdle::GetFaults ( CANdleFaults toFill)

Gets the CANdle fault status.

Parameters
toFillContainer for fault statuses.
Returns
Error Code generated by function. OK indicates no error.

◆ GetLastError()

ErrorCode ctre::phoenix::led::CANdle::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.

◆ GetMaxSimultaneousAnimationCount()

int ctre::phoenix::led::CANdle::GetMaxSimultaneousAnimationCount ( )

Gets the maximum number of simultaneous animations this version of CANdle firmware supports.

If you specify an animation slot >= to this return, Phoenix will error out. You can also get the maximum count from a self-test snapshot.

Returns
Maximum number of simultaneous animations this version of firmware supports.

◆ GetStatusFramePeriod()

int ctre::phoenix::led::CANdle::GetStatusFramePeriod ( CANdleStatusFrame  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::led::CANdle::GetStickyFaults ( CANdleStickyFaults toFill)

Gets the CANdle sticky fault status.

Parameters
toFillContainer for sticky fault statuses.
Returns
Error Code generated by function. OK indicates no error.

◆ GetTemperature()

double ctre::phoenix::led::CANdle::GetTemperature ( )

Gets the temperature of the CANdle in Celcius.

Returns
Temperature in Celcius

◆ GetVBatModulation()

double ctre::phoenix::led::CANdle::GetVBatModulation ( )

Gets the applied vbat modulation in percent.

If the CANdle is configured to always enable VBat, this returns 1 If the CANdle is confgigured to always disable VBat, this returns 0 Otherwise it returns the last set Modulation as a value [0, 1]

Returns
VBat Output Modulation

◆ HasResetOccurred()

bool ctre::phoenix::led::CANdle::HasResetOccurred ( )

Returns true if the device has reset since last call.

Returns
Has a Device Reset Occurred?

◆ ModulateVBatOutput()

ErrorCode ctre::phoenix::led::CANdle::ModulateVBatOutput ( double  dutyCyclePrcnt)

Modulates the VBat output to the specified duty cycle percentage This function will only do something if the CANdle's VBatOutput is configured to Modulated.

Parameters
dutyCyclePrcntThe duty cycle of the output modulation [0, 1]
Returns
ErrorCode generated by function. OK indicates no error.

◆ SetControlFramePeriod()

ErrorCode ctre::phoenix::led::CANdle::SetControlFramePeriod ( CANdleControlFrame  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.

◆ SetLEDs()

ctre::phoenix::ErrorCode ctre::phoenix::led::CANdle::SetLEDs ( int  r,
int  g,
int  b,
int  w = 0,
int  startIdx = 0,
int  count = 512 
)

Sets a block of LEDs to the specified color.

Parameters
rThe amount of Red to set, range is [0, 255]
gThe amount of Green to set, range is [0, 255]
bThe amount of Blue to set, range is [0, 255]
wThe amount of White to set, range is [0, 255]. This only applies for LED strips with white in them.
startIdxWhere to start setting the LEDs
countThe number of LEDs to apply this to
Returns
ErrorCode generated by function. OK indicates no error.

◆ SetStatusFramePeriod()

ErrorCode ctre::phoenix::led::CANdle::SetStatusFramePeriod ( CANdleStatusFrame  frame,
int  periodMs,
int  timeoutMs = 0 
)

Sets the period of the given status frame.

Parameters
frameFrame 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.

The documentation for this class was generated from the following file: