|
| 1 | +# ROS2 Launch System for Robot Integration |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This guide provides template launch files for developers to integrate their robots with the ROS-MCP Server. These templates demonstrate how to combine your robot's existing launch files with rosbridge for MCP communication. |
| 6 | + |
| 7 | +## Template Launch Files |
| 8 | + |
| 9 | +### `ros_mcp_rosbridge.launch.py` - Basic Rosbridge Template |
| 10 | +**Purpose**: Minimal rosbridge WebSocket server for robot integration |
| 11 | +**Use Case**: Add MCP communication to any existing robot setup |
| 12 | + |
| 13 | +```bash |
| 14 | +# Basic usage |
| 15 | +ros2 launch ros_mcp_rosbridge.launch.py |
| 16 | + |
| 17 | +# Custom port |
| 18 | +ros2 launch ros_mcp_rosbridge.launch.py port:=9090 |
| 19 | + |
| 20 | +# Specific address |
| 21 | +ros2 launch ros_mcp_rosbridge.launch.py address:=127.0.0.1 |
| 22 | +``` |
| 23 | + |
| 24 | +## Integration Patterns |
| 25 | + |
| 26 | +### How to add Rosbridge to Existing Robot |
| 27 | + |
| 28 | +#### Method 1: Include Rosbridge Launch File |
| 29 | +```python |
| 30 | +# Your existing robot launch file (e.g., my_robot.launch.py) |
| 31 | +from launch import LaunchDescription |
| 32 | +from launch.actions import IncludeLaunchDescription |
| 33 | +from launch.launch_description_sources import PythonLaunchDescriptionSource |
| 34 | +from launch_ros.actions import Node |
| 35 | + |
| 36 | +def generate_launch_description(): |
| 37 | + # Your existing robot nodes |
| 38 | + robot_node = Node( |
| 39 | + package='my_robot_pkg', |
| 40 | + executable='robot_node', |
| 41 | + name='my_robot' |
| 42 | + ) |
| 43 | + |
| 44 | + sensor_node = Node( |
| 45 | + package='my_robot_pkg', |
| 46 | + executable='sensor_node', |
| 47 | + name='sensor_node' |
| 48 | + ) |
| 49 | + |
| 50 | + # Include rosbridge for MCP communication |
| 51 | + rosbridge_launch = IncludeLaunchDescription( |
| 52 | + PythonLaunchDescriptionSource([ |
| 53 | + 'ros_mcp_server', '/launch/ros_mcp_rosbridge.launch.py' |
| 54 | + ]), |
| 55 | + launch_arguments={ |
| 56 | + 'port': '9090', |
| 57 | + 'address': '', |
| 58 | + 'log_level': 'info' |
| 59 | + }.items() |
| 60 | + ) |
| 61 | + |
| 62 | + return LaunchDescription([ |
| 63 | + robot_node, |
| 64 | + sensor_node, |
| 65 | + rosbridge_launch, # Add this line |
| 66 | + ]) |
| 67 | +``` |
| 68 | + |
| 69 | +#### Method 2: Add Rosbridge Node Directly |
| 70 | + |
| 71 | +```python |
| 72 | +# Add rosbridge node to your existing launch file |
| 73 | +from launch.actions import DeclareLaunchArgument, LogInfo |
| 74 | +from launch.substitutions import LaunchConfiguration |
| 75 | +from launch_ros.actions import Node |
| 76 | + |
| 77 | +from launch import LaunchDescription |
| 78 | + |
| 79 | + |
| 80 | +def generate_launch_description(): |
| 81 | + """Generate the launch description for rosbridge only.""" |
| 82 | + |
| 83 | + # Declare launch arguments |
| 84 | + port_arg = DeclareLaunchArgument( |
| 85 | + "port", default_value="9090", description="Port for rosbridge websocket server" |
| 86 | + ) |
| 87 | + |
| 88 | + address_arg = DeclareLaunchArgument( |
| 89 | + "address", |
| 90 | + default_value="", |
| 91 | + description="Address for rosbridge websocket server (empty for all interfaces)", |
| 92 | + ) |
| 93 | + |
| 94 | + log_level_arg = DeclareLaunchArgument( |
| 95 | + "log_level", default_value="info", description="Log level for rosbridge server" |
| 96 | + ) |
| 97 | + |
| 98 | + # Rosbridge websocket server node |
| 99 | + rosbridge_node = Node( |
| 100 | + package="rosbridge_server", |
| 101 | + executable="rosbridge_websocket", |
| 102 | + name="rosbridge_websocket", |
| 103 | + output="screen", |
| 104 | + parameters=[ |
| 105 | + { |
| 106 | + "port": LaunchConfiguration("port"), |
| 107 | + "address": LaunchConfiguration("address"), |
| 108 | + "use_compression": False, |
| 109 | + "max_message_size": 10000000, |
| 110 | + "send_action_goals_in_new_thread": True, |
| 111 | + "call_services_in_new_thread": True, |
| 112 | + "default_call_service_timeout": 5.0, |
| 113 | + } |
| 114 | + ], |
| 115 | + arguments=["--ros-args", "--log-level", LaunchConfiguration("log_level")], |
| 116 | + ) |
| 117 | + |
| 118 | + return LaunchDescription( |
| 119 | + [ |
| 120 | + port_arg, |
| 121 | + address_arg, |
| 122 | + log_level_arg, |
| 123 | + rosbridge_node, |
| 124 | + ] |
| 125 | + ) |
| 126 | +``` |
| 127 | + |
| 128 | + |
| 129 | +#### Method 3: Separate Launch Files (Recommended) |
| 130 | +```bash |
| 131 | +# Terminal 1: Launch your robot |
| 132 | +ros2 launch my_robot_pkg my_robot.launch.py |
| 133 | + |
| 134 | +# Terminal 2: Launch rosbridge for MCP |
| 135 | +ros2 launch ros_mcp_server ros_mcp_rosbridge.launch.py port:=9090 |
| 136 | +``` |
| 137 | + |
| 138 | +| Argument | Default | Description | |
| 139 | +|----------|---------|-------------| |
| 140 | +| `port` | 9090 | WebSocket server port | |
| 141 | +| `address` | "" | Bind address (empty = all interfaces) | |
| 142 | +| `log_level` | info | Log level (debug, info, warn, error) | |
0 commit comments