Beam Bots Logo

BB.LiveView

CI License: Apache 2.0 Hex version badge Hexdocs badge REUSE status Ask DeepWiki

Interactive LiveView dashboard for Beam Bots robots. Mount a fully-featured control interface into any Phoenix application with a single line of code.

Features

Installation

Add bb_liveview to your dependencies in mix.exs:

def deps do
  [
    {:bb_liveview, "~> 0.5.0"}
  ]
end

Quick Start

1. Add the dashboard route

In your Phoenix router, import the macro and mount the dashboard:

defmodule MyAppWeb.Router do
  use MyAppWeb, :router
  import BB.LiveView.Router

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_live_flash
    plug :put_root_layout, html: {MyAppWeb.Layouts, :root}
    plug :protect_from_forgery
    plug :put_secure_browser_headers
  end

  scope "/" do
    pipe_through :browser
    bb_dashboard "/robot", robot: MyApp.Robot
  end
end

2. Serve the bundled assets

Add the static plug to your endpoint, before Plug.Session:

defmodule MyAppWeb.Endpoint do
  use Phoenix.Endpoint, otp_app: :my_app

  # ... other plugs ...

  # Add this BEFORE Plug.Session
  plug Plug.Static,
    at: "/__bb_assets__",
    from: {:bb_liveview, "priv/static"},
    gzip: false

  plug Plug.Session, ...
  plug MyAppWeb.Router
end

3. Start your robot supervisor

Ensure your robot's supervision tree is started in your application:

defmodule MyApp.Application do
  use Application

  def start(_type, _args) do
    children = [
      # ... other children ...
      %{
        id: BB.Supervisor,
        start: {BB.Supervisor, :start_link, [MyApp.Robot]}
      },
      MyAppWeb.Endpoint
    ]

    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

4. Visit the dashboard

Navigate to http://localhost:4000/robot to see your robot dashboard.

Multiple Robots

Mount multiple dashboards for different robots:

scope "/" do
  pipe_through :browser
  bb_dashboard "/arm", robot: MyApp.ArmRobot
  bb_dashboard "/base", robot: MyApp.MobileBase
end

Configuration Options

The bb_dashboard/2 macro accepts the following options:

Option Required Description
:robot Yes The robot module (must use BB)
:drive No Adds the Drive widget; see Drive
:ice_servers No STUN/TURN servers for camera previews; see Cameras

Dashboard Components

Safety Widget

Displays the robot's safety state and provides arm/disarm controls:

Joint Control

Shows all movable joints with:

3D Visualisation

Interactive Three.js renderer showing:

Drive

An optional widget for driving a robot by hand, enabled with the :drive option:

bb_dashboard "/robot",
  robot: MyRobot,
  drive: [publish: {MyRobot.Drive, :tick}, stop: {MyRobot.Drive, :stop}]

Ticks stop arriving if the browser goes away, so publish should keep the robot moving only briefly after each one. See BB.LiveView.Drive.

Cameras

When the robot declares cameras (with bb_camera), the visual area gains a Cameras tab that previews them over WebRTC. Previews need the optional bb_camera_webrtc package:

{:bb_camera_webrtc, "~> 0.1"},
# Membrane's `ratio` pins `decimal` lower; only your own mix.exs can override it.
{:decimal, "~> 3.0", override: true}

See the Preview Cameras guide.

Event Stream

Real-time PubSub message monitor:

Command Panel

Execute robot commands defined in the DSL:

Parameters

View and edit runtime parameters:

Styling

The dashboard uses bundled CSS with CSS custom properties for theming. The default theme uses neutral greys with accent colours for status indicators.

To customise, you can override the CSS custom properties in your own stylesheet:

:root {
  --bb-primary: #your-color;
  --bb-success: #your-success-color;
  --bb-danger: #your-danger-color;
}

Development

To run the development server with the test robot:

cd bb_liveview
mix deps.get
cd assets && npm install && cd ..
mix phx.server

Visit http://localhost:4000 to see the dashboard with a simulated WidowX-200 style robot arm.

Requirements

Documentation

Full API documentation is available at HexDocs.