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