CTRE Phoenix 6 C++ 26.0.0-beta-1
Loading...
Searching...
No Matches
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
12#include <units/frequency.h>
13#include <units/time.h>
14
15namespace ctre {
16namespace phoenix6 {
17namespace controls {
18
19/**
20 * Animation that bounces a pocket of light across the LED strip.
21 *
22 *
23 */
24class LarsonAnimation 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
31 * strip.
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 */
39 /**
40 * \brief The slot of this animation, within [0, 7]. Each slot on the CANdle can
41 * store and run one animation.
42 */
43 int Slot = 0;
44 /**
45 * \brief The color to use in the animation.
46 */
48 /**
49 * \brief The number of LEDs in the pocket of light, up to 15.
50 */
51 int Size = 3;
52 /**
53 * \brief The behavior of the pocket of light when it reaches the end of the
54 * strip.
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 * pocket of light by one LED.
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 bounces a pocket of light across the LED strip.
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 * \param LEDEndIndex The index of the last LED this animation controls
93 * (inclusive). Indices 0-7 control the onboard LEDs, and
94 * 8-399 control an attached LED strip.
95 */
97 LEDStartIndex{std::move(LEDStartIndex)},
98 LEDEndIndex{std::move(LEDEndIndex)}
99 {}
100
101 constexpr ~LarsonAnimation() override {}
102
103 /**
104 * \brief Gets the name of this control request.
105 *
106 * \returns Name of the control request
107 */
108 constexpr std::string_view GetName() const override
109 {
110 return "LarsonAnimation";
111 }
112
113 /**
114 * \brief Modifies this Control Request's LEDStartIndex parameter and returns itself for
115 * method-chaining and easier to use request API.
116 *
117 * The index of the first LED this animation controls (inclusive). Indices 0-7
118 * control the onboard LEDs, and 8-399 control an attached LED strip.
119 *
120 * \param newLEDStartIndex Parameter to modify
121 * \returns Itself
122 */
123 constexpr LarsonAnimation &WithLEDStartIndex(int newLEDStartIndex)
124 {
125 LEDStartIndex = std::move(newLEDStartIndex);
126 return *this;
127 }
128
129 /**
130 * \brief Modifies this Control Request's LEDEndIndex parameter and returns itself for
131 * method-chaining and easier to use request API.
132 *
133 * The index of the last LED this animation controls (inclusive). Indices 0-7
134 * control the onboard LEDs, and 8-399 control an attached LED strip.
135 *
136 * \param newLEDEndIndex Parameter to modify
137 * \returns Itself
138 */
139 constexpr LarsonAnimation &WithLEDEndIndex(int newLEDEndIndex)
140 {
141 LEDEndIndex = std::move(newLEDEndIndex);
142 return *this;
143 }
144
145 /**
146 * \brief Modifies this Control Request's Slot parameter and returns itself for
147 * method-chaining and easier to use request API.
148 *
149 * The slot of this animation, within [0, 7]. Each slot on the CANdle can store
150 * and run one animation.
151 *
152 * \param newSlot Parameter to modify
153 * \returns Itself
154 */
155 constexpr LarsonAnimation &WithSlot(int newSlot)
156 {
157 Slot = std::move(newSlot);
158 return *this;
159 }
160
161 /**
162 * \brief Modifies this Control Request's Color parameter and returns itself for
163 * method-chaining and easier to use request API.
164 *
165 * The color to use in the animation.
166 *
167 * \param newColor Parameter to modify
168 * \returns Itself
169 */
171 {
172 Color = std::move(newColor);
173 return *this;
174 }
175
176 /**
177 * \brief Modifies this Control Request's Size parameter and returns itself for
178 * method-chaining and easier to use request API.
179 *
180 * The number of LEDs in the pocket of light, up to 15.
181 *
182 * \param newSize Parameter to modify
183 * \returns Itself
184 */
185 constexpr LarsonAnimation &WithSize(int newSize)
186 {
187 Size = std::move(newSize);
188 return *this;
189 }
190
191 /**
192 * \brief Modifies this Control Request's BounceMode parameter and returns itself for
193 * method-chaining and easier to use request API.
194 *
195 * The behavior of the pocket of light when it reaches the end of the strip.
196 *
197 * \param newBounceMode Parameter to modify
198 * \returns Itself
199 */
201 {
202 BounceMode = std::move(newBounceMode);
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, advancing the
214 * pocket of light by one LED.
215 *
216 * - Units: Hz
217 *
218 *
219 * \param newFrameRate Parameter to modify
220 * \returns Itself
221 */
222 constexpr LarsonAnimation &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 LarsonAnimation &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
Common interface implemented by all control requests.
Definition ControlRequest.hpp:27
Animation that bounces a pocket of light across the LED strip.
Definition LarsonAnimation.hpp:24
int LEDEndIndex
The index of the last LED this animation controls (inclusive).
Definition LarsonAnimation.hpp:38
constexpr LarsonAnimation & WithColor(signals::RGBWColor newColor)
Modifies this Control Request's Color parameter and returns itself for method-chaining and easier to ...
Definition LarsonAnimation.hpp:170
constexpr LarsonAnimation & WithSlot(int newSlot)
Modifies this Control Request's Slot parameter and returns itself for method-chaining and easier to u...
Definition LarsonAnimation.hpp:155
signals::RGBWColor Color
The color to use in the animation.
Definition LarsonAnimation.hpp:47
constexpr ~LarsonAnimation() override
Definition LarsonAnimation.hpp:101
int Size
The number of LEDs in the pocket of light, up to 15.
Definition LarsonAnimation.hpp:51
constexpr 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:222
units::frequency::hertz_t UpdateFreqHz
The frequency at which this control will update.
Definition LarsonAnimation.hpp:82
constexpr LarsonAnimation(int LEDStartIndex, int LEDEndIndex)
Animation that bounces a pocket of light across the LED strip.
Definition LarsonAnimation.hpp:96
units::frequency::hertz_t FrameRate
The frame rate of the animation, from [2, 1000] Hz.
Definition LarsonAnimation.hpp:67
constexpr LarsonAnimation & WithSize(int newSize)
Modifies this Control Request's Size parameter and returns itself for method-chaining and easier to u...
Definition LarsonAnimation.hpp:185
int Slot
The slot of this animation, within [0, 7].
Definition LarsonAnimation.hpp:43
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
constexpr LarsonAnimation & WithBounceMode(signals::LarsonBounceValue newBounceMode)
Modifies this Control Request's BounceMode parameter and returns itself for method-chaining and easie...
Definition LarsonAnimation.hpp:200
signals::LarsonBounceValue BounceMode
The behavior of the pocket of light when it reaches the end of the strip.
Definition LarsonAnimation.hpp:56
constexpr LarsonAnimation & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the frequency at which this control will update.
Definition LarsonAnimation.hpp:244
constexpr std::string_view GetName() const override
Gets the name of this control request.
Definition LarsonAnimation.hpp:108
int LEDStartIndex
The index of the first LED this animation controls (inclusive).
Definition LarsonAnimation.hpp:33
std::string ToString() const override
Returns a string representation of the object.
constexpr LarsonAnimation & WithLEDEndIndex(int newLEDEndIndex)
Modifies this Control Request's LEDEndIndex parameter and returns itself for method-chaining and easi...
Definition LarsonAnimation.hpp:139
constexpr LarsonAnimation & WithLEDStartIndex(int newLEDStartIndex)
Modifies this Control Request's LEDStartIndex parameter and returns itself for method-chaining and ea...
Definition LarsonAnimation.hpp:123
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
The behavior of the larson animation pocket of light when it reaches the end of the strip.
Definition SpnEnums.hpp:4876
static constexpr int Front
The animation bounces as soon as the first LED reaches the end of the strip.
Definition SpnEnums.hpp:4883