CTRE Phoenix 6 C++ 25.2.1
Loading...
Searching...
No Matches
ParentDevice.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
15#include <map>
16#include <memory>
17#include <mutex>
18#include <units/dimensionless.h>
19
20namespace ctre {
21namespace phoenix6 {
22namespace hardware {
23
24 /**
25 * \brief Parent class for all devices
26 */
28 {
29 protected:
31
33
34 /**
35 * \brief Type trait to verify that all types passed in are subclasses of ParentDevice.
36 */
37 template <typename... Devices>
39 std::conjunction<std::is_base_of<ParentDevice, std::remove_reference_t<Devices>>...>
40 {};
41
42 /**
43 * \brief Whether all types passed in are subclasses of ParentDevice.
44 */
45 template <typename... Devices>
46 static constexpr bool is_all_device_v = is_all_device<Devices...>::value;
47
48 private:
49 std::map<uint32_t, std::unique_ptr<BaseStatusSignal>> _signalValues;
50 std::recursive_mutex _signalValuesLck;
51 /*
52 * Use a shared pointer so users that access the control request via #GetAppliedControl has a copy
53 * of the pointer without risk of it becoming a dangling pointer due to parallel operations
54 */
55 std::shared_ptr<controls::ControlRequest> _controlReq = std::make_shared<controls::EmptyControl>();
56 std::mutex _controlReqLck;
57
58 double _creationTime = utils::GetCurrentTimeSeconds();
59
60 bool _isInitialized = false;
62 double _timeToRefreshVersion = utils::GetCurrentTimeSeconds();
63
64 StatusSignal<int> &_compliancy{LookupStatusSignal<int>(ctre::phoenix6::spns::SpnValue::Compliancy_Version, "Compliancy", false, true)};
65 StatusSignal<int> &_resetSignal{LookupStatusSignal<int>(ctre::phoenix6::spns::SpnValue::Startup_ResetFlags, "ResetFlags", false, true)};
66
67 void ReportIfTooOld();
68
69 template <typename T>
70 StatusSignal<T> &LookupCommon(
71 uint16_t spn, std::function<std::map<uint16_t, std::string>()> mapFiller,
72 std::string signalName, bool reportOnConstruction, bool refresh)
73 {
74 static StatusSignal<T> failure{ctre::phoenix::StatusCode::InvalidParamValue};
75
76 BaseStatusSignal *toFind;
77 {
78 /* lock access to the map */
79 std::lock_guard<std::recursive_mutex> lock{_signalValuesLck};
80
81 /* lookup and return if found */
82 auto iter = _signalValues.find(spn);
83 if (iter != _signalValues.end()) {
84 /* Found it, toFind is now the found StatusSignal */
85 toFind = iter->second.get();
86 /* since we didn't construct, report errors */
87 reportOnConstruction = true;
88 } else {
89 /* insert into map */
90 if (!mapFiller) {
91 _signalValues.emplace(spn,
92 std::unique_ptr<StatusSignal<T>>{new StatusSignal<T>{
94 [this] { ReportIfTooOld(); },
95 std::move(signalName)
96 }}
97 );
98 } else {
99 _signalValues.emplace(spn,
100 std::unique_ptr<StatusSignal<T>>{new StatusSignal<T>{
101 deviceIdentifier, spn,
102 [this] { ReportIfTooOld(); },
103 mapFiller, std::move(signalName)
104 }}
105 );
106 }
107
108 /* look up and return */
109 iter = _signalValues.find(spn);
110 toFind = iter->second.get();
111 }
112 }
113
114 /* Now cast it up to the StatusSignal */
115 StatusSignal<T> *ret = dynamic_cast<StatusSignal<T> *>(toFind);
116 /* If ret is null, that means the cast failed. Otherwise we can return it */
117 if (ret == nullptr) {
118 /* Cast failed, let user know this doesn't exist */
119 return failure;
120 } else {
121 /* Good cast, refresh it and return this now */
122 if (refresh) {
123 ret->Refresh(reportOnConstruction);
124 }
125 return *ret;
126 }
127 }
128
129 public:
130 ParentDevice(int deviceID, std::string model, std::string canbus) :
131 deviceIdentifier{DeviceIdentifier{deviceID, std::move(model), std::move(canbus)}}
132 {
133 /* This needs to be set to true after everything else has already been initialized */
134 _isInitialized = true;
135 }
136
137 virtual ~ParentDevice() = default;
138
139 ParentDevice(ParentDevice const &) = delete;
141
142 /**
143 * \returns The device ID of this device [0,62].
144 */
145 int GetDeviceID() const
146 {
148 }
149
150 /**
151 * \returns Name of the network this device is on.
152 */
153 const std::string &GetNetwork() const
154 {
156 }
157
158 /**
159 * \brief Gets a number unique for this device's hardware type and ID.
160 * This number is not unique across networks.
161 *
162 * \details This can be used to easily reference hardware devices on
163 * the same network in collections such as maps.
164 *
165 * \returns Hash of this device.
166 */
167 uint64_t GetDeviceHash() const
168 {
170 }
171
172 /**
173 * \brief Get the latest applied control.
174 * Caller can cast this to the derived class if they know its type. Otherwise,
175 * use controls#ControlRequest#GetControlInfo to get info out of it.
176 *
177 * \details This returns a shared pointer to avoid becoming a dangling pointer
178 * due to parallel operations changing the underlying data. Make sure
179 * to save the shared_ptr to a variable before chaining function calls,
180 * otherwise the data may be freed early.
181 *
182 * \returns Latest applied control
183 */
184 std::shared_ptr<const controls::ControlRequest> GetAppliedControl() const
185 {
186 return _controlReq;
187 }
188
189 /**
190 * \brief Get the latest applied control.
191 * Caller can cast this to the derived class if they know its type. Otherwise,
192 * use controls#ControlRequest#GetControlInfo to get info out of it.
193 *
194 * \details This returns a shared pointer to avoid becoming a dangling pointer
195 * due to parallel operations changing the underlying data. Make sure
196 * to save the shared_ptr to a variable before chaining function calls,
197 * otherwise the data may be freed early.
198 *
199 * \returns Latest applied control
200 */
201 std::shared_ptr<controls::ControlRequest> GetAppliedControl()
202 {
203 return _controlReq;
204 }
205
206 /**
207 * \returns true if device has reset since the previous call of this routine.
208 */
210 {
211 return _resetSignal.Refresh(false).HasUpdated();
212 }
213
214 /**
215 * \returns a function that checks for device resets.
216 */
217 std::function<bool()> GetResetOccurredChecker() const
218 {
219 return [resetSignal=_resetSignal]() mutable {
220 return resetSignal.Refresh(false).HasUpdated();
221 };
222 }
223
224 /**
225 * \brief Returns whether the device is still connected to the robot.
226 * This is equivalent to refreshing and checking the latency of the
227 * Version status signal.
228 *
229 * \param maxLatencySeconds The maximum latency of the Version status signal
230 * before the device is reported as disconnected
231 * \returns true if the device is connected
232 */
233 bool IsConnected(units::second_t maxLatencySeconds = 500_ms)
234 {
235 return _compliancy.Refresh(false).GetTimestamp().GetLatency() <= maxLatencySeconds;
236 }
237
238 /**
239 * \brief This is a reserved routine for internal testing. Use the other get routines to retrieve signal values.
240 *
241 * \param signal Signal to get.
242 * \param refresh Whether to refresh
243 * \returns StatusSignalValue holding value
244 */
245 StatusSignal<double> & GetGenericSignal(uint32_t signal, bool refresh = true)
246 {
247 return LookupStatusSignal<double>((uint16_t)signal, "Generic", true, refresh);
248 }
249
250 /**
251 * \brief Optimizes the device's bus utilization by reducing the update frequencies of its status signals.
252 *
253 * All status signals that have not been explicitly given an update frequency using
254 * BaseStatusSignal#SetUpdateFrequency will be disabled. Note that if other status
255 * signals in the same status frame have been given an update frequency, the update
256 * frequency will be honored for the entire frame.
257 *
258 * This function only needs to be called once on this device in the robot program. Additionally, this
259 * method does not necessarily need to be called after setting the update frequencies of other signals.
260 *
261 * To restore the default status update frequencies, call ResetSignalFrequencies.
262 * Alternatively, remove this method call, redeploy the robot application, and power-cycle
263 * the device on the bus. The user can also override individual status update frequencies
264 * using BaseStatusSignal#SetUpdateFrequency.
265 *
266 * \param optimizedFreqHz The update frequency to apply to the optimized status signals. A frequency of
267 * 0 Hz (default) will turn off the signals. Otherwise, the minimum supported signal
268 * frequency is 4 Hz.
269 * \param timeoutSeconds Maximum amount of time to wait for each status frame when performing the action
270 * \returns Status code of the first failed update frequency set call, or OK if all succeeded
271 */
272 ctre::phoenix::StatusCode OptimizeBusUtilization(units::frequency::hertz_t optimizedFreqHz = 0_Hz, units::time::second_t timeoutSeconds = 100_ms);
273
274 /**
275 * \brief Optimizes the bus utilization of the provided devices by reducing the update
276 * frequencies of their status signals.
277 *
278 * All status signals that have not been explicitly given an update frequency using
279 * BaseStatusSignal#SetUpdateFrequency will be disabled. Note that if other status
280 * signals in the same status frame have been given an update frequency, the update
281 * frequency will be honored for the entire frame.
282 *
283 * This function only needs to be called once in the robot program for the provided devices.
284 * Additionally, this method does not necessarily need to be called after setting the update
285 * frequencies of other signals.
286 *
287 * To restore the default status update frequencies, call ResetSignalFrequenciesForAll.
288 * Alternatively, remove this method call, redeploy the robot application, and power-cycle
289 * the devices on the bus. The user can also override individual status update frequencies
290 * using BaseStatusSignal#SetUpdateFrequency.
291 *
292 * This will wait up to 0.100 seconds (100ms) for each status frame.
293 *
294 * \param devices Devices for which to optimize bus utilization, passed as a comma-separated list of device references.
295 * \returns Status code of the first failed optimize call, or OK if all succeeded
296 */
297 template <typename... Devices, typename = std::enable_if_t<is_all_device_v<Devices...>>>
299 {
300 return OptimizeBusUtilizationForAll(0_Hz, devices...);
301 }
302
303 /**
304 * \brief Optimizes the bus utilization of the provided devices by reducing the update
305 * frequencies of their status signals.
306 *
307 * All status signals that have not been explicitly given an update frequency using
308 * BaseStatusSignal#SetUpdateFrequency will be disabled. Note that if other status
309 * signals in the same status frame have been given an update frequency, the update
310 * frequency will be honored for the entire frame.
311 *
312 * This function only needs to be called once in the robot program for the provided devices.
313 * Additionally, this method does not necessarily need to be called after setting the update
314 * frequencies of other signals.
315 *
316 * To restore the default status update frequencies, call ResetSignalFrequenciesForAll.
317 * Alternatively, remove this method call, redeploy the robot application, and power-cycle
318 * the devices on the bus. The user can also override individual status update frequencies
319 * using BaseStatusSignal#SetUpdateFrequency.
320 *
321 * This will wait up to 0.100 seconds (100ms) for each status frame.
322 *
323 * \param devices Devices for which to optimize bus utilization, passed as a vector or initializer list of device addresses.
324 * \returns Status code of the first failed optimize call, or OK if all succeeded
325 */
326 static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(const std::vector<ParentDevice *> &devices)
327 {
328 return OptimizeBusUtilizationForAll(0_Hz, devices);
329 }
330
331 /**
332 * \brief Optimizes the bus utilization of the provided devices by reducing the update
333 * frequencies of their status signals.
334 *
335 * All status signals that have not been explicitly given an update frequency using
336 * BaseStatusSignal#SetUpdateFrequency will be disabled. Note that if other status
337 * signals in the same status frame have been given an update frequency, the update
338 * frequency will be honored for the entire frame.
339 *
340 * This function only needs to be called once in the robot program for the provided devices.
341 * Additionally, this method does not necessarily need to be called after setting the update
342 * frequencies of other signals.
343 *
344 * To restore the default status update frequencies, call ResetSignalFrequenciesForAll.
345 * Alternatively, remove this method call, redeploy the robot application, and power-cycle
346 * the devices on the bus. The user can also override individual status update frequencies
347 * using BaseStatusSignal#SetUpdateFrequency.
348 *
349 * This will wait up to 0.100 seconds (100ms) for each status frame.
350 *
351 * \param devices Devices for which to optimize bus utilization, passed as an array of device addresses.
352 * \returns Status code of the first failed optimize call, or OK if all succeeded
353 */
354 template <size_t N>
355 static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(const std::array<ParentDevice *, N> &devices)
356 {
357 return OptimizeBusUtilizationForAll(0_Hz, devices);
358 }
359
360 /**
361 * \brief Optimizes the bus utilization of the provided devices by reducing the update
362 * frequencies of their status signals.
363 *
364 * All status signals that have not been explicitly given an update frequency using
365 * BaseStatusSignal#SetUpdateFrequency will be disabled. Note that if other status
366 * signals in the same status frame have been given an update frequency, the update
367 * frequency will be honored for the entire frame.
368 *
369 * This function only needs to be called once in the robot program for the provided devices.
370 * Additionally, this method does not necessarily need to be called after setting the update
371 * frequencies of other signals.
372 *
373 * To restore the default status update frequencies, call ResetSignalFrequenciesForAll.
374 * Alternatively, remove this method call, redeploy the robot application, and power-cycle
375 * the devices on the bus. The user can also override individual status update frequencies
376 * using BaseStatusSignal#SetUpdateFrequency.
377 *
378 * This will wait up to 0.100 seconds (100ms) for each status frame.
379 *
380 * \param optimizedFreqHz The update frequency to apply to the optimized status signals. A frequency of
381 * 0 Hz (default) will turn off the signals. Otherwise, the minimum supported signal
382 * frequency is 4 Hz.
383 * \param devices Devices for which to optimize bus utilization, passed as a comma-separated list of device references.
384 * \returns Status code of the first failed optimize call, or OK if all succeeded
385 */
386 template <typename... Devices, typename = std::enable_if_t<is_all_device_v<Devices...>>>
387 static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(units::frequency::hertz_t optimizedFreqHz, Devices &... devices)
388 {
389 return OptimizeBusUtilizationForAll(optimizedFreqHz, std::array<ParentDevice *, sizeof...(Devices)>{(&devices)...});
390 }
391
392 /**
393 * \brief Optimizes the bus utilization of the provided devices by reducing the update
394 * frequencies of their status signals.
395 *
396 * All status signals that have not been explicitly given an update frequency using
397 * BaseStatusSignal#SetUpdateFrequency will be disabled. Note that if other status
398 * signals in the same status frame have been given an update frequency, the update
399 * frequency will be honored for the entire frame.
400 *
401 * This function only needs to be called once in the robot program for the provided devices.
402 * Additionally, this method does not necessarily need to be called after setting the update
403 * frequencies of other signals.
404 *
405 * To restore the default status update frequencies, call ResetSignalFrequenciesForAll.
406 * Alternatively, remove this method call, redeploy the robot application, and power-cycle
407 * the devices on the bus. The user can also override individual status update frequencies
408 * using BaseStatusSignal#SetUpdateFrequency.
409 *
410 * This will wait up to 0.100 seconds (100ms) for each status frame.
411 *
412 * \param optimizedFreqHz The update frequency to apply to the optimized status signals. A frequency of
413 * 0 Hz (default) will turn off the signals. Otherwise, the minimum supported signal
414 * frequency is 4 Hz.
415 * \param devices Devices for which to optimize bus utilization, passed as a vector or initializer list of device addresses.
416 * \returns Status code of the first failed optimize call, or OK if all succeeded
417 */
418 static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(units::frequency::hertz_t optimizedFreqHz, const std::vector<ParentDevice *> &devices)
419 {
421 for (auto device : devices) {
422 const auto err = device->OptimizeBusUtilization(optimizedFreqHz);
423 if (retval.IsOK()) {
424 retval = err;
425 }
426 }
427 return retval;
428 }
429
430 /**
431 * \brief Optimizes the bus utilization of the provided devices by reducing the update
432 * frequencies of their status signals.
433 *
434 * All status signals that have not been explicitly given an update frequency using
435 * BaseStatusSignal#SetUpdateFrequency will be disabled. Note that if other status
436 * signals in the same status frame have been given an update frequency, the update
437 * frequency will be honored for the entire frame.
438 *
439 * This function only needs to be called once in the robot program for the provided devices.
440 * Additionally, this method does not necessarily need to be called after setting the update
441 * frequencies of other signals.
442 *
443 * To restore the default status update frequencies, call ResetSignalFrequenciesForAll.
444 * Alternatively, remove this method call, redeploy the robot application, and power-cycle
445 * the devices on the bus. The user can also override individual status update frequencies
446 * using BaseStatusSignal#SetUpdateFrequency.
447 *
448 * This will wait up to 0.100 seconds (100ms) for each status frame.
449 *
450 * \param optimizedFreqHz The update frequency to apply to the optimized status signals. A frequency of
451 * 0 Hz (default) will turn off the signals. Otherwise, the minimum supported signal
452 * frequency is 4 Hz.
453 * \param devices Devices for which to optimize bus utilization, passed as an array of device addresses.
454 * \returns Status code of the first failed optimize call, or OK if all succeeded
455 */
456 template <size_t N>
457 static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(units::frequency::hertz_t optimizedFreqHz, const std::array<ParentDevice *, N> &devices)
458 {
460 for (auto device : devices) {
461 const auto err = device->OptimizeBusUtilization(optimizedFreqHz);
462 if (retval.IsOK()) {
463 retval = err;
464 }
465 }
466 return retval;
467 }
468
469 /**
470 * \brief Resets the update frequencies of all the device's status signals to the defaults.
471 *
472 * This restores the default update frequency of all status signals, including status signals
473 * explicitly given an update frequency using BaseStatusSignal#SetUpdateFrequency and status
474 * signals optimized out using OptimizeBusUtilization.
475 *
476 * \param timeoutSeconds Maximum amount of time to wait for each status frame when performing the action
477 * \returns Status code of the first failed update frequency set call, or OK if all succeeded
478 */
479 ctre::phoenix::StatusCode ResetSignalFrequencies(units::time::second_t timeoutSeconds = 100_ms);
480
481 /**
482 * \brief Resets the update frequencies of all the devices' status signals to the defaults.
483 *
484 * This restores the default update frequency of all status signals, including status signals
485 * explicitly given an update frequency using BaseStatusSignal#SetUpdateFrequency and status
486 * signals optimized out using OptimizeBusUtilizationForAll.
487 *
488 * This will wait up to 0.100 seconds (100ms) for each status frame.
489 *
490 * \param devices Devices for which to restore default update frequencies, passed as a comma-separated list of device references.
491 * \returns Status code of the first failed restore call, or OK if all succeeded
492 */
493 template <typename... Devices, typename = std::enable_if_t<is_all_device_v<Devices...>>>
495 {
496 return ResetSignalFrequenciesForAll(std::array<ParentDevice *, sizeof...(Devices)>{(&devices)...});
497 }
498
499 /**
500 * \brief Resets the update frequencies of all the devices' status signals to the defaults.
501 *
502 * This restores the default update frequency of all status signals, including status signals
503 * explicitly given an update frequency using BaseStatusSignal#SetUpdateFrequency and status
504 * signals optimized out using OptimizeBusUtilizationForAll.
505 *
506 * This will wait up to 0.100 seconds (100ms) for each status frame.
507 *
508 * \param devices Devices for which to restore default update frequencies, passed as a vector or initializer list of device addresses.
509 * \returns Status code of the first failed restore call, or OK if all succeeded
510 */
511 static ctre::phoenix::StatusCode ResetSignalFrequenciesForAll(const std::vector<ParentDevice *> &devices)
512 {
514 for (auto device : devices) {
515 const auto err = device->ResetSignalFrequencies();
516 if (retval.IsOK()) {
517 retval = err;
518 }
519 }
520 return retval;
521 }
522
523 /**
524 * \brief Resets the update frequencies of all the devices' status signals to the defaults.
525 *
526 * This restores the default update frequency of all status signals, including status signals
527 * explicitly given an update frequency using BaseStatusSignal#SetUpdateFrequency and status
528 * signals optimized out using OptimizeBusUtilizationForAll.
529 *
530 * This will wait up to 0.100 seconds (100ms) for each status frame.
531 *
532 * \param devices Devices for which to restore default update frequencies, passed as an array of device addresses.
533 * \returns Status code of the first failed restore call, or OK if all succeeded
534 */
535 template <size_t N>
536 static ctre::phoenix::StatusCode ResetSignalFrequenciesForAll(const std::array<ParentDevice *, N> &devices)
537 {
539 for (auto device : devices) {
540 const auto err = device->ResetSignalFrequencies();
541 if (retval.IsOK()) {
542 retval = err;
543 }
544 }
545 return retval;
546 }
547
548 protected:
550
551 template <typename T>
552 StatusSignal<T> &LookupStatusSignal(uint16_t spn, std::string signalName, bool reportOnConstruction, bool refresh)
553 {
554 return LookupCommon<T>(spn, nullptr, std::move(signalName), reportOnConstruction, refresh);
555 }
556
557 template <typename T>
558 StatusSignal<T> &LookupStatusSignal(uint16_t spn, std::function<std::map<uint16_t, std::string>()> mapFiller, std::string signalName, bool reportOnConstruction, bool refresh)
559 {
560 return LookupCommon<T>(spn, std::move(mapFiller), std::move(signalName), reportOnConstruction, refresh);
561 }
562
563 /** Returns a unitless version of the StatusSignal by value. Do not store the result in a reference. */
564 template <typename T, typename U>
565 StatusSignal<T> LookupDimensionlessStatusSignal(uint16_t spn, std::string signalName, bool refresh)
566 {
567 return StatusSignal<T>{LookupStatusSignal<U>(spn, std::move(signalName), true, refresh)};
568 }
569 };
570
571}
572}
573}
bool HasUpdated()
Check whether the signal has been updated since the last check.
Definition StatusSignal.hpp:607
const Timestamp & GetTimestamp() const
Get the most accurate timestamp available for this signal.
Definition StatusSignal.hpp:592
Represents a status signal with data of type T, and operations available to retrieve information abou...
Definition StatusSignal.hpp:656
StatusSignal< T > & Refresh(bool ReportOnError=true)
Refreshes the value of this status signal.
Definition StatusSignal.hpp:785
units::time::second_t GetLatency() const
Get the latency of this timestamp compared to now.
Definition Timestamp.hpp:115
Abstract Control Request class that other control requests extend for use.
Definition ControlRequest.hpp:30
Generic Empty Control class used to do nothing.
Definition ControlRequest.hpp:73
Definition DeviceIdentifier.hpp:19
int deviceID
Definition DeviceIdentifier.hpp:23
uint32_t deviceHash
Definition DeviceIdentifier.hpp:24
std::string network
Definition DeviceIdentifier.hpp:21
Parent class for all devices.
Definition ParentDevice.hpp:28
static controls::EmptyControl _emptyControl
Definition ParentDevice.hpp:30
const std::string & GetNetwork() const
Definition ParentDevice.hpp:153
static ctre::phoenix::StatusCode ResetSignalFrequenciesForAll(const std::array< ParentDevice *, N > &devices)
Resets the update frequencies of all the devices' status signals to the defaults.
Definition ParentDevice.hpp:536
static constexpr bool is_all_device_v
Whether all types passed in are subclasses of ParentDevice.
Definition ParentDevice.hpp:46
std::shared_ptr< controls::ControlRequest > GetAppliedControl()
Get the latest applied control.
Definition ParentDevice.hpp:201
StatusSignal< T > LookupDimensionlessStatusSignal(uint16_t spn, std::string signalName, bool refresh)
Returns a unitless version of the StatusSignal by value.
Definition ParentDevice.hpp:565
DeviceIdentifier deviceIdentifier
Definition ParentDevice.hpp:32
StatusSignal< T > & LookupStatusSignal(uint16_t spn, std::string signalName, bool reportOnConstruction, bool refresh)
Definition ParentDevice.hpp:552
ParentDevice(ParentDevice const &)=delete
static ctre::phoenix::StatusCode ResetSignalFrequenciesForAll(const std::vector< ParentDevice * > &devices)
Resets the update frequencies of all the devices' status signals to the defaults.
Definition ParentDevice.hpp:511
bool IsConnected(units::second_t maxLatencySeconds=500_ms)
Returns whether the device is still connected to the robot.
Definition ParentDevice.hpp:233
std::function< bool()> GetResetOccurredChecker() const
Definition ParentDevice.hpp:217
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(units::frequency::hertz_t optimizedFreqHz, const std::array< ParentDevice *, N > &devices)
Optimizes the bus utilization of the provided devices by reducing the update frequencies of their sta...
Definition ParentDevice.hpp:457
virtual ctre::phoenix::StatusCode SetControlPrivate(const controls::ControlRequest &request)
std::shared_ptr< const controls::ControlRequest > GetAppliedControl() const
Get the latest applied control.
Definition ParentDevice.hpp:184
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(const std::array< ParentDevice *, N > &devices)
Optimizes the bus utilization of the provided devices by reducing the update frequencies of their sta...
Definition ParentDevice.hpp:355
ctre::phoenix::StatusCode OptimizeBusUtilization(units::frequency::hertz_t optimizedFreqHz=0_Hz, units::time::second_t timeoutSeconds=100_ms)
Optimizes the device's bus utilization by reducing the update frequencies of its status signals.
static ctre::phoenix::StatusCode ResetSignalFrequenciesForAll(Devices &... devices)
Resets the update frequencies of all the devices' status signals to the defaults.
Definition ParentDevice.hpp:494
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(Devices &... devices)
Optimizes the bus utilization of the provided devices by reducing the update frequencies of their sta...
Definition ParentDevice.hpp:298
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(units::frequency::hertz_t optimizedFreqHz, Devices &... devices)
Optimizes the bus utilization of the provided devices by reducing the update frequencies of their sta...
Definition ParentDevice.hpp:387
ctre::phoenix::StatusCode ResetSignalFrequencies(units::time::second_t timeoutSeconds=100_ms)
Resets the update frequencies of all the device's status signals to the defaults.
StatusSignal< T > & LookupStatusSignal(uint16_t spn, std::function< std::map< uint16_t, std::string >()> mapFiller, std::string signalName, bool reportOnConstruction, bool refresh)
Definition ParentDevice.hpp:558
int GetDeviceID() const
Definition ParentDevice.hpp:145
ParentDevice(int deviceID, std::string model, std::string canbus)
Definition ParentDevice.hpp:130
uint64_t GetDeviceHash() const
Gets a number unique for this device's hardware type and ID.
Definition ParentDevice.hpp:167
bool HasResetOccurred()
Definition ParentDevice.hpp:209
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(const std::vector< ParentDevice * > &devices)
Optimizes the bus utilization of the provided devices by reducing the update frequencies of their sta...
Definition ParentDevice.hpp:326
StatusSignal< double > & GetGenericSignal(uint32_t signal, bool refresh=true)
This is a reserved routine for internal testing.
Definition ParentDevice.hpp:245
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(units::frequency::hertz_t optimizedFreqHz, const std::vector< ParentDevice * > &devices)
Optimizes the bus utilization of the provided devices by reducing the update frequencies of their sta...
Definition ParentDevice.hpp:418
ParentDevice & operator=(ParentDevice const &)=delete
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
static constexpr int OK
No Error.
Definition StatusCodes.h:34
static constexpr int InvalidParamValue
An invalid argument was passed into the function/VI, such as a null pointer.
Definition StatusCodes.h:368
static constexpr int CouldNotRetrieveV6Firmware
Device firmware could not be retrieved.
Definition StatusCodes.h:721
constexpr bool IsOK() const
Definition StatusCodes.h:859
CTREXPORT double GetCurrentTimeSeconds()
Get the current timestamp in seconds.
Definition MotionMagicExpoTorqueCurrentFOC.hpp:18
Definition span.hpp:401
Type trait to verify that all types passed in are subclasses of ParentDevice.
Definition ParentDevice.hpp:40