BB.LiveView
Interactive LiveView dashboard for Beam Bots robots. Mount a fully-featured control interface into any Phoenix application with a single line of code.
Features
- Safety Controls - Arm/disarm robot with visual state indicators
- Joint Control - Real-time sliders for all movable joints with position feedback
- 3D Visualisation - Interactive Three.js view with orbit controls showing live robot pose
- Drive - Optional hold-to-drive with the arrow keys, WASD or an on-screen pad
- Event Stream - Monitor PubSub messages with filtering and pause/resume
- Command Execution - Dynamic forms for robot commands based on DSL definitions
- Parameter Editor - View and modify runtime parameters with type-specific controls
- Cameras - Discovers the robot's cameras and previews them over WebRTC, with the optional
bb_camera_webrtc
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:
- Disarmed (grey) - Robot is safe, no motion possible
- Armed (green) - Robot is ready to accept commands
- Error (red) - Safety system detected an issue, requires force disarm
Joint Control
Shows all movable joints with:
- Current position (degrees for revolute, mm for prismatic)
- Target slider with min/max limits from joint definition
- "SIM" badge for joints without hardware actuators
- Controls disabled when robot is disarmed
3D Visualisation
Interactive Three.js renderer showing:
- Robot geometry from visual definitions (boxes, cylinders, spheres)
- Real-time joint position updates via forward kinematics
- Orbit controls (drag to rotate, scroll to zoom, right-drag to pan)
- Reset View button to restore default camera position
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}]
- Nothing is captured until you press Take control, and never while typing in a form field
- Hold the arrow keys, WASD (by position, so any keyboard layout) or the on-screen pad for throttle and turn
- While a key is held the browser sends a tick 20 times a second (
:rate), andpublish(robot, throttle, turn)is called with each in -1..1;stop(robot)is called when you let go, release control, or the window loses focus - The same contract as bb_tui's drive extension, so one pair of functions serves both
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}
- Only the camera on screen is streamed, and an idle camera isn't started until you ask
- Video travels over WebRTC; the LiveView socket carries only the signalling
- No STUN or TURN servers by default, so the browser must reach the robot directly; pass
:ice_serversfor a browser behind NAT
See the Preview Cameras guide.
Event Stream
Real-time PubSub message monitor:
- Timestamp, path, message type, and payload preview
- Pause/Resume to freeze the stream
- Clear button to reset the message list
- Auto-scrolls to show newest messages
Command Panel
Execute robot commands defined in the DSL:
- Tab navigation for multiple commands
- Dynamic form generation based on command arguments
- State-aware availability (respects allowed states)
- Result/error display after execution
Parameters
View and edit runtime parameters:
- Grouped by parameter path
- Type-specific controls (toggles, sliders, text inputs)
- Real-time updates via PubSub
- Support for remote bridge 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
- Elixir ~> 1.19
- Phoenix LiveView ~> 1.0
- A robot module using the BB DSL
Documentation
- Your First Dashboard - getting started tutorial
- Customise Dashboard Layout - creating custom layouts
Full API documentation is available at HexDocs.