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