CTRE Phoenix 6 C++ 26.0.0-beta-1
Loading...
Searching...
No Matches
RainbowAnimation.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 creates a rainbow throughout all the LEDs.
21 *
22 *
23 */
24class RainbowAnimation 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 frame rate of the animation, from [2, 1000] Hz. This determines
59 * the speed of the animation.
60 *
61 * A frame is defined as a transition in the state of the LEDs, advancing the
62 * rainbow by about 3 degrees of hue (out of 360 degrees).
63 *
64 * - Units: Hz
65 *
66 */
67 units::frequency::hertz_t FrameRate = 100_Hz;
68
69 /**
70 * \brief The frequency at which this control will update.
71 * This is designated in Hertz, with a minimum of 20 Hz
72 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
73 * Some update frequencies are not supported and will be
74 * promoted up to the next highest supported frequency.
75 *
76 * If this field is set to 0 Hz, the control request will
77 * be sent immediately as a one-shot frame. This may be useful
78 * for advanced applications that require outputs to be
79 * synchronized with data acquisition. In this case, we
80 * recommend not exceeding 50 ms between control calls.
81 */
82 units::frequency::hertz_t UpdateFreqHz{20_Hz};
83
84 /**
85 * \brief Animation that creates a rainbow throughout all the LEDs.
86 *
87 * \details
88 *
89 * \param LEDStartIndex The index of the first LED this animation controls
90 * (inclusive). Indices 0-7 control the onboard LEDs, and
91 * 8-399 control an attached LED strip
92 *
93 * If the start index is greater than the end index, the
94 * direction will be reversed. The direction can also be
95 * changed using the Direction parameter.
96 * \param LEDEndIndex The index of the last LED this animation controls
97 * (inclusive). Indices 0-7 control the onboard LEDs, and
98 * 8-399 control an attached LED strip.
99 *
100 * If the end index is less than the start index, the
101 * direction will be reversed. The direction can also be
102 * changed using the Direction parameter.
103 */
105 LEDStartIndex{std::move(LEDStartIndex)},
106 LEDEndIndex{std::move(LEDEndIndex)}
107 {}
108
109 constexpr ~RainbowAnimation() override {}
110
111 /**
112 * \brief Gets the name of this control request.
113 *
114 * \returns Name of the control request
115 */
116 constexpr std::string_view GetName() const override
117 {
118 return "RainbowAnimation";
119 }
120
121 /**
122 * \brief Modifies this Control Request's LEDStartIndex parameter and returns itself for
123 * method-chaining and easier to use request API.
124 *
125 * The index of the first LED this animation controls (inclusive). Indices 0-7
126 * control the onboard LEDs, and 8-399 control an attached LED strip
127 *
128 * If the start index is greater than the end index, the direction will be
129 * reversed. The direction can also be changed using the Direction parameter.
130 *
131 * \param newLEDStartIndex Parameter to modify
132 * \returns Itself
133 */
134 constexpr RainbowAnimation &WithLEDStartIndex(int newLEDStartIndex)
135 {
136 LEDStartIndex = std::move(newLEDStartIndex);
137 return *this;
138 }
139
140 /**
141 * \brief Modifies this Control Request's LEDEndIndex parameter and returns itself for
142 * method-chaining and easier to use request API.
143 *
144 * The index of the last LED this animation controls (inclusive). Indices 0-7
145 * control the onboard LEDs, and 8-399 control an attached LED strip.
146 *
147 * If the end index is less than the start index, the direction will be
148 * reversed. The direction can also be changed using the Direction parameter.
149 *
150 * \param newLEDEndIndex Parameter to modify
151 * \returns Itself
152 */
153 constexpr RainbowAnimation &WithLEDEndIndex(int newLEDEndIndex)
154 {
155 LEDEndIndex = std::move(newLEDEndIndex);
156 return *this;
157 }
158
159 /**
160 * \brief Modifies this Control Request's Slot parameter and returns itself for
161 * method-chaining and easier to use request API.
162 *
163 * The slot of this animation, within [0, 7]. Each slot on the CANdle can store
164 * and run one animation.
165 *
166 * \param newSlot Parameter to modify
167 * \returns Itself
168 */
169 constexpr RainbowAnimation &WithSlot(int newSlot)
170 {
171 Slot = std::move(newSlot);
172 return *this;
173 }
174
175 /**
176 * \brief Modifies this Control Request's Brightness parameter and returns itself for
177 * method-chaining and easier to use request API.
178 *
179 * The brightness of the animation, as a scalar from 0.0 to 1.0.
180 *
181 * \param newBrightness Parameter to modify
182 * \returns Itself
183 */
184 constexpr RainbowAnimation &WithBrightness(units::dimensionless::scalar_t newBrightness)
185 {
186 Brightness = std::move(newBrightness);
187 return *this;
188 }
189
190 /**
191 * \brief Modifies this Control Request's Direction parameter and returns itself for
192 * method-chaining and easier to use request API.
193 *
194 * The direction of the animation.
195 *
196 * \param newDirection Parameter to modify
197 * \returns Itself
198 */
200 {
201 Direction = std::move(newDirection);
202 return *this;
203 }
204
205 /**
206 * \brief Modifies this Control Request's FrameRate parameter and returns itself for
207 * method-chaining and easier to use request API.
208 *
209 * The frame rate of the animation, from [2, 1000] Hz. This determines the speed
210 * of the animation.
211 *
212 * A frame is defined as a transition in the state of the LEDs, advancing the
213 * rainbow by about 3 degrees of hue (out of 360 degrees).
214 *
215 * - Units: Hz
216 *
217 *
218 * \param newFrameRate Parameter to modify
219 * \returns Itself
220 */
221 constexpr RainbowAnimation &WithFrameRate(units::frequency::hertz_t newFrameRate)
222 {
223 FrameRate = std::move(newFrameRate);
224 return *this;
225 }
226
227 /**
228 * \brief Sets the frequency at which this control will update.
229 * This is designated in Hertz, with a minimum of 20 Hz
230 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
231 * Some update frequencies are not supported and will be
232 * promoted up to the next highest supported frequency.
233 *
234 * If this field is set to 0 Hz, the control request will
235 * be sent immediately as a one-shot frame. This may be useful
236 * for advanced applications that require outputs to be
237 * synchronized with data acquisition. In this case, we
238 * recommend not exceeding 50 ms between control calls.
239 *
240 * \param newUpdateFreqHz Parameter to modify
241 * \returns Itself
242 */
243 constexpr RainbowAnimation &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
244 {
245 UpdateFreqHz = newUpdateFreqHz;
246 return *this;
247 }
248
249 /**
250 * \brief Returns a string representation of the object.
251 *
252 * \returns a string representation of the object.
253 */
254 std::string ToString() const override;
255
256 /**
257 * \brief Gets information about this control request.
258 *
259 * \returns Map of control parameter names and corresponding applied values
260 */
261 std::map<std::string, std::string> GetControlInfo() const override;
262};
263
264}
265}
266}
267
Common interface implemented by all control requests.
Definition ControlRequest.hpp:27
Animation that creates a rainbow throughout all the LEDs.
Definition RainbowAnimation.hpp:24
signals::AnimationDirectionValue Direction
The direction of the animation.
Definition RainbowAnimation.hpp:56
constexpr RainbowAnimation & WithLEDStartIndex(int newLEDStartIndex)
Modifies this Control Request's LEDStartIndex parameter and returns itself for method-chaining and ea...
Definition RainbowAnimation.hpp:134
constexpr RainbowAnimation & WithLEDEndIndex(int newLEDEndIndex)
Modifies this Control Request's LEDEndIndex parameter and returns itself for method-chaining and easi...
Definition RainbowAnimation.hpp:153
units::frequency::hertz_t UpdateFreqHz
The frequency at which this control will update.
Definition RainbowAnimation.hpp:82
units::frequency::hertz_t FrameRate
The frame rate of the animation, from [2, 1000] Hz.
Definition RainbowAnimation.hpp:67
units::dimensionless::scalar_t Brightness
The brightness of the animation, as a scalar from 0.0 to 1.0.
Definition RainbowAnimation.hpp:52
constexpr RainbowAnimation & WithBrightness(units::dimensionless::scalar_t newBrightness)
Modifies this Control Request's Brightness parameter and returns itself for method-chaining and easie...
Definition RainbowAnimation.hpp:184
int Slot
The slot of this animation, within [0, 7].
Definition RainbowAnimation.hpp:48
constexpr RainbowAnimation & WithDirection(signals::AnimationDirectionValue newDirection)
Modifies this Control Request's Direction parameter and returns itself for method-chaining and easier...
Definition RainbowAnimation.hpp:199
constexpr RainbowAnimation & WithSlot(int newSlot)
Modifies this Control Request's Slot parameter and returns itself for method-chaining and easier to u...
Definition RainbowAnimation.hpp:169
constexpr RainbowAnimation(int LEDStartIndex, int LEDEndIndex)
Animation that creates a rainbow throughout all the LEDs.
Definition RainbowAnimation.hpp:104
constexpr std::string_view GetName() const override
Gets the name of this control request.
Definition RainbowAnimation.hpp:116
constexpr ~RainbowAnimation() override
Definition RainbowAnimation.hpp:109
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
constexpr RainbowAnimation & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the frequency at which this control will update.
Definition RainbowAnimation.hpp:243
constexpr RainbowAnimation & WithFrameRate(units::frequency::hertz_t newFrameRate)
Modifies this Control Request's FrameRate parameter and returns itself for method-chaining and easier...
Definition RainbowAnimation.hpp:221
std::string ToString() const override
Returns a string representation of the object.
int LEDStartIndex
The index of the first LED this animation controls (inclusive).
Definition RainbowAnimation.hpp:35
int LEDEndIndex
The index of the last LED this animation controls (inclusive).
Definition RainbowAnimation.hpp:43
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