CTRE Phoenix 6 C++ 26.70.0-alpha-2
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 <wpi/units/frequency.hpp>
13#include <wpi/units/time.hpp>
14
15namespace ctre {
16namespace phoenix6 {
17namespace controls {
18
19/**
20 * Animation that bounces a pocket of light across the LED strip.
21 */
22class LarsonAnimation final : public ControlRequest {
23 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override;
24
25public:
26 /**
27 * \brief The index of the first LED this animation controls (inclusive).
28 * Indices 0-7 control the onboard LEDs, and 8-399 control an attached LED
29 * strip.
30 */
32 /**
33 * \brief The index of the last LED this animation controls (inclusive). Indices
34 * 0-7 control the onboard LEDs, and 8-399 control an attached LED strip.
35 */
37 /**
38 * \brief The slot of this animation, within [0, 7]. Each slot on the CANdle can
39 * store and run one animation.
40 */
41 int Slot = 0;
42 /**
43 * \brief The color to use in the animation.
44 */
46 /**
47 * \brief The number of LEDs in the pocket of light, up to 15.
48 */
49 int Size = 3;
50 /**
51 * \brief The behavior of the pocket of light when it reaches the end of the
52 * strip.
53 */
55 /**
56 * \brief The frame rate of the animation, from [2, 1000] Hz. This determines
57 * the speed of the animation.
58 *
59 * A frame is defined as a transition in the state of the LEDs, advancing the
60 * pocket of light by one LED.
61 *
62 * - Units: Hz
63 *
64 */
65 wpi::units::hertz_t FrameRate = 25_Hz;
66
67 /**
68 * \brief The frequency at which this control will update.
69 * This is designated in Hertz, with a minimum of 20 Hz
70 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
71 * Some update frequencies are not supported and will be
72 * promoted up to the next highest supported frequency.
73 *
74 * If this field is set to 0 Hz, the control request will
75 * be sent immediately as a one-shot frame. This may be useful
76 * for advanced applications that require outputs to be
77 * synchronized with data acquisition. In this case, we
78 * recommend not exceeding 50 ms between control calls.
79 */
80 wpi::units::hertz_t UpdateFreqHz{20_Hz};
81
82 /**
83 * \brief Animation that bounces a pocket of light across the LED strip.
84 *
85 * \param LEDStartIndex The index of the first LED this animation controls
86 * (inclusive). Indices 0-7 control the onboard LEDs, and
87 * 8-399 control an attached LED strip.
88 * \param LEDEndIndex The index of the last LED this animation controls
89 * (inclusive). Indices 0-7 control the onboard LEDs, and
90 * 8-399 control an attached LED strip.
91 */
93 LEDStartIndex{std::move(LEDStartIndex)},
94 LEDEndIndex{std::move(LEDEndIndex)}
95 {}
96
97 constexpr ~LarsonAnimation() override {}
98
99 /**
100 * \brief Gets the name of this control request.
101 *
102 * \returns Name of the control request
103 */
104 constexpr std::string_view GetName() const override
105 {
106 return "LarsonAnimation";
107 }
108
109 /**
110 * \brief Modifies this Control Request's LEDStartIndex parameter and returns itself for
111 * method-chaining and easier to use request API.
112 *
113 * The index of the first LED this animation controls (inclusive). Indices 0-7
114 * control the onboard LEDs, and 8-399 control an attached LED strip.
115 *
116 * \param newLEDStartIndex Parameter to modify
117 * \returns Itself
118 */
119 constexpr LarsonAnimation &WithLEDStartIndex(int newLEDStartIndex)
120 {
121 LEDStartIndex = std::move(newLEDStartIndex);
122 return *this;
123 }
124
125 /**
126 * \brief Modifies this Control Request's LEDEndIndex parameter and returns itself for
127 * method-chaining and easier to use request API.
128 *
129 * The index of the last LED this animation controls (inclusive). Indices 0-7
130 * control the onboard LEDs, and 8-399 control an attached LED strip.
131 *
132 * \param newLEDEndIndex Parameter to modify
133 * \returns Itself
134 */
135 constexpr LarsonAnimation &WithLEDEndIndex(int newLEDEndIndex)
136 {
137 LEDEndIndex = std::move(newLEDEndIndex);
138 return *this;
139 }
140
141 /**
142 * \brief Modifies this Control Request's Slot parameter and returns itself for
143 * method-chaining and easier to use request API.
144 *
145 * The slot of this animation, within [0, 7]. Each slot on the CANdle can store
146 * and run one animation.
147 *
148 * \param newSlot Parameter to modify
149 * \returns Itself
150 */
151 constexpr LarsonAnimation &WithSlot(int newSlot)
152 {
153 Slot = std::move(newSlot);
154 return *this;
155 }
156
157 /**
158 * \brief Modifies this Control Request's Color parameter and returns itself for
159 * method-chaining and easier to use request API.
160 *
161 * The color to use in the animation.
162 *
163 * \param newColor Parameter to modify
164 * \returns Itself
165 */
167 {
168 Color = std::move(newColor);
169 return *this;
170 }
171
172 /**
173 * \brief Modifies this Control Request's Size parameter and returns itself for
174 * method-chaining and easier to use request API.
175 *
176 * The number of LEDs in the pocket of light, up to 15.
177 *
178 * \param newSize Parameter to modify
179 * \returns Itself
180 */
181 constexpr LarsonAnimation &WithSize(int newSize)
182 {
183 Size = std::move(newSize);
184 return *this;
185 }
186
187 /**
188 * \brief Modifies this Control Request's BounceMode parameter and returns itself for
189 * method-chaining and easier to use request API.
190 *
191 * The behavior of the pocket of light when it reaches the end of the strip.
192 *
193 * \param newBounceMode Parameter to modify
194 * \returns Itself
195 */
197 {
198 BounceMode = std::move(newBounceMode);
199 return *this;
200 }
201
202 /**
203 * \brief Modifies this Control Request's FrameRate parameter and returns itself for
204 * method-chaining and easier to use request API.
205 *
206 * The frame rate of the animation, from [2, 1000] Hz. This determines the speed
207 * of the animation.
208 *
209 * A frame is defined as a transition in the state of the LEDs, advancing the
210 * pocket of light by one LED.
211 *
212 * - Units: Hz
213 *
214 *
215 * \param newFrameRate Parameter to modify
216 * \returns Itself
217 */
218 constexpr LarsonAnimation &WithFrameRate(wpi::units::hertz_t newFrameRate)
219 {
220 FrameRate = std::move(newFrameRate);
221 return *this;
222 }
223
224 /**
225 * \brief Sets the frequency at which this control will update.
226 * This is designated in Hertz, with a minimum of 20 Hz
227 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
228 * Some update frequencies are not supported and will be
229 * promoted up to the next highest supported frequency.
230 *
231 * If this field is set to 0 Hz, the control request will
232 * be sent immediately as a one-shot frame. This may be useful
233 * for advanced applications that require outputs to be
234 * synchronized with data acquisition. In this case, we
235 * recommend not exceeding 50 ms between control calls.
236 *
237 * \param newUpdateFreqHz Parameter to modify
238 * \returns Itself
239 */
240 constexpr LarsonAnimation &WithUpdateFreqHz(wpi::units::hertz_t newUpdateFreqHz)
241 {
242 UpdateFreqHz = newUpdateFreqHz;
243 return *this;
244 }
245
246 /**
247 * \brief Returns a string representation of the object.
248 *
249 * \returns a string representation of the object.
250 */
251 std::string ToString() const override;
252
253 /**
254 * \brief Gets information about this control request.
255 *
256 * \returns Map of control parameter names and corresponding applied values
257 */
258 std::map<std::string_view, std::string> GetControlInfo() const override;
259};
260
261}
262}
263}
264
constexpr ControlRequest(ControlRequest const &)=default
int LEDEndIndex
The index of the last LED this animation controls (inclusive).
Definition LarsonAnimation.hpp:36
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:166
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:151
wpi::units::hertz_t UpdateFreqHz
The frequency at which this control will update.
Definition LarsonAnimation.hpp:80
constexpr LarsonAnimation & WithFrameRate(wpi::units::hertz_t newFrameRate)
Modifies this Control Request's FrameRate parameter and returns itself for method-chaining and easier...
Definition LarsonAnimation.hpp:218
signals::RGBWColor Color
The color to use in the animation.
Definition LarsonAnimation.hpp:45
constexpr ~LarsonAnimation() override
Definition LarsonAnimation.hpp:97
int Size
The number of LEDs in the pocket of light, up to 15.
Definition LarsonAnimation.hpp:49
constexpr LarsonAnimation & WithUpdateFreqHz(wpi::units::hertz_t newUpdateFreqHz)
Sets the frequency at which this control will update.
Definition LarsonAnimation.hpp:240
constexpr LarsonAnimation(int LEDStartIndex, int LEDEndIndex)
Animation that bounces a pocket of light across the LED strip.
Definition LarsonAnimation.hpp:92
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:181
wpi::units::hertz_t FrameRate
The frame rate of the animation, from [2, 1000] Hz.
Definition LarsonAnimation.hpp:65
int Slot
The slot of this animation, within [0, 7].
Definition LarsonAnimation.hpp:41
constexpr LarsonAnimation & WithBounceMode(signals::LarsonBounceValue newBounceMode)
Modifies this Control Request's BounceMode parameter and returns itself for method-chaining and easie...
Definition LarsonAnimation.hpp:196
signals::LarsonBounceValue BounceMode
The behavior of the pocket of light when it reaches the end of the strip.
Definition LarsonAnimation.hpp:54
constexpr std::string_view GetName() const override
Gets the name of this control request.
Definition LarsonAnimation.hpp:104
std::map< std::string_view, std::string > GetControlInfo() const override
Gets information about this control request.
int LEDStartIndex
The index of the first LED this animation controls (inclusive).
Definition LarsonAnimation.hpp:31
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:135
constexpr LarsonAnimation & WithLEDStartIndex(int newLEDStartIndex)
Modifies this Control Request's LEDStartIndex parameter and returns itself for method-chaining and ea...
Definition LarsonAnimation.hpp:119
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 MotionMagicDutyCycle.hpp:17
Definition ExternalFeedbackConfigs.hpp:16
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:4650
static constexpr int Front
The animation bounces as soon as the first LED reaches the end of the strip.
Definition SpnEnums.hpp:4658