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
@@ -24,14 +24,8 @@ PKG_SHARE="${SENTRY_SIM_SHARE:-${WS}/src/sentry_sim}"
|
||||
`PKG_SHARE` 直接指向**这个目录本身**。没有 `install/`、没有符号链接、
|
||||
没有 `ros2 pkg prefix` —— 以前那套 ament 安装已经去掉了。
|
||||
|
||||
唯一的例外是 URDF 里引用网格的路径:
|
||||
|
||||
```xml
|
||||
<mesh filename="$(env SENTRY_SIM_SHARE)/meshes/base.stl"/>
|
||||
```
|
||||
|
||||
`scripts/sentry_up.sh` 和 `tools/gen_sdf.sh` 都会自动 `export SENTRY_SIM_SHARE`,
|
||||
你手动跑 `xacro` 时要自己设一下(不设会报 `environment variable 'SENTRY_SIM_SHARE' is not set`)。
|
||||
模型网格以模型文件所在目录为基准。生成的 URDF 也使用以自身目录为基准的相对路径。
|
||||
启动器在将机器人描述交给 ROS 时,才把网格路径解析成 RViz 能读取的 `file://` URI。
|
||||
|
||||
## 改完东西的标准流程
|
||||
|
||||
@@ -86,7 +80,7 @@ cd ~/Gazebo_projects/sentry_nav_dev && scripts/sentry_up.sh
|
||||
|
||||
| 传感器 | 位置/参数 | 话题 |
|
||||
|---|---|---|
|
||||
| 3D 激光雷达(CPU 射线) | 360 线 × 40 层,垂直 -7°~+52°,量程 0.10–12 m,10 Hz,噪声 σ=0.01;装在 `lidar_link`(z≈0.405) | gz `scan` → `/scan`(LaserScan)+ `/scan/points`(PointCloud2,frame=`lidar_link`) |
|
||||
| 3D 激光雷达(OGRE2) | 360 线 × 40 层,垂直 -7°~+52°,量程 0.10–12 m,10 Hz,噪声 σ=0.01;装在 `lidar_link`(z≈0.405) | gz `scan` → `/scan`(LaserScan)+ `/scan/points`(PointCloud2,frame=`lidar_link`) |
|
||||
| 点云自滤 | 剔除车身包围盒内回波 | 输入 `/scan/points` → 输出 `/scan/points_filtered`(frame=`base_link`) |
|
||||
| 2D 激光(定位用) | 由自滤节点从 3D 点云投影:z∈[0.05, 0.50] m、360 格 | `/scan2d`(frame=`base_link`,AMCL / collision_monitor 用) |
|
||||
| IMU | `imu_link`,100 Hz | gz `imu` → `/imu` |
|
||||
@@ -182,15 +176,11 @@ ax_min: -3.5
|
||||
两个都是**只读诊断**,不需要高性能,没有迁移成 C++ 的理由。
|
||||
`launch/sentry_arena.launch.py` 是 ROS launch 系统要求,**没法用 C++**。
|
||||
|
||||
## CPU 忙不过来怎么办(雷达是 CPU 射线)
|
||||
## Gazebo 渲染与物理
|
||||
|
||||
3D 雷达是 `type="lidar"`(CPU 射线),360×40 = **14,400 束/帧 × 10 Hz**,
|
||||
再加 Gazebo 渲染 + RViz,是整台机器最大的 CPU 消耗。可选手段:
|
||||
|
||||
1. **关 RViz**:`RVIZ=0 scripts/sentry_up.sh`(导航不受影响,需要看图时另开 RViz);
|
||||
2. **降低雷达竖直采样**:`urdf/sentry.urdf.xacro` 里 `<vertical><samples>40` 改小(如 24),
|
||||
再 `./tools/gen_sdf.sh`——代价是点云变稀;
|
||||
3. **GPU 辅助**:把传感器换成 `gpu_lidar`(OGRE2 渲染,射线在 GPU 上算)。
|
||||
前提是显卡驱动可用:本机有 RTX 5060 Max-Q,但当前 `nvidia-smi` 连不上驱动(prime on-demand
|
||||
模式下驱动未加载),**先修驱动再谈 GPU 雷达**;修好后把 URDF 换成 gpu_lidar 即可显著降 CPU。
|
||||
场地和车辆网格由 OGRE2 绘制,3D 雷达使用 `gpu_lidar`。无界面启动时,`HEADLESS=1`
|
||||
和 `headless:=true` 都启用 EGL。Gazebo 的渲染器日志可用来确认实际设备,
|
||||
其中 `llvmpipe` 表示 Mesa 软件渲染。
|
||||
|
||||
刚体碰撞、车轮关节和摩擦由 Gazebo 的默认 DART 物理引擎计算。性能对照时同时记录实时因子、
|
||||
CPU 开销和点云频率,并标注渲染设备。
|
||||
@@ -26,7 +26,7 @@ ros2 launch src/sentry_sim/launch/sentry_arena.launch.py --show-args # 看
|
||||
|
||||
| 参数 | 默认 | 说明 |
|
||||
|---|---|---|
|
||||
| `headless` | `false` | `true` = 不显示 Gazebo 界面(`gz sim -s`) |
|
||||
| `headless` | `false` | `true` = 无界面 EGL 渲染(`gz sim -s --headless-rendering`) |
|
||||
| `nav2` | `true` | `false` = 不起 Nav2 |
|
||||
| `rviz` | `true` | `false` = 不起 RViz(`headless:=true` 时自动关) |
|
||||
| `world` | `sentry_arena.sdf` | `worlds/` 下的世界文件名 |
|
||||
|
||||
@@ -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),
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<model>
|
||||
<name>catch_net</name>
|
||||
<version>1.0</version>
|
||||
<sdf version="1.12">model.sdf</sdf>
|
||||
<sdf version="1.11">model.sdf</sdf>
|
||||
<author><name>sentry_nav_dev</name><email>sentry.sim@example.com</email></author>
|
||||
<description>
|
||||
场地周边拦截网(半透明四面围网 + 四角立柱)。高 3.5 m,位于外框外侧 0.25 m。
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
如果哪天不想让激光看见,删掉 collision 段即可(只留 visual)。
|
||||
============================================================================
|
||||
-->
|
||||
<sdf version="1.12">
|
||||
<sdf version="1.11">
|
||||
<model name="catch_net">
|
||||
<static>true</static>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<sdf version='1.11'>
|
||||
<model name='sentry'>
|
||||
<link name='base_link'>
|
||||
<sdf version="1.11">
|
||||
<model name="sentry">
|
||||
<link name="base_link">
|
||||
<inertial>
|
||||
<pose>-0.0011065088757396451 -0.001789349112426035 0.18260591715976329 0 0 0</pose>
|
||||
<mass>25.350000000000001</mass>
|
||||
@@ -13,7 +13,7 @@
|
||||
<izz>1.2710893212169621</izz>
|
||||
</inertia>
|
||||
</inertial>
|
||||
<collision name='base_link_fixed_joint_lump__chassis_collision_collision'>
|
||||
<collision name="base_link_fixed_joint_lump__chassis_collision_collision">
|
||||
<pose>0 0 0.14499999999999999 0 0 0</pose>
|
||||
<geometry>
|
||||
<box>
|
||||
@@ -21,7 +21,7 @@
|
||||
</box>
|
||||
</geometry>
|
||||
</collision>
|
||||
<collision name='base_link_fixed_joint_lump__gimbal_collision_collision_1'>
|
||||
<collision name="base_link_fixed_joint_lump__gimbal_collision_collision_1">
|
||||
<pose>0.12 0 0.375 0 0 0</pose>
|
||||
<geometry>
|
||||
<box>
|
||||
@@ -29,12 +29,12 @@
|
||||
</box>
|
||||
</geometry>
|
||||
</collision>
|
||||
<visual name='base_link_visual'>
|
||||
<visual name="base_link_visual">
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
<geometry>
|
||||
<mesh>
|
||||
<scale>1 1 1</scale>
|
||||
<uri>/home/jelly_candy/VSAG_SENTRY_SIM_27RMUL/src/sentry_sim/meshes/base.stl</uri>
|
||||
<uri>../../meshes/base.stl</uri>
|
||||
</mesh>
|
||||
</geometry>
|
||||
<material>
|
||||
@@ -42,7 +42,7 @@
|
||||
<ambient>0.187500015 0.187500015 0.212500006 1</ambient>
|
||||
</material>
|
||||
</visual>
|
||||
<visual name='base_link_fixed_joint_lump__lidar_link_visual_1'>
|
||||
<visual name="base_link_fixed_joint_lump__lidar_link_visual_1">
|
||||
<pose>-0.0935 -0.1512 0.4052 0 0 0</pose>
|
||||
<geometry>
|
||||
<box>
|
||||
@@ -54,20 +54,20 @@
|
||||
<ambient>0.125 0.3125 0.75000006 1</ambient>
|
||||
</material>
|
||||
</visual>
|
||||
<sensor name='imu' type='imu'>
|
||||
<sensor name="imu" type="imu">
|
||||
<topic>imu</topic>
|
||||
<update_rate>100</update_rate>
|
||||
<always_on>true</always_on>
|
||||
<pose>0 0 0.14999999999999999 0 0 0</pose>
|
||||
<gz_frame_id>imu_link</gz_frame_id>
|
||||
<imu/>
|
||||
<imu />
|
||||
</sensor>
|
||||
<sensor name='lidar' type='lidar'>
|
||||
<sensor name="lidar" type="gpu_lidar">
|
||||
<topic>scan</topic>
|
||||
<update_rate>10</update_rate>
|
||||
<always_on>true</always_on>
|
||||
<visualize>true</visualize>
|
||||
<ray>
|
||||
<lidar>
|
||||
<scan>
|
||||
<horizontal>
|
||||
<samples>360</samples>
|
||||
@@ -92,13 +92,13 @@
|
||||
<mean>0</mean>
|
||||
<stddev>0.01</stddev>
|
||||
</noise>
|
||||
</ray>
|
||||
</lidar>
|
||||
<pose>-0.0935 -0.1512 0.4052 0 0 0</pose>
|
||||
<gz_frame_id>lidar_link</gz_frame_id>
|
||||
</sensor>
|
||||
</link>
|
||||
<joint name='wheel_bl_joint' type='revolute'>
|
||||
<pose relative_to='base_link'>-0.16582 0.21351999999999999 0.076200000000000004 0 0 0</pose>
|
||||
<joint name="wheel_bl_joint" type="revolute">
|
||||
<pose relative_to="base_link">-0.16582 0.21351999999999999 0.076200000000000004 0 0 0</pose>
|
||||
<parent>base_link</parent>
|
||||
<child>wheel_bl</child>
|
||||
<axis>
|
||||
@@ -115,8 +115,8 @@
|
||||
</dynamics>
|
||||
</axis>
|
||||
</joint>
|
||||
<link name='wheel_bl'>
|
||||
<pose relative_to='wheel_bl_joint'>0 0 0 0 0 0</pose>
|
||||
<link name="wheel_bl">
|
||||
<pose relative_to="wheel_bl_joint">0 0 0 0 0 0</pose>
|
||||
<inertial>
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
<mass>1.5</mass>
|
||||
@@ -129,7 +129,7 @@
|
||||
<izz>0.0028453662500000001</izz>
|
||||
</inertia>
|
||||
</inertial>
|
||||
<collision name='wheel_bl_collision'>
|
||||
<collision name="wheel_bl_collision">
|
||||
<pose>0 0 0 1.5708 0 0</pose>
|
||||
<geometry>
|
||||
<cylinder>
|
||||
@@ -139,7 +139,7 @@
|
||||
</geometry>
|
||||
<surface>
|
||||
<contact>
|
||||
<ode/>
|
||||
<ode />
|
||||
</contact>
|
||||
<friction>
|
||||
<ode>
|
||||
@@ -149,12 +149,12 @@
|
||||
</friction>
|
||||
</surface>
|
||||
</collision>
|
||||
<visual name='wheel_bl_visual'>
|
||||
<visual name="wheel_bl_visual">
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
<geometry>
|
||||
<mesh>
|
||||
<scale>1 1 1</scale>
|
||||
<uri>/home/jelly_candy/VSAG_SENTRY_SIM_27RMUL/src/sentry_sim/meshes/wheel.stl</uri>
|
||||
<uri>../../meshes/wheel.stl</uri>
|
||||
</mesh>
|
||||
</geometry>
|
||||
<material>
|
||||
@@ -163,8 +163,8 @@
|
||||
</material>
|
||||
</visual>
|
||||
</link>
|
||||
<joint name='wheel_br_joint' type='revolute'>
|
||||
<pose relative_to='base_link'>-0.16663 -0.21288000000000001 0.076200000000000004 0 0 0</pose>
|
||||
<joint name="wheel_br_joint" type="revolute">
|
||||
<pose relative_to="base_link">-0.16663 -0.21288000000000001 0.076200000000000004 0 0 0</pose>
|
||||
<parent>base_link</parent>
|
||||
<child>wheel_br</child>
|
||||
<axis>
|
||||
@@ -181,8 +181,8 @@
|
||||
</dynamics>
|
||||
</axis>
|
||||
</joint>
|
||||
<link name='wheel_br'>
|
||||
<pose relative_to='wheel_br_joint'>0 0 0 0 0 0</pose>
|
||||
<link name="wheel_br">
|
||||
<pose relative_to="wheel_br_joint">0 0 0 0 0 0</pose>
|
||||
<inertial>
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
<mass>1.5</mass>
|
||||
@@ -195,7 +195,7 @@
|
||||
<izz>0.0028453662500000001</izz>
|
||||
</inertia>
|
||||
</inertial>
|
||||
<collision name='wheel_br_collision'>
|
||||
<collision name="wheel_br_collision">
|
||||
<pose>0 0 0 1.5708 0 0</pose>
|
||||
<geometry>
|
||||
<cylinder>
|
||||
@@ -205,7 +205,7 @@
|
||||
</geometry>
|
||||
<surface>
|
||||
<contact>
|
||||
<ode/>
|
||||
<ode />
|
||||
</contact>
|
||||
<friction>
|
||||
<ode>
|
||||
@@ -215,12 +215,12 @@
|
||||
</friction>
|
||||
</surface>
|
||||
</collision>
|
||||
<visual name='wheel_br_visual'>
|
||||
<visual name="wheel_br_visual">
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
<geometry>
|
||||
<mesh>
|
||||
<scale>1 1 1</scale>
|
||||
<uri>/home/jelly_candy/VSAG_SENTRY_SIM_27RMUL/src/sentry_sim/meshes/wheel.stl</uri>
|
||||
<uri>../../meshes/wheel.stl</uri>
|
||||
</mesh>
|
||||
</geometry>
|
||||
<material>
|
||||
@@ -229,8 +229,8 @@
|
||||
</material>
|
||||
</visual>
|
||||
</link>
|
||||
<joint name='wheel_fl_joint' type='revolute'>
|
||||
<pose relative_to='base_link'>0.16633999999999999 0.21288000000000001 0.076200000000000004 0 0 0</pose>
|
||||
<joint name="wheel_fl_joint" type="revolute">
|
||||
<pose relative_to="base_link">0.16633999999999999 0.21288000000000001 0.076200000000000004 0 0 0</pose>
|
||||
<parent>base_link</parent>
|
||||
<child>wheel_fl</child>
|
||||
<axis>
|
||||
@@ -247,8 +247,8 @@
|
||||
</dynamics>
|
||||
</axis>
|
||||
</joint>
|
||||
<link name='wheel_fl'>
|
||||
<pose relative_to='wheel_fl_joint'>0 0 0 0 0 0</pose>
|
||||
<link name="wheel_fl">
|
||||
<pose relative_to="wheel_fl_joint">0 0 0 0 0 0</pose>
|
||||
<inertial>
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
<mass>1.5</mass>
|
||||
@@ -261,7 +261,7 @@
|
||||
<izz>0.0028453662500000001</izz>
|
||||
</inertia>
|
||||
</inertial>
|
||||
<collision name='wheel_fl_collision'>
|
||||
<collision name="wheel_fl_collision">
|
||||
<pose>0 0 0 1.5708 0 0</pose>
|
||||
<geometry>
|
||||
<cylinder>
|
||||
@@ -271,7 +271,7 @@
|
||||
</geometry>
|
||||
<surface>
|
||||
<contact>
|
||||
<ode/>
|
||||
<ode />
|
||||
</contact>
|
||||
<friction>
|
||||
<ode>
|
||||
@@ -281,12 +281,12 @@
|
||||
</friction>
|
||||
</surface>
|
||||
</collision>
|
||||
<visual name='wheel_fl_visual'>
|
||||
<visual name="wheel_fl_visual">
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
<geometry>
|
||||
<mesh>
|
||||
<scale>1 1 1</scale>
|
||||
<uri>/home/jelly_candy/VSAG_SENTRY_SIM_27RMUL/src/sentry_sim/meshes/wheel.stl</uri>
|
||||
<uri>../../meshes/wheel.stl</uri>
|
||||
</mesh>
|
||||
</geometry>
|
||||
<material>
|
||||
@@ -295,8 +295,8 @@
|
||||
</material>
|
||||
</visual>
|
||||
</link>
|
||||
<joint name='wheel_fr_joint' type='revolute'>
|
||||
<pose relative_to='base_link'>0.16553000000000001 -0.21351999999999999 0.076200000000000004 0 0 0</pose>
|
||||
<joint name="wheel_fr_joint" type="revolute">
|
||||
<pose relative_to="base_link">0.16553000000000001 -0.21351999999999999 0.076200000000000004 0 0 0</pose>
|
||||
<parent>base_link</parent>
|
||||
<child>wheel_fr</child>
|
||||
<axis>
|
||||
@@ -313,8 +313,8 @@
|
||||
</dynamics>
|
||||
</axis>
|
||||
</joint>
|
||||
<link name='wheel_fr'>
|
||||
<pose relative_to='wheel_fr_joint'>0 0 0 0 0 0</pose>
|
||||
<link name="wheel_fr">
|
||||
<pose relative_to="wheel_fr_joint">0 0 0 0 0 0</pose>
|
||||
<inertial>
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
<mass>1.5</mass>
|
||||
@@ -327,7 +327,7 @@
|
||||
<izz>0.0028453662500000001</izz>
|
||||
</inertia>
|
||||
</inertial>
|
||||
<collision name='wheel_fr_collision'>
|
||||
<collision name="wheel_fr_collision">
|
||||
<pose>0 0 0 1.5708 0 0</pose>
|
||||
<geometry>
|
||||
<cylinder>
|
||||
@@ -337,7 +337,7 @@
|
||||
</geometry>
|
||||
<surface>
|
||||
<contact>
|
||||
<ode/>
|
||||
<ode />
|
||||
</contact>
|
||||
<friction>
|
||||
<ode>
|
||||
@@ -347,12 +347,12 @@
|
||||
</friction>
|
||||
</surface>
|
||||
</collision>
|
||||
<visual name='wheel_fr_visual'>
|
||||
<visual name="wheel_fr_visual">
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
<geometry>
|
||||
<mesh>
|
||||
<scale>1 1 1</scale>
|
||||
<uri>/home/jelly_candy/VSAG_SENTRY_SIM_27RMUL/src/sentry_sim/meshes/wheel.stl</uri>
|
||||
<uri>../../meshes/wheel.stl</uri>
|
||||
</mesh>
|
||||
</geometry>
|
||||
<material>
|
||||
@@ -361,7 +361,7 @@
|
||||
</material>
|
||||
</visual>
|
||||
</link>
|
||||
<plugin name='gz::sim::systems::PosePublisher' filename='gz-sim-pose-publisher-system'>
|
||||
<plugin name="gz::sim::systems::PosePublisher" filename="gz-sim-pose-publisher-system">
|
||||
<publish_model_pose>true</publish_model_pose>
|
||||
<publish_link_pose>false</publish_link_pose>
|
||||
<publish_nested_model_pose>false</publish_nested_model_pose>
|
||||
@@ -369,7 +369,7 @@
|
||||
<update_frequency>100</update_frequency>
|
||||
<topic>/evaluation/ground_truth</topic>
|
||||
</plugin>
|
||||
<plugin name='gz::sim::systems::MecanumDrive' filename='gz-sim-mecanum-drive-system'>
|
||||
<plugin name="gz::sim::systems::MecanumDrive" filename="gz-sim-mecanum-drive-system">
|
||||
<front_left_joint>wheel_fl_joint</front_left_joint>
|
||||
<front_right_joint>wheel_fr_joint</front_right_joint>
|
||||
<back_left_joint>wheel_bl_joint</back_left_joint>
|
||||
@@ -383,16 +383,16 @@
|
||||
<odom_publish_frequency>50</odom_publish_frequency>
|
||||
<frame_id>odom</frame_id>
|
||||
</plugin>
|
||||
<frame name='imu_joint' attached_to='base_link'>
|
||||
<frame name="imu_joint" attached_to="base_link">
|
||||
<pose>0 0 0.14999999999999999 0 0 0</pose>
|
||||
</frame>
|
||||
<frame name='imu_link' attached_to='imu_joint'>
|
||||
<frame name="imu_link" attached_to="imu_joint">
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
</frame>
|
||||
<frame name='lidar_joint' attached_to='base_link'>
|
||||
<frame name="lidar_joint" attached_to="base_link">
|
||||
<pose>-0.0935 -0.1512 0.4052 0 0 0</pose>
|
||||
</frame>
|
||||
<frame name='lidar_link' attached_to='lidar_joint'>
|
||||
<frame name="lidar_link" attached_to="lidar_joint">
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
</frame>
|
||||
</model>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<model>
|
||||
<name>test_box</name>
|
||||
<version>1.0</version>
|
||||
<sdf version="1.12">model.sdf</sdf>
|
||||
<sdf version="1.11">model.sdf</sdf>
|
||||
<author><name>sentry_nav_dev</name><email>sentry.sim@example.com</email></author>
|
||||
<description>避障测试用的障碍箱(0.5×0.5×0.6 m)</description>
|
||||
</model>
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0"?>
|
||||
<sdf version="1.12">
|
||||
<sdf version="1.11">
|
||||
<model name="test_box">
|
||||
<static>true</static>
|
||||
<link name="box_link">
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
| `cmd_vel_relay.py` ~~已迁移~~ | 原 Python 版已删除;现用 `build/bin/cmd_vel_relay`(C++,源码 `src/sentry_nav/src/cmd_vel_relay.cpp`)。把 `/cmd_vel` 改名转发到 `/model/sentry/cmd_vel` |
|
||||
| (内联于 `sentry_up.sh`) | `build/bin/self_filter`:点云自滤 + 从点云投影出 `/scan2d`,Nav2 避障和 AMCL 都依赖它(xmake 产物,不是 `ros2 run`) |
|
||||
| (内联于 `sentry_up.sh`) | `map`→`field` **恒等变换**:世界和地图都已整体平移过,`map` 本身就以场地中心为原点,`field` 只是给决策代码用的别名 |
|
||||
| `spawn_robot.sh` | 用 URDF 动态生成实体(当前方案用世界 include,本脚本备用) |
|
||||
| `spawn_robot.sh` | 用生成的 SDF 动态加载实体(当前方案用世界 include,本脚本备用) |
|
||||
|
||||
## 为什么这么绕
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
| 变量 | 默认 | 说明 |
|
||||
|---|---|---|
|
||||
| `HEADLESS` | `0` | `1` = 无界面(`gz sim -s`),服务器/只想看数据时用 |
|
||||
| `HEADLESS` | `0` | `1` = 无界面 EGL 渲染(`gz sim -s --headless-rendering`),服务器/只想看数据时用 |
|
||||
| `NAV2` | `1` | `0` = 不起 Nav2 |
|
||||
| `RVIZ` | `1` | `0` = 不起 RViz |
|
||||
| `ROS_DOMAIN_ID` | `0` | 两个终端必须一致才能互相看到话题 |
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
# 用「系统安装的 Gazebo」启动仿真,绕开 ROS vendor 版 gz 的库路径污染。
|
||||
#
|
||||
# 为什么需要这个包装脚本:
|
||||
# source 过 ROS 2 之后,LD_LIBRARY_PATH 会指向 <ros 前缀>/opt/gz_*_vendor/lib,
|
||||
# 此时连系统版 gz 也会去加载 vendor 的 gz-sim 库,而 vendor 那份**没有
|
||||
# cpu-lidar 系统插件**,导致雷达传感器创建失败(世界加载了,但 /scan 一条都没有)。
|
||||
# 所以这里清掉 LD_LIBRARY_PATH 再调 gz。
|
||||
# source ROS 2 后,LD_LIBRARY_PATH 可能优先加载 vendor 版 Gazebo
|
||||
# 库。清掉它,让系统 gz 使用与自身匹配的仿真和渲染插件。
|
||||
#
|
||||
# gz 可执行文件的路径**不写死**:由 env_common.sh 探测(优先 /usr/bin/gz,
|
||||
# 其次 /usr/local/bin/gz、$PATH 上的 gz),也可以用 GZ_BIN=<路径> 强制指定。
|
||||
|
||||
@@ -63,6 +63,10 @@ fi
|
||||
HEADLESS="${HEADLESS:-0}"
|
||||
NAV2="${NAV2:-1}"
|
||||
RVIZ="${RVIZ:-1}"
|
||||
GZ_ARGS=("${GZ_VER_ARGS[@]}" -r)
|
||||
if [ "$HEADLESS" = "1" ]; then
|
||||
GZ_ARGS=(-s --headless-rendering "${GZ_ARGS[@]}")
|
||||
fi
|
||||
|
||||
# Use exactly the same defaults as the Python launch entry point.
|
||||
eval "$(python3 "$INTERNAL_TOOLS/dds_environment.py" --shell)"
|
||||
@@ -87,6 +91,7 @@ if [ "${SENTRY_DRY_RUN:-0}" != "0" ]; then
|
||||
echo " NAV_BIN_DIR = $NAV_BIN_DIR"
|
||||
echo " GZ_EXE = $GZ_EXE"
|
||||
echo " GZ 版本参数 = ${GZ_VER_ARGS[*]:-<无>}"
|
||||
echo " GZ 启动参数 = ${GZ_ARGS[*]}"
|
||||
echo " FIELD_ROOT = $FIELD_ROOT"
|
||||
echo " MAP_YAML = $MAP_YAML"
|
||||
echo " LIO_MAP = $LIO_MAP"
|
||||
@@ -148,6 +153,7 @@ fi
|
||||
WORLD="${PKG_SHARE}/worlds/sentry_arena.sdf"
|
||||
PIDS=()
|
||||
CLEANED=0
|
||||
ROBOT_PARAMS_DIR=""
|
||||
|
||||
# 递归列出某进程的全部后代,**子在前、父在后**(正好是 kill 的顺序)。
|
||||
# 用 pgrep -P 按「真实父 PID」匹配,不是按命令行字符串匹配 —— 绝不会误匹配到自己。
|
||||
@@ -170,6 +176,9 @@ cleanup() {
|
||||
[ "$CLEANED" = "1" ] && return 0
|
||||
CLEANED=1
|
||||
echo "[sentry_up] 收尾..."
|
||||
if [ -n "$ROBOT_PARAMS_DIR" ]; then
|
||||
rm -rf -- "$ROBOT_PARAMS_DIR"
|
||||
fi
|
||||
|
||||
local all=() p d
|
||||
for p in "${PIDS[@]}"; do
|
||||
@@ -214,10 +223,6 @@ fi
|
||||
# ---------- 1. Gazebo(系统版,清掉 ROS vendor 的库路径)----------
|
||||
# --force-version 的大版本号是**探测出来的**(env_gz_version_args):
|
||||
# 换了 Gazebo 大版本不用改脚本;想强制指定就 GZ_FORCE_VERSION=11。
|
||||
GZ_ARGS=("${GZ_VER_ARGS[@]}" -r)
|
||||
if [ "$HEADLESS" = "1" ]; then
|
||||
GZ_ARGS=(-s "${GZ_VER_ARGS[@]}" -r)
|
||||
fi
|
||||
echo "[sentry_up] 启动 Gazebo: ${GZ_EXE} sim ${GZ_ARGS[*]} ${WORLD}"
|
||||
env -u LD_LIBRARY_PATH "$GZ_EXE" sim "${GZ_ARGS[@]}" "${WORLD}" &
|
||||
GZ_PID=$!
|
||||
@@ -243,19 +248,14 @@ PIDS+=($!)
|
||||
|
||||
# ---------- 4. robot_state_publisher(TF 树)----------
|
||||
echo "[sentry_up] 启动 robot_state_publisher"
|
||||
# XML must be passed as a typed string; CLI YAML parsing breaks on XML comments.
|
||||
runtime_dir="${SENTRY_RUNTIME_DIR:-${WS}/generated}"
|
||||
mkdir -p "$runtime_dir"
|
||||
xacro "${PKG_SHARE}/urdf/sentry.urdf.xacro" > "$runtime_dir/robot_description.urdf"
|
||||
python3 - "$runtime_dir/robot_description.urdf" "$runtime_dir/robot_state_publisher.json" <<'PY_PARAMS'
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
text = Path(sys.argv[1]).read_text()
|
||||
Path(sys.argv[2]).write_text(json.dumps({'robot_state_publisher': {'ros__parameters': {'robot_description': text, 'use_sim_time': True}}}))
|
||||
PY_PARAMS
|
||||
# RViz resolves meshes from the runtime description's file URIs.
|
||||
runtime_dir="${SENTRY_RUNTIME_DIR:-${TMPDIR:-/tmp}}"
|
||||
mkdir -p -- "$runtime_dir"
|
||||
ROBOT_PARAMS_DIR="$(mktemp -d "$runtime_dir/sentry-robot.XXXXXXXX")"
|
||||
python3 "$INTERNAL_TOOLS/robot_description.py" runtime-params "$PKG_SHARE" \
|
||||
"$ROBOT_PARAMS_DIR/robot_state_publisher.json"
|
||||
ros2 run robot_state_publisher robot_state_publisher --ros-args \
|
||||
--params-file "$runtime_dir/robot_state_publisher.json" &
|
||||
--params-file "$ROBOT_PARAMS_DIR/robot_state_publisher.json" &
|
||||
PIDS+=($!)
|
||||
|
||||
# ---------- 5. odom -> base_link ----------
|
||||
|
||||
@@ -1,24 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
# 等 Gazebo 就绪后,用 URDF 在场地里生成哨兵。
|
||||
#
|
||||
# 为什么单独一个脚本:xacro 要先展开成 .urdf 文件,Gazebo 的 create 服务只认文件路径;
|
||||
# 而且必须等 gz server 起来(launch 里用 TimerAction 延迟调用本脚本)。
|
||||
# 在已启动的 Gazebo 世界中加载仓库生成的 SDF 模型。
|
||||
set -e
|
||||
|
||||
# 数据包直接用源码目录(本工程不使用 ament/colcon,没有 ros2 pkg prefix)
|
||||
WS="$(cd -- "$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")/../../.." && pwd)"
|
||||
pkg_share="${SENTRY_SIM_SHARE:-${WS}/src/sentry_sim}"
|
||||
export SENTRY_SIM_SHARE="$pkg_share"
|
||||
cache_dir="${HOME}/.cache/sentry_sim"
|
||||
mkdir -p "$cache_dir"
|
||||
urdf_file="${cache_dir}/sentry_robot.urdf"
|
||||
model_file="$pkg_share/models/sentry/model.sdf"
|
||||
|
||||
# shellcheck source=./env_common.sh
|
||||
. "${pkg_share}/scripts/env_common.sh"
|
||||
env_source_ros 2>/dev/null || true
|
||||
|
||||
echo "[spawn_robot] 展开 xacro -> ${urdf_file}"
|
||||
xacro "${pkg_share}/urdf/sentry.urdf.xacro" > "$urdf_file"
|
||||
env_source_ros
|
||||
if [ ! -f "$model_file" ]; then
|
||||
echo "[spawn_robot] 找不到模型:$model_file" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ⚠️ 默认出生点必须和这两处保持一致(三处不同步,车一启动就"在别处"):
|
||||
# worlds/sentry_arena.sdf 里 sentry 的 <pose>
|
||||
@@ -29,7 +23,7 @@ SPAWN_Y="${SPAWN_Y:-3.0}"
|
||||
echo "[spawn_robot] 生成实体(world=rmul_arena, x=${SPAWN_X}, y=${SPAWN_Y})"
|
||||
ros2 run ros_gz_sim create \
|
||||
-name sentry \
|
||||
-file "$urdf_file" \
|
||||
-file "$model_file" \
|
||||
-x "${SPAWN_X}" \
|
||||
-y "${SPAWN_Y}" \
|
||||
-z "${SPAWN_Z:-0.02}"
|
||||
@@ -37,6 +37,5 @@ cd ~/Gazebo_projects/sentry_nav_dev
|
||||
scripts/sentry_up.sh # 重启仿真(数据包不用编译)
|
||||
```
|
||||
|
||||
> 要点:本工程不使用 ament/colcon,URDF 里的网格路径写成
|
||||
> `$(env SENTRY_SIM_SHARE)/meshes/*.stl`,`gen_sdf.sh` 会自动设置该变量。
|
||||
> 手动跑 `xacro` 时记得自己 `export SENTRY_SIM_SHARE=<仓库>/src/sentry_sim`。
|
||||
网格路径通过 xacro 的 `mesh_prefix` 参数设置。生成器分别按 URDF 和 SDF 所在目录填写相对引用。
|
||||
启动器在发布 ROS 机器人描述时为 RViz 解析网格 URI。
|
||||
@@ -15,14 +15,12 @@
|
||||
- 轮子质量 1.5 kg
|
||||
- 雷达安装位置(本装配体里没有雷达模型,位置未知)
|
||||
|
||||
⚠️ 网格路径用 `$(env SENTRY_SIM_SHARE)`,**不是** `$(find sentry_sim)`:
|
||||
本工程不使用 ament/colcon,没有资源索引,xacro 的 `$(find pkg)` 查不到包。
|
||||
展开前必须设好环境变量,例如
|
||||
export SENTRY_SIM_SHARE=~/Gazebo_projects/sentry_nav_dev/src/sentry_sim
|
||||
(`tools/gen_sdf.sh` 和 `scripts/sentry_up.sh` 都会自动设置。)
|
||||
mesh_prefix 默认以本 xacro 文件所在目录为基准,各调用方可指定自己的资源基准。
|
||||
-->
|
||||
<robot name="sentry" xmlns:xacro="http://www.ros.org/wiki/xacro">
|
||||
|
||||
<xacro:arg name="mesh_prefix" default="../meshes"/>
|
||||
|
||||
<!-- ================= 参数区 ================= -->
|
||||
<xacro:property name="wheel_radius" value="0.0762"/>
|
||||
<xacro:property name="wheel_width" value="0.0731"/>
|
||||
@@ -42,10 +40,7 @@
|
||||
<xacro:property name="body_mass" value="25.0"/>
|
||||
<xacro:property name="wheel_mass" value="1.5"/>
|
||||
|
||||
<!-- 雷达 = MID-360 的实际安装位置(装配体实测:ROS xyz=(-0.0935, -0.1512, 0.4052))。
|
||||
⚠️ 仿真里目前用 2D 单层扫描代替 MID-360(真机是 3D 激光,含竖直方向 7 线);
|
||||
该高度 0.405 m 略低于场地围挡 0.42 m,射线擦着围挡上沿走,因此避障数据质量一般,
|
||||
导航阶段用静态地图兜底。等需要 3D 点云时再换 gpu_lidar + vertical 通道。 -->
|
||||
<!-- MID-360 安装位置,装配体实测 ROS xyz=(-0.0935, -0.1512, 0.4052)。 -->
|
||||
<xacro:property name="lidar_x" value="-0.0935"/>
|
||||
<xacro:property name="lidar_y" value="-0.1512"/>
|
||||
<xacro:property name="lidar_z" value="0.4052"/>
|
||||
@@ -58,7 +53,7 @@
|
||||
<visual>
|
||||
<origin xyz="0 0 0" rpy="0 0 0"/>
|
||||
<geometry>
|
||||
<mesh filename="$(env SENTRY_SIM_SHARE)/meshes/base.stl"/>
|
||||
<mesh filename="$(arg mesh_prefix)/base.stl"/>
|
||||
</geometry>
|
||||
<material name="dark_gray"/>
|
||||
</visual>
|
||||
@@ -98,7 +93,7 @@
|
||||
<visual>
|
||||
<origin xyz="0 0 0" rpy="0 0 0"/>
|
||||
<geometry>
|
||||
<mesh filename="$(env SENTRY_SIM_SHARE)/meshes/wheel.stl"/>
|
||||
<mesh filename="$(arg mesh_prefix)/wheel.stl"/>
|
||||
</geometry>
|
||||
<material name="dark_gray"/>
|
||||
</visual>
|
||||
@@ -200,16 +195,16 @@
|
||||
</plugin>
|
||||
</gazebo>
|
||||
|
||||
<!-- 2D 激光雷达(PLACEHOLDER:type="lidar" 走 CPU 射线,不依赖 GPU) -->
|
||||
<!-- 3D 雷达由世界的 OGRE2 Sensors 系统渲染。 -->
|
||||
<gazebo reference="lidar_link">
|
||||
<sensor name="lidar" type="lidar">
|
||||
<sensor name="lidar" type="gpu_lidar">
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
<topic>scan</topic>
|
||||
<gz_frame_id>lidar_link</gz_frame_id>
|
||||
<update_rate>10</update_rate>
|
||||
<always_on>true</always_on>
|
||||
<visualize>true</visualize>
|
||||
<ray>
|
||||
<lidar>
|
||||
<scan>
|
||||
<horizontal>
|
||||
<samples>360</samples>
|
||||
@@ -217,13 +212,7 @@
|
||||
<min_angle>-3.14159265</min_angle>
|
||||
<max_angle>3.14159265</max_angle>
|
||||
</horizontal>
|
||||
<!-- 垂直 FOV:2026-11-16 改成真机 MID-360 规格 -7° ~ +52°(59°),40 线。
|
||||
原来用的是对称 ±15° / 16 线,理由是"抬头看天没用"。
|
||||
改成真机规格的原因:体育馆有 10 m 高的天花板,
|
||||
+52° 时 12 m 处能到 15.8 m,10 m 天花板在 7.5 m 处就能打到 ——
|
||||
这样场地外壳才能真正干扰点云,环境不再是"露天理想场"。
|
||||
代价:点数 360x16=5760 → 360x40=14400(×2.5),CPU 负载上升;
|
||||
最近的地面环从 1.51 m 外移到 3.30 m(-7° 比 -15° 平)。 -->
|
||||
<!-- 垂直 FOV 对应 MID-360 的 -7° 至 +52°,共 40 线。 -->
|
||||
<vertical>
|
||||
<samples>40</samples>
|
||||
<resolution>1</resolution>
|
||||
@@ -241,7 +230,7 @@
|
||||
<mean>0.0</mean>
|
||||
<stddev>0.01</stddev>
|
||||
</noise>
|
||||
</ray>
|
||||
</lidar>
|
||||
</sensor>
|
||||
</gazebo>
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
## 其它内容
|
||||
|
||||
- 插件:Physics / UserCommands / SceneBroadcaster / **CpuLidar** / Imu
|
||||
- 插件:Physics / UserCommands / SceneBroadcaster / Sensors(OGRE2)/ Imu
|
||||
- 世界坐标已整体平移 (−6,−4):**场地中心 = 世界原点 (0,0)**,内场范围
|
||||
x[−6,6] y[−4,4];地图 `rmul_2027.yaml` 的 origin 同步改为 (−6.4,−4.4),
|
||||
保证 2D 栅格图与 AMCL/世界坐标系一致
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" ?>
|
||||
<sdf version="1.11">
|
||||
<!-- 开发用世界:RMUL 2027 场地 + 哨兵(URDF 由 create 服务生成)
|
||||
场地模型来自 ~/Gazebo_projects/RMUL2027_map_transfer_20261016_STEP_R1
|
||||
<!-- 开发用世界:RMUL 2027 场地 + 哨兵。
|
||||
场地模型由启动入口从仓库或 SENTRY_FIELD_ROOT 发现。
|
||||
运行需 GZ_SIM_RESOURCE_PATH 包含:
|
||||
<迁移包>/src/guodong_sentry_sim/models
|
||||
|
||||
@@ -20,8 +20,9 @@
|
||||
<plugin filename="gz-sim-physics-system" name="gz::sim::systems::Physics" />
|
||||
<plugin filename="gz-sim-user-commands-system" name="gz::sim::systems::UserCommands" />
|
||||
<plugin filename="gz-sim-scene-broadcaster-system" name="gz::sim::systems::SceneBroadcaster" />
|
||||
<!-- CPU 雷达不依赖渲染,无 GPU 的 headless 环境也能出数据 -->
|
||||
<plugin filename="gz-sim-cpu-lidar-system" name="gz::sim::systems::CpuLidar" />
|
||||
<plugin filename="gz-sim-sensors-system" name="gz::sim::systems::Sensors">
|
||||
<render_engine>ogre2</render_engine>
|
||||
</plugin>
|
||||
<plugin filename="gz-sim-imu-system" name="gz::sim::systems::Imu" />
|
||||
|
||||
<scene>
|
||||
|
||||
Reference in new issue
Block a user