Root Robot Integration#
The Root Robot is one of the supported devices in our environment and can be selected directly via the options drawer. It is a Bluetooth-enabled educational robot developed by iRobot, which we have integrated with our turtle canvas.
Communication with the Root Robot is achieved through the Web Bluetooth API, which is currently supported by modern Chromium-based browsers such as Google Chrome and Microsoft Edge. Due to current browser limitations, this functionality is not available in Firefox, Safari, or other non-Chromium browsers.
To manage this communication efficiently, we use the Comlink library, which abstracts the complexity of the postMessage API and allows us to call functions between main thread and web worker.
rootRobot.py#
This Python module provides a user-facing library for controlling the Root Robot. It exposes the following functions:
forward(distance)
Moves the robot forward by
distance
centimeters.
backward(distance)
Moves the robot backward by
distance
centimeters.
right(angle_degrees)
Turns the robot right by
angle_degrees
(clockwise).
left(angle_degrees)
Turns the robot left by
angle_degrees
(counterclockwise).
penUp()
Moves the Pen and Eraser up.
penDown()
Moves down the currentTool which is a pen or eraser
penErase()
changes the currentTool to an eraser
penPaint()
changes the currentTool to a pen
getPos()
gets the currentPosition which is calculated in the library and not in the robot
setPos(x,y)
calculates the fastest way to get to the given position
x
andy
resetPos()
resets the turtle position aswell as the currentPosition of the robot to (0,0)
Each of these functions constructs a BLE (Bluetooth Low Energy) packet based on the Root Robot Protocol Documentation and sends it to the main thread using a callback mechanism. The defaultrunner.callback function is used to send:
The raw command message as a bytearray
An expectedResponse (used to ignore other replies)
The corresponding turtle canvas command
To ensure communication integrity, a _checkSum function is used to calculate a CRC-8 checksum over the first 19 bytes of the command packet. This checksum is appended as the 20th byte of the message and is validated during robot communication. It is a global function and should not be used by the user.
Commands sent to the Root Robot are shown on the turtle canvas, ensuring that the on-screen simulation waits for the physical robot execution.
rootRobot.ts#
This TypeScript Class with a device interface handles all Bluetooth connectivity and message routing for the Root Robot. It is responsible for:
Establishing a Bluetooth connection with the robot using Web Bluetooth
Managing characteristic UUIDs as defined in the Root Robot protocol:
UUID_ROOT_IDENTIFIER_SERVICE
ROOT_UART_SERVICE
ROOT_TX_CHARACTERISTIC
ROOT_RX_CHARACTERISTIC
Sending constructed packets to the robot and waiting for the expected response. It can be that the UUIDs change.
Routing incoming packets and handling acknowledgments
Executing the turtle command using handleTurtle, which communicates with TurtlePixiHandler.ts for synchronized canvas updates.
The robot message is only sent if the device is connected and responds with the expected confirmation. This approach ensures a reliable interaction loop, similar to the one used in XLogo’s Bluetooth communication design.
By linking the robot and turtle canvas behavior in a single callback cycle, we ensure that the root-robot and the turtle run simultaneously.
At this point following packets dont work to send to the roboter:
Get Position
Drive Arc
There is no response coming from the robot.