NextFTC Telemetry
Logging and live telemetry for FTC robot code, in formats AdvantageScope understands. It has no FTC SDK or Android dependency, so it runs in unit tests or a desktop tool as easily as on a Robot Controller. It depends on util, which supplies the struct schemas, and on control, whose geometry types are registered as structs.
Robot code logs to Telemetry, a table, or a typed handle, and the values go to whatever backends are registered: a WPILOG file, a NetworkTables 4 server, or a mock for tests. A model of WPILib's struct serialization lets typed values like poses be logged in a layout AdvantageScope recognizes.
The NetworkTables server runs on Ktor's CIO engine, and the module also uses msgpack-core, kotlinx-serialization-json, and kotlin-reflect.
To see it working without a robot, run ./gradlew :telemetry:simulateLive. It plays a simulated Auto and TeleOp, serves NetworkTables 4 on port 5810 for AdvantageScope to connect to at localhost, and writes a log for each OpMode to telemetry/build/sim-logs. Pass options such as -PsimArgs="--auto 5 --teleop 5 --topics 100". The source, in src/simulator, shows how the pieces are wired together.
Timestamps are microseconds since an origin, measured on a TimeSource.WithComparableMarks. Give the registry, the log writer, and the server the same source and origin and they agree on every timestamp, so a value means the same moment in the log and on the wire.
Packages
Telemetry, the entry point, which wraps a shared TelemetryRegistry. Log by name with Telemetry.log("Drive/Pose", pose), or hold a typed handle for the fast path: DoubleTopic, IntTopic, LongTopic, FloatTopic and BooleanTopic for numbers and booleans, and Topic<T> for strings, arrays, structs, and lists of structs. TelemetryTable groups related topics under a path, and TelemetryLoggable lets an object publish its own fields. For a type you don't own, register a TelemetryTypeHandler in TelemetryRegistry.handlers; Measure has one by default, which logs the base-unit value with its unit.
NT4Server, a NetworkTables 4 server that dashboards such as AdvantageScope and Glass connect to. Publish a topic, set values on it, and subscribed clients are sent the topics they asked for, their current values, and every change after that. NT4Type names the types of the values it can publish.
WPILogWriter, which writes the WPILOG format to any OutputStream: entries, primitive and array values, and struct values with their schema entries. WPILogType names the types of the non-struct values.