Web App & Bridge API

How the /play 3-step wizard communicates with ros2 run unbeatabot web_bridge over HTTP/SSE, including calibration endpoints and Vercel HTTPS PNA.

The Next.js web app in web/ talks to ROS 2 through ros2_ws/src/unbeatabot/unbeatabot/web_bridge.py—a standard-library Python ThreadingHTTPServer listening on http://localhost:8780 (configurable via NEXT_PUBLIC_BRIDGE_URL and -p port:=8780).

The /play 3-Step Wizard

  1. Connect: Choose Demo (in-browser minimax) or Real robot (connects via EventSource to /api/events and displays live game manager, arm, and camera status).
  2. Calibration: Fetches GET /api/calibration, previews the board footprint (corners 1, 3, 9, 7) from above, and lets you either accept the saved calibration or open the Recalibrate wizard.
  3. Play: Displays the live 3x3 board, turn/help status banner, move sound effects, New game (/api/new_game), and Resume (/api/resume) controls.

Bridge HTTP & SSE Endpoints

Method & PathPayload / ResponseROS 2 Action
GET /api/eventsSSE stream: state, status, calibrationSubscribes to /game_state, node heartbeats, and /board_state
GET /api/calibration{ squareSize, tableZ, corners, tray, source }Reads config/calibration.yaml
POST /api/player_move{ "square": 1..9 }Publishes move to /player_move
POST /api/new_gameEmpty bodyPublishes empty trigger to /new_game
POST /api/resumeEmpty bodyPublishes empty trigger to /resume

Interactive Calibration Endpoints

The interactive browser calibration wizard uses four JSON routes backed by /get_tool and Calibration.fit_points:

EndpointRequest BodyBehavior
POST /api/calibration/startOptional { camera, view, markers }Starts a calibration session and returns ordered board & piece steps
POST /api/calibration/recordOptional { markerId, xyz }Reads live arm tool position from /get_tool (if xyz omitted) and stores point
POST /api/calibration/skipOptional { markerId }Marks the current marker skipped and advances to the next step
POST /api/calibration/finishOptional { cameraAt, updateTeach }Runs Calibration.fit_points, saves YAMLs, and broadcasts updated calibration

Vercel HTTPS & Private Network Access (PNA)

web_bridge.py restricts requests via an origin allowlist (DEFAULT_ORIGINS) so arbitrary tabs cannot command the robot arm. When the web app is deployed on Vercel over HTTPS and connects to http://localhost:8780, Chromium sends a Private Network Access preflight.

web_bridge.py CORS + PNA headers
Access-Control-Allow-Origin: https://<your-app>.vercel.app
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Private-Network: true

Custom origins at launch

You can also override allowed origins at runtime via ROS parameters: ros2 run unbeatabot web_bridge --ros-args -p origins:="['http://localhost:3000']".

Unbeatabot — an EECS 4421 project. Layout based on Animate UI. Source on GitHub.