tools/gen_sdf.sh 现在生成使用相对网格路径的 URDF 和 SDF 1.11,GPU雷达
This commit is contained in:
1 parent
c710b955b1
commit
56f4b3adb0
24 files changed
+405
-208
No files matched your search
@@ -67,8 +67,8 @@ from launch_ros.parameter_descriptions import ParameterValue
|
||||
# ---------------------------------------------------------------------------
|
||||
# 路径推算:launch/ 的上一级是 src/sentry_sim,再上三级是仓库根
|
||||
# ---------------------------------------------------------------------------
|
||||
PKG_SHARE = Path(__file__).resolve().parents[1] # src/sentry_sim
|
||||
WS = Path(__file__).resolve().parents[3] # 仓库根
|
||||
WS = Path(__file__).resolve().parents[3]
|
||||
PKG_SHARE = Path(os.environ.get('SENTRY_SIM_SHARE') or WS / 'src' / 'sentry_sim').resolve()
|
||||
SCRIPTS = PKG_SHARE / 'scripts'
|
||||
TOOLS_DIR = WS / 'tools'
|
||||
INTERNAL_TOOLS = TOOLS_DIR / '_internal'
|
||||
@@ -81,6 +81,7 @@ if str(TOOLS_DIR) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_DIR))
|
||||
import project_env # noqa: E402 (必须在 sys.path 调整之后导入)
|
||||
from _internal.dds_environment import defaults as dds_defaults # noqa: E402
|
||||
from _internal.robot_description import runtime_description # noqa: E402
|
||||
|
||||
BIN_DIR = LaunchConfiguration('_sentry_bin_dir')
|
||||
GZ_MAJOR_VERSION = LaunchConfiguration('_sentry_gz_major_version')
|
||||
@@ -111,7 +112,7 @@ def _resolve_environment(context):
|
||||
def _start_gazebo(context):
|
||||
headless = LaunchConfiguration('headless').perform(context).lower() in ('true', '1')
|
||||
# Keep -r in both modes so that the world starts unpaused.
|
||||
args = ['-s', '-r'] if headless else ['-r']
|
||||
args = ['-s', '--headless-rendering', '-r'] if headless else ['-r']
|
||||
if major := GZ_MAJOR_VERSION.perform(context):
|
||||
args.extend(['--force-version', major])
|
||||
world_path = PathJoinSubstitution([str(PKG_SHARE / 'worlds'), LaunchConfiguration('world')])
|
||||
@@ -127,20 +128,6 @@ def _on_bridge_exit(event, context):
|
||||
return []
|
||||
|
||||
|
||||
def _robot_description():
|
||||
"""在**构建 launch 描述时**就把 URDF 展开成字符串。
|
||||
|
||||
为什么不放到运行时用 `Command(['xacro ', ...])`:URDF 里的网格路径是
|
||||
`$(env SENTRY_SIM_SHARE)/meshes/*.stl`,而本工程不用 ament。
|
||||
这里显式给 xacro 传入这个环境变量,时序上最稳。
|
||||
"""
|
||||
env = dict(os.environ)
|
||||
env['SENTRY_SIM_SHARE'] = str(PKG_SHARE)
|
||||
return subprocess.run(
|
||||
['xacro', str(PKG_SHARE / 'urdf' / 'sentry.urdf.xacro')],
|
||||
env=env, capture_output=True, text=True, check=True).stdout
|
||||
|
||||
|
||||
def _gz_resource_path():
|
||||
"""GZ_SIM_RESOURCE_PATH:本包的 models + 迁移包的 models(可带用户追加的)。"""
|
||||
# 注意冒号分隔符不能漏 —— 漏了会拼成一条不存在的路径,
|
||||
@@ -208,7 +195,7 @@ def generate_launch_description():
|
||||
"'", rviz, "'.lower() in ('true', '1') and '",
|
||||
headless, "'.lower() not in ('true', '1')"])
|
||||
|
||||
robot_description = _robot_description()
|
||||
robot_description = runtime_description(PKG_SHARE)
|
||||
bridge = ExecuteProcess(
|
||||
cmd=[str(SCRIPTS / 'bridge_after_gz.sh')],
|
||||
name='ros_gz_bridge', output='screen',
|
||||
@@ -250,7 +237,7 @@ def generate_launch_description():
|
||||
# ---------------- 参数 ----------------
|
||||
DeclareLaunchArgument(
|
||||
'headless', default_value='false',
|
||||
description='true = 不显示 Gazebo 界面(gz sim -s)'),
|
||||
description='true = Gazebo 服务端使用 EGL 渲染,无界面'),
|
||||
DeclareLaunchArgument(
|
||||
'nav2', default_value='true', description='false = 不起 Nav2'),
|
||||
DeclareLaunchArgument(
|
||||
@@ -274,7 +261,7 @@ def generate_launch_description():
|
||||
'GZ_PARTITION', os.environ.get('GZ_PARTITION') or 'sentry'),
|
||||
SetEnvironmentVariable(
|
||||
'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),
|
||||
|
||||
|
||||
Reference in new issue
Block a user