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