CTRE Phoenix 6 C++ 26.0.0-beta-1
Loading...
Searching...
No Matches
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 <units/frequency.h>
12#include <units/time.h>
13#include <units/dimensionless.h>
14
15namespace ctre {
16namespace phoenix6 {
17namespace controls {
18
19/**
20 * Animation that looks similar to a flame flickering.
21 *
22 *
23 */
24class FireAnimation final : public ControlRequest {
25 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override;
26
27public:
28 /**
29 * \brief The index of the first LED this animation controls (inclusive).
30 * Indices 0-7 control the onboard LEDs, and 8-399 control an attached LED strip
31 *
32 * If the start index is greater than the end index, the direction will be
33 * reversed. The direction can also be changed using the Direction parameter.
34 */
36 /**
37 * \brief The index of the last LED this animation controls (inclusive). Indices
38 * 0-7 control the onboard LEDs, and 8-399 control an attached LED strip.
39 *
40 * If the end index is less than the start index, the direction will be
41 * reversed. The direction can also be changed using the Direction parameter.
42 */
44 /**
45 * \brief The slot of this animation, within [0, 7]. Each slot on the CANdle can
46 * store and run one animation.
47 */
48 int Slot = 0;
49 /**
50 * \brief The brightness of the animation, as a scalar from 0.0 to 1.0.
51 */
52 units::dimensionless::scalar_t Brightness = 1.0;
53 /**
54 * \brief The direction of the animation.
55 */
57 /**
58 * \brief The proportion of time in which sparks reignite the fire, as a scalar
59 * from 0.0 to 1.0.
60 */
61 units::dimensionless::scalar_t Sparking = 0.6;
62 /**
63 * \brief The rate at which the fire cools along the travel, as a scalar from
64 * 0.0 to 1.0.
65 */
66 units::dimensionless::scalar_t Cooling = 0.3;
67 /**
68 * \brief The frame rate of the animation, from [2, 1000] Hz. This determines
69 * the speed of the animation.
70 *
71 * A frame is defined as a transition in the state of the LEDs, advancing the
72 * animation of the fire.
73 *
74 * - Units: Hz
75 *
76 */
77 units::frequency::hertz_t FrameRate = 60_Hz;
78
79 /**
80 * \brief The frequency at which this control will update.
81 * This is designated in Hertz, with a minimum of 20 Hz
82 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
83 * Some update frequencies are not supported and will be
84 * promoted up to the next highest supported frequency.
85 *
86 * If this field is set to 0 Hz, the control request will
87 * be sent immediately as a one-shot frame. This may be useful
88 * for advanced applications that require outputs to be
89 * synchronized with data acquisition. In this case, we
90 * recommend not exceeding 50 ms between control calls.
91 */
92 units::frequency::hertz_t UpdateFreqHz{20_Hz};
93
94 /**
95 * \brief Animation that looks similar to a flame flickering.
96 *
97 * \details
98 *
99 * \param LEDStartIndex The index of the first LED this animation controls
100 * (inclusive). Indices 0-7 control the onboard LEDs, and
101 * 8-399 control an attached LED strip
102 *
103 * If the start index is greater than the end index, the
104 * direction will be reversed. The direction can also be
105 * changed using the Direction parameter.
106 * \param LEDEndIndex The index of the last LED this animation controls
107 * (inclusive). Indices 0-7 control the onboard LEDs, and
108 * 8-399 control an attached LED strip.
109 *
110 * If the end index is less than the start index, the
111 * direction will be reversed. The direction can also be
112 * changed using the Direction parameter.
113 */
115 LEDStartIndex{std::move(LEDStartIndex)},
116 LEDEndIndex{std::move(LEDEndIndex)}
117 {}
118
119 constexpr ~FireAnimation() override {}
120
121 /**
122 * \brief Gets the name of this control request.
123 *
124 * \returns Name of the control request
125 */
126 constexpr std::string_view GetName() const override
127 {
128 return "FireAnimation";
129 }
130
131 /**
132 * \brief Modifies this Control Request's LEDStartIndex parameter and returns itself for
133 * method-chaining and easier to use request API.
134 *
135 * The index of the first LED this animation controls (inclusive). Indices 0-7
136 * control the onboard LEDs, and 8-399 control an attached LED strip
137 *
138 * If the start index is greater than the end index, the direction will be
139 * reversed. The direction can also be changed using the Direction parameter.
140 *
141 * \param newLEDStartIndex Parameter to modify
142 * \returns Itself
143 */
144 constexpr FireAnimation &WithLEDStartIndex(int newLEDStartIndex)
145 {
146 LEDStartIndex = std::move(newLEDStartIndex);
147 return *this;
148 }
149
150 /**
151 * \brief Modifies this Control Request's LEDEndIndex parameter and returns itself for
152 * method-chaining and easier to use request API.
153 *
154 * The index of the last LED this animation controls (inclusive). Indices 0-7
155 * control the onboard LEDs, and 8-399 control an attached LED strip.
156 *
157 * If the end index is less than the start index, the direction will be
158 * reversed. The direction can also be changed using the Direction parameter.
159 *
160 * \param newLEDEndIndex Parameter to modify
161 * \returns Itself
162 */
163 constexpr FireAnimation &WithLEDEndIndex(int newLEDEndIndex)
164 {
165 LEDEndIndex = std::move(newLEDEndIndex);
166 return *this;
167 }
168
169 /**
170 * \brief Modifies this Control Request's Slot parameter and returns itself for
171 * method-chaining and easier to use request API.
172 *
173 * The slot of this animation, within [0, 7]. Each slot on the CANdle can store
174 * and run one animation.
175 *
176 * \param newSlot Parameter to modify
177 * \returns Itself
178 */
179 constexpr FireAnimation &WithSlot(int newSlot)
180 {
181 Slot = std::move(newSlot);
182 return *this;
183 }
184
185 /**
186 * \brief Modifies this Control Request's Brightness parameter and returns itself for
187 * method-chaining and easier to use request API.
188 *
189 * The brightness of the animation, as a scalar from 0.0 to 1.0.
190 *
191 * \param newBrightness Parameter to modify
192 * \returns Itself
193 */
194 constexpr FireAnimation &WithBrightness(units::dimensionless::scalar_t newBrightness)
195 {
196 Brightness = std::move(newBrightness);
197 return *this;
198 }
199
200 /**
201 * \brief Modifies this Control Request's Direction parameter and returns itself for
202 * method-chaining and easier to use request API.
203 *
204 * The direction of the animation.
205 *
206 * \param newDirection Parameter to modify
207 * \returns Itself
208 */
210 {
211 Direction = std::move(newDirection);
212 return *this;
213 }
214
215 /**
216 * \brief Modifies this Control Request's Sparking parameter and returns itself for
217 * method-chaining and easier to use request API.
218 *
219 * The proportion of time in which sparks reignite the fire, as a scalar from
220 * 0.0 to 1.0.
221 *
222 * \param newSparking Parameter to modify
223 * \returns Itself
224 */
225 constexpr FireAnimation &WithSparking(units::dimensionless::scalar_t newSparking)
226 {
227 Sparking = std::move(newSparking);
228 return *this;
229 }
230
231 /**
232 * \brief Modifies this Control Request's Cooling parameter and returns itself for
233 * method-chaining and easier to use request API.
234 *
235 * The rate at which the fire cools along the travel, as a scalar from 0.0 to
236 * 1.0.
237 *
238 * \param newCooling Parameter to modify
239 * \returns Itself
240 */
241 constexpr FireAnimation &WithCooling(units::dimensionless::scalar_t newCooling)
242 {
243 Cooling = std::move(newCooling);
244 return *this;
245 }
246
247 /**
248 * \brief Modifies this Control Request's FrameRate parameter and returns itself for
249 * method-chaining and easier to use request API.
250 *
251 * The frame rate of the animation, from [2, 1000] Hz. This determines the speed
252 * of the animation.
253 *
254 * A frame is defined as a transition in the state of the LEDs, advancing the
255 * animation of the fire.
256 *
257 * - Units: Hz
258 *
259 *
260 * \param newFrameRate Parameter to modify
261 * \returns Itself
262 */
263 constexpr FireAnimation &WithFrameRate(units::frequency::hertz_t newFrameRate)
264 {
265 FrameRate = std::move(newFrameRate);
266 return *this;
267 }
268
269 /**
270 * \brief Sets the frequency at which this control will update.
271 * This is designated in Hertz, with a minimum of 20 Hz
272 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
273 * Some update frequencies are not supported and will be
274 * promoted up to the next highest supported frequency.
275 *
276 * If this field is set to 0 Hz, the control request will
277 * be sent immediately as a one-shot frame. This may be useful
278 * for advanced applications that require outputs to be
279 * synchronized with data acquisition. In this case, we
280 * recommend not exceeding 50 ms between control calls.
281 *
282 * \param newUpdateFreqHz Parameter to modify
283 * \returns Itself
284 */
285 constexpr FireAnimation &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
286 {
287 UpdateFreqHz = newUpdateFreqHz;
288 return *this;
289 }
290
291 /**
292 * \brief Returns a string representation of the object.
293 *
294 * \returns a string representation of the object.
295 */
296 std::string ToString() const override;
297
298 /**
299 * \brief Gets information about this control request.
300 *
301 * \returns Map of control parameter names and corresponding applied values
302 */
303 std::map<std::string, std::string> GetControlInfo() const override;
304};
305
306}
307}
308}
309
Common interface implemented by all control requests.
Definition ControlRequest.hpp:27
Animation that looks similar to a flame flickering.
Definition FireAnimation.hpp:24
constexpr 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:225
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:61
constexpr FireAnimation & WithDirection(signals::AnimationDirectionValue newDirection)
Modifies this Control Request's Direction parameter and returns itself for method-chaining and easier...
Definition FireAnimation.hpp:209
std::string ToString() const override
Returns a string representation of the object.
units::dimensionless::scalar_t Brightness
The brightness of the animation, as a scalar from 0.0 to 1.0.
Definition FireAnimation.hpp:52
units::frequency::hertz_t UpdateFreqHz
The frequency at which this control will update.
Definition FireAnimation.hpp:92
constexpr 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:194
constexpr ~FireAnimation() override
Definition FireAnimation.hpp:119
int LEDEndIndex
The index of the last LED this animation controls (inclusive).
Definition FireAnimation.hpp:43
int Slot
The slot of this animation, within [0, 7].
Definition FireAnimation.hpp:48
constexpr FireAnimation & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the frequency at which this control will update.
Definition FireAnimation.hpp:285
constexpr FireAnimation & WithLEDEndIndex(int newLEDEndIndex)
Modifies this Control Request's LEDEndIndex parameter and returns itself for method-chaining and easi...
Definition FireAnimation.hpp:163
units::frequency::hertz_t FrameRate
The frame rate of the animation, from [2, 1000] Hz.
Definition FireAnimation.hpp:77
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:66
constexpr FireAnimation & WithSlot(int newSlot)
Modifies this Control Request's Slot parameter and returns itself for method-chaining and easier to u...
Definition FireAnimation.hpp:179
constexpr 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:241
constexpr std::string_view GetName() const override
Gets the name of this control request.
Definition FireAnimation.hpp:126
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
int LEDStartIndex
The index of the first LED this animation controls (inclusive).
Definition FireAnimation.hpp:35
constexpr 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:263
signals::AnimationDirectionValue Direction
The direction of the animation.
Definition FireAnimation.hpp:56
constexpr FireAnimation(int LEDStartIndex, int LEDEndIndex)
Animation that looks similar to a flame flickering.
Definition FireAnimation.hpp:114
constexpr FireAnimation & WithLEDStartIndex(int newLEDStartIndex)
Modifies this Control Request's LEDStartIndex parameter and returns itself for method-chaining and ea...
Definition FireAnimation.hpp:144
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
Definition motor_constants.h:14
Direction of the animation.
Definition SpnEnums.hpp:4819
static constexpr int Forward
The animation starts at the specified LED start index and moves towards the LED end index.
Definition SpnEnums.hpp:4826