fix(nav): stop on invalid localization and enforce final velocity path
This commit is contained in:
1 parent
b772174c1c
commit
28ac7c488e
24 files changed
+1236
-161
No files matched your search
@@ -76,6 +76,7 @@ SCRIPTS = PKG_SHARE / 'scripts'
|
||||
if str(WS / 'tools') not in sys.path:
|
||||
sys.path.insert(0, str(WS / 'tools'))
|
||||
import project_env # noqa: E402 (必须在 sys.path 调整之后导入)
|
||||
from dds_environment import defaults as dds_defaults # noqa: E402
|
||||
|
||||
BIN_DIR = project_env.find_bin_dir(WS)
|
||||
GZ_VERSION_ARGS = project_env.gz_version_args()
|
||||
@@ -128,6 +129,27 @@ def _validate_lio(context):
|
||||
return []
|
||||
|
||||
|
||||
def _preflight_nav2(context):
|
||||
if LaunchConfiguration('nav2').perform(context).lower() in ('true', '1'):
|
||||
subprocess.run(['python3', str(WS / 'tools' / 'nav2_startup.py'), '--preflight'],
|
||||
env=dict(context.environment), check=True)
|
||||
return []
|
||||
|
||||
|
||||
def _start_velocity_relay(context):
|
||||
navigation = LaunchConfiguration('nav2').perform(context).lower() in ('true', '1')
|
||||
localization = LaunchConfiguration('localization').perform(context)
|
||||
input_topic = '/cmd_vel' if navigation else context.environment.get('MANUAL_CMD_VEL_TOPIC', '/cmd_vel')
|
||||
return [ExecuteProcess(
|
||||
cmd=[str(BIN_DIR / 'cmd_vel_relay'),
|
||||
'--ros-args', '-p', 'use_sim_time:=true',
|
||||
'-p', f'navigation_mode:={str(navigation).lower()}',
|
||||
'-p', f'require_localization_health:={str(localization == "lio").lower()}',
|
||||
'-p', f'in_topic:={input_topic}'],
|
||||
name='cmd_vel_relay', output='screen',
|
||||
)]
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
headless = LaunchConfiguration('headless')
|
||||
nav2 = LaunchConfiguration('nav2')
|
||||
@@ -156,14 +178,15 @@ def generate_launch_description():
|
||||
# Use the same process boundary and options as the shell entry point.
|
||||
# The nested include path reproduced a Wait action discovery timeout on this setup.
|
||||
navigation = ExecuteProcess(
|
||||
cmd=['ros2', 'launch', 'nav2_bringup', 'bringup_launch.py',
|
||||
['map:=', map_yaml], 'use_sim_time:=true',
|
||||
cmd=['python3', str(WS / 'tools' / 'run_nav2.py'),
|
||||
'--timeout', os.environ.get('SENTRY_NAV2_TIMEOUT', '120'), '--',
|
||||
['map:=', map_yaml], 'use_sim_time:=true', 'autostart:=False',
|
||||
['params_file:=', str(PKG_SHARE / 'config' / 'nav2_params.yaml')],
|
||||
'use_composition:=False',
|
||||
['use_localization:=', PythonExpression(["'", localization, "' == 'amcl'"])],
|
||||
'serve_static_map:=True', 'use_keepout_zones:=False',
|
||||
'use_speed_zones:=False', 'slam:=False'],
|
||||
name='nav2', output='screen', condition=IfCondition(nav2_on),
|
||||
name='nav2', output='screen', condition=IfCondition(nav2_on), sigterm_timeout='20',
|
||||
)
|
||||
|
||||
actions = [
|
||||
@@ -195,13 +218,16 @@ def generate_launch_description():
|
||||
description='迁移包(guodong_sentry_sim)所在目录'),
|
||||
|
||||
# ---------------- 环境变量 ----------------
|
||||
SetEnvironmentVariable('FASTDDS_BUILTIN_TRANSPORTS',
|
||||
dds_defaults(os.environ)['FASTDDS_BUILTIN_TRANSPORTS']),
|
||||
SetEnvironmentVariable('GZ_SIM_RESOURCE_PATH', _gz_resource_path()),
|
||||
SetEnvironmentVariable(
|
||||
'GZ_PARTITION', os.environ.get('GZ_PARTITION', 'sentry')),
|
||||
SetEnvironmentVariable(
|
||||
'ROS_DOMAIN_ID', os.environ.get('ROS_DOMAIN_ID', '0')),
|
||||
'ROS_DOMAIN_ID', dds_defaults(os.environ)['ROS_DOMAIN_ID']),
|
||||
# URDF 的网格路径靠它解析;tools/check_stack.py 也读它
|
||||
SetEnvironmentVariable('SENTRY_SIM_SHARE', str(PKG_SHARE)),
|
||||
OpaqueFunction(function=_preflight_nav2),
|
||||
|
||||
# ---------------- 1. Gazebo ----------------
|
||||
# 用 run_gz.sh 包一层:它会清掉 LD_LIBRARY_PATH,
|
||||
@@ -269,27 +295,23 @@ def generate_launch_description():
|
||||
|
||||
# ---------------- 5. /cmd_vel 改名转发 ----------------
|
||||
# 插件订阅 /model/sentry/cmd_vel,而桥只支持两端同名
|
||||
ExecuteProcess(
|
||||
cmd=[str(BIN_DIR / 'cmd_vel_relay'),
|
||||
'--ros-args', '-p', 'use_sim_time:=true'],
|
||||
name='cmd_vel_relay',
|
||||
output='screen',
|
||||
),
|
||||
OpaqueFunction(function=_start_velocity_relay),
|
||||
|
||||
# ---------------- 6. 点云自滤 ----------------
|
||||
# 本工程没有 ament 注册,不能 ros2 run,直接跑 xmake 产物
|
||||
ExecuteProcess(
|
||||
cmd=[str(BIN_DIR / 'self_filter'),
|
||||
'--ros-args', '-p', 'use_sim_time:=true'],
|
||||
'--ros-args', '-p', 'use_sim_time:=true', '-p', 'reliable_clouds:=true'],
|
||||
name='self_filter',
|
||||
output='screen',
|
||||
),
|
||||
|
||||
ExecuteProcess(
|
||||
cmd=[str(BIN_DIR / 'field_localization_node'), '--ros-args',
|
||||
'-p', 'use_sim_time:=true', '-p', 'point_cloud_topic:=/scan/points_filtered',
|
||||
'-p', 'use_sim_time:=true', '-p', 'reliable_clouds:=true', '-p', 'point_cloud_topic:=/scan/points_filtered',
|
||||
'-p', ['mode:=', lio_mode], '-p', ['map_path:=', lio_map],
|
||||
'-p', ['export_map_path:=', lio_export], '-p', 'publish_map_to_odom:=true',
|
||||
'-p', "diagnostics_path:='" + os.environ.get('LIO_TRACE_PATH', '') + "'",
|
||||
'-p', ['initial_x:=', LaunchConfiguration('lio_initial_x')],
|
||||
'-p', ['initial_y:=', LaunchConfiguration('lio_initial_y')],
|
||||
'-p', ['initial_z:=', LaunchConfiguration('lio_initial_z')],
|
||||
@@ -316,6 +338,10 @@ def generate_launch_description():
|
||||
# 这里再起一份会**同名冲突**(lifecycle_manager 崩在 createLifecycleServiceServers)。
|
||||
|
||||
# ---------------- 9. Nav2 ----------------
|
||||
RegisterEventHandler(OnProcessExit(
|
||||
target_action=navigation,
|
||||
on_exit=[EmitEvent(event=Shutdown(reason='Nav2 supervisor exited'))],
|
||||
)),
|
||||
RegisterEventHandler(OnProcessExit(
|
||||
target_action=navigation_ready,
|
||||
on_exit=lambda event, context: [navigation] if event.returncode == 0 else [
|
||||
|
||||
Reference in new issue
Block a user