CTRE Phoenix 6 C++ 26.70.0-alpha-2
Loading...
Searching...
No Matches
ColorFlowAnimation.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 gradually lights the entire LED strip one LED at a time.
21 */
22class ColorFlowAnimation 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 color to use in the animation.
49 */
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, turning one on
60 * or off.
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 gradually lights the entire LED strip one LED at a
84 * time.
85 *
86 * \param LEDStartIndex The index of the first LED this animation controls
87 * (inclusive). Indices 0-7 control the onboard LEDs, and
88 * 8-399 control an attached LED strip
89 *
90 * If the start index is greater than the end index, the
91 * direction will be reversed. The direction can also be
92 * changed using the Direction parameter.
93 * \param LEDEndIndex The index of the last LED this animation controls
94 * (inclusive). Indices 0-7 control the onboard LEDs, and
95 * 8-399 control an attached LED strip.
96 *
97 * If the end index is less than the start index, the
98 * direction will be reversed. The direction can also be
99 * changed using the Direction parameter.
100 */
102 LEDStartIndex{std::move(LEDStartIndex)},
103 LEDEndIndex{std::move(LEDEndIndex)}
104 {}
105
106 constexpr ~ColorFlowAnimation() override {}
107
108 /**
109 * \brief Gets the name of this control request.
110 *
111 * \returns Name of the control request
112 */
113 constexpr std::string_view GetName() const override
114 {
115 return "ColorFlowAnimation";
116 }
117
118 /**
119 * \brief Modifies this Control Request's LEDStartIndex parameter and returns itself for
120 * method-chaining and easier to use request API.
121 *
122 * The index of the first LED this animation controls (inclusive). Indices 0-7
123 * control the onboard LEDs, and 8-399 control an attached LED strip
124 *
125 * If the start index is greater than the end index, the direction will be
126 * reversed. The direction can also be changed using the Direction parameter.
127 *
128 * \param newLEDStartIndex Parameter to modify
129 * \returns Itself
130 */
131 constexpr ColorFlowAnimation &WithLEDStartIndex(int newLEDStartIndex)
132 {
133 LEDStartIndex = std::move(newLEDStartIndex);
134 return *this;
135 }
136
137 /**
138 * \brief Modifies this Control Request's LEDEndIndex parameter and returns itself for
139 * method-chaining and easier to use request API.
140 *
141 * The index of the last LED this animation controls (inclusive). Indices 0-7
142 * control the onboard LEDs, and 8-399 control an attached LED strip.
143 *
144 * If the end index is less than the start index, the direction will be
145 * reversed. The direction can also be changed using the Direction parameter.
146 *
147 * \param newLEDEndIndex Parameter to modify
148 * \returns Itself
149 */
150 constexpr ColorFlowAnimation &WithLEDEndIndex(int newLEDEndIndex)
151 {
152 LEDEndIndex = std::move(newLEDEndIndex);
153 return *this;
154 }
155
156 /**
157 * \brief Modifies this Control Request's Slot parameter and returns itself for
158 * method-chaining and easier to use request API.
159 *
160 * The slot of this animation, within [0, 7]. Each slot on the CANdle can store
161 * and run one animation.
162 *
163 * \param newSlot Parameter to modify
164 * \returns Itself
165 */
166 constexpr ColorFlowAnimation &WithSlot(int newSlot)
167 {
168 Slot = std::move(newSlot);
169 return *this;
170 }
171
172 /**
173 * \brief Modifies this Control Request's Color parameter and returns itself for
174 * method-chaining and easier to use request API.
175 *
176 * The color to use in the animation.
177 *
178 * \param newColor Parameter to modify
179 * \returns Itself
180 */
182 {
183 Color = std::move(newColor);
184 return *this;
185 }
186
187 /**
188 * \brief Modifies this Control Request's Direction parameter and returns itself for
189 * method-chaining and easier to use request API.
190 *
191 * The direction of the animation.
192 *
193 * \param newDirection Parameter to modify
194 * \returns Itself
195 */
197 {
198 Direction = std::move(newDirection);
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, turning one on
210 * or off.
211 *
212 * - Units: Hz
213 *
214 *
215 * \param newFrameRate Parameter to modify
216 * \returns Itself
217 */
218 constexpr ColorFlowAnimation &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 ColorFlowAnimation &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 ColorFlowAnimation & WithFrameRate(wpi::units::hertz_t newFrameRate)
Modifies this Control Request's FrameRate parameter and returns itself for method-chaining and easier...
Definition ColorFlowAnimation.hpp:218
int LEDStartIndex
The index of the first LED this animation controls (inclusive).
Definition ColorFlowAnimation.hpp:33
constexpr ColorFlowAnimation & WithLEDEndIndex(int newLEDEndIndex)
Modifies this Control Request's LEDEndIndex parameter and returns itself for method-chaining and easi...
Definition ColorFlowAnimation.hpp:150
constexpr ColorFlowAnimation & WithSlot(int newSlot)
Modifies this Control Request's Slot parameter and returns itself for method-chaining and easier to u...
Definition ColorFlowAnimation.hpp:166
std::map< std::string_view, std::string > GetControlInfo() const override
Gets information about this control request.
constexpr std::string_view GetName() const override
Gets the name of this control request.
Definition ColorFlowAnimation.hpp:113
constexpr ColorFlowAnimation & WithDirection(signals::AnimationDirectionValue newDirection)
Modifies this Control Request's Direction parameter and returns itself for method-chaining and easier...
Definition ColorFlowAnimation.hpp:196
signals::RGBWColor Color
The color to use in the animation.
Definition ColorFlowAnimation.hpp:50
constexpr ColorFlowAnimation & WithColor(signals::RGBWColor newColor)
Modifies this Control Request's Color parameter and returns itself for method-chaining and easier to ...
Definition ColorFlowAnimation.hpp:181
constexpr ColorFlowAnimation & WithLEDStartIndex(int newLEDStartIndex)
Modifies this Control Request's LEDStartIndex parameter and returns itself for method-chaining and ea...
Definition ColorFlowAnimation.hpp:131
constexpr ~ColorFlowAnimation() override
Definition ColorFlowAnimation.hpp:106
int Slot
The slot of this animation, within [0, 7].
Definition ColorFlowAnimation.hpp:46
constexpr ColorFlowAnimation(int LEDStartIndex, int LEDEndIndex)
Animation that gradually lights the entire LED strip one LED at a time.
Definition ColorFlowAnimation.hpp:101
std::string ToString() const override
Returns a string representation of the object.
int LEDEndIndex
The index of the last LED this animation controls (inclusive).
Definition ColorFlowAnimation.hpp:41
wpi::units::hertz_t FrameRate
The frame rate of the animation, from [2, 1000] Hz.
Definition ColorFlowAnimation.hpp:65
constexpr ColorFlowAnimation & WithUpdateFreqHz(wpi::units::hertz_t newUpdateFreqHz)
Sets the frequency at which this control will update.
Definition ColorFlowAnimation.hpp:240
wpi::units::hertz_t UpdateFreqHz
The frequency at which this control will update.
Definition ColorFlowAnimation.hpp:80
signals::AnimationDirectionValue Direction
The direction of the animation.
Definition ColorFlowAnimation.hpp:54
constexpr ControlRequest(ControlRequest const &)=default
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
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