Tutorial · getting started

Getting started

Everything you need before the other tutorials: install the tools, get the API repository from Git, run the simulators on your own PC, drive a robot from Python, and choose between training on the CPU or on a GPU. About half an hour.

1Three ways to use it

In the browserOpen robotics.dinno.be and drive the robots with the keyboard. Nothing to install. The ROS 2 tutorials also run entirely there.
Locally, for trainingThe Node API server runs the simulators step by step in a hidden Chrome. Python talks to it. This is what the RL tutorials use.
Remote controlA simulator open in a normal browser tab, controlled in real time from Python through the PHP API.

The rest of this page sets up the second and third ways on your own PC.

2Install the tools

ToolVersionFor
Gitanygetting the code and updates
Node.js22 or newerthe API server (server.mjs). No npm install needed.
Google Chromerecentthe server runs the simulators in it. Chromium or Edge also work.
Python3.10 or neweryour own programs and the tutorial scripts

Windows

winget install Git.Git OpenJS.NodeJS.LTS Google.Chrome Python.Python.3.12

macOS (Homebrew)

brew install git node python@3.12
brew install --cask google-chrome

Ubuntu / Debian

sudo apt install git python3 python3-venv python3-pip
# Node.js 22: the apt version is often too old, use NodeSource
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install nodejs
# Chrome: download the .deb from google.com/chrome, or: sudo apt install chromium

Open a new terminal afterwards and check:

git --version
node --version       # v22.x or higher
python --version     # 3.10 or higher (Linux/macOS: python3)

3Get the code

Everything you need on your own PC (API server, Python client, tutorial scripts and trained models) is in the robotSimulatorAPI repository. The simulators themselves stay on this website: the API server fetches them from here. Clone the repository in a folder of your choice:

git clone https://github.com/mdequanter/robotSimulatorAPI.git
cd robotSimulatorAPI

All commands in these tutorials are run from inside the robotSimulatorAPI folder, so paths look like python/corridor_rl.py.

What is in it:

server.mjsthe Node API server for training
python/botopia.py (the Python client) and the scripts of every tutorial
python/models/trained models, to test without training first
README.mdthe full API reference: every endpoint, robot, lane and observation
index.phpthe PHP API for remote control; it runs on this website (step 8)

Get the latest version later with:

git pull

4Run the simulators locally

Start the API server. It also serves the simulator pages, so you need no web server:

node server.mjs
Botopia simulator API on http://localhost:8780/api/  (simulators: http://localhost:8780/)
Simulator pages from https://robotics.dinno.be/

The server fetches each simulator page from robotics.dinno.be once and keeps it in memory, so you need an internet connection when it starts a robot for the first time. The simulation itself runs on your PC. Open http://localhost:8780/ to see the simulators through your local server. Leave the terminal open; Ctrl+C stops it.

OptionWhat it does
--showa visible Chrome window, so you can watch what your program does
--port 8780another port (the server also uses the next few ports for Chrome)
--browsers 4number of Chrome processes for parallel environments (default: one per 4 CPU cores, at most 4)
--chrome "path"where Chrome is, if the server does not find it (or set CHROME)
--site URLwhere the simulator pages come from (default https://robotics.dinno.be/); also a local folder with the site

5Python environment

Make a virtual environment inside robotSimulatorAPI, so the packages stay out of your system Python:

# Windows (PowerShell)
python -m venv .venv
.venv\Scripts\Activate.ps1

# Linux / macOS
python3 -m venv .venv
source .venv/bin/activate

What to install depends on what you want to do:

GoalInstall
Drive robots from code (step 6)nothing: botopia.py uses only the standard library
Images, Gymnasium wrapperpip install numpy pillow gymnasium
RL tutorials 1, 2, 5, 6pip install stable-baselines3 gymnasium pillow
Tutorial 3 (YOLO)pip install ultralytics stable-baselines3 gymnasium
Live camera windowpip install numpy opencv-python

stable-baselines3 and ultralytics bring PyTorch along. With a plain pip install that is the CPU version on Windows and macOS. For a GPU, read step 7 before you install them.

6Your first API program

With the server from step 4 running, save this as hello.py in the robotSimulatorAPI folder:

import sys
sys.path.append("python")
from botopia import BotopiaEnv

env = BotopiaEnv(robot="skid", lane="corridor", dt=0.05, max_steps=200)
obs, info = env.reset(seed=1)
print("actions:", env.action_names)        # ['fwd', 'turn']

for t in range(200):
    obs, reward, terminated, truncated, info = env.step([0.5, 0.0])   # half speed, straight on
    if terminated or truncated:
        break
print("steps:", t + 1, "last reward:", reward)
env.close()
python hello.py

Start the server with --show to see the robot drive. Simulated time only moves when you call step, so the run is reproducible and as fast as your PC allows.

Without Python

The API is plain HTTP + JSON, so any language works. With curl:

curl localhost:8780/api/robots
curl -X POST localhost:8780/api/envs -d "{\"robot\":\"skid\",\"lane\":\"corridor\",\"seed\":1}"

The other calls (step, reset, camera images, several robots at once, direct motor control) are in the repository's README.md. Every robot and its commands are listed on the API page. For a quick demo with four robots, run python python/botopia.py.

7With or without a GPU

You do not need a graphics card. The simulators run in Chrome on the CPU, and for small networks the CPU is even faster. A GPU only speeds up the neural network, which pays off when the robot learns from camera images.

TutorialNetworkGPU?
1 · corridor (corridor_rl.py)small, 10 numbers inno, CPU is faster
2 · from the camera (track_vision_rl.py)CNN on imagesyes, clearly faster
3 · YOLO (track_yolo.py)YOLO + small policyhelps for YOLO
4 · sorting, 6 · stand rowQ-tableno
5 · arm + HER (arm_reach_her.py)smalloptional

Without a GPU (CPU only)

Install as in step 5; that is all. On Linux, plain pip install torch downloads the large CUDA build; to save a few GB, install the CPU build first:

pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install stable-baselines3 gymnasium pillow

Use more CPU cores instead: more parallel environments (--envs in the tutorial scripts) and --browsers on the server.

With an NVIDIA GPU

  1. Install a recent NVIDIA driver. nvidia-smi shows the highest CUDA version it supports.
  2. Install the CUDA build of PyTorch first, then the rest (otherwise pip may pick the CPU build). Pick the command for your system on pytorch.org; RTX 50-series cards need CUDA 12.8 or newer:
pip install torch --index-url https://download.pytorch.org/whl/cu128
pip install stable-baselines3 gymnasium pillow
python -c "import torch; print(torch.cuda.is_available())"     # True = the GPU is usable

Then train with --device cuda (or auto, which picks the GPU when PyTorch sees one):

python python/track_vision_rl.py train --device cuda

Already installed the CPU build? pip uninstall torch first, then install the CUDA build. A Mac has no CUDA: train on the CPU.

8Remote control (PHP API)

To control a simulator that is open in a normal browser tab, in real time (for example to test a trained model or to mirror a real robot), use the PHP API. It runs on this website, so you install nothing for it:

  1. Open https://robotics.dinno.be/indexSkid.php?remote=1. The page shows a session code in its bottom-right corner.
  2. Control it from Python with that code:
import sys, time
sys.path.append("python")
from botopia import RemoteSession

s = RemoteSession("https://robotics.dinno.be/api/index.php", "CODE")
s.command(action={"drive": {"fwd": 0.5, "turn": 0.0}})
time.sleep(2)
print(s.state())                       # latest observation + incidents
s.command(action={"drive": {"fwd": 0, "turn": 0}})

The PHP API runs in real time (about 5 updates per second), so use the Node API for training.

9Where to go next

10Troubleshooting

ProblemSolution
Chrome not foundStart the server with --chrome "C:/path/to/chrome.exe" or set the CHROME environment variable. Edge or Chromium also work.
SyntaxError or fetch is not defined when starting the serverNode.js is too old: node --version must be 22 or higher.
EADDRINUSEA server is already running on that port. Stop it or use --port 8790 (and --url http://localhost:8790 in the scripts).
ModuleNotFoundError: botopiaRun the script from inside the robotSimulatorAPI folder, or fix the sys.path.append path.
ConnectionRefusedError in PythonThe API server is not running (step 4).
torch.cuda.is_available() is FalseThe CPU build of PyTorch is installed, or the driver is too old for that CUDA version. See step 7.
Windows: Activate.ps1 is blockedSet-ExecutionPolicy -Scope CurrentUser RemoteSigned, then try again.
robotics.dinno.be not reachable when creating a robotThe server needs internet to fetch a simulator page the first time. Check your connection or proxy.
PHP API: the robot does not react to commandsOpen the page on robotics.dinno.be (not via your local Node server, which does not run PHP) and check the session code.