CTRE Phoenix C++ 5.36.0-beta-1
Loading...
Searching...
No Matches
CANdle.h
Go to the documentation of this file.
1/* Copyright (C) Cross The Road Electronics 2024 */
2#pragma once
3
17
18namespace ctre{ namespace phoenix{ namespace led{
19
20/**
21 * CTRE CANdle
22 *
23 * Device for controlling LEDs from the CAN bus.
24 *
25 * <pre>
26 * {@code
27 * // Example usage of a CANdle
28 * CANdle candle{0}; // creates a new CANdle with ID 0
29 *
30 * CANdleConfiguration config;
31 * config.stripType = LEDStripType::RGB; // set the strip type to RGB
32 * config.brightnessScalar = 0.5; // dim the LEDs to half brightness
33 * candle.ConfigAllSettings(config);
34 *
35 * candle.SetLEDs(255, 255, 255); // set the CANdle LEDs to white
36 *
37 * // create a rainbow animation:
38 * // - max brightness
39 * // - half speed
40 * // - 64 LEDs
41 * RainbowAnimation rainbowAnim{1, 0.5, 64};
42 * candle.Animate(rainbowAnim);
43 *
44 * ErrorCode error = candle.GetLastError(); // gets the last error generated by the CANdle
45 * CANdleFaults faults;
46 * ErrorCode faultsError = candle.GetFaults(faults); // fills faults with the current CANdle faults; returns the last error generated
47 * }
48 * </pre>
49 *
50 * @deprecated This device's Phoenix 5 API is deprecated for removal in the
51 * 2027 season. Users should update to Phoenix 6 firmware and migrate to the
52 * Phoenix 6 API. A migration guide is available at
53 * https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html.
54 *
55 * If the Phoenix 5 API must be used for this device, the device must have 22.X
56 * firmware. This firmware is available in Tuner X after selecting Phoenix 5 in
57 * the firmware year dropdown.
58 */
59class [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2027 season."
60 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
61 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
62CANdle {
63private:
64 void *_handle;
65
66
67 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2027 season."
68 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
69 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
70 ctre::phoenix::ErrorCode AnimateStandard(BaseStandardAnimation& animation, int animSlot);
71 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2027 season."
72 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
73 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
74 ctre::phoenix::ErrorCode AnimateTwoSize(BaseTwoSizeAnimation& animation, int animSlot);
75public:
76
77 /**
78 * Constructor for a CANdle Device
79 * @param deviceId The Device ID of the CANdle
80 * @param canbus Name of the CANbus; can be a SocketCAN interface (on Linux),
81 * or a CANivore device name or serial number
82 */
83 CANdle(int deviceId, std::string const &canbus = "");
85
86 /**
87 * Gets the Voltage of VBat as measured by CANdle
88 * @return Voltage of VBat
89 */
90 double GetBusVoltage();
91 /**
92 * Gets the Voltage of the 5V line as measured by CANdle
93 * @return Voltage of the 5V line
94 */
96 /**
97 * Gets the low-side current as measured by CANdle
98 * @return Current in Amps
99 */
100 double GetCurrent();
101 /**
102 * Gets the temperature of the CANdle in Celcius
103 * @return Temperature in Celcius
104 */
106 /**
107 * Gets the applied vbat modulation in percent.
108 * If the CANdle is configured to always enable VBat, this returns 1
109 * If the CANdle is confgigured to always disable VBat, this returns 0
110 * Otherwise it returns the last set Modulation as a value [0, 1]
111 * @return VBat Output Modulation
112 */
114 /**
115 * Gets the maximum number of simultaneous animations this version of CANdle firmware supports.
116 * If you specify an animation slot >= to this return, Phoenix will error out.
117 * You can also get the maximum count from a self-test snapshot.
118 * @return Maximum number of simultaneous animations this version of firmware supports.
119 */
121
122 /**
123 * Animates the CANdle with the passed-in animation
124 * If the animation changes after calling this function,
125 * it must be passed into animate again for the changes to take effect
126 * @param animation The animation that CANdle will run. If this is null, it will clear the animation at the specified slot
127 * @param animSlot The animation slot to use for the animation, range is [0, getMaxSimultaneousAnimationCount()) exclusive
128 * @return ErrorCode generated by function. OK indicates no error.
129 */
130 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2027 season."
131 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
132 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
133 ctre::phoenix::ErrorCode Animate(Animation& animation, int animSlot = 0);
134
135 /**
136 * Clears the animation occurring in the selected selected animSlot.
137 * @param animSlot Animation slot to clear
138 * @return ErrorCode generated by function. OK indicates no error.
139 */
141
142 /**
143 * Sets a block of LEDs to the specified color
144 * @param r The amount of Red to set, range is [0, 255]
145 * @param g The amount of Green to set, range is [0, 255]
146 * @param b The amount of Blue to set, range is [0, 255]
147 * @param w The amount of White to set, range is [0, 255]. This only applies for LED strips with white in them.
148 * @param startIdx Where to start setting the LEDs
149 * @param count The number of LEDs to apply this to
150 * @return ErrorCode generated by function. OK indicates no error.
151 */
152 ctre::phoenix::ErrorCode SetLEDs(int r, int g, int b, int w = 0, int startIdx = 0, int count = 512);
153
154 /**
155 * Modulates the VBat output to the specified duty cycle percentage
156 * This function will only do something if the CANdle's VBatOutput is configured to Modulated
157 * @param dutyCyclePrcnt The duty cycle of the output modulation [0, 1]
158 * @return ErrorCode generated by function. OK indicates no error.
159 */
160 ErrorCode ModulateVBatOutput(double dutyCyclePrcnt);
161
162 /**
163 * Configures what the CANdle should do if it loses communications to the Controller
164 * @param disableWhenLOS Set to true to disable the LEDs on Loss of Signal.
165 * @param timeoutMs
166 * Timeout value in ms. If nonzero, function will wait for
167 * config success and report an error if it times out.
168 * If zero, no blocking or checking is performed.
169 * @return ErrorCode generated by function. OK indicates no error.
170 */
171 ErrorCode ConfigLOSBehavior(bool disableWhenLOS, int timeoutMs = 0);
172 /**
173 * Configures the type of LED the CANdle controls
174 * @param type The type of the LEDs the CANdle controls
175 * @param timeoutMs
176 * Timeout value in ms. If nonzero, function will wait for
177 * config success and report an error if it times out.
178 * If zero, no blocking or checking is performed.
179 * @return ErrorCode generated by function. OK indicates no error.
180 */
181 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2027 season."
182 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
183 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
184 ErrorCode ConfigLEDType(LEDStripType type, int timeoutMs = 0);
185 /**
186 * Configures the brightness scalar to be applied to every LED output.
187 * This value is bounded to [0, 1].
188 *
189 * Setting this to 1 will allow the LEDs to function at max brightness.
190 * Setting this to 0.5 will scale all values to half their applied value.
191 * Setting this to 0 will turn off the LEDs.
192 *
193 * Forcing the LEDs off this way may be useful in certain testing circumstances
194 * but is generally not necessary. Self-test (Tuner) may be used to verify what
195 * the effective scalar is in case user forgot to restore the scalar to a
196 * non-zero value.
197 *
198 * @param brightness Value from [0, 1] that will scale the LED output.
199 * @param timeoutMs
200 Timeout value in ms. If nonzero, function will wait for
201 config success and report an error if it times out.
202 If zero, no blocking or checking is performed.
203 * @return Error Code generated by function. 0 indicates no error.
204 */
205 ErrorCode ConfigBrightnessScalar(double brightness, int timeoutMs = 0);
206
207 /**
208 * Configures how the status led will behave when the CANdle is actively controlling LEDs
209 * If the CANdle is LOS or not actively commanded a value, it will always turn on its status LED.
210 * @param disableWhenRunning Disables the status LED when the CANdle is running
211 * @param timeoutMs
212 Timeout value in ms. If nonzero, function will wait for
213 config success and report an error if it times out.
214 If zero, no blocking or checking is performed.
215 * @return Error Code generated by function. 0 indicates no error.
216 */
217 ErrorCode ConfigStatusLedState(bool disableWhenRunning, int timeoutMs = 0);
218 /**
219 * Configures how the VBat Output will behave
220 * @param mode VBat Output Behavior
221 * @param timeoutMs
222 Timeout value in ms. If nonzero, function will wait for
223 config success and report an error if it times out.
224 If zero, no blocking or checking is performed.
225 * @return Error Code generated by function. 0 indicates no error.
226 */
227 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2027 season."
228 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
229 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
230 ErrorCode ConfigVBatOutput(VBatOutputMode mode, int timeoutMs = 0);
231 /**
232 * Configures the enable state for the 5V rail. This also affects the on-board LEDs.
233 * @param v5Enabled True to enable the 5V rail.
234 * @param timeoutMs
235 * Timeout value in ms. If nonzero, function will wait for
236 * config success and report an error if it times out.
237 * If zero, no blocking or checking is performed.
238 * @return ErrorCode generated by function. OK indicates no error.
239 */
240 ErrorCode configV5Enabled(bool v5Enabled, int timeoutMs = 0);
241
242 /**
243 * Gets a parameter. Generally this is not used.
244 * This can be utilized in
245 * - Using new features without updating API installation.
246 * - Errata workarounds to circumvent API implementation.
247 * - Allows for rapid testing / unit testing of firmware.
248 *
249 * @param param
250 * Parameter enumeration.
251 * @param ordinal
252 * Ordinal of parameter.
253 * @param timeoutMs
254 * Timeout value in ms. If nonzero, function will wait for
255 * config success and report an error if it times out.
256 * If zero, no blocking or checking is performed.
257 * @return Value of parameter.
258 */
259 double ConfigGetParameter(ParamEnum param, int ordinal, int timeoutMs = 0);
260 /**
261 * Sets a parameter. Generally this is not used.
262 * This can be utilized in
263 * - Using new features without updating API installation.
264 * - Errata workarounds to circumvent API implementation.
265 * - Allows for rapid testing / unit testing of firmware.
266 *
267 * @param param
268 * Parameter enumeration.
269 * @param value
270 * Value of parameter.
271 * @param subValue
272 * Subvalue for parameter. Maximum value of 255.
273 * @param ordinal
274 * Ordinal of parameter.
275 * @param timeoutMs
276 * Timeout value in ms. If nonzero, function will wait for
277 * config success and report an error if it times out.
278 * If zero, no blocking or checking is performed.
279 * @return Error Code generated by function. 0 indicates no error.
280 */
281 ErrorCode ConfigSetParameter(ParamEnum param, double value, int subValue = 0, int ordinal = 0, int timeoutMs = 0);
282 /**
283 * Gets the value of a custom parameter. This is for arbitrary use.
284 *
285 * Sometimes it is necessary to save calibration/duty cycle/output
286 * information in the device. Particularly if the
287 * device is part of a subsystem that can be replaced.
288 *
289 * @param paramIndex
290 * Index of custom parameter. [0-1]
291 * @param timeoutMs
292 * Timeout value in ms. If nonzero, function will wait for
293 * config success and report an error if it times out.
294 * If zero, no blocking or checking is performed.
295 * @return Value of the custom param.
296 */
297 int ConfigGetCustomParam(int paramIndex, int timeoutMs = 0);
298 /**
299 * Sets the value of a custom parameter. This is for arbitrary use.
300 *
301 * Sometimes it is necessary to save calibration/duty cycle/output
302 * information in the device. Particularly if the
303 * device is part of a subsystem that can be replaced.
304 *
305 * @param newValue
306 * Value for custom parameter.
307 * @param paramIndex
308 * Index of custom parameter. [0-1]
309 * @param timeoutMs
310 * Timeout value in ms. If nonzero, function will wait for
311 * config success and report an error if it times out.
312 * If zero, no blocking or checking is performed.
313 * @return Error Code generated by function. 0 indicates no error.
314 */
315 ErrorCode ConfigSetCustomParam(int paramIndex, int value, int timeoutMs = 0);
316 /**
317 * Configures all persistent settings to defaults.
318 *
319 * @param timeoutMs
320 * Timeout value in ms. If nonzero, function will wait for
321 * config success and report an error if it times out.
322 * If zero, no blocking or checking is performed.
323 *
324 * @return Error Code generated by function. 0 indicates no error.
325 */
326 ErrorCode ConfigFactoryDefault(int timeoutMs = 50);
327 /**
328 * Gets the CANdle fault status
329 *
330 * @param toFill Container for fault statuses.
331 * @return Error Code generated by function. OK indicates no error.
332 */
333 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2027 season."
334 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
335 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
337 /**
338 * Gets the CANdle sticky fault status
339 *
340 * @param toFill Container for sticky fault statuses.
341 * @return Error Code generated by function. OK indicates no error.
342 */
343 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2027 season."
344 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
345 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
347 /**
348 * Clears the sticky faults.
349 *
350 * @param timeoutMs
351 * Timeout value in ms. If nonzero, function will wait for
352 * config success and report an error if it times out.
353 * If zero, no blocking or checking is performed.
354 * @return Error Code generated by function. 0 indicates no error.
355 */
356 ErrorCode ClearStickyFaults(int timeoutMs = 0);
357 /**
358 * Returns true if the device has reset since last call.
359 *
360 * @return Has a Device Reset Occurred?
361 */
363 /**
364 * Sets the period of the given status frame.
365 *
366 * @param frame
367 * Frame whose period is to be changed.
368 * @param periodMs
369 * Period in ms for the given frame.
370 * @param timeoutMs
371 * Timeout value in ms. If nonzero, function will wait for
372 * config success and report an error if it times out.
373 * If zero, no blocking or checking is performed.
374 * @return Error Code generated by function. 0 indicates no error.
375 */
376 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2027 season."
377 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
378 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
379 ErrorCode SetStatusFramePeriod(CANdleStatusFrame frame, int periodMs, int timeoutMs = 0);
380 /**
381 * Gets the period of the given status frame.
382 *
383 * @param frame
384 * Frame to get the period of.
385 * @param timeoutMs
386 * Timeout value in ms. If nonzero, function will wait for
387 * config success and report an error if it times out.
388 * If zero, no blocking or checking is performed.
389 * @return Period of the given status frame.
390 */
391 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2027 season."
392 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
393 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
394 int GetStatusFramePeriod(CANdleStatusFrame frame, int timeoutMs = 0);
395 /**
396 * Sets the period of the given control frame.
397 *
398 * @param frame
399 * Frame whose period is to be changed.
400 * @param periodMs
401 * Period in ms for the given frame.
402 * @return Error Code generated by function. 0 indicates no error.
403 */
404 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2027 season."
405 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
406 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
408
409 /**
410 * Configures all persistent settings.
411 *
412 * @param allConfigs Object with all of the persistant settings
413 * @param timeoutMs
414 * Timeout value in ms. If nonzero, function will wait for
415 * config success and report an error if it times out.
416 * If zero, no blocking or checking is performed.
417 * @return Error Code generated by function. 0 indicates no error.
418 */
419 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2027 season."
420 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
421 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
422 ErrorCode ConfigAllSettings(CANdleConfiguration allConfigs, int timeoutMs = 50);
423 /**
424 * Gets all persistant settings.
425 *
426 * @param allConfigs Object with all of the persistant settings
427 * @param timeoutMs
428 * Timeout value in ms. If nonzero, function will wait for
429 * config success and report an error if it times out.
430 * If zero, no blocking or checking is performed.
431 */
432 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2027 season."
433 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
434 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
435 void GetAllConfigs(CANdleConfiguration allConfigs, int timeoutMs = 50);
436
437 /**
438 * Call GetLastError() generated by this object.
439 * Not all functions return an error code but can
440 * potentially report errors.
441 *
442 * This function can be used to retrieve those error codes.
443 *
444 * @return The last ErrorCode generated.
445 */
447};
448
449} // namespace led
450} // namespace phoenix
451} // namespace ctre
452
The base class for all animations that CANdle supports.
Definition Animation.h:26
The base class for one generic type of animation.
Definition BaseStandardAnimation.h:24
The base class for one generic type of animation.
Definition BaseTwoSizeAnimation.h:24
CTRE CANdle.
Definition CANdle.h:62
ErrorCode GetStickyFaults(CANdleStickyFaults &toFill)
Gets the CANdle sticky fault status.
ErrorCode ClearStickyFaults(int timeoutMs=0)
Clears the sticky faults.
ErrorCode ConfigLOSBehavior(bool disableWhenLOS, int timeoutMs=0)
Configures what the CANdle should do if it loses communications to the Controller.
ErrorCode ConfigSetCustomParam(int paramIndex, int value, int timeoutMs=0)
Sets the value of a custom parameter.
int ConfigGetCustomParam(int paramIndex, int timeoutMs=0)
Gets the value of a custom parameter.
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...
double GetCurrent()
Gets the low-side current as measured by CANdle.
ErrorCode ConfigVBatOutput(VBatOutputMode mode, int timeoutMs=0)
Configures how the VBat Output will behave.
ErrorCode SetStatusFramePeriod(CANdleStatusFrame frame, int periodMs, int timeoutMs=0)
Sets the period of the given status frame.
double GetBusVoltage()
Gets the Voltage of VBat as measured by CANdle.
ErrorCode ConfigAllSettings(CANdleConfiguration allConfigs, int timeoutMs=50)
Configures all persistent settings.
ErrorCode ConfigSetParameter(ParamEnum param, double value, int subValue=0, int ordinal=0, int timeoutMs=0)
Sets a parameter.
ErrorCode ConfigLEDType(LEDStripType type, int timeoutMs=0)
Configures the type of LED the CANdle controls.
ErrorCode ConfigFactoryDefault(int timeoutMs=50)
Configures all persistent settings to defaults.
ErrorCode GetFaults(CANdleFaults &toFill)
Gets the CANdle fault status.
ErrorCode ModulateVBatOutput(double dutyCyclePrcnt)
Modulates the VBat output to the specified duty cycle percentage This function will only do something...
ErrorCode configV5Enabled(bool v5Enabled, int timeoutMs=0)
Configures the enable state for the 5V rail.
int GetStatusFramePeriod(CANdleStatusFrame frame, int timeoutMs=0)
Gets the period of the given status frame.
void GetAllConfigs(CANdleConfiguration allConfigs, int timeoutMs=50)
Gets all persistant settings.
double Get5VRailVoltage()
Gets the Voltage of the 5V line as measured by CANdle.
ctre::phoenix::ErrorCode ClearAnimation(int animSlot)
Clears the animation occurring in the selected selected animSlot.
int GetMaxSimultaneousAnimationCount()
Gets the maximum number of simultaneous animations this version of CANdle firmware supports.
ErrorCode ConfigBrightnessScalar(double brightness, int timeoutMs=0)
Configures the brightness scalar to be applied to every LED output.
ErrorCode GetLastError()
Call GetLastError() generated by this object.
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.
bool HasResetOccurred()
Returns true if the device has reset since last call.
ErrorCode SetControlFramePeriod(CANdleControlFrame frame, int periodMs)
Sets the period of the given control frame.
double GetVBatModulation()
Gets the applied vbat modulation in percent.
CANdle(int deviceId, std::string const &canbus="")
Constructor for a CANdle Device.
ErrorCode ConfigStatusLedState(bool disableWhenRunning, int timeoutMs=0)
Configures how the status led will behave when the CANdle is actively controlling LEDs If the CANdle ...
double GetTemperature()
Gets the temperature of the CANdle in Celcius.
double ConfigGetParameter(ParamEnum param, int ordinal, int timeoutMs=0)
Gets a parameter.
CANdleControlFrame
Enumerated type for status frame types.
Definition CANdleControlFrame.h:20
LEDStripType
The various LED types that the CANdle can support.
Definition CANdleLedStripType.h:17
VBatOutputMode
The various methods of managing the VBat output behavior.
Definition VBatOutputMode.h:18
CANdleStatusFrame
Enumerated type for status frame types.
Definition CANdleStatusFrame.h:20
ParamEnum
Signal enumeration for generic signal access.
Definition paramEnum.h:13
ErrorCode
Definition ErrorCode.h:13
WPI Compliant Pigeon class.
Definition PigeonIMU_StickyFaults.h:6
Configurables available to CANdle.
Definition CANdleConfiguration.h:23
Faults available to CANdle.
Definition CANdleFaults.h:25
Faults available to CANdle.
Definition CANdleFaults.h:136