Spark DSL extension for integrating Reactor with the BB robotics framework.
Add bb_reactor to your dependencies in mix.exs:
def deps do
[
{:bb_reactor, "~> 0.1"}
]
enddefmodule MyRobot.PickAndPlace do
use Reactor, extensions: [BB.Reactor]
input :pick_pose
input :place_pose
# Wait for robot to be ready
wait_for_state :ready do
states [:idle]
timeout 5000
end
# Execute movement command
command :approach do
command :move_to_pose
argument :target, input(:pick_pose)
wait_for :ready
end
# Close gripper
command :grip do
command :close_gripper
wait_for :approach
end
# Wait for force sensor event
wait_for_event :gripped do
path [:sensor, :force]
timeout 2000
wait_for :grip
end
# Move to place position with compensation
command :retreat do
command :move_to_pose
argument :target, input(:place_pose)
wait_for :gripped
compensate :return_home
end
return :retreat
end
# Run the reactor
Reactor.run(MyRobot.PickAndPlace, inputs, %{private: %{bb_robot: MyRobot}})Execute a BB command with safety handling and compensation support.
command :move do
command :move_to_pose # The BB command to execute
argument :target, input(:pose) # Arguments passed to the command
timeout 30_000 # Optional timeout (default: :infinity)
compensate :return_home # Optional compensation command for undo
endWait for a PubSub event matching a pattern.
wait_for_event :force_detected do
path [:sensor, :force_torque] # PubSub path to subscribe to
timeout 5000 # Optional timeout
message_types [ForceTorque] # Optional: filter by message type
filter &MyFilters.threshold?/1 # Optional: custom filter function
endWait for the robot to reach a specific state.
wait_for_state :wait_for_idle do
states [:idle] # Target states (any-of matching)
timeout 5000 # Optional timeout
endThe BB.Reactor.Middleware.Safety middleware can be added to report reactor errors to the BB safety system:
defmodule MyRobot.SafeReactor do
use Reactor, extensions: [BB.Reactor]
middlewares do
middleware BB.Reactor.Middleware.Safety
end
# ... steps
endThis allows the robot's auto_disarm_on_error configuration to control whether errors trigger automatic disarm.
Apache License 2.0
