18#include <units/dimensionless.h>
37 template <
typename... Devices>
39 std::conjunction<std::is_base_of<ParentDevice, std::remove_reference_t<Devices>>...>
45 template <
typename... Devices>
49 std::map<uint32_t, std::unique_ptr<BaseStatusSignal>> _signalValues;
50 std::recursive_mutex _signalValuesLck;
55 std::shared_ptr<controls::ControlRequest> _controlReq = std::make_shared<controls::EmptyControl>();
56 std::mutex _controlReqLck;
60 bool _isInitialized =
false;
67 void ReportIfTooOld();
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)
76 BaseStatusSignal *toFind;
79 std::lock_guard<std::recursive_mutex> lock{_signalValuesLck};
82 auto iter = _signalValues.find(spn);
83 if (iter != _signalValues.end()) {
85 toFind = iter->second.get();
87 reportOnConstruction =
true;
91 _signalValues.emplace(spn,
92 std::unique_ptr<StatusSignal<T>>{
new StatusSignal<T>{
94 [
this] { ReportIfTooOld(); },
99 _signalValues.emplace(spn,
100 std::unique_ptr<StatusSignal<T>>{
new StatusSignal<T>{
102 [
this] { ReportIfTooOld(); },
103 mapFiller, std::move(signalName)
109 iter = _signalValues.find(spn);
110 toFind = iter->second.get();
115 StatusSignal<T> *ret =
dynamic_cast<StatusSignal<T> *
>(toFind);
117 if (ret ==
nullptr) {
123 ret->Refresh(reportOnConstruction);
134 _isInitialized =
true;
219 return [resetSignal=_resetSignal]()
mutable {
220 return resetSignal.Refresh(
false).HasUpdated();
297 template <
typename... Devices,
typename = std::enable_if_t<
is_all_device_v<Devices...>>>
386 template <
typename... Devices,
typename = std::enable_if_t<
is_all_device_v<Devices...>>>
421 for (
auto device : devices) {
422 const auto err = device->OptimizeBusUtilization(optimizedFreqHz);
460 for (
auto device : devices) {
461 const auto err = device->OptimizeBusUtilization(optimizedFreqHz);
493 template <
typename... Devices,
typename = std::enable_if_t<
is_all_device_v<Devices...>>>
514 for (
auto device : devices) {
515 const auto err = device->ResetSignalFrequencies();
539 for (
auto device : devices) {
540 const auto err = device->ResetSignalFrequencies();
551 template <
typename T>
554 return LookupCommon<T>(spn,
nullptr, std::move(signalName), reportOnConstruction, refresh);
557 template <
typename T>
560 return LookupCommon<T>(spn, std::move(mapFiller), std::move(signalName), reportOnConstruction, refresh);
564 template <
typename T,
typename U>
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
virtual ~ParentDevice()=default
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
Type trait to verify that all types passed in are subclasses of ParentDevice.
Definition ParentDevice.hpp:40