Valkyrie 2026
Loading...
Searching...
No Matches
valor::Loggable Class Reference

Base helper for publishing and subscribing values to NetworkTables. More...

#include <valkyrie/Loggable.h>

Inheritance diagram for valor::Loggable:
valor::sensors::BaseSensor< std::optional< PoseEstimate > > valor::sensors::BaseSensor< double > valor::sensors::BaseSensor< int > valor::sensors::BaseSensor< units::ampere_t > valor::sensors::BaseSensor< bool > valor::sensors::BaseSensor< std::optional< frc::Pose3d > > valor::sensors::BaseSensor< LaserProximityData > valor::sensors::BaseSensor< units::millimeter_t > valor::BaseController valor::BaseSubsystem valor::WorldAlign valor::cameras::Limelight valor::sensors::BaseSensor< T > valor::swerve::SwerveModule

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.

Detailed Description

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:

  • Use WriteLog<T>(field, value) to publish a value of type T.
  • Use ReadLog<T>(field, defaultValue) to subscribe and read a value of type T.

The class also supports hierarchical logging by exposing LogChild() to register child Loggable or Sendable objects under a named subtree.

Constructor & Destructor Documentation

◆ Loggable() [1/3]

valor::Loggable::Loggable ( std::string_view name)
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)).

Parameters
nameTable name to use for this Loggable instance.

◆ Loggable() [2/3]

valor::Loggable::Loggable ( std::shared_ptr< nt::NetworkTable > table)
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:

  • The Loggable does not modify the provided table's path; it uses the table pointer as-is. If you want the Loggable to be placed under a particular namespace (for example /SmartDashboard/<name>), acquire the appropriate subtable before passing it in.
  • Ownership of the table is shared (std::shared_ptr). The caller may keep or drop their reference; the Loggable will retain its copy.
Parameters
tableShared pointer to an already-initialized NetworkTable to use for publishing and subscribing.

◆ Loggable() [3/3]

valor::Loggable::Loggable ( )
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.

Member Function Documentation

◆ LogChild() [1/2]

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.

Parameters
nameThe name under which the child will be visible.
childPointer to the child Loggable instance. Ownership is not transferred; caller must ensure lifetime.

◆ LogChild() [2/2]

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).

Parameters
nameThe name under which the child will be visible.
childPointer to a wpi::Sendable instance. Ownership is not transferred; caller must ensure lifetime.

◆ LoggablePeriodic()

virtual void valor::Loggable::LoggablePeriodic ( )
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.

◆ OnLoggingStart()

virtual void valor::Loggable::OnLoggingStart ( )
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.


The documentation for this class was generated from the following file: