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