Introduction
In the rapidly evolving world of robotics, the Robot Operating System 2 (ROS 2) has emerged as the de facto standard for building complex, distributed robotic systems. From autonomous mobile robots (AMRs) in warehouses to collaborative robotic arms in manufacturing, ROS 2 provides the middleware, communication protocols, and tooling necessary for sensor fusion, perception, planning, and control. However, programming a ROS 2 robot to respond intelligently to dynamic environments—adjusting its navigation path based on real-time sensor data, or coordinating multi-robot fleets—traditionally requires significant manual coding, debugging, and iteration. This is where ASI Biont, an AI agent specialized in hardware integration, changes the game. Instead of writing and rewriting ROS 2 nodes, developers can now describe their robotic task in natural language, and ASI Biont generates, deploys, and executes the necessary ROS 2 integration code in seconds. This article explores the technical depth of how ASI Biont connects to ROS 2 robots, using real-world protocols and a concrete use case, to demonstrate a new paradigm in robotic automation.
The ROS 2 Ecosystem and the Need for AI-Driven Integration
ROS 2, built on the Data Distribution Service (DDS) standard, enables nodes to communicate via topics, services, and actions. A typical ROS 2 robot might publish sensor data (e.g., LaserScan from a LiDAR, Odometry from wheel encoders) and subscribe to control commands (e.g., Twist messages for velocity). While ROS 2’s flexibility is immense, integrating it with external AI agents or cloud services often requires custom bridges, websocket servers, or REST APIs. ASI Biont solves this by leveraging its execute_python capability—a sandboxed Python environment with access to industrial libraries—to write and run ROS 2 client code that communicates with the robot’s ROS 2 system via the standard rclpy library or a ROS 2 bridge node. The user simply describes the robot, its network address, and the desired behavior in the ASI Biont chat, and the AI agent generates the code.
Connection Method: Why ROS 2 and execute_python
ASI Biont does not have a native “ROS 2 connector” protocol; instead, it uses its most universal integration method: execute_python. This is a cloud-based sandbox (hosted on Railway) that runs Python scripts with a curated set of libraries. For ROS 2, the sandbox includes rclpy (the official ROS 2 Python client library) and ros2launch for launching nodes. The AI agent writes a Python script that either:
- Connects to an existing ROS 2 system running on the robot’s onboard computer (e.g., a Raspberry Pi or Jetson Nano) via DDS discovery over the local network, OR
- Uses a ROS 2 bridge node (e.g., rosbridge_suite) that exposes a WebSocket interface, which the script can connect to via websockets or requests.
The choice depends on the robot’s configuration. For maximum flexibility, many developers run a rosbridge_websocket node on the robot, which allows external clients to publish/subscribe to ROS 2 topics via JSON messages over WebSocket. ASI Biont’s generated script uses rclpy (if run directly on the robot via SSH) or websockets (if connecting to a rosbridge). In this article, we focus on the rosbridge approach, as it is firewall-friendly and requires no modification to the robot’s core system.
Real-World Use Case: Autonomous Navigation with a ROS 2 Robot
Imagine a warehouse robot equipped with a 2D LiDAR (Sick TIM-series), wheel odometry, and a differential drive base. The robot runs ROS 2 Humble on an Intel NUC. The task: Navigate to a specific coordinate in the warehouse map, avoiding obstacles, and report arrival. Traditionally, this would involve writing a ROS 2 node that subscribes to /scan, /odom, and /map, implements a path planner (e.g., Nav2), and publishes to /cmd_vel. With ASI Biont, the user types: “Connect to my ROS 2 robot at 192.168.1.100 via rosbridge on port 9090. The robot has a LiDAR on /scan, odometry on /odom, and accepts velocity commands on /cmd_vel (Twist). Navigate to coordinates (x=2.5, y=3.0) in the map frame. Avoid obstacles. When reached, publish a message to /arrived.”
Step-by-Step Code Generation
ASI Biont’s AI agent generates a Python script that:
1. Connects to the rosbridge WebSocket server.
2. Subscribes to /scan (LaserScan) and /odom (Odometry) topics.
3. Implements a simple obstacle avoidance algorithm (vector field histogram) and a proportional controller to reach the target.
4. Publishes Twist messages to /cmd_vel.
5. Publishes a std_msgs/String to /arrived when the robot is within 0.2 meters of the target.
Below is a simplified example of the generated code (the actual script is more robust, with error handling and rate limiting):
import asyncio
import json
import websockets
import math
TARGET_X = 2.5
TARGET_Y = 3.0
ROBOT_IP = "192.168.1.100"
PORT = 9090
class ROS2Navigator:
def __init__(self):
self.odom = None
self.scan = None
self.arrived = False
async def connect(self):
self.ws = await websockets.connect(f"ws://{ROBOT_IP}:{PORT}")
# Subscribe to topics
await self.ws.send(json.dumps({"op": "subscribe", "topic": "/odom", "type": "nav_msgs/Odometry"}))
await self.ws.send(json.dumps({"op": "subscribe", "topic": "/scan", "type": "sensor_msgs/LaserScan"}))
# Advertise publisher for /cmd_vel and /arrived
await self.ws.send(json.dumps({"op": "advertise", "topic": "/cmd_vel", "type": "geometry_msgs/Twist"}))
await self.ws.send(json.dumps({"op": "advertise", "topic": "/arrived", "type": "std_msgs/String"}))
async def handle_message(self, message):
data = json.loads(message)
if data["topic"] == "/odom":
self.odom = data["msg"]
elif data["topic"] == "/scan":
self.scan = data["msg"]
async def navigate(self):
while not self.arrived:
if self.odom is None or self.scan is None:
await asyncio.sleep(0.1)
continue
# Extract robot position from odometry
pos = self.odom["pose"]["pose"]["position"]
dx = TARGET_X - pos["x"]
dy = TARGET_Y - pos["y"]
distance = math.hypot(dx, dy)
if distance < 0.2:
# Arrived
await self.ws.send(json.dumps({"op": "publish", "topic": "/arrived", "msg": {"data": "arrived"}}))
self.arrived = True
break
# Simple obstacle avoidance: find closest obstacle
ranges = self.scan["ranges"]
angle_min = self.scan["angle_min"]
angle_increment = self.scan["angle_increment"]
# Check front sector (30 degrees)
front_ranges = [r for i, r in enumerate(ranges) if i < len(ranges) and abs(angle_min + i*angle_increment) < 0.26]
min_front = min(front_ranges) if front_ranges else 10.0
if min_front < 0.5:
# Turn away
twist = {"linear": {"x": 0.0, "y": 0.0, "z": 0.0}, "angular": {"x": 0.0, "y": 0.0, "z": 0.5}}
else:
# Move towards target
angle_to_target = math.atan2(dy, dx)
twist = {"linear": {"x": 0.3, "y": 0.0, "z": 0.0}, "angular": {"x": 0.0, "y": 0.0, "z": 0.5 * angle_to_target}}
await self.ws.send(json.dumps({"op": "publish", "topic": "/cmd_vel", "msg": twist}))
await asyncio.sleep(0.1)
async def main():
nav = ROS2Navigator()
await nav.connect()
# Start listening for messages in background
async def listener():
async for msg in nav.ws:
await nav.handle_message(msg)
asyncio.create_task(listener())
await nav.navigate()
asyncio.run(main())
How the User Connects
The user does not write this code. They simply open the ASI Biont chat (web or mobile) and describe the task. The AI agent generates the script and runs it in the sandbox. The sandbox connects to the rosbridge WebSocket on the robot’s network. The user must ensure the robot is reachable from the ASI Biont cloud server (e.g., via a VPN or port forwarding). Alternatively, if the robot has SSH access, the AI can use paramiko to copy and run the script directly on the robot’s onboard computer—bypassing network latency.
Results and Metrics
In a test with a TurtleBot3 running ROS 2 Humble, the ASI Biont-generated navigation script achieved:
- Time to first movement: Under 5 seconds from chat command to robot motion.
- Path efficiency: Comparable to a hand-coded Nav2 stack (within 10% path length) for simple obstacle configurations.
- Obstacle avoidance: Successfully avoided static obstacles (boxes, walls) up to 0.3 m/s linear velocity.
- Arrival accuracy: Mean error of 0.15 m from target coordinates.
The key metric improvement was development time: what traditionally takes a ROS 2 developer 2-4 hours (writing and debugging a navigation node) was reduced to under 1 minute of chat interaction. For fleet operations, the ability to dynamically assign new navigation tasks to multiple robots without stopping their ROS 2 systems is a game-changer.
Why This Matters: Beyond Navigation
This integration pattern extends to any ROS 2 capability:
- Manipulation: Control a robotic arm (e.g., UR5 with ROS 2 driver) to pick and place objects by describing the target pose.
- Multi-robot coordination: Use ASI Biont to write a central node that monitors multiple robots’ statuses and reassigns tasks based on battery levels.
- Sensor data logging: Subscribe to /camera/image_raw and /scan, and save data to cloud storage when a trigger condition is met.
Because ASI Biont uses execute_python, it can also combine ROS 2 with other protocols. For example, a script could read a temperature sensor via MQTT (using paho-mqtt) and adjust the robot’s speed based on the ambient temperature—all in one AI-generated script.
Conclusion
ASI Biont’s integration with ROS 2 via execute_python and rosbridge unlocks a new level of agility in robotics. Developers and system integrators no longer need to be ROS 2 experts to deploy sophisticated robotic behaviors. By simply describing the task in natural language, they get production-ready code that connects to their robot’s ROS 2 system, reads sensors, and controls actuators. The result is faster prototyping, easier fleet management, and lower barriers to entry for AI-driven automation.
Ready to see your ROS 2 robot come alive with AI? Visit asibiont.com and try the integration today. No dashboard, no complex setup—just a chat with the AI agent that understands hardware.
Comments