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