CTRE Phoenix 6 C++ 26.2.0
Loading...
Searching...
No Matches
StatusSignal.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
14#include <array>
15#include <functional>
16#include <map>
17#include <ostream>
18#include <span>
19#include <sstream>
20#include <string>
21#include <units/frequency.h>
22#include <units/math.h>
23#include <units/time.h>
24
25namespace ctre {
26namespace phoenix6 {
27
28 namespace hardware {
29 class ParentDevice;
30 }
31
32 template <typename T>
33 class StatusSignal;
34
35 /**
36 * \brief Class that provides operations to
37 * retrieve information about a status signal.
38 */
40 private:
41 hardware::DeviceIdentifier deviceIdentifier;
42 uint16_t spn;
43 std::string name;
44 std::function<void()> _checkFirmVersFunction;
45
46 std::map<uint16_t, std::string> _unitStrings{};
47 uint16_t _unitsKey;
48
49 units::time::second_t _lastTimestamp{0_s};
50
51 protected:
52 std::string units;
53 double baseValue = 0;
56
58 hardware::DeviceIdentifier deviceIdentifier,
59 uint16_t spn,
60 std::string signalName,
61 std::function<void()> checkFirmVersFunction
62 ) :
63 deviceIdentifier{std::move(deviceIdentifier)},
64 spn{spn},
65 name{std::move(signalName)},
66 _checkFirmVersFunction{std::move(checkFirmVersFunction)},
67 _unitsKey{spn},
69 {
70 }
71
73 hardware::DeviceIdentifier deviceIdentifier,
74 uint16_t spn,
75 std::string signalName,
76 std::function<void()> checkFirmVersFunction,
77 std::function<std::map<uint16_t, std::string>()> const &unitsGenerator
78 ) :
79 deviceIdentifier{std::move(deviceIdentifier)},
80 spn{spn},
81 name{std::move(signalName)},
82 _checkFirmVersFunction{std::move(checkFirmVersFunction)},
83 _unitStrings{unitsGenerator()},
84 _unitsKey{spn},
86 {
87 for (auto &unitString : _unitStrings) {
88 unitString.second = Status_GetUnits(unitString.first);
89 }
90 }
91
92 /* Constructor for an invalid BaseStatusSignal */
94 deviceIdentifier{hardware::DeviceIdentifier{}},
95 spn{0},
96 name{"Invalid"},
97 _checkFirmVersFunction{[] {}},
98 _unitsKey{spn},
99 error{error}
100 {
101 }
102
103 static std::string Status_GetUnits(uint32_t signal);
104
106 BaseStatusSignal &signal,
107 char const *network,
108 bool bWaitForUpdate,
109 double timeoutSeconds);
111 std::span<BaseStatusSignal* const> signals,
112 char const *network,
113 double timeoutSeconds);
114
116 BaseStatusSignal &signal,
117 double frequencyHz,
118 double timeoutSeconds);
120 std::span<BaseStatusSignal* const> signals,
121 double frequencyHz,
122 double timeoutSeconds);
123 static double Status_GetAppliedUpdateFrequency(char const *canbus, uint32_t deviceHash, uint16_t spn);
124
126 char const *location,
127 units::time::second_t timeoutSeconds,
128 std::span<BaseStatusSignal* const> signals);
129
130 void RefreshValue(bool waitForUpdate, units::time::second_t timeout, bool ReportOnError);
131 void UpdateUnits(uint16_t unitsKey);
132
133 public:
134 virtual ~BaseStatusSignal() = 0; // Declare virtual destructor to make this class abstract
135
136 /**
137 * \brief Gets the name of this signal.
138 *
139 * \returns Name of this signal
140 */
141 std::string const &GetName() const { return name; }
142 /**
143 * \brief Gets the units for this signal.
144 *
145 * \returns String representation of units for this signal
146 */
147 std::string const &GetUnits() const { return units; }
148 /**
149 * \brief Gets the value of this signal as a double.
150 *
151 * \return Value of this signal as a double instead of the generic type
152 */
153 double GetValueAsDouble() const { return baseValue; }
154 /**
155 * \brief Gets the timestamps of this signals.
156 *
157 * \returns All timestamps for this signal
158 */
159 AllTimestamps const &GetAllTimestamps() const { return timestamps; }
160 /**
161 * \brief Gets the most accurate timestamp available for this signal.
162 *
163 * \details The timestamp sources from most to least accurate are:
164 *
165 * - Timestamp#TimestampSource#Device
166 * - Timestamp#TimestampSource#CANivore
167 * - Timestamp#TimestampSource#System
168 *
169 * Note that some of these sources may not be available.
170 *
171 * \returns The most accurate timestamp available for this signal
172 */
173 Timestamp const &GetTimestamp() const { return timestamps.GetBestTimestamp(); }
174 /**
175 * \brief Gets the status code of the last time this signal was refreshed.
176 *
177 * \returns Status code of the last time this signal was refreshed
178 */
179 ctre::phoenix::StatusCode GetStatus() const { return error; }
180
181 /**
182 * \brief Checks whether the signal has been updated since the last check.
183 *
184 * Note that the signal must be refreshed before calling this routine.
185 *
186 * \returns true if the signal has updated since the previous call of this routine
187 */
189 {
190 bool retval = false;
191 /* did we receive an update */
192 auto const &timestamp = GetAllTimestamps().GetSystemTimestamp();
193 if (timestamp.IsValid()) {
194 /* if the update timestamp is new, then a new frame was sent */
195 if (_lastTimestamp != timestamp.GetTime()) {
196 _lastTimestamp = timestamp.GetTime();
197 retval = true;
198 }
199 }
200 return retval;
201 }
202
203 /**
204 * \brief Sets the rate at which the device will publish this signal.
205 *
206 * A frequency of 0 Hz will turn off the signal. Otherwise, the minimum supported signal
207 * frequency is 4 Hz, and the maximum is 1000 Hz. Additionally, some update frequencies are
208 * not supported and will be promoted up to the next highest supported frequency.
209 *
210 * If other StatusSignals in the same status frame have been set to an update frequency,
211 * the fastest requested update frequency will be applied to the frame.
212 *
213 * \param frequencyHz Rate to publish the signal in Hz.
214 * \param timeoutSeconds Maximum amount of time to wait when performing the action
215 * \returns Status code of setting the update frequency
216 */
217 ctre::phoenix::StatusCode SetUpdateFrequency(units::frequency::hertz_t frequencyHz, units::time::second_t timeoutSeconds = 100_ms)
218 {
219 return Status_SetUpdateFrequency(
220 *this,
221 frequencyHz.to<double>(),
222 timeoutSeconds.to<double>()
223 );
224 }
225
226 /**
227 * \brief Gets the rate at which the device will publish this signal.
228 *
229 * This is typically the last value passed into #SetUpdateFrequency. The returned value
230 * may be higher if another StatusSignal in the same status frame has been set to a higher
231 * update frequency.
232 *
233 * \returns Applied update frequency of the signal in Hz
234 */
235 units::frequency::hertz_t GetAppliedUpdateFrequency() const
236 {
237 return units::frequency::hertz_t{
238 Status_GetAppliedUpdateFrequency(
239 this->deviceIdentifier.network.c_str(),
240 this->deviceIdentifier.deviceHash,
241 this->spn
242 )
243 };
244 }
245
246 /**
247 * \brief Performs latency compensation on signal using the signalSlope and signal's latency to determine
248 * the magnitude of compensation. The caller must refresh these StatusSignals beforehand;
249 * this function only does the math required for latency compensation.
250 *
251 * \details Example usage:
252 * \code
253 * units::turn_t compensatedTurns = BaseStatusSignal::GetLatencyCompensatedValue(fx.GetPosition(), fx.GetVelocity());
254 * \endcode
255 *
256 * \tparam U Type of signal's underlying type. This is the type that the function will return.
257 * \tparam U_PER_SEC Type of signalSlope's underlying type. This must be the derivative of U.
258 * \param signal Signal to be latency compensated. Caller must make sure this signal is up to date
259 * either by calling \c Refresh() or \c WaitForUpdate().
260 * \param signalSlope Derivative of signal that informs compensation magnitude. Caller must make sure this
261 * signal is up to date either by calling \c Refresh() or \c WaitForUpdate().
262 * \param maxLatencySeconds The maximum amount of latency to compensate for in seconds. A negative or zero
263 * value disables the max latency cap. This is used to cap the contribution of
264 * latency compensation for stale signals, such as after the device has been
265 * disconnected from the CAN bus.
266 * \returns Latency compensated value from the signal StatusSignal.
267 */
268 template <typename U, typename U_PER_SEC>
269 requires units::traits::is_unit_t_v<U> && units::traits::is_unit_t_v<U_PER_SEC> &&
270 units::traits::is_convertible_unit_v<
271 typename units::traits::unit_t_traits<U>::unit_type,
272 units::compound_unit<typename units::traits::unit_t_traits<U_PER_SEC>::unit_type, units::seconds>
273 >
274 static U GetLatencyCompensatedValue(StatusSignal<U> const &signal, StatusSignal<U_PER_SEC> const &signalSlope, units::time::second_t maxLatencySeconds = 0.300_s)
275 {
276 U const nonCompensatedSignal = signal.GetValue();
277 U_PER_SEC const changeInSignal = signalSlope.GetValue();
278 units::second_t latency = signal.GetTimestamp().GetLatency();
279 if (maxLatencySeconds > 0_s && latency > maxLatencySeconds) {
280 latency = maxLatencySeconds;
281 }
282 return nonCompensatedSignal + (changeInSignal * latency);
283 }
284
285 /**
286 * \brief Waits for new data on all provided signals up to timeout.
287 * This API is typically used with CANivore Bus signals as they will be synced using the
288 * CANivore Timesync feature and arrive simultaneously. Signals on a roboRIO bus cannot
289 * be synced and may require a significantly longer blocking call to receive all signals.
290 *
291 * Note that CANivore Timesync requires Phoenix Pro.
292 *
293 * This can also be used with a timeout of zero to refresh many signals at once, which
294 * is faster than calling Refresh() on every signal. This is equivalent to calling #RefreshAll.
295 *
296 * If a signal arrives multiple times while waiting, such as when *not* using CANivore
297 * Timesync, the newest signal data is fetched. Additionally, if this function times out,
298 * the newest signal data is fetched for all signals (when possible). We recommend checking
299 * the individual status codes using GetStatus() when this happens.
300 *
301 * \param timeoutSeconds Maximum time to wait for all the signals to arrive.
302 * Pass zero to refresh all signals without blocking.
303 * \param signals Signals to wait on, passed as a comma-separated list of signal references.
304 * \return InvalidNetwork if signals are on different CAN bus networks,
305 * RxTimeout if it took longer than timeoutSeconds to receive all the signals,
306 * MultiSignalNotSupported if using the roboRIO bus with more than one signal and a non-zero timeout.
307 * An OK status code means that all signals arrived within timeoutSeconds and they are all OK.
308 *
309 * Any other value represents the StatusCode of the first failed signal.
310 * Call GetStatus() on each signal to determine which ones failed.
311 */
312 template <std::derived_from<BaseStatusSignal>... Signals>
313 static ctre::phoenix::StatusCode WaitForAll(units::time::second_t timeoutSeconds, Signals &... signals)
314 {
315 return WaitForAll(
316 timeoutSeconds,
317 std::array<BaseStatusSignal *, sizeof...(Signals)>{(&signals)...}
318 );
319 }
320 /**
321 * \brief Waits for new data on all provided signals up to timeout.
322 * This API is typically used with CANivore Bus signals as they will be synced using the
323 * CANivore Timesync feature and arrive simultaneously. Signals on a roboRIO bus cannot
324 * be synced and may require a significantly longer blocking call to receive all signals.
325 *
326 * Note that CANivore Timesync requires Phoenix Pro.
327 *
328 * This can also be used with a timeout of zero to refresh many signals at once, which
329 * is faster than calling Refresh() on every signal. This is equivalent to calling #RefreshAll.
330 *
331 * If a signal arrives multiple times while waiting, such as when *not* using CANivore
332 * Timesync, the newest signal data is fetched. Additionally, if this function times out,
333 * the newest signal data is fetched for all signals (when possible). We recommend checking
334 * the individual status codes using GetStatus() when this happens.
335 *
336 * \param timeoutSeconds Maximum time to wait for all the signals to arrive.
337 * Pass zero to refresh all signals without blocking.
338 * \param signals Signals to wait on, passed as a span of signal pointers.
339 * \return InvalidNetwork if signals are on different CAN bus networks,
340 * RxTimeout if it took longer than timeoutSeconds to receive all the signals,
341 * MultiSignalNotSupported if using the roboRIO bus with more than one signal and a non-zero timeout.
342 * An OK status code means that all signals arrived within timeoutSeconds and they are all OK.
343 *
344 * Any other value represents the StatusCode of the first failed signal.
345 * Call GetStatus() on each signal to determine which ones failed.
346 */
347 static ctre::phoenix::StatusCode WaitForAll(units::time::second_t timeoutSeconds, std::span<BaseStatusSignal* const> signals)
348 {
349 /* static string for location */
350 constexpr char kLocation[] = "ctre::phoenix6::BaseStatusSignal::WaitForAll";
351 return WaitForAllImpl(kLocation, timeoutSeconds, signals);
352 }
353
354 /**
355 * \brief Performs a non-blocking refresh on all provided signals.
356 *
357 * This provides a performance improvement over separately calling Refresh() on each signal.
358 *
359 * \param signals Signals to refresh, passed as a comma-separated list of signal references.
360 * \return InvalidNetwork if signals are on different CAN bus networks.
361 * An OK status code means that all signals are OK.
362 *
363 * Any other value represents the StatusCode of the first failed signal.
364 * Call GetStatus() on each signal to determine which ones failed.
365 */
366 template <std::derived_from<BaseStatusSignal>... Signals>
367 static ctre::phoenix::StatusCode RefreshAll(Signals &... signals)
368 {
369 return RefreshAll(std::array<BaseStatusSignal *, sizeof...(Signals)>{(&signals)...});
370 }
371 /**
372 * \brief Performs a non-blocking refresh on all provided signals.
373 *
374 * This provides a performance improvement over separately calling Refresh() on each signal.
375 *
376 * \param signals Signals to refresh, passed as a span of signal pointers.
377 * \return InvalidNetwork if signals are on different CAN bus networks.
378 * An OK status code means that all signals are OK.
379 *
380 * Any other value represents the StatusCode of the first failed signal.
381 * Call GetStatus() on each signal to determine which ones failed.
382 */
383 static ctre::phoenix::StatusCode RefreshAll(std::span<BaseStatusSignal* const> signals)
384 {
385 /* static string for location */
386 constexpr char kLocation[] = "ctre::phoenix6::BaseStatusSignal::RefreshAll";
387 return WaitForAllImpl(kLocation, 0_s, signals);
388 }
389
390 /**
391 * \brief Checks if all signals have an OK error code.
392 *
393 * \param signals Signals to check error code of, passed as a comma-separated list of signal references.
394 * \returns True if all signals are OK, false otherwise
395 */
396 template <std::derived_from<BaseStatusSignal>... Signals>
397 static bool IsAllGood(Signals const &... signals)
398 {
399 return IsAllGood(std::array<BaseStatusSignal const *, sizeof...(Signals)>{(&signals)...});
400 }
401 /**
402 * \brief Checks if all signals have an OK error code.
403 *
404 * \param signals Signals to check error code of, passed as a span of signal pointers.
405 * \returns True if all signals are OK, false otherwise
406 */
407 static bool IsAllGood(std::span<BaseStatusSignal const *const> signals)
408 {
409 for (auto signal : signals) {
410 if (!signal->GetStatus().IsOK()) {
411 return false;
412 }
413 }
414 return true;
415 }
416
417 /**
418 * \brief Sets the update frequency of all specified status signals to the provided common frequency.
419 *
420 * A frequency of 0 Hz will turn off the signal. Otherwise, the minimum supported signal frequency
421 * is 4 Hz, and the maximum is 1000 Hz. Additionally, some update frequencies are not supported and
422 * will be promoted up to the next highest supported frequency.
423 *
424 * If other StatusSignals in the same status frame have been set to an update frequency,
425 * the fastest requested update frequency will be applied to the frame.
426 *
427 * This will wait up to 0.100 seconds (100ms) for each signal.
428 *
429 * \param frequencyHz Rate to publish the signal in Hz.
430 * \param signals Signals to apply the update frequency to, passed as a comma-separated list of signal references.
431 * \returns Status code of the first failed update frequency set call, or OK if all succeeded
432 */
433 template <std::derived_from<BaseStatusSignal>... Signals>
434 static ctre::phoenix::StatusCode SetUpdateFrequencyForAll(units::frequency::hertz_t frequencyHz, Signals &... signals)
435 {
436 return SetUpdateFrequencyForAll(frequencyHz, std::array<BaseStatusSignal *, sizeof...(Signals)>{(&signals)...});
437 }
438 /**
439 * \brief Sets the update frequency of all specified status signals to the provided common frequency.
440 *
441 * A frequency of 0 Hz will turn off the signal. Otherwise, the minimum supported signal frequency
442 * is 4 Hz, and the maximum is 1000 Hz. Additionally, some update frequencies are not supported and
443 * will be promoted up to the next highest supported frequency.
444 *
445 * If other StatusSignals in the same status frame have been set to an update frequency,
446 * the fastest requested update frequency will be applied to the frame.
447 *
448 * This will wait up to 0.100 seconds (100ms) for each signal.
449 *
450 * \param frequencyHz Rate to publish the signal in Hz.
451 * \param signals Signals to apply the update frequency to, passed as a span of signal pointers.
452 * \returns Status code of the first failed update frequency set call, or OK if all succeeded
453 */
454 static ctre::phoenix::StatusCode SetUpdateFrequencyForAll(units::frequency::hertz_t frequencyHz, std::span<BaseStatusSignal* const> signals)
455 {
456 return Status_SetUpdateFrequencyForAll(signals, frequencyHz.to<double>(), 0.100);
457 }
458 };
459
460 /**
461 * \brief Represents a status signal with data of type T,
462 * and operations available to retrieve information about
463 * the signal.
464 */
465 template <typename T>
468
470 hardware::DeviceIdentifier deviceIdentifier,
471 uint16_t spn,
472 std::string signalName,
473 std::function<void()> checkFirmVersFunction
474 ) :
476 std::move(deviceIdentifier),
477 spn, std::move(signalName),
478 std::move(checkFirmVersFunction)
479 }
480 {
481 }
482
484 hardware::DeviceIdentifier deviceIdentifier,
485 uint16_t spn,
486 std::string signalName,
487 std::function<void()> checkFirmVersFunction,
488 std::function<std::map<uint16_t, std::string>()> const &unitsGenerator
489 ) :
491 std::move(deviceIdentifier),
492 spn, std::move(signalName),
493 std::move(checkFirmVersFunction),
494 unitsGenerator
495 }
496 {
497 }
498
499 /* Constructor for an invalid StatusSignal */
500 StatusSignal(ctre::phoenix::StatusCode error) :
501 BaseStatusSignal{error}
502 {
503 }
504
505 public:
506 /**
507 * \brief Gets the cached value from this status signal.
508 *
509 * \details Gets the cached value. To make sure the value is up-to-date
510 * call \c Refresh() or \c WaitForUpdate()
511 *
512 * \returns Cached value
513 */
514 T GetValue() const
515 {
516 if constexpr(units::traits::is_unit_t_v<T>) {
517 return units::make_unit<T>(this->baseValue);
518 } else {
519 return static_cast<T>(this->baseValue);
520 }
521 }
522
523 /**
524 * \brief Refreshes the value of this status signal.
525 *
526 * If the user application caches this StatusSignal object
527 * instead of periodically fetching it from the hardware device,
528 * this function must be called to fetch fresh data.
529 *
530 * \details This performs a non-blocking refresh operation. If
531 * you want to wait until you receive the signal, call
532 * \c WaitForUpdate() instead.
533 *
534 * \param ReportOnError Whether to report any errors to the Driver Station/stderr.
535 *
536 * \returns Reference to itself
537 */
538 StatusSignal<T> &Refresh(bool ReportOnError = true)
539 {
540 RefreshValue(false, 0_s, ReportOnError); // Don't block and error if signal is older than a default timeout
541 return *this;
542 }
543 /**
544 * \brief Waits up to timeoutSec to get the up-to-date status signal value.
545 *
546 * \details This performs a blocking refresh operation. If
547 * you want to non-blocking refresh the signal, call
548 * \c Refresh() instead.
549 *
550 * \param timeoutSec Maximum time to wait for the signal to update
551 * \param ReportOnError Whether to report any errors to the Driver Station/stderr.
552 *
553 * \returns Reference to itself
554 */
555 StatusSignal<T> &WaitForUpdate(units::time::second_t timeoutSec, bool ReportOnError = true)
556 {
557 RefreshValue(true, timeoutSec, ReportOnError);
558 return *this;
559 }
560
561 /**
562 * \brief Checks whether the signal is near a target value within the
563 * given tolerance.
564 *
565 * \param target The target value of the signal
566 * \param tolerance The error tolerance between the target and measured values
567 * \returns Whether the signal is near the target value
568 */
569 bool IsNear(T target, T tolerance) const
570 requires (std::same_as<T, double>)
571 {
572 return fabs(GetValue() - target) <= tolerance;
573 }
574
575 /**
576 * \brief Checks whether the signal is near a target value within the
577 * given tolerance.
578 *
579 * \param target The target value of the signal
580 * \param tolerance The error tolerance between the target and measured values
581 * \returns Whether the signal is near the target value
582 */
583 bool IsNear(T target, T tolerance) const
584 requires (units::traits::is_unit_t_v<T>)
585 {
586 return units::math::abs(GetValue() - target) <= tolerance;
587 }
588
589 /**
590 * \brief Get a basic data-only container with a copy of the current signal data.
591 *
592 * If looking for Phoenix 6 logging features, see the SignalLogger class instead.
593 *
594 * \returns Basic structure with all relevant information
595 */
597 {
599 toRet.name = GetName();
600 toRet.value = GetValue();
601 toRet.timestamp = GetTimestamp().GetTime();
602 toRet.units = GetUnits();
603 toRet.status = GetStatus();
604 return toRet;
605 }
606
607 /**
608 * \brief Returns a lambda that calls #Refresh and #GetValue on this object. This is useful for command-based programming.
609 *
610 * \returns std::function<T()> that calls #Refresh and returns this signal's value.
611 */
612 std::function<T()> AsSupplier()
613 {
614 return [this]() { return Refresh().GetValue(); };
615 }
616
617 friend std::ostream &operator<<(std::ostream &os, StatusSignal<T> const &data)
618 {
619 /* Units may contain UTF-8 characters */
621
622 if constexpr(units::traits::is_unit_t_v<T>) {
623 os << data.GetValue().value() << " " << data.GetUnits();
624 } else {
625 os << data.GetValue() << " " << data.GetUnits();
626 }
627 return os;
628 }
629 std::string ToString() const
630 {
631 std::stringstream ss;
632 ss << *this;
633 return ss.str();
634 }
635 };
636
637}
638}
A collection of timestamps for a received signal.
Definition Timestamp.hpp:125
Class that provides operations to retrieve information about a status signal.
Definition StatusSignal.hpp:39
AllTimestamps timestamps
Definition StatusSignal.hpp:54
AllTimestamps const & GetAllTimestamps() const
Gets the timestamps of this signals.
Definition StatusSignal.hpp:159
ctre::phoenix::StatusCode error
Definition StatusSignal.hpp:55
static std::string Status_GetUnits(uint32_t signal)
static double Status_GetAppliedUpdateFrequency(char const *canbus, uint32_t deviceHash, uint16_t spn)
static ctre::phoenix::StatusCode RefreshAll(std::span< BaseStatusSignal *const > signals)
Performs a non-blocking refresh on all provided signals.
Definition StatusSignal.hpp:383
std::string units
Definition StatusSignal.hpp:52
static ctre::phoenix::StatusCode SetUpdateFrequencyForAll(units::frequency::hertz_t frequencyHz, std::span< BaseStatusSignal *const > signals)
Sets the update frequency of all specified status signals to the provided common frequency.
Definition StatusSignal.hpp:454
std::string const & GetName() const
Gets the name of this signal.
Definition StatusSignal.hpp:141
BaseStatusSignal(hardware::DeviceIdentifier deviceIdentifier, uint16_t spn, std::string signalName, std::function< void()> checkFirmVersFunction, std::function< std::map< uint16_t, std::string >()> const &unitsGenerator)
Definition StatusSignal.hpp:72
ctre::phoenix::StatusCode SetUpdateFrequency(units::frequency::hertz_t frequencyHz, units::time::second_t timeoutSeconds=100_ms)
Sets the rate at which the device will publish this signal.
Definition StatusSignal.hpp:217
ctre::phoenix::StatusCode GetStatus() const
Gets the status code of the last time this signal was refreshed.
Definition StatusSignal.hpp:179
void RefreshValue(bool waitForUpdate, units::time::second_t timeout, bool ReportOnError)
static ctre::phoenix::StatusCode WaitForAll(units::time::second_t timeoutSeconds, std::span< BaseStatusSignal *const > signals)
Waits for new data on all provided signals up to timeout.
Definition StatusSignal.hpp:347
static ctre::phoenix::StatusCode WaitForAll(units::time::second_t timeoutSeconds, Signals &... signals)
Waits for new data on all provided signals up to timeout.
Definition StatusSignal.hpp:313
static ctre::phoenix::StatusCode Status_Get(BaseStatusSignal &signal, char const *network, bool bWaitForUpdate, double timeoutSeconds)
static bool IsAllGood(Signals const &... signals)
Checks if all signals have an OK error code.
Definition StatusSignal.hpp:397
bool HasUpdated()
Checks whether the signal has been updated since the last check.
Definition StatusSignal.hpp:188
BaseStatusSignal(ctre::phoenix::StatusCode error)
Definition StatusSignal.hpp:93
units::frequency::hertz_t GetAppliedUpdateFrequency() const
Gets the rate at which the device will publish this signal.
Definition StatusSignal.hpp:235
double baseValue
Definition StatusSignal.hpp:53
std::string const & GetUnits() const
Gets the units for this signal.
Definition StatusSignal.hpp:147
static U GetLatencyCompensatedValue(StatusSignal< U > const &signal, StatusSignal< U_PER_SEC > const &signalSlope, units::time::second_t maxLatencySeconds=0.300_s)
Performs latency compensation on signal using the signalSlope and signal's latency to determine the m...
Definition StatusSignal.hpp:274
static ctre::phoenix::StatusCode Status_WaitForAll(std::span< BaseStatusSignal *const > signals, char const *network, double timeoutSeconds)
static ctre::phoenix::StatusCode RefreshAll(Signals &... signals)
Performs a non-blocking refresh on all provided signals.
Definition StatusSignal.hpp:367
static ctre::phoenix::StatusCode Status_SetUpdateFrequency(BaseStatusSignal &signal, double frequencyHz, double timeoutSeconds)
static ctre::phoenix::StatusCode SetUpdateFrequencyForAll(units::frequency::hertz_t frequencyHz, Signals &... signals)
Sets the update frequency of all specified status signals to the provided common frequency.
Definition StatusSignal.hpp:434
double GetValueAsDouble() const
Gets the value of this signal as a double.
Definition StatusSignal.hpp:153
static bool IsAllGood(std::span< BaseStatusSignal const *const > signals)
Checks if all signals have an OK error code.
Definition StatusSignal.hpp:407
Timestamp const & GetTimestamp() const
Gets the most accurate timestamp available for this signal.
Definition StatusSignal.hpp:173
BaseStatusSignal(hardware::DeviceIdentifier deviceIdentifier, uint16_t spn, std::string signalName, std::function< void()> checkFirmVersFunction)
Definition StatusSignal.hpp:57
void UpdateUnits(uint16_t unitsKey)
static ctre::phoenix::StatusCode Status_SetUpdateFrequencyForAll(std::span< BaseStatusSignal *const > signals, double frequencyHz, double timeoutSeconds)
static ctre::phoenix::StatusCode WaitForAllImpl(char const *location, units::time::second_t timeoutSeconds, std::span< BaseStatusSignal *const > signals)
Represents a status signal with data of type T, and operations available to retrieve information abou...
Definition StatusSignal.hpp:466
std::string ToString() const
Definition StatusSignal.hpp:629
T GetValue() const
Gets the cached value from this status signal.
Definition StatusSignal.hpp:514
friend std::ostream & operator<<(std::ostream &os, StatusSignal< T > const &data)
Definition StatusSignal.hpp:617
StatusSignal< T > & Refresh(bool ReportOnError=true)
Refreshes the value of this status signal.
Definition StatusSignal.hpp:538
SignalMeasurement< T > GetDataCopy() const
Get a basic data-only container with a copy of the current signal data.
Definition StatusSignal.hpp:596
bool IsNear(T target, T tolerance) const
Checks whether the signal is near a target value within the given tolerance.
Definition StatusSignal.hpp:583
std::function< T()> AsSupplier()
Returns a lambda that calls Refresh and GetValue on this object.
Definition StatusSignal.hpp:612
StatusSignal< T > & WaitForUpdate(units::time::second_t timeoutSec, bool ReportOnError=true)
Waits up to timeoutSec to get the up-to-date status signal value.
Definition StatusSignal.hpp:555
bool IsNear(T target, T tolerance) const
Checks whether the signal is near a target value within the given tolerance.
Definition StatusSignal.hpp:569
Information about the timestamp of a signal.
Definition Timestamp.hpp:17
units::time::second_t GetLatency() const
Get the latency of this timestamp compared to now.
Definition Timestamp.hpp:107
Definition DeviceIdentifier.hpp:16
std::string network
Definition DeviceIdentifier.hpp:18
Parent class for all devices.
Definition ParentDevice.hpp:23
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
static constexpr int SigNotUpdated
No new response to update signal.
Definition StatusCodes.h:420
CTREXPORT void EnableConsoleUTF8Output()
Enables UTF-8 console output.
Definition motor_constants.h:14
Information from a single measurement of a status signal.
Definition SignalMeasurement.hpp:20
T value
The value of the signal.
Definition SignalMeasurement.hpp:28
std::string units
The units of the signal measurement.
Definition SignalMeasurement.hpp:36
ctre::phoenix::StatusCode status
Status code response of getting the data.
Definition SignalMeasurement.hpp:40
units::time::second_t timestamp
Timestamp of when the data point was taken.
Definition SignalMeasurement.hpp:32
std::string_view name
The name of the signal.
Definition SignalMeasurement.hpp:24