|
Valkyrie 2026
|
Base helper for publishing and subscribing values to NetworkTables. More...
#include <valkyrie/Loggable.h>
Public Member Functions | |
| Loggable (std::string_view name) | |
| Construct a Loggable that registers a top-level table name. | |
| Loggable (std::shared_ptr< nt::NetworkTable > table) | |
| Construct a Loggable that uses an existing NetworkTable. | |
| Loggable ()=default | |
| Default construct an uninitialized Loggable. | |
| void | LogChild (std::string_view name, Loggable *child) |
| Register a child Loggable under a named subtree. | |
| void | LogChild (std::string_view name, wpi::Sendable *child) |
| Register a child Sendable under a named subtree. | |
| bool | WriteLog (std::string_view field, bool data) |
| double | WriteLog (std::string_view field, double data) |
| void | WriteLog (std::string_view field, const std::vector< double > &data) |
|
template<typename U> requires units::traits::is_unit_t_v<U> | |
| U | WriteLog (std::string_view field, U data) |
| void | WriteLog (std::string_view field, std::string_view data) |
|
template<typename E> requires std::is_enum_v<E> | |
| void | WriteLog (std::string_view field, E data) |
|
template<typename T> requires wpi::StructSerializable<T> && (!std::is_arithmetic_v<T>) | |
| void | WriteLog (std::string_view field, const T &data) |
|
template<typename T> requires wpi::StructSerializable<T> && (!std::is_arithmetic_v<T>) | |
| void | WriteLog (std::string_view field, const std::vector< T > &data) |
| bool | ReadLog (std::string_view field, bool defaultValue) |
| double | ReadLog (std::string_view field, double defaultValue) |
|
template<typename U> requires units::traits::is_unit_t_v<U> | |
| U | ReadLog (std::string_view field, U defaultValue) |
Static Public Member Functions | |
| static constexpr Loggable & | GetRoot () |
Protected Member Functions | |
| virtual void | OnLoggingStart () |
| Hook invoked when logging is started for this object. | |
| virtual void | LoggablePeriodic () |
| Periodic callback for logging updates. | |
Base helper for publishing and subscribing values to NetworkTables.
The Loggable class provides a type-safe wrapper around NetworkTables publishers and subscribers. It lazily creates publishers/subscribers for fields on first use and handles mapping of C++ types (including unit types and container types) to the appropriate NetworkTables topic types.
Typical usage:
The class also supports hierarchical logging by exposing LogChild() to register child Loggable or Sendable objects under a named subtree.
|
explicit |
Construct a Loggable that registers a top-level table name.
This constructor will create or acquire a NetworkTable for the specified name and later use it when publishing or subscribing fields.
Note: the implementation acquires the table under the "/LiveWindow" root (i.e. GetTable("/LiveWindow")->GetSubTable(name)).
| name | Table name to use for this Loggable instance. |
|
explicit |
Construct a Loggable that uses an existing NetworkTable.
Use this constructor when the caller has already created or acquired a NetworkTable and wants this Loggable to publish/subscribe directly on that table. The provided table is stored as a shared_ptr and the Loggable will call EnableLogging() during construction (see implementation in Loggable.cpp).
Notes:
| table | Shared pointer to an already-initialized NetworkTable to use for publishing and subscribing. |
|
default |
Default construct an uninitialized Loggable.
Use this constructor when the derived type will initialize the table at a later time or when the object is intended to act only as a container for children.
| void valor::Loggable::LogChild | ( | std::string_view | name, |
| Loggable * | child ) |
Register a child Loggable under a named subtree.
The child will be exposed under this object's table namespace and publishing/subscribing calls made by the child will use the child's table.
| name | The name under which the child will be visible. |
| child | Pointer to the child Loggable instance. Ownership is not transferred; caller must ensure lifetime. |
| void valor::Loggable::LogChild | ( | std::string_view | name, |
| wpi::Sendable * | child ) |
Register a child Sendable under a named subtree.
This overload allows registering objects implementing wpi::Sendable so they can also be displayed/inspected in dashboards that consume NetworkTables data.
The implementation registers the sendable with the LiveWindow/sendable registry (via wpi::SendableRegistry::AddLW) and enables LiveWindow telemetry for the object (via frc::LiveWindow::EnableTelemetry).
| name | The name under which the child will be visible. |
| child | Pointer to a wpi::Sendable instance. Ownership is not transferred; caller must ensure lifetime. |
|
inlineprotectedvirtual |
Periodic callback for logging updates.
If a derived class needs to perform periodic updates to published values, override this method. It is intended to be called by the logging framework; this base class provides an empty implementation.
Reimplemented in valor::BaseController, valor::cameras::Limelight, valor::CorePhoenixController, valor::NeoController, valor::sensors::apriltag::Limelight, valor::sensors::CurrentSensor, valor::sensors::DebounceSensor, valor::sensors::LidarSensor, valor::swerve::Swerve, valor::swerve::SwerveModule, and valor::WorldAlign.
|
inlineprotectedvirtual |
Hook invoked when logging is started for this object.
Derived classes may override to perform initialization when the NetworkTables table becomes active for this Loggable.
Reimplemented in valor::BaseController.