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