A small Python API for students who use an ML model or robotics modelling toolbox to control a ROS robot through rosbridge. It exposes only the main operations a student control loop needs:
- sign in to borrow the robot and another sign-in for the battery
- log into
turtlebot-MMR wifi, pwd:Turtlebot - ping 192.168.1.2XX where XX is the TurtleBot ID
- query the latest compressed camera image as a BGR NumPy array;
- query the latest laser scan as angle and range NumPy arrays;
- publish linear and angular velocity to
/cmd_vel; - stop and disconnect safely.
The robot must:
- run a rosbridge WebSocket server reachable by the student's computer;
- accept
geometry_msgs/msg/Twistmessages on/cmd_vel; - publish
sensor_msgs/msg/CompressedImagemessages on/camera/image_raw/compressed; - publish
sensor_msgs/msg/LaserScanmessages on/scan.
Topic names can be changed when constructing RosbridgeRobot.
From this directory:
python -m pip install .Include the keyboard teleoperation dependency with:
python -m pip install ".[teleop]"For active development, use an editable installation:
python -m pip install -e ".[teleop,dev]"from rosbridge_api import RosbridgeRobot
with RosbridgeRobot("192.168.1.213") as robot:
while True:
image = robot.query_image(timeout=2.0, wait_for_new=True)
if image is None:
continue
linear_velocity, angular_velocity = controller(image)
robot.send_command(linear_velocity, angular_velocity)query_image() returns a copy, so student code may safely annotate or resize it.
Its colour order is BGR, as expected by OpenCV.
The runnable examples are kept separately from the library in examples/.
After installing the package, run them from the project directory:
python examples/camera.py 192.168.1.213
python examples/laser_scan.py 192.168.1.213
python examples/teleop.py 192.168.1.213The camera and laser-scan visualisers exit with Q or Escape. The teleop
controls are W/S for forward/backward, A/D for turning, Space for an immediate
stop, and Escape to exit.
python -m unittest discover -s tests -v
python -m build
python -m twine check --strict dist/*The tests mock rosbridge and do not require a physical robot.
Before publishing, choose the final project name, add author/project metadata, choose a licence, and verify installation from the generated wheel in a clean virtual environment.