Action builders and executor for reactive controllers.
Provides two action types:
Command- invokes a robot commandCallback- calls an arbitrary function with the message and context
DSL Builders
These functions are imported into the controller entity scope:
controller :over_current, {BB.Controller.Threshold,
topic: [:sensor, :servo_status],
field: :current,
max: 1.21,
action: command(:disarm)
}
controller :collision, {BB.Controller.PatternMatch,
topic: [:sensor, :proximity],
match: fn msg -> msg.payload.distance < 0.05 end,
action: handle_event(fn msg, ctx ->
Logger.warning("Collision detected")
:ok
end)
}
Summary
Functions
Build a command action that invokes the named robot command.
Execute an action with the given message and context.
Build a callback action that calls the given function.
Types
@type t() :: BB.Controller.Action.Command.t() | BB.Controller.Action.Callback.t()
Functions
@spec command(atom()) :: BB.Controller.Action.Command.t()
Build a command action that invokes the named robot command.
Examples
command(:disarm)
command(:move_to, target: pose)
@spec command( atom(), keyword() ) :: BB.Controller.Action.Command.t()
@spec execute(t(), BB.Message.t(), BB.Controller.Action.Context.t()) :: any()
Execute an action with the given message and context.
@spec handle_event((BB.Message.t(), BB.Controller.Action.Context.t() -> any())) :: BB.Controller.Action.Callback.t()
Build a callback action that calls the given function.
The function receives the triggering message and a context struct.
Examples
handle_event(fn msg, ctx ->
Logger.info("Received: #{inspect(msg)}")
:ok
end)