11#include <wpi/datalog/DataLog.hpp>
12#include <wpi/nt/DoubleTopic.hpp>
13#include <wpi/nt/NetworkTable.hpp>
14#include <wpi/nt/StructArrayTopic.hpp>
15#include <wpi/nt/StructTopic.hpp>
16#include <wpi/system/DataLogManager.hpp>
17#include <wpi/util/json.hpp>
20class SmartMotorController;
60 void SetupTelemetry(
const std::string& mechanismName,
const std::string& dataLogName);
91 std::function<void(
double)>
PublishDouble(
const std::string& key,
const std::string& unit =
"");
102 template <
typename T>
104 auto publisher = std::make_shared<wpi::nt::StructPublisher<T>>(
105 m_networkTable->template GetStructTopic<T>(key).Publish());
106 std::shared_ptr<wpi::log::StructLogEntry<T>> logEntry;
108 logEntry = std::make_shared<wpi::log::StructLogEntry<T>>(wpi::DataLogManager::GetLog(),
109 *m_dataLogName +
"/" + key);
111 return [publisher, logEntry](
const T& value) {
112 publisher->Set(value);
113 if (logEntry) logEntry->Append(value);
126 template <
typename T>
128 auto publisher = std::make_shared<wpi::nt::StructArrayPublisher<T>>(
129 m_networkTable->template GetStructArrayTopic<T>(key).Publish());
130 std::shared_ptr<wpi::log::StructArrayLogEntry<T>> logEntry;
132 logEntry = std::make_shared<wpi::log::StructArrayLogEntry<T>>(wpi::DataLogManager::GetLog(),
133 *m_dataLogName +
"/" + key);
135 return [publisher, logEntry](std::span<const T> value) {
136 publisher->Set(value);
137 if (logEntry) logEntry->Append(value);
151 void SetupLoopTime();
153 std::shared_ptr<wpi::nt::NetworkTable> m_networkTable;
154 std::shared_ptr<wpi::nt::NetworkTable> m_tuningNetworkTable;
155 std::optional<wpi::nt::DoublePublisher> m_loopTimePublisher;
156 double m_prevTimestamp{0.0};
157 std::optional<std::string> m_dataLogName;
Definition SmartMotorController.hpp:48
Definition MechanismTelemetry.hpp:34
std::function< void(std::span< const T >)> PublishStructArray(const std::string &key)
Definition MechanismTelemetry.hpp:127
std::shared_ptr< wpi::nt::NetworkTable > GetDataTable() const
void SetupTelemetry(const std::string &mechanismName, motorcontrollers::SmartMotorController &motorController)
std::function< void(double)> PublishDouble(const std::string &key, const std::string &unit="")
std::function< void(const T &)> PublishStruct(const std::string &key)
Definition MechanismTelemetry.hpp:103
void SetupTelemetry(const std::string &mechanismName, const std::string &dataLogName)
void SetupTelemetry(const std::string &mechanismName)
std::shared_ptr< wpi::nt::NetworkTable > GetTuningTable() const
void AddMotorController(const std::string &subTableName, motorcontrollers::SmartMotorController &motorController)
Definition SimSensorConfig.hpp:15
Definition SwerveDrive.hpp:864