fix(sim): clean up interrupted runs and document usage and migration

Prevent ROS cleanup errors from skipping owned Gazebo process teardown.
Reject occupied master ports before launching nodes and stop the stack when
its GUI closes. Add --gui to the automatic LIO navigation checks.

Expand the root README and add a beginner guide covering manual goals,
automatic tests, restart troubleshooting, MID360 assumptions and staged
migration to real hardware. Preserve lifecycle and GUI validation evidence.

Validation: three navigation restart cycles, two busy-port rejection cases,
SIGINT/SIGHUP cleanup and a GUI straight-route check. Current source hashes,
Python syntax, documentation shell syntax and local links verified. Hardware
migration remains unverified; no push performed.
This commit is contained in:
2026-11-08 22:44:02 +08:00
parent 664eaa81e5
commit ca61aa63b5
21 changed files with 1022 additions and 59 deletions
@@ -37,6 +37,7 @@
import os
import tempfile
import math
import socket
import yaml
import xacro
@@ -61,6 +62,19 @@ DEFAULT_Z = '0.17'
DEFAULT_YAW = '0.0'
def require_free_master(context):
# Check before starting sensors/estimators: they must not consume an older
# world's clock or IMU while a second gzserver fails to bind its port.
with socket.socket() as connection:
connection.settimeout(0.3)
if connection.connect_ex(('127.0.0.1', 11355)) == 0:
raise RuntimeError(
'Gazebo 端口 11355 已被占用:已有仿真或自动测试仍在运行。'
'请在原启动终端按 Ctrl+C,等待退出后重试。'
'可用 ss -ltnp "sport = :11355" 查看占用者;本入口不会终止已有进程。')
return []
def generate_launch_description():
gz_share = get_package_share_directory('robocon_gazebo')
robot_share = get_package_share_directory('r2027_robot_description')
@@ -162,6 +176,7 @@ def generate_launch_description():
PythonLaunchDescriptionSource(
os.path.join(gazebo_ros_share, 'launch', 'gzclient.launch.py')),
condition=IfCondition(LaunchConfiguration('gui')),
launch_arguments={'gui_required': 'true'}.items(),
)
spawn = Node(
@@ -232,5 +247,5 @@ def generate_launch_description():
return LaunchDescription(
declared_args + env_actions
+ [OpaqueFunction(function=expand_model), gzserver, gzclient, spawn,
+ [OpaqueFunction(function=require_free_master), OpaqueFunction(function=expand_model), gzserver, gzclient, spawn,
world_to_odom, cmd_timeout, lidar_tf, adapter, imu_tf])
@@ -23,6 +23,7 @@
"""
import os
import socket
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
@@ -30,6 +31,7 @@ from launch.actions import (
DeclareLaunchArgument,
IncludeLaunchDescription,
SetEnvironmentVariable,
OpaqueFunction,
)
from launch.conditions import IfCondition
from launch.launch_description_sources import PythonLaunchDescriptionSource
@@ -40,6 +42,16 @@ GAZEBO_MASTER_URI = 'http://127.0.0.1:11355'
ROS_DOMAIN_ID = '77'
def require_free_master(context):
with socket.socket() as connection:
connection.settimeout(0.3)
if connection.connect_ex(('127.0.0.1', 11355)) == 0:
raise RuntimeError(
'Gazebo 端口 11355 已被占用:请先在原仿真或自动测试终端按 Ctrl+C,'
'等待退出后重试。本入口不会终止已有进程。')
return []
def generate_launch_description():
share = get_package_share_directory('robocon_gazebo')
models_dir = os.path.join(share, 'models')
@@ -89,6 +101,7 @@ def generate_launch_description():
PythonLaunchDescriptionSource(
os.path.join(gazebo_ros_share, 'launch', 'gzclient.launch.py')),
condition=IfCondition(LaunchConfiguration('gui')),
launch_arguments={'gui_required': 'true'}.items(),
)
return LaunchDescription(env_actions + declared_args + [gzserver, gzclient])
return LaunchDescription(env_actions + declared_args + [OpaqueFunction(function=require_free_master), gzserver, gzclient])