Loading [MathJax]/extensions/tex2jax.js
CTRE Phoenix 6 C++ 25.4.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LarsonAnimation.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
15#include <units/frequency.h>
16#include <units/time.h>
17
18namespace ctre {
19namespace phoenix6 {
20namespace controls {
21
22/**
23 * Animation that bounces a pocket of light across the LED strip.
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<LarsonAnimation *>(req.get());
34 if (reqCast != nullptr)
35 {
36 *reqCast = *this;
37 }
38 else
39 {
40 req = std::make_shared<LarsonAnimation>(*this);
41 }
42 }
43
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
51 * strip.
52 */
54 /**
55 * \brief The index of the last LED this animation controls (inclusive). Indices
56 * 0-7 control the onboard LEDs, and 8-399 control an attached LED strip.
57 */
59 /**
60 * \brief The slot of this animation, within [0, 7]. Each slot on the CANdle can
61 * store and run one animation.
62 */
63 int Slot = 0;
64 /**
65 * \brief The color to use in the animation.
66 */
68 /**
69 * \brief The number of LEDs in the pocket of light, up to 15.
70 */
71 int Size = 3;
72 /**
73 * \brief The behavior of the pocket of light when it reaches the end of the
74 * strip.
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 * pocket of light by one LED.
83 *
84 * - Units: Hz
85 *
86 */
87 units::frequency::hertz_t FrameRate = 25_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 bounces a pocket of light across the LED strip.
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 * \param LEDEndIndex The index of the last LED this animation controls
111 * (inclusive). Indices 0-7 control the onboard LEDs, and
112 * 8-399 control an attached LED strip.
113 */
117 {}
118
119 /**
120 * \brief Modifies this Control Request's LEDStartIndex parameter and returns itself for
121 * method-chaining and easier to use request API.
122 *
123 * The index of the first LED this animation controls (inclusive). Indices 0-7
124 * control the onboard LEDs, and 8-399 control an attached LED strip.
125 *
126 * \param newLEDStartIndex Parameter to modify
127 * \returns Itself
128 */
129 LarsonAnimation &WithLEDStartIndex(int newLEDStartIndex)
130 {
131 LEDStartIndex = std::move(newLEDStartIndex);
132 return *this;
133 }
134
135 /**
136 * \brief Modifies this Control Request's LEDEndIndex parameter and returns itself for
137 * method-chaining and easier to use request API.
138 *
139 * The index of the last LED this animation controls (inclusive). Indices 0-7
140 * control the onboard LEDs, and 8-399 control an attached LED strip.
141 *
142 * \param newLEDEndIndex Parameter to modify
143 * \returns Itself
144 */
145 LarsonAnimation &WithLEDEndIndex(int newLEDEndIndex)
146 {
147 LEDEndIndex = std::move(newLEDEndIndex);
148 return *this;
149 }
150
151 /**
152 * \brief Modifies this Control Request's Slot parameter and returns itself for
153 * method-chaining and easier to use request API.
154 *
155 * The slot of this animation, within [0, 7]. Each slot on the CANdle can store
156 * and run one animation.
157 *
158 * \param newSlot Parameter to modify
159 * \returns Itself
160 */
162 {
163 Slot = std::move(newSlot);
164 return *this;
165 }
166
167 /**
168 * \brief Modifies this Control Request's Color parameter and returns itself for
169 * method-chaining and easier to use request API.
170 *
171 * The color to use in the animation.
172 *
173 * \param newColor Parameter to modify
174 * \returns Itself
175 */
177 {
178 Color = std::move(newColor);
179 return *this;
180 }
181
182 /**
183 * \brief Modifies this Control Request's Size parameter and returns itself for
184 * method-chaining and easier to use request API.
185 *
186 * The number of LEDs in the pocket of light, up to 15.
187 *
188 * \param newSize Parameter to modify
189 * \returns Itself
190 */
192 {
193 Size = std::move(newSize);
194 return *this;
195 }
196
197 /**
198 * \brief Modifies this Control Request's BounceMode parameter and returns itself for
199 * method-chaining and easier to use request API.
200 *
201 * The behavior of the pocket of light when it reaches the end of the strip.
202 *
203 * \param newBounceMode Parameter to modify
204 * \returns Itself
205 */
207 {
208 BounceMode = std::move(newBounceMode);
209 return *this;
210 }
211
212 /**
213 * \brief Modifies this Control Request's FrameRate parameter and returns itself for
214 * method-chaining and easier to use request API.
215 *
216 * The frame rate of the animation, from [2, 1000] Hz. This determines the speed
217 * of the animation.
218 *
219 * A frame is defined as a transition in the state of the LEDs, advancing the
220 * pocket of light by one LED.
221 *
222 * - Units: Hz
223 *
224 *
225 * \param newFrameRate Parameter to modify
226 * \returns Itself
227 */
228 LarsonAnimation &WithFrameRate(units::frequency::hertz_t newFrameRate)
229 {
230 FrameRate = std::move(newFrameRate);
231 return *this;
232 }
233 /**
234 * \brief Sets the period at which this control will update at.
235 * This is designated in Hertz, with a minimum of 20 Hz
236 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
237 *
238 * If this field is set to 0 Hz, the control request will
239 * be sent immediately as a one-shot frame. This may be useful
240 * for advanced applications that require outputs to be
241 * synchronized with data acquisition. In this case, we
242 * recommend not exceeding 50 ms between control calls.
243 *
244 * \param newUpdateFreqHz Parameter to modify
245 * \returns Itself
246 */
247 LarsonAnimation &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
248 {
249 UpdateFreqHz = newUpdateFreqHz;
250 return *this;
251 }
252 /**
253 * \brief Returns a string representation of the object.
254 *
255 * \returns a string representation of the object.
256 */
257 std::string ToString() const override
258 {
259 std::stringstream ss;
260 ss << "Control: LarsonAnimation" << std::endl;
261 ss << " LEDStartIndex: " << LEDStartIndex << std::endl;
262 ss << " LEDEndIndex: " << LEDEndIndex << std::endl;
263 ss << " Slot: " << Slot << std::endl;
264 ss << " Color: " << Color << std::endl;
265 ss << " Size: " << Size << std::endl;
266 ss << " BounceMode: " << BounceMode << std::endl;
267 ss << " FrameRate: " << FrameRate.to<double>() << " Hz" << std::endl;
268 return ss.str();
269 }
270
271 /**
272 * \brief Gets information about this control request.
273 *
274 * \returns Map of control parameter names and corresponding applied values
275 */
276 std::map<std::string, std::string> GetControlInfo() const override
277 {
278 std::map<std::string, std::string> controlInfo;
279 std::stringstream ss;
280 controlInfo["Name"] = GetName();
281 ss << LEDStartIndex; controlInfo["LEDStartIndex"] = ss.str(); ss.str(std::string{});
282 ss << LEDEndIndex; controlInfo["LEDEndIndex"] = ss.str(); ss.str(std::string{});
283 ss << Slot; controlInfo["Slot"] = ss.str(); ss.str(std::string{});
284 ss << Color; controlInfo["Color"] = ss.str(); ss.str(std::string{});
285 ss << Size; controlInfo["Size"] = ss.str(); ss.str(std::string{});
286 ss << BounceMode; controlInfo["BounceMode"] = ss.str(); ss.str(std::string{});
287 ss << FrameRate.to<double>(); controlInfo["FrameRate"] = ss.str(); ss.str(std::string{});
288 return controlInfo;
289 }
290};
291
292}
293}
294}
295
CTREXPORT int c_ctre_phoenix6_RequestControlLarsonAnimation(const char *canbus, uint32_t ecuEncoding, double updateFrequency, int LEDStartIndex, int LEDEndIndex, int Slot, int Color_Red, int Color_Green, int Color_Blue, int Color_White, int Size, int BounceMode, 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 bounces a pocket of light across the LED strip.
Definition LarsonAnimation.hpp:28
int LEDEndIndex
The index of the last LED this animation controls (inclusive).
Definition LarsonAnimation.hpp:58
LarsonAnimation & WithColor(signals::RGBWColor newColor)
Modifies this Control Request's Color parameter and returns itself for method-chaining and easier to ...
Definition LarsonAnimation.hpp:176
signals::RGBWColor Color
The color to use in the animation.
Definition LarsonAnimation.hpp:67
LarsonAnimation & WithFrameRate(units::frequency::hertz_t newFrameRate)
Modifies this Control Request's FrameRate parameter and returns itself for method-chaining and easier...
Definition LarsonAnimation.hpp:228
LarsonAnimation & WithSlot(int newSlot)
Modifies this Control Request's Slot parameter and returns itself for method-chaining and easier to u...
Definition LarsonAnimation.hpp:161
LarsonAnimation & WithLEDEndIndex(int newLEDEndIndex)
Modifies this Control Request's LEDEndIndex parameter and returns itself for method-chaining and easi...
Definition LarsonAnimation.hpp:145
int Size
The number of LEDs in the pocket of light, up to 15.
Definition LarsonAnimation.hpp:71
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition LarsonAnimation.hpp:100
LarsonAnimation & WithSize(int newSize)
Modifies this Control Request's Size parameter and returns itself for method-chaining and easier to u...
Definition LarsonAnimation.hpp:191
units::frequency::hertz_t FrameRate
The frame rate of the animation, from [2, 1000] Hz.
Definition LarsonAnimation.hpp:87
int Slot
The slot of this animation, within [0, 7].
Definition LarsonAnimation.hpp:63
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition LarsonAnimation.hpp:276
LarsonAnimation(int LEDStartIndex, int LEDEndIndex)
Animation that bounces a pocket of light across the LED strip.
Definition LarsonAnimation.hpp:114
LarsonAnimation & WithBounceMode(signals::LarsonBounceValue newBounceMode)
Modifies this Control Request's BounceMode parameter and returns itself for method-chaining and easie...
Definition LarsonAnimation.hpp:206
signals::LarsonBounceValue BounceMode
The behavior of the pocket of light when it reaches the end of the strip.
Definition LarsonAnimation.hpp:76
LarsonAnimation & WithLEDStartIndex(int newLEDStartIndex)
Modifies this Control Request's LEDStartIndex parameter and returns itself for method-chaining and ea...
Definition LarsonAnimation.hpp:129
int LEDStartIndex
The index of the first LED this animation controls (inclusive).
Definition LarsonAnimation.hpp:53
std::string ToString() const override
Returns a string representation of the object.
Definition LarsonAnimation.hpp:257
LarsonAnimation & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition LarsonAnimation.hpp:247
The behavior of the larson animation pocket of light when it reaches the end of the strip.
Definition SpnEnums.hpp:6470
int value
Definition SpnEnums.hpp:6472
static constexpr int Front
The animation bounces as soon as the first LED reaches the end of the strip.
Definition SpnEnums.hpp:6478
Represents an RGBW color that can be applied to an LED.
Definition RGBWColor.hpp:27
uint8_t Green
The green component of the color, within [0, 255].
Definition RGBWColor.hpp:36
uint8_t Blue
The blue component of the color, within [0, 255].
Definition RGBWColor.hpp:40
uint8_t White
The white component of the color, within [0, 255].
Definition RGBWColor.hpp:45
uint8_t Red
The red component of the color, within [0, 255].
Definition RGBWColor.hpp:32
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition Diff_PositionDutyCycle_Position.hpp:15
Definition span.hpp:401