Loading [MathJax]/extensions/tex2jax.js
CTRE Phoenix 6 C++ 25.4.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FireAnimation.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
11#include <sstream>
12
14#include <units/frequency.h>
15#include <units/time.h>
16#include <units/dimensionless.h>
17
18namespace ctre {
19namespace phoenix6 {
20namespace controls {
21
22/**
23 * Animation that looks similar to a flame flickering.
24 *
25 *
26 */
28{
29 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override
30 {
31 if (req.get() != this)
32 {
33 auto const reqCast = dynamic_cast<FireAnimation *>(req.get());
34 if (reqCast != nullptr)
35 {
36 *reqCast = *this;
37 }
38 else
39 {
40 req = std::make_shared<FireAnimation>(*this);
41 }
42 }
43
44 return c_ctre_phoenix6_RequestControlFireAnimation(network, deviceHash, UpdateFreqHz.to<double>(), LEDStartIndex, LEDEndIndex, Slot, Brightness.to<double>(), Direction.value, Sparking.to<double>(), Cooling.to<double>(), FrameRate.to<double>());
45 }
46
47public:
48 /**
49 * \brief The index of the first LED this animation controls (inclusive).
50 * Indices 0-7 control the onboard LEDs, and 8-399 control an attached LED strip
51 *
52 * If the start index is greater than the end index, the direction will be
53 * reversed. The direction can also be changed using the Direction parameter.
54 */
56 /**
57 * \brief The index of the last LED this animation controls (inclusive). Indices
58 * 0-7 control the onboard LEDs, and 8-399 control an attached LED strip.
59 *
60 * If the end index is less than the start index, the direction will be
61 * reversed. The direction can also be changed using the Direction parameter.
62 */
64 /**
65 * \brief The slot of this animation, within [0, 7]. Each slot on the CANdle can
66 * store and run one animation.
67 */
68 int Slot = 0;
69 /**
70 * \brief The brightness of the animation, as a scalar from 0.0 to 1.0.
71 */
72 units::dimensionless::scalar_t Brightness = 1.0;
73 /**
74 * \brief The direction of the animation.
75 */
77 /**
78 * \brief The proportion of time in which sparks reignite the fire, as a scalar
79 * from 0.0 to 1.0.
80 */
81 units::dimensionless::scalar_t Sparking = 0.6;
82 /**
83 * \brief The rate at which the fire cools along the travel, as a scalar from
84 * 0.0 to 1.0.
85 */
86 units::dimensionless::scalar_t Cooling = 0.3;
87 /**
88 * \brief The frame rate of the animation, from [2, 1000] Hz. This determines
89 * the speed of the animation.
90 *
91 * A frame is defined as a transition in the state of the LEDs, advancing the
92 * animation of the fire.
93 *
94 * - Units: Hz
95 *
96 */
97 units::frequency::hertz_t FrameRate = 60_Hz;
98
99 /**
100 * \brief The period at which this control will update at.
101 * This is designated in Hertz, with a minimum of 20 Hz
102 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
103 *
104 * If this field is set to 0 Hz, the control request will
105 * be sent immediately as a one-shot frame. This may be useful
106 * for advanced applications that require outputs to be
107 * synchronized with data acquisition. In this case, we
108 * recommend not exceeding 50 ms between control calls.
109 */
110 units::frequency::hertz_t UpdateFreqHz{20_Hz};
111
112 /**
113 * \brief Animation that looks similar to a flame flickering.
114 *
115 * \details
116 *
117 * \param LEDStartIndex The index of the first LED this animation controls
118 * (inclusive). Indices 0-7 control the onboard LEDs,
119 * and 8-399 control an attached LED strip
120 *
121 * If the start index is greater than the end index, the
122 * direction will be reversed. The direction can also be
123 * changed using the Direction parameter.
124 * \param LEDEndIndex The index of the last LED this animation controls
125 * (inclusive). Indices 0-7 control the onboard LEDs, and
126 * 8-399 control an attached LED strip.
127 *
128 * If the end index is less than the start index, the
129 * direction will be reversed. The direction can also be
130 * changed using the Direction parameter.
131 */
135 {}
136
137 /**
138 * \brief Modifies this Control Request's LEDStartIndex parameter and returns itself for
139 * method-chaining and easier to use request API.
140 *
141 * The index of the first LED this animation controls (inclusive). Indices 0-7
142 * control the onboard LEDs, and 8-399 control an attached LED strip
143 *
144 * If the start index is greater than the end index, the direction will be
145 * reversed. The direction can also be changed using the Direction parameter.
146 *
147 * \param newLEDStartIndex Parameter to modify
148 * \returns Itself
149 */
150 FireAnimation &WithLEDStartIndex(int newLEDStartIndex)
151 {
152 LEDStartIndex = std::move(newLEDStartIndex);
153 return *this;
154 }
155
156 /**
157 * \brief Modifies this Control Request's LEDEndIndex parameter and returns itself for
158 * method-chaining and easier to use request API.
159 *
160 * The index of the last LED this animation controls (inclusive). Indices 0-7
161 * control the onboard LEDs, and 8-399 control an attached LED strip.
162 *
163 * If the end index is less than the start index, the direction will be
164 * reversed. The direction can also be changed using the Direction parameter.
165 *
166 * \param newLEDEndIndex Parameter to modify
167 * \returns Itself
168 */
169 FireAnimation &WithLEDEndIndex(int newLEDEndIndex)
170 {
171 LEDEndIndex = std::move(newLEDEndIndex);
172 return *this;
173 }
174
175 /**
176 * \brief Modifies this Control Request's Slot parameter and returns itself for
177 * method-chaining and easier to use request API.
178 *
179 * The slot of this animation, within [0, 7]. Each slot on the CANdle can store
180 * and run one animation.
181 *
182 * \param newSlot Parameter to modify
183 * \returns Itself
184 */
186 {
187 Slot = std::move(newSlot);
188 return *this;
189 }
190
191 /**
192 * \brief Modifies this Control Request's Brightness parameter and returns itself for
193 * method-chaining and easier to use request API.
194 *
195 * The brightness of the animation, as a scalar from 0.0 to 1.0.
196 *
197 * \param newBrightness Parameter to modify
198 * \returns Itself
199 */
200 FireAnimation &WithBrightness(units::dimensionless::scalar_t newBrightness)
201 {
202 Brightness = std::move(newBrightness);
203 return *this;
204 }
205
206 /**
207 * \brief Modifies this Control Request's Direction parameter and returns itself for
208 * method-chaining and easier to use request API.
209 *
210 * The direction of the animation.
211 *
212 * \param newDirection Parameter to modify
213 * \returns Itself
214 */
216 {
217 Direction = std::move(newDirection);
218 return *this;
219 }
220
221 /**
222 * \brief Modifies this Control Request's Sparking parameter and returns itself for
223 * method-chaining and easier to use request API.
224 *
225 * The proportion of time in which sparks reignite the fire, as a scalar from
226 * 0.0 to 1.0.
227 *
228 * \param newSparking Parameter to modify
229 * \returns Itself
230 */
231 FireAnimation &WithSparking(units::dimensionless::scalar_t newSparking)
232 {
233 Sparking = std::move(newSparking);
234 return *this;
235 }
236
237 /**
238 * \brief Modifies this Control Request's Cooling parameter and returns itself for
239 * method-chaining and easier to use request API.
240 *
241 * The rate at which the fire cools along the travel, as a scalar from 0.0 to
242 * 1.0.
243 *
244 * \param newCooling Parameter to modify
245 * \returns Itself
246 */
247 FireAnimation &WithCooling(units::dimensionless::scalar_t newCooling)
248 {
249 Cooling = std::move(newCooling);
250 return *this;
251 }
252
253 /**
254 * \brief Modifies this Control Request's FrameRate parameter and returns itself for
255 * method-chaining and easier to use request API.
256 *
257 * The frame rate of the animation, from [2, 1000] Hz. This determines the speed
258 * of the animation.
259 *
260 * A frame is defined as a transition in the state of the LEDs, advancing the
261 * animation of the fire.
262 *
263 * - Units: Hz
264 *
265 *
266 * \param newFrameRate Parameter to modify
267 * \returns Itself
268 */
269 FireAnimation &WithFrameRate(units::frequency::hertz_t newFrameRate)
270 {
271 FrameRate = std::move(newFrameRate);
272 return *this;
273 }
274 /**
275 * \brief Sets the period at which this control will update at.
276 * This is designated in Hertz, with a minimum of 20 Hz
277 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
278 *
279 * If this field is set to 0 Hz, the control request will
280 * be sent immediately as a one-shot frame. This may be useful
281 * for advanced applications that require outputs to be
282 * synchronized with data acquisition. In this case, we
283 * recommend not exceeding 50 ms between control calls.
284 *
285 * \param newUpdateFreqHz Parameter to modify
286 * \returns Itself
287 */
288 FireAnimation &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
289 {
290 UpdateFreqHz = newUpdateFreqHz;
291 return *this;
292 }
293 /**
294 * \brief Returns a string representation of the object.
295 *
296 * \returns a string representation of the object.
297 */
298 std::string ToString() const override
299 {
300 std::stringstream ss;
301 ss << "Control: FireAnimation" << std::endl;
302 ss << " LEDStartIndex: " << LEDStartIndex << std::endl;
303 ss << " LEDEndIndex: " << LEDEndIndex << std::endl;
304 ss << " Slot: " << Slot << std::endl;
305 ss << " Brightness: " << Brightness.to<double>() << std::endl;
306 ss << " Direction: " << Direction << std::endl;
307 ss << " Sparking: " << Sparking.to<double>() << std::endl;
308 ss << " Cooling: " << Cooling.to<double>() << std::endl;
309 ss << " FrameRate: " << FrameRate.to<double>() << " Hz" << std::endl;
310 return ss.str();
311 }
312
313 /**
314 * \brief Gets information about this control request.
315 *
316 * \returns Map of control parameter names and corresponding applied values
317 */
318 std::map<std::string, std::string> GetControlInfo() const override
319 {
320 std::map<std::string, std::string> controlInfo;
321 std::stringstream ss;
322 controlInfo["Name"] = GetName();
323 ss << LEDStartIndex; controlInfo["LEDStartIndex"] = ss.str(); ss.str(std::string{});
324 ss << LEDEndIndex; controlInfo["LEDEndIndex"] = ss.str(); ss.str(std::string{});
325 ss << Slot; controlInfo["Slot"] = ss.str(); ss.str(std::string{});
326 ss << Brightness.to<double>(); controlInfo["Brightness"] = ss.str(); ss.str(std::string{});
327 ss << Direction; controlInfo["Direction"] = ss.str(); ss.str(std::string{});
328 ss << Sparking.to<double>(); controlInfo["Sparking"] = ss.str(); ss.str(std::string{});
329 ss << Cooling.to<double>(); controlInfo["Cooling"] = ss.str(); ss.str(std::string{});
330 ss << FrameRate.to<double>(); controlInfo["FrameRate"] = ss.str(); ss.str(std::string{});
331 return controlInfo;
332 }
333};
334
335}
336}
337}
338
CTREXPORT int c_ctre_phoenix6_RequestControlFireAnimation(const char *canbus, uint32_t ecuEncoding, double updateFrequency, int LEDStartIndex, int LEDEndIndex, int Slot, double Brightness, int Direction, double Sparking, double Cooling, double FrameRate)
Abstract Control Request class that other control requests extend for use.
Definition ControlRequest.hpp:30
std::string const & GetName() const
Definition ControlRequest.hpp:53
Animation that looks similar to a flame flickering.
Definition FireAnimation.hpp:28
FireAnimation & WithBrightness(units::dimensionless::scalar_t newBrightness)
Modifies this Control Request's Brightness parameter and returns itself for method-chaining and easie...
Definition FireAnimation.hpp:200
FireAnimation & WithSparking(units::dimensionless::scalar_t newSparking)
Modifies this Control Request's Sparking parameter and returns itself for method-chaining and easier ...
Definition FireAnimation.hpp:231
units::dimensionless::scalar_t Sparking
The proportion of time in which sparks reignite the fire, as a scalar from 0.0 to 1....
Definition FireAnimation.hpp:81
FireAnimation & WithDirection(signals::AnimationDirectionValue newDirection)
Modifies this Control Request's Direction parameter and returns itself for method-chaining and easier...
Definition FireAnimation.hpp:215
FireAnimation & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition FireAnimation.hpp:288
std::string ToString() const override
Returns a string representation of the object.
Definition FireAnimation.hpp:298
units::dimensionless::scalar_t Brightness
The brightness of the animation, as a scalar from 0.0 to 1.0.
Definition FireAnimation.hpp:72
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition FireAnimation.hpp:110
FireAnimation & WithSlot(int newSlot)
Modifies this Control Request's Slot parameter and returns itself for method-chaining and easier to u...
Definition FireAnimation.hpp:185
FireAnimation & WithFrameRate(units::frequency::hertz_t newFrameRate)
Modifies this Control Request's FrameRate parameter and returns itself for method-chaining and easier...
Definition FireAnimation.hpp:269
int LEDEndIndex
The index of the last LED this animation controls (inclusive).
Definition FireAnimation.hpp:63
int Slot
The slot of this animation, within [0, 7].
Definition FireAnimation.hpp:68
units::frequency::hertz_t FrameRate
The frame rate of the animation, from [2, 1000] Hz.
Definition FireAnimation.hpp:97
FireAnimation(int LEDStartIndex, int LEDEndIndex)
Animation that looks similar to a flame flickering.
Definition FireAnimation.hpp:132
units::dimensionless::scalar_t Cooling
The rate at which the fire cools along the travel, as a scalar from 0.0 to 1.0.
Definition FireAnimation.hpp:86
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition FireAnimation.hpp:318
int LEDStartIndex
The index of the first LED this animation controls (inclusive).
Definition FireAnimation.hpp:55
signals::AnimationDirectionValue Direction
The direction of the animation.
Definition FireAnimation.hpp:76
FireAnimation & WithLEDEndIndex(int newLEDEndIndex)
Modifies this Control Request's LEDEndIndex parameter and returns itself for method-chaining and easi...
Definition FireAnimation.hpp:169
FireAnimation & WithLEDStartIndex(int newLEDStartIndex)
Modifies this Control Request's LEDStartIndex parameter and returns itself for method-chaining and ea...
Definition FireAnimation.hpp:150
FireAnimation & WithCooling(units::dimensionless::scalar_t newCooling)
Modifies this Control Request's Cooling parameter and returns itself for method-chaining and easier t...
Definition FireAnimation.hpp:247
Direction of the animation.
Definition SpnEnums.hpp:6388
int value
Definition SpnEnums.hpp:6390
static constexpr int Forward
The animation starts at the specified LED start index and moves towards the LED end index.
Definition SpnEnums.hpp:6396
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition Diff_PositionDutyCycle_Position.hpp:15
Definition span.hpp:401