CTRE Phoenix 6 C++ 26.0.0-beta-1
Loading...
Searching...
No Matches
RgbFadeAnimation.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
10#include <units/frequency.h>
11#include <units/time.h>
12#include <units/dimensionless.h>
13
14namespace ctre {
15namespace phoenix6 {
16namespace controls {
17
18/**
19 * Animation that fades all the LEDs of a strip simultaneously between Red,
20 * Green, and Blue.
21 *
22 *
23 */
24class RgbFadeAnimation 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 brightness of the animation, as a scalar from 0.0 to 1.0.
46 */
47 units::dimensionless::scalar_t Brightness = 1.0;
48 /**
49 * \brief The frame rate of the animation, from [2, 1000] Hz. This determines
50 * the speed of the animation.
51 *
52 * A frame is defined as a transition in the state of the LEDs, adjusting the
53 * brightness of the LEDs by 1%.
54 *
55 * - Units: Hz
56 *
57 */
58 units::frequency::hertz_t FrameRate = 100_Hz;
59
60 /**
61 * \brief The frequency at which this control will update.
62 * This is designated in Hertz, with a minimum of 20 Hz
63 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
64 * Some update frequencies are not supported and will be
65 * promoted up to the next highest supported frequency.
66 *
67 * If this field is set to 0 Hz, the control request will
68 * be sent immediately as a one-shot frame. This may be useful
69 * for advanced applications that require outputs to be
70 * synchronized with data acquisition. In this case, we
71 * recommend not exceeding 50 ms between control calls.
72 */
73 units::frequency::hertz_t UpdateFreqHz{20_Hz};
74
75 /**
76 * \brief Animation that fades all the LEDs of a strip simultaneously between
77 * Red, Green, and Blue.
78 *
79 * \details
80 *
81 * \param LEDStartIndex The index of the first LED this animation controls
82 * (inclusive). Indices 0-7 control the onboard LEDs, and
83 * 8-399 control an attached LED strip.
84 * \param LEDEndIndex The index of the last LED this animation controls
85 * (inclusive). Indices 0-7 control the onboard LEDs, and
86 * 8-399 control an attached LED strip.
87 */
89 LEDStartIndex{std::move(LEDStartIndex)},
90 LEDEndIndex{std::move(LEDEndIndex)}
91 {}
92
93 constexpr ~RgbFadeAnimation() override {}
94
95 /**
96 * \brief Gets the name of this control request.
97 *
98 * \returns Name of the control request
99 */
100 constexpr std::string_view GetName() const override
101 {
102 return "RgbFadeAnimation";
103 }
104
105 /**
106 * \brief Modifies this Control Request's LEDStartIndex parameter and returns itself for
107 * method-chaining and easier to use request API.
108 *
109 * The index of the first LED this animation controls (inclusive). Indices 0-7
110 * control the onboard LEDs, and 8-399 control an attached LED strip.
111 *
112 * \param newLEDStartIndex Parameter to modify
113 * \returns Itself
114 */
115 constexpr RgbFadeAnimation &WithLEDStartIndex(int newLEDStartIndex)
116 {
117 LEDStartIndex = std::move(newLEDStartIndex);
118 return *this;
119 }
120
121 /**
122 * \brief Modifies this Control Request's LEDEndIndex parameter and returns itself for
123 * method-chaining and easier to use request API.
124 *
125 * The index of the last LED this animation controls (inclusive). Indices 0-7
126 * control the onboard LEDs, and 8-399 control an attached LED strip.
127 *
128 * \param newLEDEndIndex Parameter to modify
129 * \returns Itself
130 */
131 constexpr RgbFadeAnimation &WithLEDEndIndex(int newLEDEndIndex)
132 {
133 LEDEndIndex = std::move(newLEDEndIndex);
134 return *this;
135 }
136
137 /**
138 * \brief Modifies this Control Request's Slot parameter and returns itself for
139 * method-chaining and easier to use request API.
140 *
141 * The slot of this animation, within [0, 7]. Each slot on the CANdle can store
142 * and run one animation.
143 *
144 * \param newSlot Parameter to modify
145 * \returns Itself
146 */
147 constexpr RgbFadeAnimation &WithSlot(int newSlot)
148 {
149 Slot = std::move(newSlot);
150 return *this;
151 }
152
153 /**
154 * \brief Modifies this Control Request's Brightness parameter and returns itself for
155 * method-chaining and easier to use request API.
156 *
157 * The brightness of the animation, as a scalar from 0.0 to 1.0.
158 *
159 * \param newBrightness Parameter to modify
160 * \returns Itself
161 */
162 constexpr RgbFadeAnimation &WithBrightness(units::dimensionless::scalar_t newBrightness)
163 {
164 Brightness = std::move(newBrightness);
165 return *this;
166 }
167
168 /**
169 * \brief Modifies this Control Request's FrameRate parameter and returns itself for
170 * method-chaining and easier to use request API.
171 *
172 * The frame rate of the animation, from [2, 1000] Hz. This determines the speed
173 * of the animation.
174 *
175 * A frame is defined as a transition in the state of the LEDs, adjusting the
176 * brightness of the LEDs by 1%.
177 *
178 * - Units: Hz
179 *
180 *
181 * \param newFrameRate Parameter to modify
182 * \returns Itself
183 */
184 constexpr RgbFadeAnimation &WithFrameRate(units::frequency::hertz_t newFrameRate)
185 {
186 FrameRate = std::move(newFrameRate);
187 return *this;
188 }
189
190 /**
191 * \brief Sets the frequency at which this control will update.
192 * This is designated in Hertz, with a minimum of 20 Hz
193 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
194 * Some update frequencies are not supported and will be
195 * promoted up to the next highest supported frequency.
196 *
197 * If this field is set to 0 Hz, the control request will
198 * be sent immediately as a one-shot frame. This may be useful
199 * for advanced applications that require outputs to be
200 * synchronized with data acquisition. In this case, we
201 * recommend not exceeding 50 ms between control calls.
202 *
203 * \param newUpdateFreqHz Parameter to modify
204 * \returns Itself
205 */
206 constexpr RgbFadeAnimation &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
207 {
208 UpdateFreqHz = newUpdateFreqHz;
209 return *this;
210 }
211
212 /**
213 * \brief Returns a string representation of the object.
214 *
215 * \returns a string representation of the object.
216 */
217 std::string ToString() const override;
218
219 /**
220 * \brief Gets information about this control request.
221 *
222 * \returns Map of control parameter names and corresponding applied values
223 */
224 std::map<std::string, std::string> GetControlInfo() const override;
225};
226
227}
228}
229}
230
Common interface implemented by all control requests.
Definition ControlRequest.hpp:27
Animation that fades all the LEDs of a strip simultaneously between Red, Green, and Blue.
Definition RgbFadeAnimation.hpp:24
constexpr RgbFadeAnimation(int LEDStartIndex, int LEDEndIndex)
Animation that fades all the LEDs of a strip simultaneously between Red, Green, and Blue.
Definition RgbFadeAnimation.hpp:88
constexpr ~RgbFadeAnimation() override
Definition RgbFadeAnimation.hpp:93
units::dimensionless::scalar_t Brightness
The brightness of the animation, as a scalar from 0.0 to 1.0.
Definition RgbFadeAnimation.hpp:47
int LEDStartIndex
The index of the first LED this animation controls (inclusive).
Definition RgbFadeAnimation.hpp:33
units::frequency::hertz_t FrameRate
The frame rate of the animation, from [2, 1000] Hz.
Definition RgbFadeAnimation.hpp:58
constexpr RgbFadeAnimation & WithLEDEndIndex(int newLEDEndIndex)
Modifies this Control Request's LEDEndIndex parameter and returns itself for method-chaining and easi...
Definition RgbFadeAnimation.hpp:131
units::frequency::hertz_t UpdateFreqHz
The frequency at which this control will update.
Definition RgbFadeAnimation.hpp:73
int LEDEndIndex
The index of the last LED this animation controls (inclusive).
Definition RgbFadeAnimation.hpp:38
constexpr RgbFadeAnimation & WithSlot(int newSlot)
Modifies this Control Request's Slot parameter and returns itself for method-chaining and easier to u...
Definition RgbFadeAnimation.hpp:147
constexpr RgbFadeAnimation & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the frequency at which this control will update.
Definition RgbFadeAnimation.hpp:206
constexpr RgbFadeAnimation & WithLEDStartIndex(int newLEDStartIndex)
Modifies this Control Request's LEDStartIndex parameter and returns itself for method-chaining and ea...
Definition RgbFadeAnimation.hpp:115
constexpr RgbFadeAnimation & WithFrameRate(units::frequency::hertz_t newFrameRate)
Modifies this Control Request's FrameRate parameter and returns itself for method-chaining and easier...
Definition RgbFadeAnimation.hpp:184
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
std::string ToString() const override
Returns a string representation of the object.
constexpr RgbFadeAnimation & WithBrightness(units::dimensionless::scalar_t newBrightness)
Modifies this Control Request's Brightness parameter and returns itself for method-chaining and easie...
Definition RgbFadeAnimation.hpp:162
int Slot
The slot of this animation, within [0, 7].
Definition RgbFadeAnimation.hpp:43
constexpr std::string_view GetName() const override
Gets the name of this control request.
Definition RgbFadeAnimation.hpp:100
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
Definition motor_constants.h:14