This file provides guidance to AI coding assistants when working with code in this repository.
Example Phoenix application demonstrating the BB (Beam Bots) robotics framework with a SO-101 robot arm from TheRobotStudio. This project integrates bb_liveview to provide a real-time web dashboard for robot control and 3D visualisation.
The SO-101 is a 6-DOF desktop robot arm using Feetech STS3215 serial bus servos.
mix setup # Install deps and build assets
SIMULATE=1 mix phx.server # Start in simulation mode (no hardware)
mix phx.server # Start with real hardware
iex -S mix phx.server # Start with IEx shell
mix test # Run all tests
mix test path:42 # Run single test at line
mix check --no-retry # Run all checks (compile, format, credo, dialyzer)mix so101.setup_servos /dev/ttyUSB0 # Assign servo IDs (one at a time)
mix so101.calibrate /dev/ttyUSB0 # Calibrate centre offsets
mix so101.calibrate /dev/ttyUSB0 -n # Dry run (show offsets without writing)The robot is defined using BB's Spark DSL with four main sections:
- parameters - Configures bridges (servo communication adapters) and runtime config
- commands - Defines available robot commands with state machine constraints
- controllers - Hardware communication (Feetech STS3215 via serial)
- topology - URDF-like kinematic chain with joints, links, visuals, and actuators
The robot starts as a supervised child in application.ex and exposes commands like BB.Example.SO101.Robot.home().
Derived from the official SO-ARM100 URDF:
| Joint | Servo ID | Type | Range | Link Length |
|---|---|---|---|---|
| shoulder_pan | 1 | revolute | ±110° | 62mm (base height) |
| shoulder_lift | 2 | revolute | -10° to 190° | 54mm |
| elbow_flex | 3 | revolute | -187° to 7° | 113mm (upper arm) |
| wrist_flex | 4 | revolute | ±95° | 135mm (forearm) |
| wrist_roll | 5 | revolute | ±160° | 61mm (wrist) |
| gripper | 6 | revolute | -10° to 100° | ~98mm to EE |
so101.setup_servos- Interactive wizard for assigning servo IDs. Guides the user through connecting each servo one at a time and setting IDs 1-6.so101.calibrate- Calibrates servo centre offsets. Disables torque, tracks min/max positions as the user moves each joint through its full range, then writes position offsets so the mechanical centre maps to 0 radians.
The router mounts bb_dashboard("/", robot: BB.Example.SO101.Robot) from bb_liveview, providing:
- Real-time joint state visualisation
- 3D robot model rendering
- Command execution interface
- Safety controls (arm/disarm)
Commands implement BB.Command behaviour with handle_command/2. They receive a context containing the compiled robot struct and can send motion commands via BB.Motion.
BB uses the ~u sigil for physical quantities throughout the DSL:
~u(0.1 meter)
~u(90 degree)
~u(360 degree_per_second)
~u(2.5 newton_meter)Set SIMULATE=1 to run without hardware. In simulation mode:
- Controllers and bridges are omitted/mocked
BB.Sim.Actuatorpublishes simulated motion messages- Joint positions are estimated via
OpenLoopPositionEstimator
The serial port defaults to /dev/ttyUSB0 at 1Mbaud. To change it, edit
lib/bb_example_so101/application.ex in the robot_opts/0 function.
Local path dependencies to sibling BB repositories:
bb- Core frameworkbb_liveview- Phoenix LiveView dashboardbb_servo_feetech- Feetech STS servo driverbb_ik_dls- Damped Least Squares inverse kinematicsfeetech- Feetech serial protocol