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