1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
* Copyright (C) Cross The Road Electronics. All rights reserved.
* License information can be found in CTRE_LICENSE.txt
* For support and suggestions contact support@ctr-electronics.com or file
* an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
*/
#pragma once
#include "ctre/phoenix6/controls/ControlRequest.hpp"
#include "ctre/phoenix6/signals/SpnEnums.hpp"
#include "ctre/phoenix6/signals/RGBWColor.hpp"
#include <units/frequency.h>
#include <units/time.h>
namespace ctre {
namespace phoenix6 {
namespace controls {
/**
* Animation that bounces a pocket of light across the LED strip.
*
*
*/
class LarsonAnimation final : public ControlRequest {
ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override;
public:
/**
* \brief The index of the first LED this animation controls (inclusive).
* Indices 0-7 control the onboard LEDs, and 8-399 control an attached LED
* strip.
*/
int LEDStartIndex;
/**
* \brief The index of the last LED this animation controls (inclusive). Indices
* 0-7 control the onboard LEDs, and 8-399 control an attached LED strip.
*/
int LEDEndIndex;
/**
* \brief The slot of this animation, within [0, 7]. Each slot on the CANdle can
* store and run one animation.
*/
int Slot = 0;
/**
* \brief The color to use in the animation.
*/
signals::RGBWColor Color = signals::RGBWColor{};
/**
* \brief The number of LEDs in the pocket of light, up to 15.
*/
int Size = 3;
/**
* \brief The behavior of the pocket of light when it reaches the end of the
* strip.
*/
signals::LarsonBounceValue BounceMode = signals::LarsonBounceValue::Front;
/**
* \brief The frame rate of the animation, from [2, 1000] Hz. This determines
* the speed of the animation.
*
* A frame is defined as a transition in the state of the LEDs, advancing the
* pocket of light by one LED.
*
* - Units: Hz
*
*/
units::frequency::hertz_t FrameRate = 25_Hz;
/**
* \brief The frequency at which this control will update.
* This is designated in Hertz, with a minimum of 20 Hz
* (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
* Some update frequencies are not supported and will be
* promoted up to the next highest supported frequency.
*
* If this field is set to 0 Hz, the control request will
* be sent immediately as a one-shot frame. This may be useful
* for advanced applications that require outputs to be
* synchronized with data acquisition. In this case, we
* recommend not exceeding 50 ms between control calls.
*/
units::frequency::hertz_t UpdateFreqHz{20_Hz};
/**
* \brief Animation that bounces a pocket of light across the LED strip.
*
* \details
*
* \param LEDStartIndex The index of the first LED this animation controls
* (inclusive). Indices 0-7 control the onboard LEDs, and
* 8-399 control an attached LED strip.
* \param LEDEndIndex The index of the last LED this animation controls
* (inclusive). Indices 0-7 control the onboard LEDs, and
* 8-399 control an attached LED strip.
*/
constexpr LarsonAnimation(int LEDStartIndex, int LEDEndIndex) : ControlRequest{},
LEDStartIndex{std::move(LEDStartIndex)},
LEDEndIndex{std::move(LEDEndIndex)}
{}
constexpr ~LarsonAnimation() override {}
/**
* \brief Gets the name of this control request.
*
* \returns Name of the control request
*/
constexpr std::string_view GetName() const override
{
return "LarsonAnimation";
}
/**
* \brief Modifies this Control Request's LEDStartIndex parameter and returns itself for
* method-chaining and easier to use request API.
*
* The index of the first LED this animation controls (inclusive). Indices 0-7
* control the onboard LEDs, and 8-399 control an attached LED strip.
*
* \param newLEDStartIndex Parameter to modify
* \returns Itself
*/
constexpr LarsonAnimation &WithLEDStartIndex(int newLEDStartIndex)
{
LEDStartIndex = std::move(newLEDStartIndex);
return *this;
}
/**
* \brief Modifies this Control Request's LEDEndIndex parameter and returns itself for
* method-chaining and easier to use request API.
*
* The index of the last LED this animation controls (inclusive). Indices 0-7
* control the onboard LEDs, and 8-399 control an attached LED strip.
*
* \param newLEDEndIndex Parameter to modify
* \returns Itself
*/
constexpr LarsonAnimation &WithLEDEndIndex(int newLEDEndIndex)
{
LEDEndIndex = std::move(newLEDEndIndex);
return *this;
}
/**
* \brief Modifies this Control Request's Slot parameter and returns itself for
* method-chaining and easier to use request API.
*
* The slot of this animation, within [0, 7]. Each slot on the CANdle can store
* and run one animation.
*
* \param newSlot Parameter to modify
* \returns Itself
*/
constexpr LarsonAnimation &WithSlot(int newSlot)
{
Slot = std::move(newSlot);
return *this;
}
/**
* \brief Modifies this Control Request's Color parameter and returns itself for
* method-chaining and easier to use request API.
*
* The color to use in the animation.
*
* \param newColor Parameter to modify
* \returns Itself
*/
constexpr LarsonAnimation &WithColor(signals::RGBWColor newColor)
{
Color = std::move(newColor);
return *this;
}
/**
* \brief Modifies this Control Request's Size parameter and returns itself for
* method-chaining and easier to use request API.
*
* The number of LEDs in the pocket of light, up to 15.
*
* \param newSize Parameter to modify
* \returns Itself
*/
constexpr LarsonAnimation &WithSize(int newSize)
{
Size = std::move(newSize);
return *this;
}
/**
* \brief Modifies this Control Request's BounceMode parameter and returns itself for
* method-chaining and easier to use request API.
*
* The behavior of the pocket of light when it reaches the end of the strip.
*
* \param newBounceMode Parameter to modify
* \returns Itself
*/
constexpr LarsonAnimation &WithBounceMode(signals::LarsonBounceValue newBounceMode)
{
BounceMode = std::move(newBounceMode);
return *this;
}
/**
* \brief Modifies this Control Request's FrameRate parameter and returns itself for
* method-chaining and easier to use request API.
*
* The frame rate of the animation, from [2, 1000] Hz. This determines the speed
* of the animation.
*
* A frame is defined as a transition in the state of the LEDs, advancing the
* pocket of light by one LED.
*
* - Units: Hz
*
*
* \param newFrameRate Parameter to modify
* \returns Itself
*/
constexpr LarsonAnimation &WithFrameRate(units::frequency::hertz_t newFrameRate)
{
FrameRate = std::move(newFrameRate);
return *this;
}
/**
* \brief Sets the frequency at which this control will update.
* This is designated in Hertz, with a minimum of 20 Hz
* (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
* Some update frequencies are not supported and will be
* promoted up to the next highest supported frequency.
*
* If this field is set to 0 Hz, the control request will
* be sent immediately as a one-shot frame. This may be useful
* for advanced applications that require outputs to be
* synchronized with data acquisition. In this case, we
* recommend not exceeding 50 ms between control calls.
*
* \param newUpdateFreqHz Parameter to modify
* \returns Itself
*/
constexpr LarsonAnimation &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
{
UpdateFreqHz = newUpdateFreqHz;
return *this;
}
/**
* \brief Returns a string representation of the object.
*
* \returns a string representation of the object.
*/
std::string ToString() const override;
/**
* \brief Gets information about this control request.
*
* \returns Map of control parameter names and corresponding applied values
*/
std::map<std::string, std::string> GetControlInfo() const override;
};
}
}
}