Loading [MathJax]/jax/input/TeX/config.js
CTRE Phoenix 6 C++ 25.4.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 <sstream>
12
14#include <units/frequency.h>
15#include <units/time.h>
16#include <units/dimensionless.h>
17
18namespace ctre {
19namespace phoenix6 {
20namespace controls {
21
22/**
23 * Animation that randomly turns LEDs on and off to a certain color.
24 *
25 *
26 */
28{
29 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override
30 {
31 if (req.get() != this)
32 {
33 auto const reqCast = dynamic_cast<TwinkleAnimation *>(req.get());
34 if (reqCast != nullptr)
35 {
36 *reqCast = *this;
37 }
38 else
39 {
40 req = std::make_shared<TwinkleAnimation>(*this);
41 }
42 }
43
45 }
46
47public:
48 /**
49 * \brief The index of the first LED this animation controls (inclusive).
50 * Indices 0-7 control the onboard LEDs, and 8-399 control an attached LED
51 * strip.
52 */
54 /**
55 * \brief The index of the last LED this animation controls (inclusive). Indices
56 * 0-7 control the onboard LEDs, and 8-399 control an attached LED strip.
57 */
59 /**
60 * \brief The slot of this animation, within [0, 7]. Each slot on the CANdle can
61 * store and run one animation.
62 */
63 int Slot = 0;
64 /**
65 * \brief The color to use in the animation.
66 */
68 /**
69 * \brief The max proportion of LEDs that can be on, in the range [0.1, 1.0].
70 */
71 units::dimensionless::scalar_t MaxLEDsOnProportion = 0.5;
72 /**
73 * \brief The frame rate of the animation, from [2, 1000] Hz. This determines
74 * the speed of the animation.
75 *
76 * A frame is defined as a transition in the state of the LEDs, turning one on
77 * or off.
78 *
79 * - Units: Hz
80 *
81 */
82 units::frequency::hertz_t FrameRate = 100_Hz;
83
84 /**
85 * \brief The period at which this control will update at.
86 * This is designated in Hertz, with a minimum of 20 Hz
87 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
88 *
89 * If this field is set to 0 Hz, the control request will
90 * be sent immediately as a one-shot frame. This may be useful
91 * for advanced applications that require outputs to be
92 * synchronized with data acquisition. In this case, we
93 * recommend not exceeding 50 ms between control calls.
94 */
95 units::frequency::hertz_t UpdateFreqHz{20_Hz};
96
97 /**
98 * \brief Animation that randomly turns LEDs on and off to a certain color.
99 *
100 * \details
101 *
102 * \param LEDStartIndex The index of the first LED this animation controls
103 * (inclusive). Indices 0-7 control the onboard LEDs,
104 * and 8-399 control an attached LED strip.
105 * \param LEDEndIndex The index of the last LED this animation controls
106 * (inclusive). Indices 0-7 control the onboard LEDs, and
107 * 8-399 control an attached LED strip.
108 */
112 {}
113
114 /**
115 * \brief Modifies this Control Request's LEDStartIndex parameter and returns itself for
116 * method-chaining and easier to use request API.
117 *
118 * The index of the first LED this animation controls (inclusive). Indices 0-7
119 * control the onboard LEDs, and 8-399 control an attached LED strip.
120 *
121 * \param newLEDStartIndex Parameter to modify
122 * \returns Itself
123 */
124 TwinkleAnimation &WithLEDStartIndex(int newLEDStartIndex)
125 {
126 LEDStartIndex = std::move(newLEDStartIndex);
127 return *this;
128 }
129
130 /**
131 * \brief Modifies this Control Request's LEDEndIndex parameter and returns itself for
132 * method-chaining and easier to use request API.
133 *
134 * The index of the last LED this animation controls (inclusive). Indices 0-7
135 * control the onboard LEDs, and 8-399 control an attached LED strip.
136 *
137 * \param newLEDEndIndex Parameter to modify
138 * \returns Itself
139 */
141 {
142 LEDEndIndex = std::move(newLEDEndIndex);
143 return *this;
144 }
145
146 /**
147 * \brief Modifies this Control Request's Slot parameter and returns itself for
148 * method-chaining and easier to use request API.
149 *
150 * The slot of this animation, within [0, 7]. Each slot on the CANdle can store
151 * and run one animation.
152 *
153 * \param newSlot Parameter to modify
154 * \returns Itself
155 */
157 {
158 Slot = std::move(newSlot);
159 return *this;
160 }
161
162 /**
163 * \brief Modifies this Control Request's Color parameter and returns itself for
164 * method-chaining and easier to use request API.
165 *
166 * The color to use in the animation.
167 *
168 * \param newColor Parameter to modify
169 * \returns Itself
170 */
172 {
173 Color = std::move(newColor);
174 return *this;
175 }
176
177 /**
178 * \brief Modifies this Control Request's MaxLEDsOnProportion parameter and returns itself for
179 * method-chaining and easier to use request API.
180 *
181 * The max proportion of LEDs that can be on, in the range [0.1, 1.0].
182 *
183 * \param newMaxLEDsOnProportion Parameter to modify
184 * \returns Itself
185 */
186 TwinkleAnimation &WithMaxLEDsOnProportion(units::dimensionless::scalar_t newMaxLEDsOnProportion)
187 {
188 MaxLEDsOnProportion = std::move(newMaxLEDsOnProportion);
189 return *this;
190 }
191
192 /**
193 * \brief Modifies this Control Request's FrameRate parameter and returns itself for
194 * method-chaining and easier to use request API.
195 *
196 * The frame rate of the animation, from [2, 1000] Hz. This determines the speed
197 * of the animation.
198 *
199 * A frame is defined as a transition in the state of the LEDs, turning one on
200 * or off.
201 *
202 * - Units: Hz
203 *
204 *
205 * \param newFrameRate Parameter to modify
206 * \returns Itself
207 */
208 TwinkleAnimation &WithFrameRate(units::frequency::hertz_t newFrameRate)
209 {
210 FrameRate = std::move(newFrameRate);
211 return *this;
212 }
213 /**
214 * \brief Sets the period at which this control will update at.
215 * This is designated in Hertz, with a minimum of 20 Hz
216 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
217 *
218 * If this field is set to 0 Hz, the control request will
219 * be sent immediately as a one-shot frame. This may be useful
220 * for advanced applications that require outputs to be
221 * synchronized with data acquisition. In this case, we
222 * recommend not exceeding 50 ms between control calls.
223 *
224 * \param newUpdateFreqHz Parameter to modify
225 * \returns Itself
226 */
227 TwinkleAnimation &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
228 {
229 UpdateFreqHz = newUpdateFreqHz;
230 return *this;
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 std::stringstream ss;
240 ss << "Control: TwinkleAnimation" << std::endl;
241 ss << " LEDStartIndex: " << LEDStartIndex << std::endl;
242 ss << " LEDEndIndex: " << LEDEndIndex << std::endl;
243 ss << " Slot: " << Slot << std::endl;
244 ss << " Color: " << Color << std::endl;
245 ss << " MaxLEDsOnProportion: " << MaxLEDsOnProportion.to<double>() << std::endl;
246 ss << " FrameRate: " << FrameRate.to<double>() << " Hz" << std::endl;
247 return ss.str();
248 }
249
250 /**
251 * \brief Gets information about this control request.
252 *
253 * \returns Map of control parameter names and corresponding applied values
254 */
255 std::map<std::string, std::string> GetControlInfo() const override
256 {
257 std::map<std::string, std::string> controlInfo;
258 std::stringstream ss;
259 controlInfo["Name"] = GetName();
260 ss << LEDStartIndex; controlInfo["LEDStartIndex"] = ss.str(); ss.str(std::string{});
261 ss << LEDEndIndex; controlInfo["LEDEndIndex"] = ss.str(); ss.str(std::string{});
262 ss << Slot; controlInfo["Slot"] = ss.str(); ss.str(std::string{});
263 ss << Color; controlInfo["Color"] = ss.str(); ss.str(std::string{});
264 ss << MaxLEDsOnProportion.to<double>(); controlInfo["MaxLEDsOnProportion"] = ss.str(); ss.str(std::string{});
265 ss << FrameRate.to<double>(); controlInfo["FrameRate"] = ss.str(); ss.str(std::string{});
266 return controlInfo;
267 }
268};
269
270}
271}
272}
273
CTREXPORT int c_ctre_phoenix6_RequestControlTwinkleAnimation(const char *canbus, uint32_t ecuEncoding, double updateFrequency, int LEDStartIndex, int LEDEndIndex, int Slot, int Color_Red, int Color_Green, int Color_Blue, int Color_White, double MaxLEDsOnProportion, double FrameRate)
Abstract Control Request class that other control requests extend for use.
Definition ControlRequest.hpp:30
std::string const & GetName() const
Definition ControlRequest.hpp:53
Animation that randomly turns LEDs on and off to a certain color.
Definition TwinkleAnimation.hpp:28
TwinkleAnimation & WithSlot(int newSlot)
Modifies this Control Request's Slot parameter and returns itself for method-chaining and easier to u...
Definition TwinkleAnimation.hpp:156
units::dimensionless::scalar_t MaxLEDsOnProportion
The max proportion of LEDs that can be on, in the range [0.1, 1.0].
Definition TwinkleAnimation.hpp:71
int Slot
The slot of this animation, within [0, 7].
Definition TwinkleAnimation.hpp:63
TwinkleAnimation & WithLEDEndIndex(int newLEDEndIndex)
Modifies this Control Request's LEDEndIndex parameter and returns itself for method-chaining and easi...
Definition TwinkleAnimation.hpp:140
int LEDEndIndex
The index of the last LED this animation controls (inclusive).
Definition TwinkleAnimation.hpp:58
TwinkleAnimation & WithLEDStartIndex(int newLEDStartIndex)
Modifies this Control Request's LEDStartIndex parameter and returns itself for method-chaining and ea...
Definition TwinkleAnimation.hpp:124
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition TwinkleAnimation.hpp:95
TwinkleAnimation(int LEDStartIndex, int LEDEndIndex)
Animation that randomly turns LEDs on and off to a certain color.
Definition TwinkleAnimation.hpp:109
TwinkleAnimation & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition TwinkleAnimation.hpp:227
signals::RGBWColor Color
The color to use in the animation.
Definition TwinkleAnimation.hpp:67
TwinkleAnimation & WithMaxLEDsOnProportion(units::dimensionless::scalar_t newMaxLEDsOnProportion)
Modifies this Control Request's MaxLEDsOnProportion parameter and returns itself for method-chaining ...
Definition TwinkleAnimation.hpp:186
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:208
std::string ToString() const override
Returns a string representation of the object.
Definition TwinkleAnimation.hpp:237
int LEDStartIndex
The index of the first LED this animation controls (inclusive).
Definition TwinkleAnimation.hpp:53
units::frequency::hertz_t FrameRate
The frame rate of the animation, from [2, 1000] Hz.
Definition TwinkleAnimation.hpp:82
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition TwinkleAnimation.hpp:255
TwinkleAnimation & WithColor(signals::RGBWColor newColor)
Modifies this Control Request's Color parameter and returns itself for method-chaining and easier to ...
Definition TwinkleAnimation.hpp:171
Represents an RGBW color that can be applied to an LED.
Definition RGBWColor.hpp:27
uint8_t Green
The green component of the color, within [0, 255].
Definition RGBWColor.hpp:36
uint8_t Blue
The blue component of the color, within [0, 255].
Definition RGBWColor.hpp:40
uint8_t White
The white component of the color, within [0, 255].
Definition RGBWColor.hpp:45
uint8_t Red
The red component of the color, within [0, 255].
Definition RGBWColor.hpp:32
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition Diff_PositionDutyCycle_Position.hpp:15
Definition span.hpp:401