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