CTRE Phoenix C++ 5.33.1
|
#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... | |
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
ctre::phoenix::led::CANdle::CANdle | ( | int | deviceId, |
std::string const & | canbus = "" |
||
) |
ctre::phoenix::led::CANdle::~CANdle | ( | ) |
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.
animation | The animation that CANdle will run. If this is null, it will clear the animation at the specified slot |
animSlot | The animation slot to use for the animation, range is [0, getMaxSimultaneousAnimationCount()) exclusive |
ctre::phoenix::ErrorCode ctre::phoenix::led::CANdle::ClearAnimation | ( | int | animSlot | ) |
Clears the animation occurring in the selected selected animSlot.
animSlot | Animation slot to clear |
ErrorCode ctre::phoenix::led::CANdle::ClearStickyFaults | ( | int | timeoutMs = 0 | ) |
Clears the sticky faults.
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. |
ErrorCode ctre::phoenix::led::CANdle::ConfigAllSettings | ( | CANdleConfiguration | allConfigs, |
int | timeoutMs = 50 |
||
) |
Configures all persistent settings.
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. |
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.
brightness | Value from [0, 1] that will scale the LED output. |
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. |
ErrorCode ctre::phoenix::led::CANdle::ConfigFactoryDefault | ( | int | timeoutMs = 50 | ) |
Configures all persistent settings to defaults.
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. |
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.
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. |
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
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. |
ErrorCode ctre::phoenix::led::CANdle::ConfigLEDType | ( | LEDStripType | type, |
int | timeoutMs = 0 |
||
) |
Configures the type of LED the CANdle controls.
type | The type of the LEDs the CANdle controls |
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. |
ErrorCode ctre::phoenix::led::CANdle::ConfigLOSBehavior | ( | bool | disableWhenLOS, |
int | timeoutMs = 0 |
||
) |
Configures what the CANdle should do if it loses communications to the Controller.
disableWhenLOS | Set to true to disable the LEDs on Loss of Signal. |
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. |
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.
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. |
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
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. |
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.
disableWhenRunning | Disables the status LED when the CANdle is running |
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. |
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.
v5Enabled | True to enable the 5V rail. |
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. |
ErrorCode ctre::phoenix::led::CANdle::ConfigVBatOutput | ( | VBatOutputMode | mode, |
int | timeoutMs = 0 |
||
) |
Configures how the VBat Output will behave.
mode | VBat Output Behavior |
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. |
double ctre::phoenix::led::CANdle::Get5VRailVoltage | ( | ) |
Gets the Voltage of the 5V line as measured by CANdle.
void ctre::phoenix::led::CANdle::GetAllConfigs | ( | CANdleConfiguration | allConfigs, |
int | timeoutMs = 50 |
||
) |
Gets all persistant settings.
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. |
double ctre::phoenix::led::CANdle::GetBusVoltage | ( | ) |
Gets the Voltage of VBat as measured by CANdle.
double ctre::phoenix::led::CANdle::GetCurrent | ( | ) |
Gets the low-side current as measured by CANdle.
ErrorCode ctre::phoenix::led::CANdle::GetFaults | ( | CANdleFaults & | toFill | ) |
Gets the CANdle fault status.
toFill | Container for fault statuses. |
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.
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.
int ctre::phoenix::led::CANdle::GetStatusFramePeriod | ( | CANdleStatusFrame | frame, |
int | timeoutMs = 0 |
||
) |
Gets the period of the given status frame.
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. |
ErrorCode ctre::phoenix::led::CANdle::GetStickyFaults | ( | CANdleStickyFaults & | toFill | ) |
Gets the CANdle sticky fault status.
toFill | Container for sticky fault statuses. |
double ctre::phoenix::led::CANdle::GetTemperature | ( | ) |
Gets the temperature of the CANdle in Celcius.
double ctre::phoenix::led::CANdle::GetVBatModulation | ( | ) |
bool ctre::phoenix::led::CANdle::HasResetOccurred | ( | ) |
Returns true if the device has reset since last call.
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.
dutyCyclePrcnt | The duty cycle of the output modulation [0, 1] |
ErrorCode ctre::phoenix::led::CANdle::SetControlFramePeriod | ( | CANdleControlFrame | frame, |
int | periodMs | ||
) |
Sets the period of the given control frame.
frame | Frame whose period is to be changed. |
periodMs | Period in ms for the given frame. |
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.
r | The amount of Red to set, range is [0, 255] |
g | The amount of Green to set, range is [0, 255] |
b | The amount of Blue to set, range is [0, 255] |
w | The amount of White to set, range is [0, 255]. This only applies for LED strips with white in them. |
startIdx | Where to start setting the LEDs |
count | The number of LEDs to apply this to |
ErrorCode ctre::phoenix::led::CANdle::SetStatusFramePeriod | ( | CANdleStatusFrame | frame, |
int | periodMs, | ||
int | timeoutMs = 0 |
||
) |
Sets the period of the given status frame.
frame | 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. |