5. Connecting to the real robots
The room’s controller, and your two robots on the floor
http://<instructor-ip>:8000, and the controller reaches the robots.
Compare with step 3: only the address changes.
The problem. Your script runs in the simulator on your laptop. The real robots are on the floor, and your laptop cannot talk to them by itself: the instructor’s controller can. This step connects you to it and finds your two robots; step 6 runs your script on them.
The PyDotBot docs promise it at the top of Try it in the simulator, the guide whose Drive it from your own code you met in step 4: the simulator exposes the same REST API as the real controller, so code written against one runs unchanged against the other. Step 6 checks that promise.
How the room is wired
Figure 1 is all you need: your script and your browser talk to one controller, the instructor’s, with the same REST API as your simulator. Behind it, in small print in Figure 1:
- The MQTT broker runs on the instructor’s laptop and carries every message between the controller and the gateway.
- The gateway, a board plugged into that laptop, turns those messages into Mari radio packets, and back.
- The robots run
remote-control, the program that answers the controller: the console pad and your scripts.
The full architecture, with the simulator and flashing, is the slide How it fits together from step 2.
Nothing of this changes your code: only the address it talks to, and the label of the robot. You configure no site and no MQTT broker for your scripts or for the console: the controller URL is all they need. Broker settings matter only for dotbot swarm commands, in the extra module Extra: Flash it, where your duo.toml holds them.
What to do
The console. Open the instructor’s console,
http://<instructor-ip>:8000/console/, with the address from the board. Open its List view and find your two robots by the labels on their stickers.Your two robots. Save
connect.py(below) next toacademy.py, setBASE_URLtohttp://<instructor-ip>:8000andLABELSto your two labels, then run it:python connect.py
You should see
Your two robots light up green on the floor, and so do their dots on the instructor’s map. The terminal prints how many robots the controller knows, then each of your labels with its position on the floor.
Core light your two robots
connect.py
"""Step 5: connecting to the real robots.
Point academy at the instructor's controller, find your two robots by their
labels, and light them up to check they are yours.
You should see: your two robots on the floor turn green, and their dots in
the instructor's console turn green too.
"""
import academy
BASE_URL = "http://192.168.1.10:8000" # TODO: the instructor's controller, from the board
LABELS = ["A1B2C3", "D4E5F6"] # TODO: the labels on your two robots
robots = academy.connect(BASE_URL)
print(len(robots), "robots on the controller")
for label in LABELS:
robot = academy.bot(label)
print("Found", label, "at", robot.position())
robot.led(0, 255, 0) # green: this one is yoursWhen connect.py finds both robots and they turn green, you are connected: go on to step 6. Keep BASE_URL and your two labels at hand, the next steps use them.
LookupError: 0 robots match: the label has a typo, or the robot is off. Check it in the console’s List view.ConnectionError: the controller address is wrong, or your laptop is not on the workshop Wi-Fi.- Nothing happens on the floor: call the instructor.