Integrating ROS/ROS2 with ASI Biont: AI-Powered Robot Control and Automation

Introduction

In the world of robotics and automation, the Robot Operating System (ROS) and its next-generation successor ROS2 have become the de facto standard for building complex robotic systems. From autonomous mobile robots (AMRs) in warehouses to collaborative robotic arms (cobots) on factory floors, ROS/ROS2 provides a flexible framework for sensor integration, motion planning, and control. However, configuring, monitoring, and adapting these systems in real time often requires deep technical expertise and manual scripting. Enter ASI Biont—an AI agent that can connect directly to your ROS/ROS2 environment via WebSocket, parse sensor data, execute control commands, and respond to natural-language instructions. This article explores how ASI Biont integrates with ROS/ROS2 to solve real-world problems, with a focus on a concrete use case: controlling a simulated turtlebot in ROS2 using a WebSocket bridge.

Why Integrate an AI Agent with ROS/ROS2?

Traditional ROS/ROS2 workflows involve writing launch files, subscribing to topics, publishing messages, and often writing Python or C++ nodes to implement logic. While powerful, this approach can be slow to iterate on, especially when you need to react to unexpected sensor readings or change control parameters on the fly. An AI agent like ASI Biont brings several advantages:

  • Natural-language interface: You describe what you want the robot to do (e.g., "move forward 0.5 meters, then rotate 90 degrees") and the AI translates that into ROS2 commands.
  • Dynamic decision-making: The AI can analyze lidar data, camera feeds, or odometry in real time and adjust behavior without requiring a human to rewrite code.
  • Rapid prototyping: Instead of spending hours debugging a node, you ask the AI to write and execute the integration code in seconds.

ASI Biont connects to ROS/ROS2 using a WebSocket bridge—a common ROS package (rosbridge_suite) that exposes ROS topics and services over WebSocket. This is the method used because it is lightweight, does not require modifying the robot's existing ROS nodes, and works over any network. The AI agent sends JSON-formatted commands (e.g., publish to a cmd_vel topic) and subscribes to topics (e.g., /scan for lidar data) via the WebSocket connection.

Use Case: Autonomous Navigation with a TurtleBot3

Scenario

You have a TurtleBot3 robot running ROS2 (Foxy or later) in a simulated environment (Gazebo). The robot has a lidar sensor publishing to /scan, odometry on /odom, and accepts velocity commands on /cmd_vel. You want to:

  1. Monitor the robot's position and obstacle distances.
  2. Send movement commands to explore the environment.
  3. Automatically stop if an obstacle is too close.
  4. Log all data to a file for later analysis.

Connection Method

ASI Biont uses the execute_python method to run a Python script that connects to the rosbridge WebSocket server. The script uses the websockets library (available in the sandbox) to communicate with rosbridge. No local bridge.py is needed because the robot's ROS2 system is networked (e.g., on the same LAN as the ASI Biont server). The user simply provides the IP address and port of the rosbridge server (default: ws://192.168.1.100:9090).

Step-by-Step Integration

  1. User describes the task in chat: "Connect to my TurtleBot3 at 192.168.1.100:9090 via rosbridge, subscribe to /odom and /scan, and let me send movement commands."

  2. ASI Biont writes and executes the following Python script (simplified for clarity):

import asyncio
import json
import websockets

async def connect_and_control():
    uri = "ws://192.168.1.100:9090"
    async with websockets.connect(uri) as ws:
        # Subscribe to /odom (Odometry message)
        sub_odom = {
            "op": "subscribe",
            "topic": "/odom",
            "type": "nav_msgs/msg/Odometry"
        }
        await ws.send(json.dumps(sub_odom))

        # Subscribe to /scan (LaserScan message)
        sub_scan = {
            "op": "subscribe",
            "topic": "/scan",
            "type": "sensor_msgs/msg/LaserScan"
        }
        await ws.send(json.dumps(sub_scan))

        # Wait for a few messages to get initial data
        await asyncio.sleep(1)

        # Publish a velocity command: move forward at 0.2 m/s
        twist = {
            "op": "publish",
            "topic": "/cmd_vel",
            "msg": {
                "linear": {"x": 0.2, "y": 0.0, "z": 0.0},
                "angular": {"x": 0.0, "y": 0.0, "z": 0.0}
            }
        }
        await ws.send(json.dumps(twist))

        # Listen for incoming messages
        for _ in range(10):
            msg = await ws.recv()
            data = json.loads(msg)
            if data.get("topic") == "/odom":
                # Extract position
                pos = data["msg"]["pose"]["pose"]["position"]
                print(f"Position: x={pos['x']:.2f}, y={pos['y']:.2f}")
            elif data.get("topic") == "/scan":
                # Check minimum distance in front (middle of 360 points)
                ranges = data["msg"]["ranges"]
                front_dist = ranges[len(ranges)//2]
                print(f"Front distance: {front_dist:.2f} m")
                if front_dist < 0.3:
                    # Emergency stop
                    stop = {
                        "op": "publish",
                        "topic": "/cmd_vel",
                        "msg": {"linear": {"x": 0.0, "y": 0.0, "z": 0.0},
                                "angular": {"x": 0.0, "y": 0.0, "z": 0.0}}
                    }
                    await ws.send(json.dumps(stop))
                    print("Obstacle too close! Stopping.")
                    break

asyncio.run(connect_and_control())
  1. AI explains the code: It shows how the script subscribes to topics, parses the JSON messages, extracts relevant data (position from odometry, distances from laser scan), and publishes velocity commands.

  2. User can now interact: The AI agent continues to run in the chat, accepting natural language commands like:

  3. "Turn left 45 degrees."
  4. "Speed up to 0.5 m/s."
  5. "Log the last 10 positions to a CSV."

Each command triggers a new execute_python call that publishes appropriate Twist messages or records data.

Results Achieved

  • Time to first movement: Under 30 seconds from the user's first message.
  • Obstacle avoidance: The AI autonomously stopped the robot when the front distance fell below 0.3 meters, preventing a collision.
  • Data logging: The AI wrote a second script that saved odometry and scan data to a CSV file, which the user downloaded directly from the chat.
  • No manual coding: The user never wrote a single line of ROS2 code—they described their intent, and the AI handled the integration.

How ASI Biont Connects to Any Device via execute_python

One of the most powerful features of ASI Biont is its ability to connect to any device through the execute_python method. The AI has access to a rich sandbox environment with dozens of libraries (see the full list in the introduction). You simply describe in the chat:

  • What device you want to connect to (e.g., "my ROS2 robot at 192.168.1.100:9090").
  • What protocol to use (e.g., WebSocket for rosbridge).
  • What you want to do (e.g., "read lidar data and move the robot").

The AI then writes the Python code using the appropriate library (e.g., websockets, paho-mqtt, pymodbus, paramiko) and executes it in the sandbox. There are no dashboard panels or "add device" buttons—everything happens through the chat conversation. This means you can integrate hardware that ASI Biont has never seen before, without waiting for developers to add support.

Why This Approach Is a Game-Changer

  • Speed: Traditional ROS2 integration projects take days or weeks. ASI Biont does it in minutes.
  • Flexibility: You can change the robot's behavior on the fly by simply asking the AI. No need to edit launch files or restart nodes.
  • Accessibility: Engineers who are not ROS experts can still control complex robots using natural language.
  • Scalability: The same approach works for multiple robots, multi-sensor setups, and fleets.

Other Integration Examples with ROS/ROS2

Use Case Connection Method What the AI Does
Monitor robot joint states WebSocket (rosbridge) Subscribes to /joint_states, plots angles, alerts if out of range
Control a robotic arm WebSocket (rosbridge) Publishes to /arm_controller/command to move to a target pose
Read camera feed WebSocket (rosbridge) Subscribes to /camera/image_raw, decodes compressed images, runs object detection (OpenCV)
Log sensor data to database WebSocket (rosbridge) + psycopg2 Subscribes to multiple topics, inserts into PostgreSQL
Multi-robot coordination WebSocket (rosbridge) on each robot Publishes different cmd_vel for each robot based on their namespace

Conclusion

Integrating an AI agent like ASI Biont with ROS/ROS2 opens up a new paradigm in robotics and automation. Instead of being locked into rigid scripts, you gain a conversational interface that can adapt to changing conditions, handle exceptions, and execute complex sequences—all without writing boilerplate code. The WebSocket bridge method is proven, reliable, and works with any ROS2 system out of the box.

Whether you're a robotics researcher, a factory automation engineer, or a hobbyist building your own robot, ASI Biont can save you hours of work and let you focus on the high-level behavior. Try it today: go to asibiont.com, describe your ROS2 setup in the chat, and let the AI take control of your robot.

Ready to automate your robot fleet? Connect to ASI Biont now and see the difference.

← All posts

Comments