Class DashboardBridge
This class only knows about wire-level int/boolean channels and the
edge-detection/dirty-check plumbing around them -- it has no idea what any channel *means*.
Bitfield packing, game rules, and 3D pose visualization are all the consumer's job, layered on
top of this class in a per-year robot repo.
Not a singleton -- a robot may host zero or one of these; there's no reason to force a single shared instance.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionDashboardBridge(DashboardBridge.Config config, DashboardChannel... channels) Convenience constructor bound to the default (real robot) NetworkTableInstance.DashboardBridge(NetworkTableInstance nt, DashboardBridge.Config config, List<DashboardChannel> channels) Primary constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleangetBool(DashboardChannel channel) Last known value for this channel, whether or not it changed this tick.getBoolIfChanged(DashboardChannel channel) Did the dashboard send a new value for this bidirectional boolean channel this tick?intgetInt(DashboardChannel channel) Last known value for this channel, whether or not it changed this tick.getIntIfChanged(DashboardChannel channel) Did the dashboard send a new value for this bidirectional int channel this tick?static <T> Set<T>publishIfChanged(StructArrayPublisher<T> publisher, Set<T> previousValues, Set<T> newValues, IntFunction<T[]> arrayGenerator) PublishesnewValuesviapublisheronly if it differs frompreviousValues.voidCall once per loop, before anygetIntIfChanged/getBoolIfChangedcalls.voidset(DashboardChannel channel, boolean value) Seeset(DashboardChannel, int)-- same dirty-check reasoning applies here.voidset(DashboardChannel channel, int value) Sets the authoritative value the robot reports to the dashboard for this channel.voidStarts serving the static dashboard web app.
-
Constructor Details
-
DashboardBridge
Convenience constructor bound to the default (real robot) NetworkTableInstance. -
DashboardBridge
public DashboardBridge(NetworkTableInstance nt, DashboardBridge.Config config, List<DashboardChannel> channels) Primary constructor. Takes an explicitNetworkTableInstanceso tests can pass a scratch instance fromNetworkTableInstance.create()instead of polluting the global one shared with real robot code.
-
-
Method Details
-
startWebServer
public void startWebServer()Starts serving the static dashboard web app. Call once from production robot code (e.g. during subsystem construction); skip in tests, which don't need the HTTP server. -
readInputs
public void readInputs()Call once per loop, before anygetIntIfChanged/getBoolIfChangedcalls. Drains every bidirectional channel's inbound queue and records which channels received a new value this tick. -
getIntIfChanged
Did the dashboard send a new value for this bidirectional int channel this tick? -
getBoolIfChanged
Did the dashboard send a new value for this bidirectional boolean channel this tick? -
getInt
Last known value for this channel, whether or not it changed this tick. -
getBool
Last known value for this channel, whether or not it changed this tick. -
set
Sets the authoritative value the robot reports to the dashboard for this channel. Safe to call unconditionally every loop -- only writes to NetworkTables when the value actually differs from what was last published, so redundant calls cost nothing on the wire.The dirty-check here compares against
last_published_int_, notcurrent_int_values_. Those two must stay separate: if the dashboard just sent2for this channel,readInputs()already setcurrent_int_values_to2before consumer code callsset(channel, 2)to echo it back. Comparing againstcurrent_int_values_would see "2 == 2" and skip the publish -- but the dashboard was never actually told the robot accepted that value; nothing has gone out over the wire yet. Comparing againstlast_published_int_instead means the firstset()call after any inbound change always publishes (no prior "last published" entry), and only genuinely repeated calls get suppressed. -
set
Seeset(DashboardChannel, int)-- same dirty-check reasoning applies here. -
publishIfChanged
public static <T> Set<T> publishIfChanged(StructArrayPublisher<T> publisher, Set<T> previousValues, Set<T> newValues, IntFunction<T[]> arrayGenerator) PublishesnewValuesviapublisheronly if it differs frompreviousValues. Returns the value to remember as "previous" for the next call.For the "recompute a derived
Set<T>every tick, only callStructArrayPublisher.set()if it actually changed" idiom -- e.g. broadcasting scored game-piece poses to AdvantageScope without spamming NT on every unchanged tick. The pose math itself is inherently game-specific and stays in consumer code; only this dirty-check shape is generic.
-