Skip to content

Publishers

The FateWeaver extension includes an additional feature called publishers, which allow you to register a channel that will be automatically logged to every loop.

Take our lift subsystem from the guide. Let's add a public state getter:

kotlin
val state get() = motor.state

Now, in the onStartButtonPressed method of our OpMode, we can register a publisher for the lift's state:

kotlin
val stateChannel = FateComponent.createChannel("Lift State", KineticState::class)
FateComponent.registerPublisher(stateChannel, Lift::state)

This will automatically publish the lift's state to the log file at the end of every loop.

There is an overload for registerPublisher that takes a channel name and schema (or class) instead of a channel object, which could be used as follows:

kotlin
FateComponent.registerPublisher("LiftState", KineticState::class, Lift::state)

Publishers are automatically unregistered when the OpMode ends.

In this example, we use method and property references to simplify the code, but you can also use lambda expressions. WPILib has has an amazing explanation of method references and lambda expressions here. For information on Kotlin method references and lambda expressions, see the Kotlin documentation.