BB.Controller.Action (bb v0.15.2)

Copy Markdown View Source

Action builders and executor for reactive controllers.

Provides two action types:

  • Command - invokes a robot command
  • Callback - 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

Functions

command(name)

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

command(name, args)

@spec command(
  atom(),
  keyword()
) :: BB.Controller.Action.Command.t()

execute(arg1, message, context)

@spec execute(t(), BB.Message.t(), BB.Controller.Action.Context.t()) :: any()

Execute an action with the given message and context.

handle_event(fun)

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)