BB.Reactor.Middleware.Context (bb_reactor v0.2.3)

Copy Markdown View Source

Middleware that injects BB context into the reactor.

This middleware must be included in any reactor that uses BB steps. It creates a BB.Reactor.Context and stores it in context.private.bb, making robot information available to all steps.

Usage

Add to your reactor's middleware:

defmodule MyRobot.PickAndPlace do
  use Reactor, extensions: [BB.Reactor]

  # BB.Reactor extension automatically adds this middleware
  # ...
end

Or manually:

defmodule MyReactor do
  use Reactor

  middlewares do
    middleware {BB.Reactor.Middleware.Context, robot: MyRobot}
  end
end

Accessing Context in Steps

def run(arguments, context, options) do
  bb = context.private.bb

  # Access robot module
  robot = bb.robot_module

  # Access static robot struct
  links = bb.robot.links

  # Check current state
  if bb.robot_state == :idle do
    # ...
  end
end