|
Valor 6800 1.0
|
Base helper for publishing and subscribing values to NetworkTables. More...
#include <Loggable.h>
Public Member Functions | |
| 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. | |
| void | setLoggingPeriod (units::millisecond_t period) |
| Set the minimum period between LoggablePeriodic() invocations. | |
| template<> | |
| decltype(Loggable::subscribers) ::iterator | addSubscriber (std::string_view field, const std::vector< bool > &defaultValue) |
| template<> | |
| void | WriteLogImpl (nt::Publisher *pub, const std::vector< bool > &data) |
| template<> | |
| std::vector< bool > | ReadLogImpl (nt::Subscriber *sub) |
Static Public Member Functions | |
| static units::millisecond_t | GetLoggingTime () |
Protected Member Functions | |
| Loggable (std::string_view name) | |
| Construct a Loggable that registers a top-level table name. | |
| Loggable () | |
| Default construct an uninitialized Loggable. | |
| virtual | ~Loggable ()=default |
| Virtual destructor. | |
| virtual void | OnLoggingStart () |
| Hook invoked when logging is started for this object. | |
| virtual void | LoggablePeriodic () |
| Periodic callback for logging updates. | |
| template<typename T > | |
| T | WriteLog (std::string_view field, const T &data) |
| Publish a value to NetworkTables under the given field. | |
| template<typename T > | |
| T | ReadLog (std::string_view field, const T &defaultValue={}) |
| Read a value from NetworkTables for the given field. | |
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.
|
explicitprotected |
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. |
|
protected |
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.
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. |
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::NeoController, valor::PhoenixController< VelocityOutput, PositionOutput >, valor::Swerve, valor::SwerveModule, valor::AprilTagsSensor, valor::GamePieceSensor, and valor::WorldAlign.
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.
|
inlineprotected |
Read a value from NetworkTables for the given field.
If a subscriber for the specified field does not yet exist it is created and subscribed with the provided default value. The value is returned converted to the requested template type T.
| T | The requested return type. Must be compatible with the stored NetworkTables type; unit types and vectors are supported. |
| field | Name of the entry (relative to this object's table). |
| defaultValue | Value to return if the entry does not yet exist. |
|
inline |
Set the minimum period between LoggablePeriodic() invocations.
When set to a value greater than zero, LoggablePeriodic() will only execute when at least this much time has elapsed since the last invocation. A value of 0ms (the default) means LoggablePeriodic() runs every scheduler cycle (~20ms).
| period | Minimum time between LoggablePeriodic() calls. |
Publish a value to NetworkTables under the given field.
If a publisher for the specified field does not yet exist it is created automatically. The function is a template and supports primitive types, STL containers (e.g., std::vector), unit types (from the units library), and other serializable types supported by NetworkTables.
| T | The type of the value to publish. Must be compatible with NetworkTables (see nt_traits in the implementation). |
| field | Name of the entry (relative to this object's table). |
| data | The value to publish. |