Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions docs/launch_system.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the intended audience for this instruction file?

Specifically the line "The ROS-MCP Server uses proper ROS2 launch files for process management." is a bit confusing since the ROS-MCP server does not explicitly need to use any launch files at all.

They are useful tools in the examples and tutorials, and having good, modern launch files for these is valuable. But do we need a document telling users of the MCP server about why we chose certain launch systems for the examples?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a guide that 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.

Future Vision: As rosbridge becomes a standard ROS node, the ROS-MCP Server itself will be launchable through ROS2 launch files, making integration even more seamless.

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# ROS2 Launch System

## Overview

The ROS-MCP Server uses proper ROS2 launch files for process management.

## Available Launch Files

### `ros_mcp_rosbridge.launch.py`
**Purpose**: Launch only Rosbridge WebSocket server
**Use Case**: External robots, custom setups, testing

```bash
# Basic usage
ros2 launch ros_mcp_rosbridge.launch.py

# Custom port
ros2 launch ros_mcp_rosbridge.launch.py port:=9091

# Specific address
ros2 launch ros_mcp_rosbridge.launch.py address:=127.0.0.1
```

## Benefits

- ✅ **Proper process management** - Automatic cleanup on shutdown
- ✅ **Configuration options** - Parameter passing and validation
- ✅ **ROS2 integration** - Works with `ros2 launch` command
- ✅ **Logging control** - Configurable log levels
- ✅ **Signal handling** - Proper SIGINT/SIGTERM handling

## Common Arguments

| Argument | Default | Description |
|----------|---------|-------------|
| `port` | 9090 | WebSocket server port |
| `address` | "" | Bind address (empty = all interfaces) |
| `log_level` | info | Log level (debug, info, warn, error) |

## Examples

### External Robot Connection
```bash
# Start rosbridge for external robot
ros2 launch ros_mcp_server ros_mcp_rosbridge.launch.py port:=9090

# Connect MCP server to robot IP
# (Configure in MCP client settings)
```

### Debug Mode
```bash
# Enable debug logging
ros2 launch ros_mcp_server ros_mcp_rosbridge.launch.py log_level:=debug
```

## Troubleshooting

### Port Already in Use
```bash
# Check port usage
netstat -tulpn | grep :9090

# Use different port
ros2 launch ros_mcp_server ros_mcp_rosbridge.launch.py port:=9091
```

### Missing Dependencies
```bash
# Install required packages
sudo apt install ros-jazzy-rosbridge-server
```

### Check Node Status
```bash
# List running nodes
ros2 node list

# Check topics
ros2 topic list
```
86 changes: 86 additions & 0 deletions examples/1_turtlesim/ros_mcp_turtlesim.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env python3

"""
ROS2 Launch file for ROS-MCP Server
Replaces the functionality of scripts/launch_ros.sh with proper ROS2 launch system.

This launch file starts:
- rosbridge_websocket server
- turtlesim node
- Provides proper process management and cleanup
"""

from launch.actions import DeclareLaunchArgument, LogInfo
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node

from launch import LaunchDescription


def generate_launch_description():
"""Generate the launch description for ROS-MCP Server."""

# Declare launch arguments
rosbridge_port_arg = DeclareLaunchArgument(
"port", default_value="9090", description="Port for rosbridge websocket server"
)

rosbridge_address_arg = DeclareLaunchArgument(
"address",
default_value="",
description="Address for rosbridge websocket server (empty for all interfaces)",
)

turtlesim_name_arg = DeclareLaunchArgument(
"turtlesim_name", default_value="turtlesim", description="Name for the turtlesim node"
)

# Rosbridge websocket server node
rosbridge_node = Node(
package="rosbridge_server",
executable="rosbridge_websocket",
name="rosbridge_websocket",
output="screen",
parameters=[
{
"port": LaunchConfiguration("port"),
"address": LaunchConfiguration("address"),
"use_compression": False,
"max_message_size": 10000000,
"send_action_goals_in_new_thread": True,
"call_services_in_new_thread": True,
}
],
arguments=["--ros-args", "--log-level", "info"],
)

# Turtlesim node
turtlesim_node = Node(
package="turtlesim",
executable="turtlesim_node",
name=LaunchConfiguration("turtlesim_name"),
output="screen",
arguments=["--ros-args", "--log-level", "info"],
)

# Log info about what's being launched
log_info = LogInfo(
msg=[
"Starting ROS-MCP Server with:",
" - Rosbridge WebSocket on port: ",
LaunchConfiguration("port"),
" - Turtlesim node: ",
LaunchConfiguration("turtlesim_name"),
]
)

return LaunchDescription(
[
rosbridge_port_arg,
rosbridge_address_arg,
turtlesim_name_arg,
log_info,
rosbridge_node,
turtlesim_node,
]
)
3 changes: 2 additions & 1 deletion examples/8_images/ros_mcp_images_demo.launch.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.launch_description_sources import AnyLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node

from launch import LaunchDescription


def generate_launch_description():
# Declare port argument for rosbridge
Expand Down
76 changes: 76 additions & 0 deletions launch/ros_mcp_rosbridge.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env python3

"""
ROS2 Launch file for Rosbridge WebSocket Server only
Launches only the rosbridge server without turtlesim.

Use this when you want to connect to an external robot or simulation.
"""

from launch.actions import DeclareLaunchArgument, LogInfo
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node

from launch import LaunchDescription


def generate_launch_description():
"""Generate the launch description for rosbridge only."""

# Declare launch arguments
port_arg = DeclareLaunchArgument(
"port", default_value="9090", description="Port for rosbridge websocket server"
)

address_arg = DeclareLaunchArgument(
"address",
default_value="",
description="Address for rosbridge websocket server (empty for all interfaces)",
)

log_level_arg = DeclareLaunchArgument(
"log_level", default_value="info", description="Log level for rosbridge server"
)

# Rosbridge websocket server node
rosbridge_node = Node(
package="rosbridge_server",
executable="rosbridge_websocket",
name="rosbridge_websocket",
output="screen",
parameters=[
{
"port": LaunchConfiguration("port"),
"address": LaunchConfiguration("address"),
"use_compression": False,
"max_message_size": 10000000,
"send_action_goals_in_new_thread": True,
"call_services_in_new_thread": True,
"default_call_service_timeout": 5.0,
}
],
arguments=["--ros-args", "--log-level", LaunchConfiguration("log_level")],
)

# Log info
log_info = LogInfo(
msg=[
"Starting Rosbridge WebSocket Server:",
" - Port: ",
LaunchConfiguration("port"),
" - Address: ",
LaunchConfiguration("address"),
" - Log level: ",
LaunchConfiguration("log_level"),
]
)

return LaunchDescription(
[
port_arg,
address_arg,
log_level_arg,
log_info,
rosbridge_node,
]
)
53 changes: 0 additions & 53 deletions scripts/launch_ros.sh

This file was deleted.