Loading [MathJax]/extensions/tex2jax.js
CTRE Phoenix 6 C++ 25.4.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 <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 creates a rainbow throughout all the LEDs.
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<RainbowAnimation *>(req.get());
34 if (reqCast != nullptr)
35 {
36 *reqCast = *this;
37 }
38 else
39 {
40 req = std::make_shared<RainbowAnimation>(*this);
41 }
42 }
43
44 return c_ctre_phoenix6_RequestControlRainbowAnimation(network, deviceHash, UpdateFreqHz.to<double>(), LEDStartIndex, LEDEndIndex, Slot, Brightness.to<double>(), Direction.value, 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 frame rate of the animation, from [2, 1000] Hz. This determines
79 * the speed of the animation.
80 *
81 * A frame is defined as a transition in the state of the LEDs, advancing the
82 * rainbow by about 3 degrees of hue (out of 360 degrees).
83 *
84 * - Units: Hz
85 *
86 */
87 units::frequency::hertz_t FrameRate = 100_Hz;
88
89 /**
90 * \brief The period at which this control will update at.
91 * This is designated in Hertz, with a minimum of 20 Hz
92 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
93 *
94 * If this field is set to 0 Hz, the control request will
95 * be sent immediately as a one-shot frame. This may be useful
96 * for advanced applications that require outputs to be
97 * synchronized with data acquisition. In this case, we
98 * recommend not exceeding 50 ms between control calls.
99 */
100 units::frequency::hertz_t UpdateFreqHz{20_Hz};
101
102 /**
103 * \brief Animation that creates a rainbow throughout all the LEDs.
104 *
105 * \details
106 *
107 * \param LEDStartIndex The index of the first LED this animation controls
108 * (inclusive). Indices 0-7 control the onboard LEDs,
109 * and 8-399 control an attached LED strip
110 *
111 * If the start index is greater than the end index, the
112 * direction will be reversed. The direction can also be
113 * changed using the Direction parameter.
114 * \param LEDEndIndex The index of the last LED this animation controls
115 * (inclusive). Indices 0-7 control the onboard LEDs, and
116 * 8-399 control an attached LED strip.
117 *
118 * If the end index is less than the start index, the
119 * direction will be reversed. The direction can also be
120 * changed using the Direction parameter.
121 */
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 RainbowAnimation &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 */
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 */
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 RainbowAnimation &WithBrightness(units::dimensionless::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 FrameRate parameter and returns itself for
213 * method-chaining and easier to use request API.
214 *
215 * The frame rate of the animation, from [2, 1000] Hz. This determines the speed
216 * of the animation.
217 *
218 * A frame is defined as a transition in the state of the LEDs, advancing the
219 * rainbow by about 3 degrees of hue (out of 360 degrees).
220 *
221 * - Units: Hz
222 *
223 *
224 * \param newFrameRate Parameter to modify
225 * \returns Itself
226 */
227 RainbowAnimation &WithFrameRate(units::frequency::hertz_t newFrameRate)
228 {
229 FrameRate = std::move(newFrameRate);
230 return *this;
231 }
232 /**
233 * \brief Sets the period at which this control will update at.
234 * This is designated in Hertz, with a minimum of 20 Hz
235 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
236 *
237 * If this field is set to 0 Hz, the control request will
238 * be sent immediately as a one-shot frame. This may be useful
239 * for advanced applications that require outputs to be
240 * synchronized with data acquisition. In this case, we
241 * recommend not exceeding 50 ms between control calls.
242 *
243 * \param newUpdateFreqHz Parameter to modify
244 * \returns Itself
245 */
246 RainbowAnimation &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
247 {
248 UpdateFreqHz = newUpdateFreqHz;
249 return *this;
250 }
251 /**
252 * \brief Returns a string representation of the object.
253 *
254 * \returns a string representation of the object.
255 */
256 std::string ToString() const override
257 {
258 std::stringstream ss;
259 ss << "Control: RainbowAnimation" << std::endl;
260 ss << " LEDStartIndex: " << LEDStartIndex << std::endl;
261 ss << " LEDEndIndex: " << LEDEndIndex << std::endl;
262 ss << " Slot: " << Slot << std::endl;
263 ss << " Brightness: " << Brightness.to<double>() << std::endl;
264 ss << " Direction: " << Direction << std::endl;
265 ss << " FrameRate: " << FrameRate.to<double>() << " Hz" << std::endl;
266 return ss.str();
267 }
268
269 /**
270 * \brief Gets information about this control request.
271 *
272 * \returns Map of control parameter names and corresponding applied values
273 */
274 std::map<std::string, std::string> GetControlInfo() const override
275 {
276 std::map<std::string, std::string> controlInfo;
277 std::stringstream ss;
278 controlInfo["Name"] = GetName();
279 ss << LEDStartIndex; controlInfo["LEDStartIndex"] = ss.str(); ss.str(std::string{});
280 ss << LEDEndIndex; controlInfo["LEDEndIndex"] = ss.str(); ss.str(std::string{});
281 ss << Slot; controlInfo["Slot"] = ss.str(); ss.str(std::string{});
282 ss << Brightness.to<double>(); controlInfo["Brightness"] = ss.str(); ss.str(std::string{});
283 ss << Direction; controlInfo["Direction"] = ss.str(); ss.str(std::string{});
284 ss << FrameRate.to<double>(); controlInfo["FrameRate"] = ss.str(); ss.str(std::string{});
285 return controlInfo;
286 }
287};
288
289}
290}
291}
292
CTREXPORT int c_ctre_phoenix6_RequestControlRainbowAnimation(const char *canbus, uint32_t ecuEncoding, double updateFrequency, int LEDStartIndex, int LEDEndIndex, int Slot, double Brightness, int Direction, 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 creates a rainbow throughout all the LEDs.
Definition RainbowAnimation.hpp:28
signals::AnimationDirectionValue Direction
The direction of the animation.
Definition RainbowAnimation.hpp:76
RainbowAnimation & WithLEDEndIndex(int newLEDEndIndex)
Modifies this Control Request's LEDEndIndex parameter and returns itself for method-chaining and easi...
Definition RainbowAnimation.hpp:159
RainbowAnimation & WithLEDStartIndex(int newLEDStartIndex)
Modifies this Control Request's LEDStartIndex parameter and returns itself for method-chaining and ea...
Definition RainbowAnimation.hpp:140
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition RainbowAnimation.hpp:100
RainbowAnimation & WithSlot(int newSlot)
Modifies this Control Request's Slot parameter and returns itself for method-chaining and easier to u...
Definition RainbowAnimation.hpp:175
units::frequency::hertz_t FrameRate
The frame rate of the animation, from [2, 1000] Hz.
Definition RainbowAnimation.hpp:87
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:227
RainbowAnimation(int LEDStartIndex, int LEDEndIndex)
Animation that creates a rainbow throughout all the LEDs.
Definition RainbowAnimation.hpp:122
units::dimensionless::scalar_t Brightness
The brightness of the animation, as a scalar from 0.0 to 1.0.
Definition RainbowAnimation.hpp:72
int Slot
The slot of this animation, within [0, 7].
Definition RainbowAnimation.hpp:68
RainbowAnimation & WithDirection(signals::AnimationDirectionValue newDirection)
Modifies this Control Request's Direction parameter and returns itself for method-chaining and easier...
Definition RainbowAnimation.hpp:205
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition RainbowAnimation.hpp:274
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:190
std::string ToString() const override
Returns a string representation of the object.
Definition RainbowAnimation.hpp:256
RainbowAnimation & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition RainbowAnimation.hpp:246
int LEDStartIndex
The index of the first LED this animation controls (inclusive).
Definition RainbowAnimation.hpp:55
int LEDEndIndex
The index of the last LED this animation controls (inclusive).
Definition RainbowAnimation.hpp:63
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