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