修改功能包分布和整合launch
This commit is contained in:
+63
-25
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
当前使用 Ubuntu 22.04、ROS 2 Humble、Gazebo Classic 11.10.2。
|
当前使用 Ubuntu 22.04、ROS 2 Humble、Gazebo Classic 11.10.2。
|
||||||
完整场地以 `src/robocon_gazebo` 为准,复用仓库现有 SCAN 规划器和闭环控制器。
|
完整场地以 `src/robocon_gazebo` 为准,复用仓库现有 SCAN 规划器和闭环控制器。
|
||||||
Gazebo、导航与可选 RViz 均可在笔记本运行;双机预备入口另见下文。
|
Gazebo、导航与 RViz 均可在笔记本运行;也可按功能分别启动。
|
||||||
|
|
||||||
第一次使用请先读 **[仿真使用与实车迁移指南](docs/USER_GUIDE.md)**:包含手动发目标、
|
第一次使用请先读 **[仿真使用与实车迁移指南](docs/USER_GUIDE.md)**:包含手动发目标、
|
||||||
带窗口自动测试、关闭重启、常见问题,以及共用代码如何分阶段迁移到实车。
|
带窗口自动测试、关闭重启、常见问题,以及共用代码如何分阶段迁移到实车。
|
||||||
@@ -18,6 +18,30 @@ flowchart LR
|
|||||||
G -. 独立真值评分 .-> T[验收工具]
|
G -. 独立真值评分 .-> T[验收工具]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 先看懂功能包与文件归属
|
||||||
|
|
||||||
|
这套平地导航仿真由五个独立入口组成。`sim_ws/src` 放场地、机器人和仿真启动配置;
|
||||||
|
`minco_ws/src` 放复用的定位、规划算法。系统安装的 ROS 2、Gazebo、RViz 等依赖不在这两个源码目录中。
|
||||||
|
日常只需按下文从仓库根目录构建,再 `source sim_ws/install/classic/setup.bash`,无需分别启动两个工作空间。
|
||||||
|
|
||||||
|
| 顺序 | 独立启动命令中的功能包与 launch | 实际调用的主要程序或 launch | 源码归属 |
|
||||||
|
|---|---|---|---|
|
||||||
|
| 1 场地 | `robocon_gazebo robocon_gazebo.launch.py` | 系统包 `gazebo_ros` 的 `gzserver.launch.py`;开启窗口时还有 `gzclient.launch.py` | `sim_ws/src/robocon_gazebo/` |
|
||||||
|
| 2 机器人 | `r2027_robot_description robocon_robot.launch.py` | 本包的 `spawn_existing_world.py` 生成实体、`cmd_vel_timeout.py` 保护停车,另有 TF 节点;底盘插件由 Gazebo 加载 | `sim_ws/src/r2027_robot_description/` |
|
||||||
|
| 3 传感器 | `r2027_robot_description mid360_sensors.launch.py` | 本包的 `mid360_control.py` 启用并维持机器人上的 MID360、IMU 插件采样 | `sim_ws/src/r2027_robot_description/` |
|
||||||
|
| 4 导航 | `br_sim_bringup scan_lio_navigation.launch.py` | `point_lio` 的 `pointlio_mapping`、本包的 `lio_navigation_adapter.py`、`scan_planner` 的 `scan_planner_node` 和 `closed_loop_controller` | 入口和适配器在 `sim_ws/src/br_sim_bringup/`;算法在 `minco_ws/src/` |
|
||||||
|
| 5 显示 | `br_sim_bringup rviz.launch.py` | 系统包 `rviz2` 的 `rviz2`,载入本工程的显示配置 | launch 和配置在 `sim_ws/src/br_sim_bringup/` |
|
||||||
|
|
||||||
|
模型和传感器代码的位置:
|
||||||
|
|
||||||
|
- **场地模型**:默认场景是 [`src/robocon_gazebo/worlds/robocon_robot.world`](src/robocon_gazebo/worlds/robocon_robot.world),引用 [`src/robocon_gazebo/models/robocon_ground_full/model.sdf`](src/robocon_gazebo/models/robocon_ground_full/model.sdf);网格在同一模型目录的 `meshes/`。
|
||||||
|
- **机器人模型**:外形、底盘、传感器安装位置和插件声明在 [`src/r2027_robot_description/sdf/r2027_omni_robot.sdf.xacro`](src/r2027_robot_description/sdf/r2027_omni_robot.sdf.xacro)。机器人入口展开该文件,再向已运行的 Gazebo 生成实体。
|
||||||
|
- **传感器仿真**:MID360 与 IMU 插件源码分别是 [`mid360_sensor.cpp`](src/r2027_robot_description/src/mid360_sensor.cpp) 和 [`mid360_imu.cpp`](src/r2027_robot_description/src/mid360_imu.cpp),噪声档位在 [`sensor_profiles.yaml`](src/r2027_robot_description/config/sensor_profiles.yaml)。插件随机器人实体装入 Gazebo,初始不采样;第三个入口负责启用和维持采样。`minco_ws/src/perception/livox_ros_driver2/` 提供点云使用的 Livox 消息类型,并非这里的传感器仿真程序。
|
||||||
|
- **定位与规划**:Point-LIO 源码在 `minco_ws/src/perception/Point-LIO/`;SCAN 规划器、控制器及其依赖在 `minco_ws/src/scan/`。本仿真的算法参数在 `src/br_sim_bringup/config/`,RViz 配置在 [`src/br_sim_bringup/rviz/scan_lio.rviz`](src/br_sim_bringup/rviz/scan_lio.rviz)。
|
||||||
|
|
||||||
|
这些是**五个运行入口,并非五个独立 ROS 功能包**:机器人和传感器共用一个包,导航组合与 RViz 配置也共用一个包。
|
||||||
|
一键入口 `ros2 launch br_sim_bringup scan_lio.launch.py` 会组合这五层;分别启动的命令见下文。
|
||||||
|
|
||||||
## 当前状态
|
## 当前状态
|
||||||
|
|
||||||
- P1 场地:完整地图已导入;8 个接触抽样跨轮次通过。
|
- P1 场地:完整地图已导入;8 个接触抽样跨轮次通过。
|
||||||
@@ -35,11 +59,13 @@ flowchart LR
|
|||||||
|
|
||||||
## 启动
|
## 启动
|
||||||
|
|
||||||
工作目录为仓库根目录。本机已具备 Ubuntu 22.04 / ROS 2 Humble、Gazebo Classic 11、
|
在**仓库根目录**执行。首次使用先运行 `bash sim_ws/tools/build_sim.sh`;脚本会构建
|
||||||
`gazebo_ros_pkgs`、xacro、PCL/pcl_conversions、Eigen、glog、colcon、系统 Python 3.10 与 numpy/yaml。
|
`sim_ws/src` 的仿真包,以及 `minco_ws/src` 中复用的 Point-LIO、SCAN 等依赖。
|
||||||
构建脚本只构建源码,不安装系统依赖,不安装真实雷达 SDK。首次运行
|
本机环境为 Ubuntu 22.04、ROS 2 Humble 和 Gazebo Classic 11。
|
||||||
`bash sim_ws/tools/build_sim.sh`,默认两路编译,可用 `BR_SIM_BUILD_JOBS` 调整。
|
|
||||||
推荐估计导航入口:
|
### 一键启动五层
|
||||||
|
|
||||||
|
以下命令依次启动场地、机器人、MID360/IMU、Point-LIO + SCAN,以及预设好的 RViz:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
source /opt/ros/humble/setup.bash
|
source /opt/ros/humble/setup.bash
|
||||||
@@ -49,21 +75,37 @@ export GAZEBO_MASTER_URI=http://127.0.0.1:11355
|
|||||||
ros2 launch br_sim_bringup scan_lio.launch.py
|
ros2 launch br_sim_bringup scan_lio.launch.py
|
||||||
```
|
```
|
||||||
|
|
||||||
`gui:=false` 可无界面运行。与实车节点、其他仿真互斥运行;一个入口只起一个 server。
|
默认同时打开 Gazebo 和 RViz。RViz 的 Fixed Frame 已设为 `world`,显示 MID360 原始点云、
|
||||||
另开终端时,重复 source 和上述环境设置。
|
配准点云和 TF;规划点云可在 Displays 中开启。场地加载和定位初始化需要数秒,点云不会在
|
||||||
关闭整套仿真时,在启动终端按 Ctrl+C,等待终端返回命令提示符后再重新启动。
|
RViz 窗口出现的瞬间就显示。不打开 Gazebo 窗口用 `gui:=false`;不打开 RViz 用
|
||||||
GUI 模式现在正常关闭 Gazebo 窗口也会联动退出整套程序;无界面模式仍从启动终端退出。
|
`with_rviz:=false`;两项都设为 `false` 可无界面运行。
|
||||||
自动验收工具会自行启动另一套仿真,不能与手动 launch 同时运行;中途 Ctrl+C 会清理本轮进程,
|
|
||||||
中断记录不算测试通过。若提示“11355 已被占用”,先结束仍运行的仿真/自动测试;查看占用者:
|
### 分五个终端启动
|
||||||
|
|
||||||
|
每个终端都先执行上面四行 `source` / `export`,然后按顺序各执行一行:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
ss -ltnp 'sport = :11355'
|
# 1. 场地:唯一 Gazebo server、/clock 与实体生成服务
|
||||||
|
ros2 launch robocon_gazebo robocon_gazebo.launch.py
|
||||||
|
# 2. 机器人:生成实体、运动插件、命令保护与 TF
|
||||||
|
ros2 launch r2027_robot_description robocon_robot.launch.py drive:=contact z:=0.15
|
||||||
|
# 3. MID360 与 IMU:可用 ideal、mild 或 stress 档位
|
||||||
|
ros2 launch r2027_robot_description mid360_sensors.launch.py sensor_profile:=ideal
|
||||||
|
# 4. Point-LIO、坐标适配、SCAN 与闭环控制
|
||||||
|
ros2 launch br_sim_bringup scan_lio_navigation.launch.py
|
||||||
|
# 5. 只启动带预设配置的 RViz,不重复启动仿真或算法
|
||||||
|
ros2 launch br_sim_bringup rviz.launch.py
|
||||||
```
|
```
|
||||||
|
|
||||||
启动入口不会自动杀掉占用端口的其他进程。中断清理与重复启动修复的证据见
|
关闭时按 RViz → 导航 → 传感器 → 机器人 → 场地的顺序,在各自终端按 Ctrl+C。
|
||||||
[RESTART.md](docs/RESTART.md)。
|
关闭机器人 launch 不会删除 Gazebo 中的实体;要重新生成机器人,先关闭场地并重启整套。
|
||||||
|
传感器 launch 可单独重启换档位,退出后停止发布,意外退出时最多约 1 秒停止。
|
||||||
|
|
||||||
目标下发、RViz 配置、从源码构建与验收命令见 [导航说明](docs/P3_P4_NAVIGATION.md)。
|
一键入口与五个独立入口**不要同时运行**,自动验收工具也会自行启动一套仿真。
|
||||||
|
若端口已被占用,先结束原仿真;可用 `ss -ltnp 'sport = :11355'` 查看。
|
||||||
|
入口不会自动终止其他进程。关闭与重启细节见 [RESTART.md](docs/RESTART.md)。
|
||||||
|
|
||||||
|
目标下发、从源码构建与验收命令见 [导航说明](docs/P3_P4_NAVIGATION.md)。
|
||||||
推荐入口使用 MID360/IMU 与原 Point-LIO,只接受固定已知起点先验;等待感知就绪后发目标。
|
推荐入口使用 MID360/IMU 与原 Point-LIO,只接受固定已知起点先验;等待感知就绪后发目标。
|
||||||
另一终端重复上面的 source/export,观察 `ros2 topic echo /planning/perception_ready` 输出为 `data: true`,
|
另一终端重复上面的 source/export,观察 `ros2 topic echo /planning/perception_ready` 输出为 `data: true`,
|
||||||
再发默认起点附近已验收的直达目标:
|
再发默认起点附近已验收的直达目标:
|
||||||
@@ -93,17 +135,11 @@ ros2 topic echo /planning/trajectory_status --qos-durability transient_local
|
|||||||
等感知就绪后下发三维参考路径;路径命令、4 cm 专用裕度和物理边界见 [LIO 坡道说明](docs/P6_LIO_TERRAIN.md)。
|
等感知就绪后下发三维参考路径;路径命令、4 cm 专用裕度和物理边界见 [LIO 坡道说明](docs/P6_LIO_TERRAIN.md)。
|
||||||
原真值平地/坡道入口 `scan_sim.launch.py`、`scan_terrain.launch.py` 保留作对照。
|
原真值平地/坡道入口 `scan_sim.launch.py`、`scan_terrain.launch.py` 保留作对照。
|
||||||
|
|
||||||
其他入口:
|
其他完整入口:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 场地单独运行
|
|
||||||
ros2 launch robocon_gazebo robocon_gazebo.launch.py
|
|
||||||
# 机器人与雷达,不启动导航
|
|
||||||
ros2 launch r2027_robot_description robocon_robot.launch.py lidar:=true
|
|
||||||
# MID360 兼容传感器 + 原 Point-LIO(暂不启动 SCAN)
|
# MID360 兼容传感器 + 原 Point-LIO(暂不启动 SCAN)
|
||||||
ros2 launch br_sim_bringup mid360_sim.launch.py with_lio:=true
|
ros2 launch br_sim_bringup mid360_sim.launch.py with_lio:=true
|
||||||
# MID360 + 原 Point-LIO + SCAN 平地闭环(已知起点先验,独立于真值入口)
|
|
||||||
ros2 launch br_sim_bringup scan_lio.launch.py
|
|
||||||
# MID360 + Point-LIO + SCAN 指定坡道三维参考路径(独立低速配置)
|
# MID360 + Point-LIO + SCAN 指定坡道三维参考路径(独立低速配置)
|
||||||
ros2 launch br_sim_bringup scan_lio_terrain.launch.py
|
ros2 launch br_sim_bringup scan_lio_terrain.launch.py
|
||||||
```
|
```
|
||||||
@@ -113,7 +149,7 @@ P6 扫描图案是近似,默认 ideal 无注入噪声,可选 mild/stress 工
|
|||||||
接口、构建与误差见 [P6 定位说明](docs/P6_LOCALIZATION.md)。
|
接口、构建与误差见 [P6 定位说明](docs/P6_LOCALIZATION.md)。
|
||||||
估计导航的坐标转换、已知起点、失效停车和实测证据见 [P6 导航说明](docs/P6_NAVIGATION.md)。
|
估计导航的坐标转换、已知起点、失效停车和实测证据见 [P6 导航说明](docs/P6_NAVIGATION.md)。
|
||||||
LIO 坡道路径下发、专用过滤和适用边界见 [P6 坡道说明](docs/P6_LIO_TERRAIN.md)。
|
LIO 坡道路径下发、专用过滤和适用边界见 [P6 坡道说明](docs/P6_LIO_TERRAIN.md)。
|
||||||
所有节点使用仿真时间;机器人/导航入口配置 /clock 100 Hz,场地单独入口保留其基线配置。
|
所有节点使用仿真时间,场地入口发布约 100 Hz 的 `/clock`。
|
||||||
Classic 暂停时不发布新的 /clock,暂停判据和证据见对应验收说明。
|
Classic 暂停时不发布新的 /clock,暂停判据和证据见对应验收说明。
|
||||||
|
|
||||||
## 压力、连续任务与双机入口
|
## 压力、连续任务与双机入口
|
||||||
@@ -141,7 +177,9 @@ Classic 暂停时不发布新的 /clock,暂停判据和证据见对应验收
|
|||||||
|---|---|
|
|---|---|
|
||||||
| `src/robocon_gazebo` | 完整场地、world、来源哈希与场地入口 |
|
| `src/robocon_gazebo` | 完整场地、world、来源哈希与场地入口 |
|
||||||
| `src/r2027_robot_description` | 简化全向车体、雷达、命令超时保护、真值数据适配 |
|
| `src/r2027_robot_description` | 简化全向车体、雷达、命令超时保护、真值数据适配 |
|
||||||
| `src/br_sim_bringup` | SCAN 仿真参数、导航入口、点云过滤和就绪门控 |
|
| `src/br_sim_bringup` | 一键/独立导航入口、RViz 配置、点云过滤和就绪门控 |
|
||||||
|
| `../minco_ws/src/perception/Point-LIO` | 复用的定位源码,由构建脚本安装到 `sim_ws/install/localization` |
|
||||||
|
| `../minco_ws/src/scan` | 复用的 SCAN 源码,由构建脚本安装到 `sim_ws/install/navigation` |
|
||||||
| `tools/check_classic_baseline.py` | 场地资源、时钟、接触抽样验收 |
|
| `tools/check_classic_baseline.py` | 场地资源、时钟、接触抽样验收 |
|
||||||
| `tools/check_omni_robot.py` | 底盘 9 项验收 |
|
| `tools/check_omni_robot.py` | 底盘 9 项验收 |
|
||||||
| `tools/check_sim_lidar.py` | 点云坐标和场地几何检查 |
|
| `tools/check_sim_lidar.py` | 点云坐标和场地几何检查 |
|
||||||
|
|||||||
@@ -17,9 +17,12 @@ source /opt/ros/humble/setup.bash
|
|||||||
source sim_ws/install/classic/setup.bash
|
source sim_ws/install/classic/setup.bash
|
||||||
export ROS_DOMAIN_ID=77 ROS_LOCALHOST_ONLY=0
|
export ROS_DOMAIN_ID=77 ROS_LOCALHOST_ONLY=0
|
||||||
export GAZEBO_MASTER_URI=http://127.0.0.1:11355
|
export GAZEBO_MASTER_URI=http://127.0.0.1:11355
|
||||||
|
ros2 launch robocon_gazebo robocon_gazebo.launch.py
|
||||||
|
# 另一个终端(相同 source/export)
|
||||||
ros2 launch r2027_robot_description robocon_robot.launch.py \
|
ros2 launch r2027_robot_description robocon_robot.launch.py \
|
||||||
lidar:=true sensor_model:=mid360 drive:=contact \
|
lidar:=true sensor_model:=mid360 drive:=contact x:=-4.5 y:=4.5 z:=0.15 yaw:=0.0
|
||||||
x:=-4.5 y:=4.5 z:=0.15 yaw:=0.0 sensor_profile:=ideal
|
# 第三个终端(相同 source/export)
|
||||||
|
ros2 launch r2027_robot_description mid360_sensors.launch.py sensor_profile:=ideal
|
||||||
```
|
```
|
||||||
|
|
||||||
这里只运行场地、机器人、物理雷达/IMU、命令保护与真值观测接口,不运行 Point-LIO/SCAN。
|
这里只运行场地、机器人、物理雷达/IMU、命令保护与真值观测接口,不运行 Point-LIO/SCAN。
|
||||||
@@ -38,11 +41,11 @@ PATH=/usr/bin:$PATH colcon build --base-paths sim_ws/src/br_sim_bringup \
|
|||||||
--install-base sim_ws/install/classic --symlink-install
|
--install-base sim_ws/install/classic --symlink-install
|
||||||
source sim_ws/install/classic/setup.bash
|
source sim_ws/install/classic/setup.bash
|
||||||
export ROS_DOMAIN_ID=77 ROS_LOCALHOST_ONLY=0
|
export ROS_DOMAIN_ID=77 ROS_LOCALHOST_ONLY=0
|
||||||
ros2 launch br_sim_bringup scan_lio.launch.py start_sim:=false \
|
ros2 launch br_sim_bringup scan_lio_navigation.launch.py \
|
||||||
x:=-4.5 y:=4.5 z:=0.15 yaw:=0.0
|
x:=-4.5 y:=4.5 z:=0.15 yaw:=0.0
|
||||||
```
|
```
|
||||||
|
|
||||||
`start_sim:=false` 不查找机器人描述包、不加载 Gazebo、不创建第二个 server。
|
该入口不查找机器人描述包、不加载 Gazebo、不创建第二个 server。
|
||||||
算法只需要 ROS 消息、Point-LIO、SCAN 与 br_sim_bringup 的 launch/脚本资源。
|
算法只需要 ROS 消息、Point-LIO、SCAN 与 br_sim_bringup 的 launch/脚本资源。
|
||||||
此端不需要 Gazebo master 地址,通信通过 ROS 2 DDS。
|
此端不需要 Gazebo master 地址,通信通过 ROS 2 DDS。
|
||||||
实车算法包没有新增 Gazebo 依赖,仿真与实车安装前缀应分别使用。
|
实车算法包没有新增 Gazebo 依赖,仿真与实车安装前缀应分别使用。
|
||||||
|
|||||||
@@ -68,6 +68,21 @@ source 让当前终端找到项目程序和消息;新开终端需要重新执
|
|||||||
ROS 域 77 用于本机仿真,11355 是本项目的 Gazebo master 端口。
|
ROS 域 77 用于本机仿真,11355 是本项目的 Gazebo master 端口。
|
||||||
所有仿真节点使用仿真时间。不要在同一终端混合 source 实车和仿真安装前缀。
|
所有仿真节点使用仿真时间。不要在同一终端混合 source 实车和仿真安装前缀。
|
||||||
|
|
||||||
|
### 2.1 本机实测补充(2026-11-09)
|
||||||
|
|
||||||
|
以下四项在本机复现过,按需在公共环境命令后追加:
|
||||||
|
|
||||||
|
| 现象 | 处理 |
|
||||||
|
|---|---|
|
||||||
|
| 构建时报 `error writing to /tmp/... 设备上没有空间` | `/tmp` 是小 tmpfs:`TMPDIR=$HOME/.cache/colcon-tmp bash sim_ws/tools/build_sim.sh` |
|
||||||
|
| `spawn_entity` 报 `No module named 'numpy'`,或脚本行为异常 | `export PATH=/usr/bin:$PATH`。本机 PATH 中 Python 3.13 排在前面,rclpy/numpy 只装在系统 3.10 下 |
|
||||||
|
| gzserver 立即退出,报 `X Error ... GLX ... X_GLXCreateContext` | 无桌面时先 `unset DISPLAY`。指向不可用 X 服务器的 `DISPLAY` 会让 gzserver 在渲染初始化处崩溃,`gui:=false` 并不能规避 |
|
||||||
|
| 启动报「Gazebo 端口 11355 已被占用」,但 `ps` 看不到占用进程 | 换端口:`export BR_SIM_MASTER_PORT=11801 GAZEBO_MASTER_URI=http://127.0.0.1:11801`(需与 launch 一致,所有终端同值) |
|
||||||
|
| 机器人一直不出现,规划器只打印 `no odom.` | 场地加载约需 20 s。机器人在等待 `spawn_delay`(默认 20 s)后才生成;若仍失败,用 `spawn_delay:=30` 放大 |
|
||||||
|
|
||||||
|
`spawn_delay` 是 `robocon_robot.launch.py` 的 launch 参数,可直接在 `scan_lio.launch.py`
|
||||||
|
之后传 `spawn_delay:=30`(该入口已转发给机器人 launch)。
|
||||||
|
|
||||||
## 3. 手动体验:启动、发目标、观察停车
|
## 3. 手动体验:启动、发目标、观察停车
|
||||||
|
|
||||||
这种方式由你发目标,适合观察导航行为。准备两个终端,两边都执行第 2 节公共环境命令。
|
这种方式由你发目标,适合观察导航行为。准备两个终端,两边都执行第 2 节公共环境命令。
|
||||||
@@ -78,12 +93,12 @@ ROS 域 77 用于本机仿真,11355 是本项目的 Gazebo master 端口。
|
|||||||
ros2 launch br_sim_bringup scan_lio.launch.py
|
ros2 launch br_sim_bringup scan_lio.launch.py
|
||||||
```
|
```
|
||||||
|
|
||||||
默认打开 Gazebo,包含场地、机器人、MID360/IMU、Point-LIO、SCAN 和控制器。
|
默认打开 Gazebo 和预设好的 RViz,包含场地、机器人、MID360/IMU、Point-LIO、SCAN 和控制器。
|
||||||
终端一保持运行。默认已知起点为世界坐标 (-4.5,4.5,0.15) m、yaw=0,车头朝世界 +X。
|
终端一保持运行。默认已知起点为世界坐标 (-4.5,4.5,0.15) m、yaw=0,车头朝世界 +X。
|
||||||
先保持机器人静止,等待定位完成初始化;不要在 Gazebo 中拖动车辆、重置世界或暂停后继续当作正常测试。
|
先保持机器人静止,等待定位完成初始化;不要在 Gazebo 中拖动车辆、重置世界或暂停后继续当作正常测试。
|
||||||
固定起点对齐只做一次,车辆被挪走或仿真时间重置后应重新启动整套程序。
|
固定起点对齐只做一次,车辆被挪走或仿真时间重置后应重新启动整套程序。
|
||||||
|
|
||||||
不需要画面时,在启动命令后加 `gui:=false`,不用同时执行两个启动命令。
|
不需要画面时,在启动命令后加 `gui:=false with_rviz:=false`。
|
||||||
|
|
||||||
### 3.2 终端二等待感知就绪
|
### 3.2 终端二等待感知就绪
|
||||||
|
|
||||||
@@ -178,6 +193,12 @@ X 和朝向不变、Y 减少 1 m,机器人应基本保持车头朝向并横移
|
|||||||
|
|
||||||
## 5. RViz、状态和速度怎么看
|
## 5. RViz、状态和速度怎么看
|
||||||
|
|
||||||
|
推荐的 `scan_lio.launch.py` 已同时打开预设好的 RViz。
|
||||||
|
默认显示 MID360 原始点云、配准点云和 TF,Fixed Frame 已设为 `world`;
|
||||||
|
规划点云已配置,可在 Displays 中启用。一键入口不能与另一套仿真同时运行。
|
||||||
|
已有四层仿真在运行时,第五个终端执行
|
||||||
|
`ros2 launch br_sim_bringup rviz.launch.py`,只打开预设 RViz。
|
||||||
|
|
||||||
Gazebo 展示物理场景和运动;RViz 展示算法的点云、坐标和规划结果。
|
Gazebo 展示物理场景和运动;RViz 展示算法的点云、坐标和规划结果。
|
||||||
第三个终端先执行第 2 节公共环境,再运行:
|
第三个终端先执行第 2 节公共环境,再运行:
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
cmake_minimum_required(VERSION 3.8)
|
cmake_minimum_required(VERSION 3.8)
|
||||||
project(br_sim_bringup)
|
project(br_sim_bringup)
|
||||||
find_package(ament_cmake REQUIRED)
|
find_package(ament_cmake REQUIRED)
|
||||||
install(DIRECTORY launch config DESTINATION share/${PROJECT_NAME}
|
install(DIRECTORY launch config rviz DESTINATION share/${PROJECT_NAME}
|
||||||
PATTERN "__pycache__" EXCLUDE)
|
PATTERN "__pycache__" EXCLUDE)
|
||||||
install(PROGRAMS scripts/scan_cloud_gate.py scripts/lio_navigation_adapter.py DESTINATION lib/${PROJECT_NAME})
|
install(PROGRAMS scripts/scan_cloud_gate.py scripts/lio_navigation_adapter.py DESTINATION lib/${PROJECT_NAME})
|
||||||
ament_package()
|
ament_package()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
"""Independent MID360-compatible sensors and optional Point-LIO evaluation; no SCAN."""
|
"""Combined Classic world, robot and MID360 sensors, with optional Point-LIO."""
|
||||||
import os
|
import os
|
||||||
from ament_index_python.packages import get_package_share_directory
|
from ament_index_python.packages import get_package_share_directory
|
||||||
from launch import LaunchDescription
|
from launch import LaunchDescription
|
||||||
@@ -10,29 +10,46 @@ from launch_ros.actions import Node
|
|||||||
|
|
||||||
def generate_launch_description():
|
def generate_launch_description():
|
||||||
own = get_package_share_directory('br_sim_bringup')
|
own = get_package_share_directory('br_sim_bringup')
|
||||||
|
|
||||||
def simulation(context):
|
def simulation(context):
|
||||||
if LaunchConfiguration('start_sim').perform(context).lower()!='true':return []
|
if LaunchConfiguration('start_sim').perform(context).lower() != 'true':
|
||||||
|
return []
|
||||||
|
world = get_package_share_directory('robocon_gazebo')
|
||||||
robot = get_package_share_directory('r2027_robot_description')
|
robot = get_package_share_directory('r2027_robot_description')
|
||||||
return [IncludeLaunchDescription(PythonLaunchDescriptionSource(os.path.join(robot,'launch','robocon_robot.launch.py')),
|
return [
|
||||||
launch_arguments={'sensor_profile':LaunchConfiguration('sensor_profile'),'gui':LaunchConfiguration('gui'),'lidar':'true','sensor_model':'mid360','drive':'contact',
|
IncludeLaunchDescription(PythonLaunchDescriptionSource(
|
||||||
'x':LaunchConfiguration('x'),'y':LaunchConfiguration('y'),'z':LaunchConfiguration('z'),'yaw':LaunchConfiguration('yaw')}.items())]
|
os.path.join(world, 'launch', 'robocon_gazebo.launch.py')),
|
||||||
|
launch_arguments={'gui': LaunchConfiguration('gui')}.items()),
|
||||||
|
IncludeLaunchDescription(PythonLaunchDescriptionSource(
|
||||||
|
os.path.join(robot, 'launch', 'robocon_robot.launch.py')),
|
||||||
|
launch_arguments={'sensor_model': 'mid360', 'lidar': 'true', 'drive': 'contact',
|
||||||
|
**{k: LaunchConfiguration(k) for k in ('x', 'y', 'z', 'yaw')}}.items()),
|
||||||
|
IncludeLaunchDescription(PythonLaunchDescriptionSource(
|
||||||
|
os.path.join(robot, 'launch', 'mid360_sensors.launch.py')),
|
||||||
|
launch_arguments={'sensor_profile': LaunchConfiguration('sensor_profile')}.items()),
|
||||||
|
]
|
||||||
|
|
||||||
def estimator(context):
|
def estimator(context):
|
||||||
if LaunchConfiguration('with_lio').perform(context).lower()!='true':return []
|
if LaunchConfiguration('with_lio').perform(context).lower() != 'true':
|
||||||
|
return []
|
||||||
lio = get_package_share_directory('point_lio')
|
lio = get_package_share_directory('point_lio')
|
||||||
return [Node(package='point_lio', executable='pointlio_mapping', name='point_lio_sim',
|
return [Node(package='point_lio', executable='pointlio_mapping', name='point_lio_sim',
|
||||||
namespace='sim/lio', output='screen',
|
namespace='sim/lio', output='screen',
|
||||||
parameters=[os.path.join(lio,'config','mid360.yaml'),os.path.join(own,'config','point_lio_sim.yaml'),
|
parameters=[os.path.join(lio, 'config', 'mid360.yaml'),
|
||||||
LaunchConfiguration('lio_profile')],
|
LaunchConfiguration('lio_profile')],
|
||||||
# Three absolute publishers in the existing implementation need explicit remaps.
|
|
||||||
remappings=[('/cloud_registered_full', '/sim/lio/cloud_registered_full'),
|
remappings=[('/cloud_registered_full', '/sim/lio/cloud_registered_full'),
|
||||||
('/cloud_registered_full_lidar', '/sim/lio/cloud_registered_full_lidar')])]
|
('/cloud_registered_full_lidar', '/sim/lio/cloud_registered_full_lidar')])]
|
||||||
|
|
||||||
return LaunchDescription([
|
return LaunchDescription([
|
||||||
DeclareLaunchArgument('gui', default_value='true'),
|
DeclareLaunchArgument('gui', default_value='true'),
|
||||||
DeclareLaunchArgument('with_lio', default_value='false'),
|
DeclareLaunchArgument('with_lio', default_value='false'),
|
||||||
DeclareLaunchArgument('start_sim', default_value='true'),
|
DeclareLaunchArgument('start_sim', default_value='true'),
|
||||||
DeclareLaunchArgument('sensor_profile', default_value='ideal'),
|
DeclareLaunchArgument('sensor_profile', default_value='ideal'),
|
||||||
DeclareLaunchArgument('lio_profile', default_value=os.path.join(own, 'config', 'point_lio_sim.yaml')),
|
DeclareLaunchArgument('lio_profile', default_value=os.path.join(own, 'config', 'point_lio_sim.yaml')),
|
||||||
DeclareLaunchArgument('x',default_value='-4.5'),DeclareLaunchArgument('y',default_value='4.5'),
|
DeclareLaunchArgument('x', default_value='-4.5'),
|
||||||
DeclareLaunchArgument('z',default_value='0.17'),DeclareLaunchArgument('yaw',default_value='0.0'),
|
DeclareLaunchArgument('y', default_value='4.5'),
|
||||||
OpaqueFunction(function=simulation),
|
DeclareLaunchArgument('z', default_value='0.17'),
|
||||||
OpaqueFunction(function=estimator)])
|
DeclareLaunchArgument('yaw', default_value='0.0'),
|
||||||
|
DeclareLaunchArgument('spawn_delay', default_value='0.0'),
|
||||||
|
OpaqueFunction(function=simulation), OpaqueFunction(function=estimator),
|
||||||
|
])
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
"""Compatibility one-command world + robot bringup for robot and lidar checks."""
|
||||||
|
import os
|
||||||
|
from ament_index_python.packages import get_package_share_directory
|
||||||
|
from launch import LaunchDescription
|
||||||
|
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, OpaqueFunction
|
||||||
|
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||||
|
from launch.substitutions import LaunchConfiguration
|
||||||
|
|
||||||
|
|
||||||
|
def generate_launch_description():
|
||||||
|
world = get_package_share_directory('robocon_gazebo')
|
||||||
|
robot = get_package_share_directory('r2027_robot_description')
|
||||||
|
|
||||||
|
def sensor(context):
|
||||||
|
if (LaunchConfiguration('lidar').perform(context).lower() == 'true' and
|
||||||
|
LaunchConfiguration('sensor_model').perform(context) == 'mid360'):
|
||||||
|
return [IncludeLaunchDescription(PythonLaunchDescriptionSource(
|
||||||
|
os.path.join(robot, 'launch', 'mid360_sensors.launch.py')),
|
||||||
|
launch_arguments={'sensor_profile': LaunchConfiguration('sensor_profile')}.items())]
|
||||||
|
return []
|
||||||
|
|
||||||
|
return LaunchDescription([
|
||||||
|
DeclareLaunchArgument('gui', default_value='true'),
|
||||||
|
DeclareLaunchArgument('world', default_value=os.path.join(world, 'worlds', 'robocon_robot.world')),
|
||||||
|
DeclareLaunchArgument('lidar', default_value='false'),
|
||||||
|
DeclareLaunchArgument('drive', default_value='planar'),
|
||||||
|
DeclareLaunchArgument('sensor_model', default_value='generic'),
|
||||||
|
DeclareLaunchArgument('sensor_profile', default_value='ideal'),
|
||||||
|
DeclareLaunchArgument('x', default_value='-4.5'),
|
||||||
|
DeclareLaunchArgument('y', default_value='4.5'),
|
||||||
|
DeclareLaunchArgument('z', default_value='0.17'),
|
||||||
|
DeclareLaunchArgument('yaw', default_value='0.0'),
|
||||||
|
IncludeLaunchDescription(PythonLaunchDescriptionSource(
|
||||||
|
os.path.join(world, 'launch', 'robocon_gazebo.launch.py')),
|
||||||
|
launch_arguments={'gui': LaunchConfiguration('gui'), 'world': LaunchConfiguration('world')}.items()),
|
||||||
|
IncludeLaunchDescription(PythonLaunchDescriptionSource(
|
||||||
|
os.path.join(robot, 'launch', 'robocon_robot.launch.py')),
|
||||||
|
launch_arguments={k: LaunchConfiguration(k) for k in
|
||||||
|
('lidar', 'drive', 'sensor_model', 'sensor_profile', 'x', 'y', 'z', 'yaw')}.items()),
|
||||||
|
OpaqueFunction(function=sensor),
|
||||||
|
])
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
"""Display the already running four-layer simulation in RViz only."""
|
||||||
|
import os
|
||||||
|
|
||||||
|
from ament_index_python.packages import get_package_share_directory
|
||||||
|
from launch import LaunchDescription
|
||||||
|
from launch.actions import SetEnvironmentVariable
|
||||||
|
from launch.substitutions import EnvironmentVariable
|
||||||
|
from launch_ros.actions import Node
|
||||||
|
|
||||||
|
|
||||||
|
def generate_launch_description():
|
||||||
|
config = os.path.join(
|
||||||
|
get_package_share_directory('br_sim_bringup'), 'rviz', 'scan_lio.rviz')
|
||||||
|
return LaunchDescription([
|
||||||
|
SetEnvironmentVariable('ROS_DOMAIN_ID', EnvironmentVariable('ROS_DOMAIN_ID', default_value='77')),
|
||||||
|
SetEnvironmentVariable('ROS_LOCALHOST_ONLY', EnvironmentVariable('ROS_LOCALHOST_ONLY', default_value='1')),
|
||||||
|
Node(package='rviz2', executable='rviz2', name='rviz2', output='screen',
|
||||||
|
arguments=['-d', config], parameters=[{'use_sim_time': True}]),
|
||||||
|
])
|
||||||
@@ -1,36 +1,41 @@
|
|||||||
"""Flat SCAN closed loop from Point-LIO only; truth remains an independent observer."""
|
"""One command for the five simulation layers; optional headless mode for tests."""
|
||||||
import os
|
import os
|
||||||
from ament_index_python.packages import get_package_share_directory
|
from ament_index_python.packages import get_package_share_directory
|
||||||
from launch import LaunchDescription
|
from launch import LaunchDescription
|
||||||
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, OpaqueFunction
|
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, OpaqueFunction
|
||||||
|
from launch.conditions import IfCondition
|
||||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||||
from launch.substitutions import LaunchConfiguration
|
from launch.substitutions import LaunchConfiguration
|
||||||
from launch_ros.actions import Node
|
|
||||||
|
|
||||||
|
|
||||||
def generate_launch_description():
|
def generate_launch_description():
|
||||||
own=get_package_share_directory('br_sim_bringup');scan=get_package_share_directory('scan_planner')
|
own = get_package_share_directory('br_sim_bringup')
|
||||||
base=os.path.join(own,'config','scan_sim.yaml');profile=os.path.join(own,'config','lio_navigation.yaml')
|
|
||||||
def bringup(context):
|
def layers(context):
|
||||||
pose=[float(LaunchConfiguration(k).perform(context)) for k in ('x','y','z','yaw')]
|
actions = []
|
||||||
return [
|
if LaunchConfiguration('start_sim').perform(context).lower() == 'true':
|
||||||
IncludeLaunchDescription(PythonLaunchDescriptionSource(os.path.join(own,'launch','mid360_sim.launch.py')),
|
actions.append(IncludeLaunchDescription(PythonLaunchDescriptionSource(
|
||||||
launch_arguments={'gui':LaunchConfiguration('gui'),'with_lio':'true',
|
os.path.join(own, 'launch', 'mid360_sim.launch.py')),
|
||||||
'start_sim':LaunchConfiguration('start_sim'),'sensor_profile':LaunchConfiguration('sensor_profile'),
|
launch_arguments={'gui': LaunchConfiguration('gui'), 'with_lio': 'false',
|
||||||
**{k:LaunchConfiguration(k) for k in ('x','y','z','yaw')}}.items()),
|
'sensor_profile': LaunchConfiguration('sensor_profile'),
|
||||||
Node(package='br_sim_bringup',executable='lio_navigation_adapter.py',name='lio_navigation_adapter',
|
**{k: LaunchConfiguration(k) for k in ('x', 'y', 'z', 'yaw')}}.items()))
|
||||||
output='screen',parameters=[profile,{'initial_base_pose':pose}]),
|
actions.append(IncludeLaunchDescription(PythonLaunchDescriptionSource(
|
||||||
Node(package='scan_planner',executable='scan_planner_node',name='scan_planner_node',output='screen',
|
os.path.join(own, 'launch', 'scan_lio_navigation.launch.py')),
|
||||||
parameters=[os.path.join(scan,'config','planner_vehicle.yaml'),base,profile],
|
launch_arguments={k: LaunchConfiguration(k) for k in ('x', 'y', 'z', 'yaw')}.items()))
|
||||||
remappings=[('body_pose','/sim/navigation/body_odom'),('sensor_pose','/sim/navigation/sensor_odom'),
|
return actions
|
||||||
('cloud','/sim/navigation/planning_cloud')]),
|
|
||||||
Node(package='scan_planner',executable='closed_loop_controller',name='closed_loop_controller',output='screen',
|
|
||||||
parameters=[os.path.join(scan,'config','controllers_vehicle.yaml'),base,profile],
|
|
||||||
remappings=[('body_pose','/sim/navigation/body_odom'),('cmd_vel','/cmd_vel')]),
|
|
||||||
]
|
|
||||||
return LaunchDescription([
|
return LaunchDescription([
|
||||||
DeclareLaunchArgument('start_sim',default_value='true'),DeclareLaunchArgument('sensor_profile',default_value='ideal'),
|
DeclareLaunchArgument('start_sim', default_value='true'),
|
||||||
|
DeclareLaunchArgument('with_rviz', default_value='true'),
|
||||||
|
DeclareLaunchArgument('sensor_profile', default_value='ideal'),
|
||||||
DeclareLaunchArgument('gui', default_value='true'),
|
DeclareLaunchArgument('gui', default_value='true'),
|
||||||
DeclareLaunchArgument('x',default_value='-4.5'),DeclareLaunchArgument('y',default_value='4.5'),
|
DeclareLaunchArgument('x', default_value='-4.5'),
|
||||||
DeclareLaunchArgument('z',default_value='0.15',description='Known settled base height in this flat profile'),
|
DeclareLaunchArgument('y', default_value='4.5'),
|
||||||
DeclareLaunchArgument('yaw',default_value='0.0'),OpaqueFunction(function=bringup)])
|
DeclareLaunchArgument('z', default_value='0.15'),
|
||||||
|
DeclareLaunchArgument('yaw', default_value='0.0'),
|
||||||
|
DeclareLaunchArgument('spawn_delay', default_value='0.0'),
|
||||||
|
OpaqueFunction(function=layers),
|
||||||
|
IncludeLaunchDescription(PythonLaunchDescriptionSource(
|
||||||
|
os.path.join(own, 'launch', 'rviz.launch.py')),
|
||||||
|
condition=IfCondition(LaunchConfiguration('with_rviz'))),
|
||||||
|
])
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
"""Pure software Point-LIO, navigation adapter, SCAN and controller."""
|
||||||
|
import os
|
||||||
|
from ament_index_python.packages import get_package_share_directory
|
||||||
|
from launch import LaunchDescription
|
||||||
|
from launch.actions import DeclareLaunchArgument, OpaqueFunction, SetEnvironmentVariable
|
||||||
|
from launch.substitutions import LaunchConfiguration, EnvironmentVariable
|
||||||
|
from launch_ros.actions import Node
|
||||||
|
|
||||||
|
|
||||||
|
def generate_launch_description():
|
||||||
|
own = get_package_share_directory('br_sim_bringup')
|
||||||
|
scan = get_package_share_directory('scan_planner')
|
||||||
|
lio = get_package_share_directory('point_lio')
|
||||||
|
base = os.path.join(own, 'config', 'scan_sim.yaml')
|
||||||
|
profile = os.path.join(own, 'config', 'lio_navigation.yaml')
|
||||||
|
|
||||||
|
def nodes(context):
|
||||||
|
pose = [float(LaunchConfiguration(k).perform(context)) for k in ('x', 'y', 'z', 'yaw')]
|
||||||
|
return [
|
||||||
|
Node(package='point_lio', executable='pointlio_mapping', name='point_lio_sim',
|
||||||
|
namespace='sim/lio', output='screen',
|
||||||
|
parameters=[os.path.join(lio, 'config', 'mid360.yaml'),
|
||||||
|
os.path.join(own, 'config', 'point_lio_sim.yaml')],
|
||||||
|
remappings=[('/cloud_registered_full', '/sim/lio/cloud_registered_full'),
|
||||||
|
('/cloud_registered_full_lidar', '/sim/lio/cloud_registered_full_lidar')]),
|
||||||
|
Node(package='br_sim_bringup', executable='lio_navigation_adapter.py',
|
||||||
|
name='lio_navigation_adapter', output='screen',
|
||||||
|
parameters=[profile, {'initial_base_pose': pose}]),
|
||||||
|
Node(package='scan_planner', executable='scan_planner_node',
|
||||||
|
name='scan_planner_node', output='screen',
|
||||||
|
parameters=[os.path.join(scan, 'config', 'planner_vehicle.yaml'), base, profile],
|
||||||
|
remappings=[('body_pose', '/sim/navigation/body_odom'),
|
||||||
|
('sensor_pose', '/sim/navigation/sensor_odom'),
|
||||||
|
('cloud', '/sim/navigation/planning_cloud')]),
|
||||||
|
Node(package='scan_planner', executable='closed_loop_controller',
|
||||||
|
name='closed_loop_controller', output='screen',
|
||||||
|
parameters=[os.path.join(scan, 'config', 'controllers_vehicle.yaml'), base, profile],
|
||||||
|
remappings=[('body_pose', '/sim/navigation/body_odom'), ('cmd_vel', '/cmd_vel')]),
|
||||||
|
]
|
||||||
|
|
||||||
|
return LaunchDescription([
|
||||||
|
SetEnvironmentVariable('ROS_DOMAIN_ID', EnvironmentVariable('ROS_DOMAIN_ID', default_value='77')),
|
||||||
|
SetEnvironmentVariable('ROS_LOCALHOST_ONLY', EnvironmentVariable('ROS_LOCALHOST_ONLY', default_value='1')),
|
||||||
|
DeclareLaunchArgument('x', default_value='-4.5'),
|
||||||
|
DeclareLaunchArgument('y', default_value='4.5'),
|
||||||
|
DeclareLaunchArgument('z', default_value='0.15'),
|
||||||
|
DeclareLaunchArgument('yaw', default_value='0.0'),
|
||||||
|
OpaqueFunction(function=nodes),
|
||||||
|
])
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
"""Start the full MID360 navigation simulation and RViz with ready-made displays."""
|
||||||
|
import os
|
||||||
|
|
||||||
|
from ament_index_python.packages import get_package_share_directory
|
||||||
|
from launch import LaunchDescription
|
||||||
|
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, SetEnvironmentVariable
|
||||||
|
from launch.conditions import IfCondition
|
||||||
|
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||||
|
from launch.substitutions import EnvironmentVariable, LaunchConfiguration
|
||||||
|
from launch_ros.actions import Node
|
||||||
|
|
||||||
|
|
||||||
|
def generate_launch_description():
|
||||||
|
share = get_package_share_directory('br_sim_bringup')
|
||||||
|
return LaunchDescription([
|
||||||
|
SetEnvironmentVariable('ROS_DOMAIN_ID', EnvironmentVariable('ROS_DOMAIN_ID', default_value='77')),
|
||||||
|
SetEnvironmentVariable('ROS_LOCALHOST_ONLY', EnvironmentVariable('ROS_LOCALHOST_ONLY', default_value='1')),
|
||||||
|
DeclareLaunchArgument('gazebo_gui', default_value='false'),
|
||||||
|
DeclareLaunchArgument('start_sim', default_value='true'),
|
||||||
|
DeclareLaunchArgument('sensor_profile', default_value='ideal'),
|
||||||
|
DeclareLaunchArgument('x', default_value='-4.5'),
|
||||||
|
DeclareLaunchArgument('y', default_value='4.5'),
|
||||||
|
DeclareLaunchArgument('z', default_value='0.15'),
|
||||||
|
DeclareLaunchArgument('yaw', default_value='0.0'),
|
||||||
|
IncludeLaunchDescription(PythonLaunchDescriptionSource(
|
||||||
|
os.path.join(share, 'launch', 'scan_lio.launch.py')),
|
||||||
|
condition=IfCondition(LaunchConfiguration('start_sim')),
|
||||||
|
launch_arguments={'gui': LaunchConfiguration('gazebo_gui'), 'with_rviz': 'false',
|
||||||
|
'sensor_profile': LaunchConfiguration('sensor_profile'),
|
||||||
|
**{k: LaunchConfiguration(k) for k in ('x', 'y', 'z', 'yaw')}}.items()),
|
||||||
|
Node(package='rviz2', executable='rviz2', name='rviz2', output='screen',
|
||||||
|
arguments=['-d', os.path.join(share, 'rviz', 'scan_lio.rviz')],
|
||||||
|
parameters=[{'use_sim_time': True}]),
|
||||||
|
])
|
||||||
@@ -8,11 +8,15 @@ def generate_launch_description():
|
|||||||
def hosts(context):
|
def hosts(context):
|
||||||
values={k:LaunchConfiguration(k).perform(context) for k in ('x','y','z','yaw','gui','sensor_profile','terrain')}
|
values={k:LaunchConfiguration(k).perform(context) for k in ('x','y','z','yaw','gui','sensor_profile','terrain')}
|
||||||
terrain=values.pop('terrain').lower()=='true'
|
terrain=values.pop('terrain').lower()=='true'
|
||||||
args=[k+':='+v for k,v in values.items()]
|
physical_args=[k+':='+v for k,v in values.items()]
|
||||||
return [ExecuteProcess(cmd=['ros2','launch','r2027_robot_description','robocon_robot.launch.py',
|
navigation_args=[k+':='+values[k] for k in ('x','y','z','yaw')]
|
||||||
'lidar:=true','drive:=contact','sensor_model:=mid360']+args,output='screen'),
|
if terrain:
|
||||||
|
navigation_args += ['start_sim:=false']
|
||||||
|
return [ExecuteProcess(cmd=['ros2','launch','br_sim_bringup','mid360_sim.launch.py',
|
||||||
|
'with_lio:=false']+physical_args,output='screen'),
|
||||||
ExecuteProcess(cmd=['ros2','launch','br_sim_bringup',
|
ExecuteProcess(cmd=['ros2','launch','br_sim_bringup',
|
||||||
'scan_lio_terrain.launch.py' if terrain else 'scan_lio.launch.py','start_sim:=false']+args,output='screen')]
|
'scan_lio_terrain.launch.py' if terrain else 'scan_lio_navigation.launch.py']+
|
||||||
|
navigation_args,output='screen')]
|
||||||
return LaunchDescription([DeclareLaunchArgument(k,default_value=v) for k,v in
|
return LaunchDescription([DeclareLaunchArgument(k,default_value=v) for k,v in
|
||||||
[('x','-4.5'),('y','4.5'),('z','0.15'),('yaw','0.0'),('gui','false'),('sensor_profile','ideal'),('terrain','false')]]+
|
[('x','-4.5'),('y','4.5'),('z','0.15'),('yaw','0.0'),('gui','false'),('sensor_profile','ideal'),('terrain','false')]]+
|
||||||
[OpaqueFunction(function=hosts)])
|
[OpaqueFunction(function=hosts)])
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from launch_ros.actions import Node
|
|||||||
|
|
||||||
def generate_launch_description():
|
def generate_launch_description():
|
||||||
robot = get_package_share_directory('r2027_robot_description')
|
robot = get_package_share_directory('r2027_robot_description')
|
||||||
|
world = get_package_share_directory('robocon_gazebo')
|
||||||
scan = get_package_share_directory('scan_planner')
|
scan = get_package_share_directory('scan_planner')
|
||||||
own = get_package_share_directory('br_sim_bringup')
|
own = get_package_share_directory('br_sim_bringup')
|
||||||
overrides = os.path.join(own, 'config', 'scan_sim.yaml')
|
overrides = os.path.join(own, 'config', 'scan_sim.yaml')
|
||||||
@@ -23,10 +24,13 @@ def generate_launch_description():
|
|||||||
DeclareLaunchArgument('y', default_value='4.5'),
|
DeclareLaunchArgument('y', default_value='4.5'),
|
||||||
DeclareLaunchArgument('z', default_value='0.15'),
|
DeclareLaunchArgument('z', default_value='0.15'),
|
||||||
DeclareLaunchArgument('yaw', default_value='0.0'),
|
DeclareLaunchArgument('yaw', default_value='0.0'),
|
||||||
|
IncludeLaunchDescription(PythonLaunchDescriptionSource(
|
||||||
|
os.path.join(world, 'launch', 'robocon_gazebo.launch.py')),
|
||||||
|
launch_arguments={'gui': LaunchConfiguration('gui'), 'paused': LaunchConfiguration('paused')}.items()),
|
||||||
IncludeLaunchDescription(PythonLaunchDescriptionSource(
|
IncludeLaunchDescription(PythonLaunchDescriptionSource(
|
||||||
os.path.join(robot, 'launch', 'robocon_robot.launch.py')),
|
os.path.join(robot, 'launch', 'robocon_robot.launch.py')),
|
||||||
launch_arguments={'gui': LaunchConfiguration('gui'),
|
launch_arguments={'gui': LaunchConfiguration('gui'),
|
||||||
'paused': LaunchConfiguration('paused'), 'lidar': 'true',
|
'paused': LaunchConfiguration('paused'), 'lidar': 'true', 'sensor_model': 'generic',
|
||||||
'x': LaunchConfiguration('x'), 'y': LaunchConfiguration('y'),
|
'x': LaunchConfiguration('x'), 'y': LaunchConfiguration('y'),
|
||||||
'z': LaunchConfiguration('z'), 'yaw': LaunchConfiguration('yaw')}.items()),
|
'z': LaunchConfiguration('z'), 'yaw': LaunchConfiguration('yaw')}.items()),
|
||||||
Node(package='br_sim_bringup', executable='scan_cloud_gate.py',
|
Node(package='br_sim_bringup', executable='scan_cloud_gate.py',
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from launch_ros.actions import Node
|
|||||||
def generate_launch_description():
|
def generate_launch_description():
|
||||||
own=get_package_share_directory('br_sim_bringup')
|
own=get_package_share_directory('br_sim_bringup')
|
||||||
robot=get_package_share_directory('r2027_robot_description')
|
robot=get_package_share_directory('r2027_robot_description')
|
||||||
|
world=get_package_share_directory('robocon_gazebo')
|
||||||
scan=get_package_share_directory('scan_planner')
|
scan=get_package_share_directory('scan_planner')
|
||||||
base=os.path.join(own,'config','scan_sim.yaml')
|
base=os.path.join(own,'config','scan_sim.yaml')
|
||||||
terrain=os.path.join(own,'config','terrain_sim.yaml')
|
terrain=os.path.join(own,'config','terrain_sim.yaml')
|
||||||
@@ -20,8 +21,10 @@ def generate_launch_description():
|
|||||||
DeclareLaunchArgument('x',default_value='3.5'),DeclareLaunchArgument('y',default_value='3.5125'),
|
DeclareLaunchArgument('x',default_value='3.5'),DeclareLaunchArgument('y',default_value='3.5125'),
|
||||||
DeclareLaunchArgument('z',default_value='0.15'),
|
DeclareLaunchArgument('z',default_value='0.15'),
|
||||||
DeclareLaunchArgument('yaw',default_value='0.0'),
|
DeclareLaunchArgument('yaw',default_value='0.0'),
|
||||||
|
IncludeLaunchDescription(PythonLaunchDescriptionSource(os.path.join(world,'launch','robocon_gazebo.launch.py')),
|
||||||
|
launch_arguments={'gui':LaunchConfiguration('gui')}.items()),
|
||||||
IncludeLaunchDescription(PythonLaunchDescriptionSource(os.path.join(robot,'launch','robocon_robot.launch.py')),
|
IncludeLaunchDescription(PythonLaunchDescriptionSource(os.path.join(robot,'launch','robocon_robot.launch.py')),
|
||||||
launch_arguments={'gui':LaunchConfiguration('gui'),'lidar':'true','drive':'contact',
|
launch_arguments={'gui':LaunchConfiguration('gui'),'lidar':'true','sensor_model':'generic','drive':'contact',
|
||||||
'x':LaunchConfiguration('x'),'y':LaunchConfiguration('y'),'z':LaunchConfiguration('z'),'yaw':LaunchConfiguration('yaw')}.items()),
|
'x':LaunchConfiguration('x'),'y':LaunchConfiguration('y'),'z':LaunchConfiguration('z'),'yaw':LaunchConfiguration('yaw')}.items()),
|
||||||
Node(package='br_sim_bringup',executable='scan_cloud_gate.py',name='scan_cloud_gate',parameters=[base,terrain]),
|
Node(package='br_sim_bringup',executable='scan_cloud_gate.py',name='scan_cloud_gate',parameters=[base,terrain]),
|
||||||
Node(package='step_blocker',executable='step_blocker',name='step_blocker',parameters=[terrain]),
|
Node(package='step_blocker',executable='step_blocker',name='step_blocker',parameters=[terrain]),
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
<exec_depend>scan_planner</exec_depend>
|
<exec_depend>scan_planner</exec_depend>
|
||||||
<exec_depend>step_blocker</exec_depend>
|
<exec_depend>step_blocker</exec_depend>
|
||||||
<exec_depend>point_lio</exec_depend>
|
<exec_depend>point_lio</exec_depend>
|
||||||
|
<exec_depend>rviz2</exec_depend>
|
||||||
<exec_depend>launch</exec_depend>
|
<exec_depend>launch</exec_depend>
|
||||||
<exec_depend>launch_ros</exec_depend>
|
<exec_depend>launch_ros</exec_depend>
|
||||||
<exec_depend>ament_index_python</exec_depend>
|
<exec_depend>ament_index_python</exec_depend>
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
Panels:
|
||||||
|
- Class: rviz_common/Displays
|
||||||
|
Name: Displays
|
||||||
|
Property Tree Widget:
|
||||||
|
Expanded:
|
||||||
|
- /Global Options1
|
||||||
|
- /MID360 Raw1
|
||||||
|
- /Registered Cloud1
|
||||||
|
- /Planning Cloud1
|
||||||
|
Splitter Ratio: 0.55
|
||||||
|
Tree Height: 700
|
||||||
|
Visualization Manager:
|
||||||
|
Class: ""
|
||||||
|
Displays:
|
||||||
|
- Class: rviz_default_plugins/Grid
|
||||||
|
Name: Ground Grid
|
||||||
|
Enabled: true
|
||||||
|
Alpha: 0.45
|
||||||
|
Cell Size: 1
|
||||||
|
Color: 160; 160; 164
|
||||||
|
Line Style:
|
||||||
|
Line Width: 0.03
|
||||||
|
Value: Lines
|
||||||
|
Normal Cell Count: 0
|
||||||
|
Offset: {X: 0, Y: 0, Z: 0}
|
||||||
|
Plane: XY
|
||||||
|
Plane Cell Count: 20
|
||||||
|
Reference Frame: <Fixed Frame>
|
||||||
|
Value: true
|
||||||
|
- Class: rviz_default_plugins/TF
|
||||||
|
Name: TF
|
||||||
|
Enabled: true
|
||||||
|
Frame Timeout: 15
|
||||||
|
Frames: {All Enabled: true}
|
||||||
|
Marker Scale: 0.5
|
||||||
|
Show Arrows: true
|
||||||
|
Show Axes: true
|
||||||
|
Show Names: false
|
||||||
|
Update Interval: 0
|
||||||
|
Value: true
|
||||||
|
- Class: rviz_default_plugins/PointCloud2
|
||||||
|
Name: MID360 Raw
|
||||||
|
Enabled: true
|
||||||
|
Alpha: 0.65
|
||||||
|
Color: 0; 160; 255
|
||||||
|
Color Transformer: FlatColor
|
||||||
|
Position Transformer: XYZ
|
||||||
|
Selectable: true
|
||||||
|
Size (Pixels): 3
|
||||||
|
Size (m): 0.04
|
||||||
|
Style: Flat Squares
|
||||||
|
Decay Time: 0
|
||||||
|
Topic:
|
||||||
|
Depth: 5
|
||||||
|
Durability Policy: Volatile
|
||||||
|
Filter size: 10
|
||||||
|
History Policy: Keep Last
|
||||||
|
Reliability Policy: Best Effort
|
||||||
|
Value: /sim/mid360/points
|
||||||
|
Use Fixed Frame: true
|
||||||
|
Value: true
|
||||||
|
- Class: rviz_default_plugins/PointCloud2
|
||||||
|
Name: Registered Cloud
|
||||||
|
Enabled: true
|
||||||
|
Alpha: 1
|
||||||
|
Color: 255; 210; 75
|
||||||
|
Color Transformer: FlatColor
|
||||||
|
Position Transformer: XYZ
|
||||||
|
Selectable: true
|
||||||
|
Size (Pixels): 3
|
||||||
|
Size (m): 0.045
|
||||||
|
Style: Flat Squares
|
||||||
|
Decay Time: 0
|
||||||
|
Topic:
|
||||||
|
Depth: 5
|
||||||
|
Durability Policy: Volatile
|
||||||
|
Filter size: 10
|
||||||
|
History Policy: Keep Last
|
||||||
|
Reliability Policy: Best Effort
|
||||||
|
Value: /sim/navigation/cloud_registered
|
||||||
|
Use Fixed Frame: true
|
||||||
|
Value: true
|
||||||
|
- Class: rviz_default_plugins/PointCloud2
|
||||||
|
Name: Planning Cloud
|
||||||
|
Enabled: false
|
||||||
|
Alpha: 0.9
|
||||||
|
Color: 65; 220; 105
|
||||||
|
Color Transformer: FlatColor
|
||||||
|
Position Transformer: XYZ
|
||||||
|
Selectable: true
|
||||||
|
Size (Pixels): 3
|
||||||
|
Size (m): 0.045
|
||||||
|
Style: Flat Squares
|
||||||
|
Decay Time: 0
|
||||||
|
Topic:
|
||||||
|
Depth: 5
|
||||||
|
Durability Policy: Volatile
|
||||||
|
Filter size: 10
|
||||||
|
History Policy: Keep Last
|
||||||
|
Reliability Policy: Best Effort
|
||||||
|
Value: /sim/navigation/planning_cloud
|
||||||
|
Use Fixed Frame: true
|
||||||
|
Value: false
|
||||||
|
Enabled: true
|
||||||
|
Global Options:
|
||||||
|
Background Color: 35; 40; 48
|
||||||
|
Fixed Frame: world
|
||||||
|
Frame Rate: 30
|
||||||
|
Name: root
|
||||||
|
Tools:
|
||||||
|
- Class: rviz_default_plugins/Interact
|
||||||
|
- Class: rviz_default_plugins/MoveCamera
|
||||||
|
- Class: rviz_default_plugins/Select
|
||||||
|
- Class: rviz_default_plugins/FocusCamera
|
||||||
|
- Class: rviz_default_plugins/Measure
|
||||||
|
Transformation:
|
||||||
|
Current:
|
||||||
|
Class: rviz_default_plugins/TF
|
||||||
|
Value: true
|
||||||
|
Views:
|
||||||
|
Current:
|
||||||
|
Class: rviz_default_plugins/Orbit
|
||||||
|
Distance: 14
|
||||||
|
Focal Point: {X: -3.5, Y: 3.5, Z: 0}
|
||||||
|
Name: Current View
|
||||||
|
Pitch: 0.95
|
||||||
|
Target Frame: <Fixed Frame>
|
||||||
|
Value: Orbit (rviz_default_plugins)
|
||||||
|
Yaw: 1.57
|
||||||
|
Saved: ~
|
||||||
@@ -13,6 +13,7 @@ find_package(tf2_ros REQUIRED)
|
|||||||
find_package(livox_ros_driver2 REQUIRED)
|
find_package(livox_ros_driver2 REQUIRED)
|
||||||
find_package(sensor_msgs REQUIRED)
|
find_package(sensor_msgs REQUIRED)
|
||||||
find_package(std_msgs REQUIRED)
|
find_package(std_msgs REQUIRED)
|
||||||
|
find_package(std_srvs REQUIRED)
|
||||||
|
|
||||||
add_library(br_contact_drive SHARED src/contact_drive.cpp)
|
add_library(br_contact_drive SHARED src/contact_drive.cpp)
|
||||||
target_include_directories(br_contact_drive PRIVATE ${GAZEBO_INCLUDE_DIRS})
|
target_include_directories(br_contact_drive PRIVATE ${GAZEBO_INCLUDE_DIRS})
|
||||||
@@ -23,13 +24,13 @@ install(TARGETS br_contact_drive LIBRARY DESTINATION lib)
|
|||||||
add_library(br_mid360_sensor SHARED src/mid360_sensor.cpp)
|
add_library(br_mid360_sensor SHARED src/mid360_sensor.cpp)
|
||||||
target_include_directories(br_mid360_sensor PRIVATE ${GAZEBO_INCLUDE_DIRS})
|
target_include_directories(br_mid360_sensor PRIVATE ${GAZEBO_INCLUDE_DIRS})
|
||||||
target_link_libraries(br_mid360_sensor ${GAZEBO_LIBRARIES})
|
target_link_libraries(br_mid360_sensor ${GAZEBO_LIBRARIES})
|
||||||
ament_target_dependencies(br_mid360_sensor gazebo_ros rclcpp livox_ros_driver2 sensor_msgs std_msgs)
|
ament_target_dependencies(br_mid360_sensor gazebo_ros rclcpp livox_ros_driver2 sensor_msgs std_msgs std_srvs)
|
||||||
install(TARGETS br_mid360_sensor LIBRARY DESTINATION lib)
|
install(TARGETS br_mid360_sensor LIBRARY DESTINATION lib)
|
||||||
|
|
||||||
add_library(br_mid360_imu SHARED src/mid360_imu.cpp)
|
add_library(br_mid360_imu SHARED src/mid360_imu.cpp)
|
||||||
target_include_directories(br_mid360_imu PRIVATE ${GAZEBO_INCLUDE_DIRS})
|
target_include_directories(br_mid360_imu PRIVATE ${GAZEBO_INCLUDE_DIRS})
|
||||||
target_link_libraries(br_mid360_imu ${GAZEBO_LIBRARIES})
|
target_link_libraries(br_mid360_imu ${GAZEBO_LIBRARIES})
|
||||||
ament_target_dependencies(br_mid360_imu gazebo_ros rclcpp sensor_msgs)
|
ament_target_dependencies(br_mid360_imu gazebo_ros rclcpp sensor_msgs std_msgs std_srvs)
|
||||||
install(TARGETS br_mid360_imu LIBRARY DESTINATION lib)
|
install(TARGETS br_mid360_imu LIBRARY DESTINATION lib)
|
||||||
|
|
||||||
# SIM-P2-001: 只装本包自己的资源。
|
# SIM-P2-001: 只装本包自己的资源。
|
||||||
@@ -40,7 +41,7 @@ install(DIRECTORY launch sdf config
|
|||||||
PATTERN "__pycache__" EXCLUDE
|
PATTERN "__pycache__" EXCLUDE
|
||||||
PATTERN "*.pyc" EXCLUDE)
|
PATTERN "*.pyc" EXCLUDE)
|
||||||
|
|
||||||
install(PROGRAMS scripts/cmd_vel_timeout.py scripts/sim_data_adapter.py
|
install(PROGRAMS scripts/cmd_vel_timeout.py scripts/sim_data_adapter.py scripts/spawn_existing_world.py scripts/mid360_control.py
|
||||||
DESTINATION lib/${PROJECT_NAME})
|
DESTINATION lib/${PROJECT_NAME})
|
||||||
|
|
||||||
install(FILES SOURCE_PROVENANCE.md
|
install(FILES SOURCE_PROVENANCE.md
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
"""Run MID360 and IMU simulation on an already spawned robot."""
|
||||||
|
from launch import LaunchDescription
|
||||||
|
from launch.actions import DeclareLaunchArgument, SetEnvironmentVariable
|
||||||
|
from launch.substitutions import LaunchConfiguration, EnvironmentVariable
|
||||||
|
from launch_ros.actions import Node
|
||||||
|
|
||||||
|
|
||||||
|
def generate_launch_description():
|
||||||
|
return LaunchDescription([
|
||||||
|
SetEnvironmentVariable('ROS_DOMAIN_ID', EnvironmentVariable('ROS_DOMAIN_ID', default_value='77')),
|
||||||
|
SetEnvironmentVariable('ROS_LOCALHOST_ONLY', EnvironmentVariable('ROS_LOCALHOST_ONLY', default_value='1')),
|
||||||
|
DeclareLaunchArgument('sensor_profile', default_value='ideal'),
|
||||||
|
Node(package='r2027_robot_description', executable='mid360_control.py',
|
||||||
|
name='mid360_control', output='screen',
|
||||||
|
arguments=[LaunchConfiguration('sensor_profile')]),
|
||||||
|
])
|
||||||
@@ -1,43 +1,8 @@
|
|||||||
"""启动简化全向机器人(SIM-P2-001)。
|
"""向已运行的 Gazebo Classic 场地生成机器人,不创建第二个 server。"""
|
||||||
|
|
||||||
入口:
|
|
||||||
ros2 launch r2027_robot_description robocon_robot.launch.py
|
|
||||||
ros2 launch r2027_robot_description robocon_robot.launch.py gui:=false paused:=true
|
|
||||||
|
|
||||||
参数:
|
|
||||||
drive planar(默认平地)或 contact(重力/接触决定高度和倾斜)
|
|
||||||
gui 是否启动 gzclient(默认 true)
|
|
||||||
paused 是否以暂停状态启动 gzserver(默认 false)
|
|
||||||
verbose gzserver 详细日志(默认 false)
|
|
||||||
world 覆盖 world(默认 robocon_gazebo/worlds/robocon_robot.world)
|
|
||||||
x / y / z / yaw 出生位姿(默认 -4.5 / 4.5 / 0.17 / 0.0)
|
|
||||||
entity 模型名(默认 r2027_omni)
|
|
||||||
|
|
||||||
启动的节点:
|
|
||||||
gzserver(官方 gazebo_ros gzserver.launch.py,init/factory 各一次,force_system:=false)
|
|
||||||
spawn_entity.py(-file,插入 xacro 展开后的 SDF 模型)
|
|
||||||
static_transform_publisher(world -> odom,单位变换)
|
|
||||||
cmd_vel_timeout(/cmd_vel -> /sim/cmd_vel,仿真时间超时零速)
|
|
||||||
|
|
||||||
为什么模型是 SDF 而不是 URDF:
|
|
||||||
URDF 的 <gazebo reference="link"><mu1>/<mu2>/<kp>/<kd> 在本机链路上**不会**进入物理引擎
|
|
||||||
(`gz sdf -p` 转换出的 collision 没有 <surface>,且 μ=0.05 与 μ=0.0 实测位移完全相同)。
|
|
||||||
轮子因此退回默认 μ=1.0,planar_move 设定的速度每 10 ms 被摩擦拉低,2 s 只走出 0.31 m。
|
|
||||||
改原生 SDF 后接触参数真正生效。代价是不再有 robot_state_publisher 的 URDF 关节树,
|
|
||||||
而任务要求的 TF 只有 world->odom(静态)与 odom->base_link(插件发布),
|
|
||||||
不含轮子帧,因此不需要 robot_state_publisher。
|
|
||||||
|
|
||||||
设计约束:
|
|
||||||
1. 只起一个 gzserver;不启动 ros_gz_bridge、不加载 Fortress。
|
|
||||||
2. odom->base_link 只由插件发布,world->odom 只由静态变换发布,没有第二处重复。
|
|
||||||
3. 世界文件只比 robocon_track_full.world 多一个 libgazebo_ros_state.so world 插件。
|
|
||||||
4. GAZEBO_MASTER_URI=11355、ROS_DOMAIN_ID=77、ROS_LOCALHOST_ONLY=1 与已验收基线一致。
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import math
|
import math
|
||||||
import socket
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
import xacro
|
import xacro
|
||||||
@@ -45,16 +10,20 @@ from ament_index_python.packages import get_package_share_directory, get_package
|
|||||||
from launch import LaunchDescription
|
from launch import LaunchDescription
|
||||||
from launch.actions import (
|
from launch.actions import (
|
||||||
DeclareLaunchArgument,
|
DeclareLaunchArgument,
|
||||||
IncludeLaunchDescription,
|
|
||||||
SetEnvironmentVariable,
|
SetEnvironmentVariable,
|
||||||
OpaqueFunction,
|
OpaqueFunction,
|
||||||
|
RegisterEventHandler,
|
||||||
|
EmitEvent,
|
||||||
)
|
)
|
||||||
|
from launch.event_handlers import OnProcessExit
|
||||||
|
from launch.events import Shutdown
|
||||||
from launch.conditions import IfCondition
|
from launch.conditions import IfCondition
|
||||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
|
||||||
from launch.substitutions import LaunchConfiguration, PythonExpression, EnvironmentVariable
|
from launch.substitutions import LaunchConfiguration, PythonExpression, EnvironmentVariable
|
||||||
from launch_ros.actions import Node
|
from launch_ros.actions import Node
|
||||||
|
|
||||||
GAZEBO_MASTER_URI = 'http://127.0.0.1:11355'
|
# 端口可用环境变量 BR_SIM_MASTER_PORT 覆盖(默认 11355),须与 Gazebo 场地入口一致。
|
||||||
|
MASTER_PORT = int(os.environ.get('BR_SIM_MASTER_PORT', '11355'))
|
||||||
|
GAZEBO_MASTER_URI = f'http://127.0.0.1:{MASTER_PORT}'
|
||||||
|
|
||||||
DEFAULT_X = '-4.5'
|
DEFAULT_X = '-4.5'
|
||||||
DEFAULT_Y = '4.5'
|
DEFAULT_Y = '4.5'
|
||||||
@@ -62,23 +31,9 @@ DEFAULT_Z = '0.17'
|
|||||||
DEFAULT_YAW = '0.0'
|
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():
|
def generate_launch_description():
|
||||||
gz_share = get_package_share_directory('robocon_gazebo')
|
gz_share = get_package_share_directory('robocon_gazebo')
|
||||||
robot_share = get_package_share_directory('r2027_robot_description')
|
robot_share = get_package_share_directory('r2027_robot_description')
|
||||||
gazebo_ros_share = get_package_share_directory('gazebo_ros')
|
|
||||||
|
|
||||||
sdf_xacro = os.path.join(robot_share, 'sdf', 'r2027_omni_robot.sdf.xacro')
|
sdf_xacro = os.path.join(robot_share, 'sdf', 'r2027_omni_robot.sdf.xacro')
|
||||||
# 展开期就确定下来,写成一个文件交给 spawn_entity(-file),
|
# 展开期就确定下来,写成一个文件交给 spawn_entity(-file),
|
||||||
@@ -129,8 +84,8 @@ def generate_launch_description():
|
|||||||
DeclareLaunchArgument('ros_domain_id',default_value=EnvironmentVariable('ROS_DOMAIN_ID',default_value='77')),
|
DeclareLaunchArgument('ros_domain_id',default_value=EnvironmentVariable('ROS_DOMAIN_ID',default_value='77')),
|
||||||
DeclareLaunchArgument('ros_localhost_only',default_value=EnvironmentVariable('ROS_LOCALHOST_ONLY',default_value='1')),
|
DeclareLaunchArgument('ros_localhost_only',default_value=EnvironmentVariable('ROS_LOCALHOST_ONLY',default_value='1')),
|
||||||
DeclareLaunchArgument('drive', default_value='planar'),
|
DeclareLaunchArgument('drive', default_value='planar'),
|
||||||
DeclareLaunchArgument('sensor_model', default_value='generic'),
|
DeclareLaunchArgument('sensor_model', default_value='mid360'),
|
||||||
DeclareLaunchArgument('lidar', default_value='false',
|
DeclareLaunchArgument('lidar', default_value='true',
|
||||||
description='Enable generic CPU 3D lidar and truth data adapter'),
|
description='Enable generic CPU 3D lidar and truth data adapter'),
|
||||||
DeclareLaunchArgument('gui', default_value='true'),
|
DeclareLaunchArgument('gui', default_value='true'),
|
||||||
DeclareLaunchArgument('paused', default_value='false'),
|
DeclareLaunchArgument('paused', default_value='false'),
|
||||||
@@ -141,6 +96,10 @@ def generate_launch_description():
|
|||||||
DeclareLaunchArgument('z', default_value=DEFAULT_Z),
|
DeclareLaunchArgument('z', default_value=DEFAULT_Z),
|
||||||
DeclareLaunchArgument('yaw', default_value=DEFAULT_YAW),
|
DeclareLaunchArgument('yaw', default_value=DEFAULT_YAW),
|
||||||
DeclareLaunchArgument('entity', default_value='r2027_omni'),
|
DeclareLaunchArgument('entity', default_value='r2027_omni'),
|
||||||
|
# 场地较大、加载耗时(本机约 20 s)。gzserver 尚未就绪时调用 /spawn_entity
|
||||||
|
# 会一直挂起且因 use_sim_time 永不超时,所以延迟再生成机器人。
|
||||||
|
DeclareLaunchArgument('spawn_delay', default_value='0.0',
|
||||||
|
description='兼容旧命令;现在由服务就绪检查决定生成时机'),
|
||||||
]
|
]
|
||||||
|
|
||||||
env_actions = [
|
env_actions = [
|
||||||
@@ -157,42 +116,16 @@ def generate_launch_description():
|
|||||||
SetEnvironmentVariable('PATH', '/usr/bin:' + os.environ.get('PATH', '')),
|
SetEnvironmentVariable('PATH', '/usr/bin:' + os.environ.get('PATH', '')),
|
||||||
]
|
]
|
||||||
|
|
||||||
gzserver = IncludeLaunchDescription(
|
|
||||||
PythonLaunchDescriptionSource(
|
|
||||||
os.path.join(gazebo_ros_share, 'launch', 'gzserver.launch.py')),
|
|
||||||
launch_arguments={
|
|
||||||
'world': LaunchConfiguration('world'),
|
|
||||||
'verbose': LaunchConfiguration('verbose'),
|
|
||||||
'pause': LaunchConfiguration('paused'),
|
|
||||||
'init': 'true',
|
|
||||||
'factory': 'true',
|
|
||||||
'force_system': 'false',
|
|
||||||
'params_file': os.path.join(robot_share, 'config', 'gazebo.yaml'),
|
|
||||||
'server_required': 'true',
|
|
||||||
}.items(),
|
|
||||||
)
|
|
||||||
|
|
||||||
gzclient = IncludeLaunchDescription(
|
|
||||||
PythonLaunchDescriptionSource(
|
|
||||||
os.path.join(gazebo_ros_share, 'launch', 'gzclient.launch.py')),
|
|
||||||
condition=IfCondition(LaunchConfiguration('gui')),
|
|
||||||
launch_arguments={'gui_required': 'true'}.items(),
|
|
||||||
)
|
|
||||||
|
|
||||||
spawn = Node(
|
spawn = Node(
|
||||||
package='gazebo_ros',
|
package='r2027_robot_description',
|
||||||
executable='spawn_entity.py',
|
executable='spawn_existing_world.py',
|
||||||
name='spawn_entity',
|
name='spawn_existing_world',
|
||||||
output='screen',
|
output='screen',
|
||||||
parameters=[{'use_sim_time': True}],
|
parameters=[{'use_sim_time': True}],
|
||||||
arguments=[
|
arguments=[
|
||||||
'-file', LaunchConfiguration('expanded_model'),
|
LaunchConfiguration('expanded_model'), LaunchConfiguration('entity'),
|
||||||
'-entity', LaunchConfiguration('entity'),
|
LaunchConfiguration('x'), LaunchConfiguration('y'),
|
||||||
'-x', LaunchConfiguration('x'),
|
LaunchConfiguration('z'), LaunchConfiguration('yaw'),
|
||||||
'-y', LaunchConfiguration('y'),
|
|
||||||
'-z', LaunchConfiguration('z'),
|
|
||||||
'-Y', LaunchConfiguration('yaw'),
|
|
||||||
'-timeout', '120',
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -247,5 +180,8 @@ def generate_launch_description():
|
|||||||
|
|
||||||
return LaunchDescription(
|
return LaunchDescription(
|
||||||
declared_args + env_actions
|
declared_args + env_actions
|
||||||
+ [OpaqueFunction(function=require_free_master), OpaqueFunction(function=expand_model), gzserver, gzclient, spawn,
|
+ [OpaqueFunction(function=expand_model), spawn,
|
||||||
|
RegisterEventHandler(OnProcessExit(target_action=spawn,
|
||||||
|
on_exit=lambda event, context: [EmitEvent(event=Shutdown(reason='robot spawn failed'))]
|
||||||
|
if event.returncode != 0 else [])),
|
||||||
world_to_odom, cmd_timeout, lidar_tf, adapter, imu_tf])
|
world_to_odom, cmd_timeout, lidar_tf, adapter, imu_tf])
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
<depend>livox_ros_driver2</depend>
|
<depend>livox_ros_driver2</depend>
|
||||||
<build_depend>sensor_msgs</build_depend>
|
<build_depend>sensor_msgs</build_depend>
|
||||||
<depend>std_msgs</depend>
|
<depend>std_msgs</depend>
|
||||||
|
<depend>std_srvs</depend>
|
||||||
|
|
||||||
<exec_depend>gazebo_ros</exec_depend>
|
<exec_depend>gazebo_ros</exec_depend>
|
||||||
<exec_depend>gazebo_plugins</exec_depend>
|
<exec_depend>gazebo_plugins</exec_depend>
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Configure and lease the dormant Gazebo MID360 and IMU plugins."""
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
import rclpy
|
||||||
|
from rclpy.signals import SignalHandlerOptions
|
||||||
|
from std_msgs.msg import Empty
|
||||||
|
from std_srvs.srv import Trigger
|
||||||
|
|
||||||
|
|
||||||
|
def invoke(node, name, wait=120.0):
|
||||||
|
client = node.create_client(Trigger, name)
|
||||||
|
if not client.wait_for_service(timeout_sec=wait):
|
||||||
|
raise RuntimeError(f'传感器服务未就绪:{name};先启动带 MID360 的机器人')
|
||||||
|
future = client.call_async(Trigger.Request())
|
||||||
|
rclpy.spin_until_future_complete(node, future, timeout_sec=5.0)
|
||||||
|
if not future.done() or future.exception() or not future.result().success:
|
||||||
|
raise RuntimeError(f'传感器服务调用失败:{name}')
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
profile = sys.argv[1] if len(sys.argv) > 1 else 'ideal'
|
||||||
|
if profile not in ('ideal', 'mild', 'stress'):
|
||||||
|
print('sensor_profile must be ideal, mild or stress', file=sys.stderr)
|
||||||
|
return 2
|
||||||
|
rclpy.init(signal_handler_options=SignalHandlerOptions.NO)
|
||||||
|
node = rclpy.create_node('mid360_control')
|
||||||
|
publisher = node.create_publisher(Empty, '/sim/mid360/heartbeat', 10)
|
||||||
|
try:
|
||||||
|
for component in ('lidar', 'imu'):
|
||||||
|
invoke(node, f'/sim/mid360/{component}/profile/{profile}')
|
||||||
|
node.get_logger().info(f'MID360 与 IMU 已配置为 {profile}')
|
||||||
|
while rclpy.ok():
|
||||||
|
publisher.publish(Empty())
|
||||||
|
rclpy.spin_once(node, timeout_sec=0.2)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
except Exception as exc:
|
||||||
|
node.get_logger().error(str(exc))
|
||||||
|
return 1
|
||||||
|
finally:
|
||||||
|
for component in ('lidar', 'imu'):
|
||||||
|
try:
|
||||||
|
invoke(node, f'/sim/mid360/{component}/disable', wait=0.2)
|
||||||
|
except BaseException:
|
||||||
|
pass
|
||||||
|
node.destroy_node()
|
||||||
|
if rclpy.ok():
|
||||||
|
rclpy.shutdown()
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(main())
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Spawn one robot into an already running Gazebo Classic world."""
|
||||||
|
import math
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
import rclpy
|
||||||
|
from gazebo_msgs.srv import GetEntityState, SpawnEntity
|
||||||
|
from geometry_msgs.msg import Pose
|
||||||
|
|
||||||
|
|
||||||
|
def call(node, client, request, timeout=15.0):
|
||||||
|
future = client.call_async(request)
|
||||||
|
rclpy.spin_until_future_complete(node, future, timeout_sec=timeout)
|
||||||
|
if not future.done() or future.exception():
|
||||||
|
raise RuntimeError(f'{client.srv_name} did not respond within {timeout:g} s')
|
||||||
|
return future.result()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
path, entity, x, y, z, yaw = sys.argv[1:7]
|
||||||
|
rclpy.init()
|
||||||
|
node = rclpy.create_node('spawn_existing_world_client')
|
||||||
|
try:
|
||||||
|
spawn = node.create_client(SpawnEntity, '/spawn_entity')
|
||||||
|
state = node.create_client(GetEntityState, '/gazebo/get_entity_state')
|
||||||
|
if not spawn.wait_for_service(timeout_sec=120.0) or not state.wait_for_service(timeout_sec=30.0):
|
||||||
|
raise RuntimeError('场地服务未就绪;先启动 robocon_gazebo.launch.py(robocon_robot.world)')
|
||||||
|
query = GetEntityState.Request()
|
||||||
|
query.name = entity
|
||||||
|
if call(node, state, query).success:
|
||||||
|
raise RuntimeError(f'机器人实体 {entity} 已存在;请勿重复启动机器人入口')
|
||||||
|
request = SpawnEntity.Request()
|
||||||
|
request.name = entity
|
||||||
|
with open(path, encoding='utf-8') as stream:
|
||||||
|
request.xml = stream.read()
|
||||||
|
pose = Pose()
|
||||||
|
pose.position.x, pose.position.y, pose.position.z = map(float, (x, y, z))
|
||||||
|
half = float(yaw) / 2.0
|
||||||
|
pose.orientation.z, pose.orientation.w = math.sin(half), math.cos(half)
|
||||||
|
request.initial_pose = pose
|
||||||
|
request.reference_frame = 'world'
|
||||||
|
result = call(node, spawn, request, 120.0)
|
||||||
|
if not result.success:
|
||||||
|
raise RuntimeError(f'生成机器人失败:{result.status_message}')
|
||||||
|
node.get_logger().info(f'已生成机器人 {entity}')
|
||||||
|
except Exception as exc:
|
||||||
|
node.get_logger().error(str(exc))
|
||||||
|
return 1
|
||||||
|
finally:
|
||||||
|
node.destroy_node()
|
||||||
|
rclpy.shutdown()
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(main())
|
||||||
@@ -9,6 +9,10 @@
|
|||||||
#include <gazebo_ros/node.hpp>
|
#include <gazebo_ros/node.hpp>
|
||||||
#include <gazebo_ros/conversions/builtin_interfaces.hpp>
|
#include <gazebo_ros/conversions/builtin_interfaces.hpp>
|
||||||
#include <sensor_msgs/msg/imu.hpp>
|
#include <sensor_msgs/msg/imu.hpp>
|
||||||
|
#include <std_msgs/msg/empty.hpp>
|
||||||
|
#include <std_srvs/srv/trigger.hpp>
|
||||||
|
#include <atomic>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
namespace br_sim {
|
namespace br_sim {
|
||||||
class Mid360Imu : public gazebo::SensorPlugin {
|
class Mid360Imu : public gazebo::SensorPlugin {
|
||||||
@@ -22,13 +26,40 @@ class Mid360Imu : public gazebo::SensorPlugin {
|
|||||||
gyro_bias_=sdf->Get<ignition::math::Vector3d>("gyro_bias",{}).first;
|
gyro_bias_=sdf->Get<ignition::math::Vector3d>("gyro_bias",{}).first;
|
||||||
if(!std::isfinite(accel_stddev_) || accel_stddev_<0 || !std::isfinite(gyro_stddev_) || gyro_stddev_<0 ||
|
if(!std::isfinite(accel_stddev_) || accel_stddev_<0 || !std::isfinite(gyro_stddev_) || gyro_stddev_<0 ||
|
||||||
!accel_bias_.IsFinite() || !gyro_bias_.IsFinite()) throw std::invalid_argument("Invalid IMU noise/bias");
|
!accel_bias_.IsFinite() || !gyro_bias_.IsFinite()) throw std::invalid_argument("Invalid IMU noise/bias");
|
||||||
rng_.seed(sdf->Get<unsigned>("noise_seed",2027u).first+1u);
|
seed_=sdf->Get<unsigned>("noise_seed",2027u).first;
|
||||||
|
rng_.seed(seed_+1u);
|
||||||
node_=gazebo_ros::Node::Get(sdf);
|
node_=gazebo_ros::Node::Get(sdf);
|
||||||
|
for (int i=0;i<3;++i) {
|
||||||
|
const std::string name=std::string("/sim/mid360/imu/profile/")+profiles_[i];
|
||||||
|
profile_services_[i]=node_->create_service<std_srvs::srv::Trigger>(name,
|
||||||
|
[this,i](const std::shared_ptr<std_srvs::srv::Trigger::Request>,
|
||||||
|
std::shared_ptr<std_srvs::srv::Trigger::Response> response) {
|
||||||
|
profile_.store(i); response->success=true; response->message=profiles_[i]; });
|
||||||
|
}
|
||||||
|
disable_service_=node_->create_service<std_srvs::srv::Trigger>("/sim/mid360/imu/disable",
|
||||||
|
[this](const std::shared_ptr<std_srvs::srv::Trigger::Request>,
|
||||||
|
std::shared_ptr<std_srvs::srv::Trigger::Response> response) {
|
||||||
|
last_heartbeat_.store(0); response->success=true; response->message="disabled"; });
|
||||||
|
heartbeat_=node_->create_subscription<std_msgs::msg::Empty>("/sim/mid360/heartbeat",10,
|
||||||
|
[this](const std_msgs::msg::Empty::SharedPtr) { last_heartbeat_.store(NowSteady()); });
|
||||||
pub_=node_->create_publisher<sensor_msgs::msg::Imu>("/sim/mid360/imu",rclcpp::SensorDataQoS().reliable());
|
pub_=node_->create_publisher<sensor_msgs::msg::Imu>("/sim/mid360/imu",rclcpp::SensorDataQoS().reliable());
|
||||||
update_=sensor_->ConnectUpdated(std::bind(&Mid360Imu::Publish,this));
|
update_=sensor_->ConnectUpdated(std::bind(&Mid360Imu::Publish,this));
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
static int64_t NowSteady() { return std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||||
|
std::chrono::steady_clock::now().time_since_epoch()).count(); }
|
||||||
void Publish() {
|
void Publish() {
|
||||||
|
if (NowSteady()-last_heartbeat_.load()>1000000000LL) return;
|
||||||
|
const int selected=profile_.load();
|
||||||
|
if (selected!=applied_profile_) {
|
||||||
|
constexpr double accel_noise[]={0.,.01,.04},gyro_noise[]={0.,.0005,.0015};
|
||||||
|
accel_stddev_=accel_noise[selected];gyro_stddev_=gyro_noise[selected];
|
||||||
|
const double accel_bias[][3]={{0,0,0},{.005,-.005,.01},{.02,.01,.03}};
|
||||||
|
const double gyro_bias[][3]={{0,0,0},{.0001,-.0001,.0002},{.0005,-.0005,.001}};
|
||||||
|
accel_bias_.Set(accel_bias[selected][0],accel_bias[selected][1],accel_bias[selected][2]);
|
||||||
|
gyro_bias_.Set(gyro_bias[selected][0],gyro_bias[selected][1],gyro_bias[selected][2]);
|
||||||
|
rng_.seed(seed_+1u);applied_profile_=selected;
|
||||||
|
}
|
||||||
// One synchronized sensor reading, including its actual link-data timestamp.
|
// One synchronized sensor reading, including its actual link-data timestamp.
|
||||||
const auto reading=sensor_->ImuMessage();
|
const auto reading=sensor_->ImuMessage();
|
||||||
sensor_msgs::msg::Imu msg;
|
sensor_msgs::msg::Imu msg;
|
||||||
@@ -60,6 +91,12 @@ class Mid360Imu : public gazebo::SensorPlugin {
|
|||||||
gazebo_ros::Node::SharedPtr node_;
|
gazebo_ros::Node::SharedPtr node_;
|
||||||
rclcpp::Publisher<sensor_msgs::msg::Imu>::SharedPtr pub_;
|
rclcpp::Publisher<sensor_msgs::msg::Imu>::SharedPtr pub_;
|
||||||
gazebo::event::ConnectionPtr update_;
|
gazebo::event::ConnectionPtr update_;
|
||||||
|
const char *profiles_[3]={"ideal","mild","stress"};
|
||||||
|
unsigned seed_{2027};
|
||||||
|
std::atomic<int> profile_{0}; int applied_profile_{-1};
|
||||||
|
std::atomic<int64_t> last_heartbeat_{0};
|
||||||
|
rclcpp::Subscription<std_msgs::msg::Empty>::SharedPtr heartbeat_;
|
||||||
|
rclcpp::Service<std_srvs::srv::Trigger>::SharedPtr profile_services_[3],disable_service_;
|
||||||
};
|
};
|
||||||
GZ_REGISTER_SENSOR_PLUGIN(Mid360Imu)
|
GZ_REGISTER_SENSOR_PLUGIN(Mid360Imu)
|
||||||
} // namespace br_sim
|
} // namespace br_sim
|
||||||
|
|||||||
@@ -15,6 +15,10 @@
|
|||||||
#include <sensor_msgs/msg/point_cloud2.hpp>
|
#include <sensor_msgs/msg/point_cloud2.hpp>
|
||||||
#include <sensor_msgs/point_cloud2_iterator.hpp>
|
#include <sensor_msgs/point_cloud2_iterator.hpp>
|
||||||
#include <std_msgs/msg/string.hpp>
|
#include <std_msgs/msg/string.hpp>
|
||||||
|
#include <std_msgs/msg/empty.hpp>
|
||||||
|
#include <std_srvs/srv/trigger.hpp>
|
||||||
|
#include <atomic>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
namespace br_sim {
|
namespace br_sim {
|
||||||
class Mid360Sensor : public gazebo::ModelPlugin {
|
class Mid360Sensor : public gazebo::ModelPlugin {
|
||||||
@@ -33,6 +37,19 @@ class Mid360Sensor : public gazebo::ModelPlugin {
|
|||||||
throw std::invalid_argument("Invalid MID360 range noise/dropout");
|
throw std::invalid_argument("Invalid MID360 range noise/dropout");
|
||||||
rng_.seed(seed_);
|
rng_.seed(seed_);
|
||||||
node_=gazebo_ros::Node::Get(sdf);
|
node_=gazebo_ros::Node::Get(sdf);
|
||||||
|
for (int i=0;i<3;++i) {
|
||||||
|
const std::string name=std::string("/sim/mid360/lidar/profile/")+profiles_[i];
|
||||||
|
profile_services_[i]=node_->create_service<std_srvs::srv::Trigger>(name,
|
||||||
|
[this,i](const std::shared_ptr<std_srvs::srv::Trigger::Request>,
|
||||||
|
std::shared_ptr<std_srvs::srv::Trigger::Response> response) {
|
||||||
|
profile_.store(i); response->success=true; response->message=profiles_[i]; });
|
||||||
|
}
|
||||||
|
disable_service_=node_->create_service<std_srvs::srv::Trigger>("/sim/mid360/lidar/disable",
|
||||||
|
[this](const std::shared_ptr<std_srvs::srv::Trigger::Request>,
|
||||||
|
std::shared_ptr<std_srvs::srv::Trigger::Response> response) {
|
||||||
|
last_heartbeat_.store(0); response->success=true; response->message="disabled"; });
|
||||||
|
heartbeat_=node_->create_subscription<std_msgs::msg::Empty>("/sim/mid360/heartbeat",10,
|
||||||
|
[this](const std_msgs::msg::Empty::SharedPtr) { last_heartbeat_.store(NowSteady()); });
|
||||||
ray_=boost::dynamic_pointer_cast<gazebo::physics::RayShape>(
|
ray_=boost::dynamic_pointer_cast<gazebo::physics::RayShape>(
|
||||||
world_->Physics()->CreateShape("ray",gazebo::physics::CollisionPtr()));
|
world_->Physics()->CreateShape("ray",gazebo::physics::CollisionPtr()));
|
||||||
if(!ray_) { gzerr << "Physics engine does not provide RayShape\n";return; }
|
if(!ray_) { gzerr << "Physics engine does not provide RayShape\n";return; }
|
||||||
@@ -46,6 +63,8 @@ class Mid360Sensor : public gazebo::ModelPlugin {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static double Fraction(double x) { return x-std::floor(x); }
|
static double Fraction(double x) { return x-std::floor(x); }
|
||||||
|
static int64_t NowSteady() { return std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||||
|
std::chrono::steady_clock::now().time_since_epoch()).count(); }
|
||||||
void Begin(int64_t now) {
|
void Begin(int64_t now) {
|
||||||
frame_=livox_ros_driver2::msg::CustomMsg();
|
frame_=livox_ros_driver2::msg::CustomMsg();
|
||||||
frame_.header.frame_id="lidar";
|
frame_.header.frame_id="lidar";
|
||||||
@@ -54,6 +73,13 @@ class Mid360Sensor : public gazebo::ModelPlugin {
|
|||||||
frame_.points.reserve(20000);first_=now;last_sample_=now;rays_=0;hits_=0;dropped_=0;rejected_=0;
|
frame_.points.reserve(20000);first_=now;last_sample_=now;rays_=0;hits_=0;dropped_=0;rejected_=0;
|
||||||
}
|
}
|
||||||
void Sample() {
|
void Sample() {
|
||||||
|
if (NowSteady()-last_heartbeat_.load()>1000000000LL) { first_=-1; last_=-1; return; }
|
||||||
|
const int selected=profile_.load();
|
||||||
|
if (selected!=applied_profile_) {
|
||||||
|
constexpr double range_noise[]={0.,.005,.015},dropout[]={0.,.01,.05};
|
||||||
|
range_stddev_=range_noise[selected];dropout_=dropout[selected];rng_.seed(seed_);
|
||||||
|
applied_profile_=selected;first_=-1;last_=-1;
|
||||||
|
}
|
||||||
const int64_t now=world_->SimTime().sec*int64_t(1000000000)+world_->SimTime().nsec;
|
const int64_t now=world_->SimTime().sec*int64_t(1000000000)+world_->SimTime().nsec;
|
||||||
if(first_<0) Begin(now);
|
if(first_<0) Begin(now);
|
||||||
if(last_>=0 && now-last_!=step_ns_) {
|
if(last_>=0 && now-last_!=step_ns_) {
|
||||||
@@ -132,6 +158,11 @@ class Mid360Sensor : public gazebo::ModelPlugin {
|
|||||||
std::normal_distribution<double> normal_{0.,1.};
|
std::normal_distribution<double> normal_{0.,1.};
|
||||||
std::uniform_real_distribution<double> uniform_{0.,1.};
|
std::uniform_real_distribution<double> uniform_{0.,1.};
|
||||||
gazebo::event::ConnectionPtr update_;
|
gazebo::event::ConnectionPtr update_;
|
||||||
|
const char *profiles_[3]={"ideal","mild","stress"};
|
||||||
|
std::atomic<int> profile_{0}; int applied_profile_{-1};
|
||||||
|
std::atomic<int64_t> last_heartbeat_{0};
|
||||||
|
rclcpp::Subscription<std_msgs::msg::Empty>::SharedPtr heartbeat_;
|
||||||
|
rclcpp::Service<std_srvs::srv::Trigger>::SharedPtr profile_services_[3],disable_service_;
|
||||||
};
|
};
|
||||||
GZ_REGISTER_MODEL_PLUGIN(Mid360Sensor)
|
GZ_REGISTER_MODEL_PLUGIN(Mid360Sensor)
|
||||||
} // namespace br_sim
|
} // namespace br_sim
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ find_package(ament_cmake REQUIRED)
|
|||||||
# worlds/ robocon_track_full.world(仅移除两个错位的 ROS 系统插件声明)
|
# worlds/ robocon_track_full.world(仅移除两个错位的 ROS 系统插件声明)
|
||||||
# models/ robocon_ground_full(model.config + model.sdf + meshes/)
|
# models/ robocon_ground_full(model.config + model.sdf + meshes/)
|
||||||
|
|
||||||
install(DIRECTORY launch worlds models
|
install(DIRECTORY launch worlds models config
|
||||||
DESTINATION share/${PROJECT_NAME}
|
DESTINATION share/${PROJECT_NAME}
|
||||||
PATTERN "__pycache__" EXCLUDE
|
PATTERN "__pycache__" EXCLUDE
|
||||||
PATTERN "*.pyc" EXCLUDE)
|
PATTERN "*.pyc" EXCLUDE)
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
gazebo:
|
||||||
|
ros__parameters:
|
||||||
|
publish_rate: 100.0
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
"""启动 ROBOCON 2027 完整场地(Gazebo Classic 11 + ROS 2 Humble)。
|
"""启动 ROBOCON 2027 完整场地与机器人生成服务(Gazebo Classic 11)。
|
||||||
|
|
||||||
入口统一为:
|
入口统一为:
|
||||||
ros2 launch robocon_gazebo robocon_gazebo.launch.py
|
ros2 launch robocon_gazebo robocon_gazebo.launch.py
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
gui 是否启动一个 gzclient(默认 true)
|
gui 是否启动一个 gzclient(默认 true)
|
||||||
paused 是否以暂停状态启动 gzserver(默认 false)
|
paused 是否以暂停状态启动 gzserver(默认 false)
|
||||||
verbose gzserver 是否输出详细日志(默认 false)
|
verbose gzserver 是否输出详细日志(默认 false)
|
||||||
world 可覆盖 world 路径(默认包内 worlds/robocon_track_full.world)
|
world 可覆盖 world 路径(默认包内 worlds/robocon_robot.world)
|
||||||
|
|
||||||
设计要点(SIM-P1-004-C):
|
设计要点(SIM-P1-004-C):
|
||||||
1. 只通过**官方 gazebo_ros 的 gzserver.launch.py** 加载 libgazebo_ros_init.so 与
|
1. 只通过**官方 gazebo_ros 的 gzserver.launch.py** 加载 libgazebo_ros_init.so 与
|
||||||
@@ -19,13 +19,13 @@
|
|||||||
3. 不启动 ros_gz_bridge,不加载 Fortress(ignition)任何组件。
|
3. 不启动 ros_gz_bridge,不加载 Fortress(ignition)任何组件。
|
||||||
4. GAZEBO_MASTER_URI 固定到 127.0.0.1:11355(与默认 11345 隔离),
|
4. GAZEBO_MASTER_URI 固定到 127.0.0.1:11355(与默认 11345 隔离),
|
||||||
server / client / 采集工具共用同一 master;ROS_DOMAIN_ID=77、ROS_LOCALHOST_ONLY=1。
|
server / client / 采集工具共用同一 master;ROS_DOMAIN_ID=77、ROS_LOCALHOST_ONLY=1。
|
||||||
5. 不接入机器人、TF、里程计、点云或 /cmd_vel。
|
5. 不生成机器人、TF、里程计、点云或 /cmd_vel;world 插件提供实体状态服务。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from ament_index_python.packages import get_package_share_directory
|
from ament_index_python.packages import get_package_share_directory, get_package_prefix
|
||||||
from launch import LaunchDescription
|
from launch import LaunchDescription
|
||||||
from launch.actions import (
|
from launch.actions import (
|
||||||
DeclareLaunchArgument,
|
DeclareLaunchArgument,
|
||||||
@@ -35,27 +35,30 @@ from launch.actions import (
|
|||||||
)
|
)
|
||||||
from launch.conditions import IfCondition
|
from launch.conditions import IfCondition
|
||||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||||
from launch.substitutions import LaunchConfiguration
|
from launch.substitutions import LaunchConfiguration, EnvironmentVariable
|
||||||
|
|
||||||
# 与采集工具、手动 gzclient 保持一致(改这里就要同步改 tools/check_classic_baseline.py)
|
# 与采集工具、手动 gzclient 保持一致(改这里就要同步改 tools/check_classic_baseline.py)
|
||||||
GAZEBO_MASTER_URI = 'http://127.0.0.1:11355'
|
# 端口可用环境变量 BR_SIM_MASTER_PORT 覆盖(默认 11355):端口被其他程序占用时换一个即可。
|
||||||
|
MASTER_PORT = int(os.environ.get('BR_SIM_MASTER_PORT', '11355'))
|
||||||
|
GAZEBO_MASTER_URI = f'http://127.0.0.1:{MASTER_PORT}'
|
||||||
ROS_DOMAIN_ID = '77'
|
ROS_DOMAIN_ID = '77'
|
||||||
|
|
||||||
|
|
||||||
def require_free_master(context):
|
def require_free_master(context):
|
||||||
with socket.socket() as connection:
|
with socket.socket() as connection:
|
||||||
connection.settimeout(0.3)
|
connection.settimeout(0.3)
|
||||||
if connection.connect_ex(('127.0.0.1', 11355)) == 0:
|
if connection.connect_ex(('127.0.0.1', MASTER_PORT)) == 0:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
'Gazebo 端口 11355 已被占用:请先在原仿真或自动测试终端按 Ctrl+C,'
|
f'Gazebo 端口 {MASTER_PORT} 已被占用:请先在原仿真或自动测试终端按 Ctrl+C,'
|
||||||
'等待退出后重试。本入口不会终止已有进程。')
|
'等待退出后重试;或设置 BR_SIM_MASTER_PORT 换端口。'
|
||||||
|
'本入口不会终止已有进程。')
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def generate_launch_description():
|
def generate_launch_description():
|
||||||
share = get_package_share_directory('robocon_gazebo')
|
share = get_package_share_directory('robocon_gazebo')
|
||||||
models_dir = os.path.join(share, 'models')
|
models_dir = os.path.join(share, 'models')
|
||||||
default_world = os.path.join(share, 'worlds', 'robocon_track_full.world')
|
default_world = os.path.join(share, 'worlds', 'robocon_robot.world')
|
||||||
gazebo_ros_share = get_package_share_directory('gazebo_ros')
|
gazebo_ros_share = get_package_share_directory('gazebo_ros')
|
||||||
|
|
||||||
# 模型查找路径:本包安装的模型在前,其余沿用环境与 ~/.gazebo/models
|
# 模型查找路径:本包安装的模型在前,其余沿用环境与 ~/.gazebo/models
|
||||||
@@ -78,9 +81,12 @@ def generate_launch_description():
|
|||||||
# 环境隔离:master 端口、ROS 域、仅本机通信、模型路径
|
# 环境隔离:master 端口、ROS 域、仅本机通信、模型路径
|
||||||
env_actions = [
|
env_actions = [
|
||||||
SetEnvironmentVariable('GAZEBO_MASTER_URI', GAZEBO_MASTER_URI),
|
SetEnvironmentVariable('GAZEBO_MASTER_URI', GAZEBO_MASTER_URI),
|
||||||
SetEnvironmentVariable('ROS_DOMAIN_ID', ROS_DOMAIN_ID),
|
SetEnvironmentVariable('ROS_DOMAIN_ID', EnvironmentVariable('ROS_DOMAIN_ID', default_value=ROS_DOMAIN_ID)),
|
||||||
SetEnvironmentVariable('ROS_LOCALHOST_ONLY', '1'),
|
SetEnvironmentVariable('ROS_LOCALHOST_ONLY', EnvironmentVariable('ROS_LOCALHOST_ONLY', default_value='1')),
|
||||||
SetEnvironmentVariable('GAZEBO_MODEL_PATH', model_path),
|
SetEnvironmentVariable('GAZEBO_MODEL_PATH', model_path),
|
||||||
|
SetEnvironmentVariable('GAZEBO_PLUGIN_PATH', os.pathsep.join([
|
||||||
|
os.path.join(get_package_prefix('r2027_robot_description'), 'lib'),
|
||||||
|
os.environ.get('GAZEBO_PLUGIN_PATH', '')])),
|
||||||
]
|
]
|
||||||
|
|
||||||
gzserver = IncludeLaunchDescription(
|
gzserver = IncludeLaunchDescription(
|
||||||
@@ -93,6 +99,7 @@ def generate_launch_description():
|
|||||||
'init': 'true', # -s libgazebo_ros_init.so
|
'init': 'true', # -s libgazebo_ros_init.so
|
||||||
'factory': 'true', # -s libgazebo_ros_factory.so
|
'factory': 'true', # -s libgazebo_ros_factory.so
|
||||||
'force_system': 'false', # 不再多加载一个系统插件
|
'force_system': 'false', # 不再多加载一个系统插件
|
||||||
|
'params_file': os.path.join(share, 'config', 'gazebo.yaml'),
|
||||||
'server_required': 'true', # 关掉 launch 时一起收掉 gzserver
|
'server_required': 'true', # 关掉 launch 时一起收掉 gzserver
|
||||||
}.items(),
|
}.items(),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -256,10 +256,12 @@ class Sim(object):
|
|||||||
'br_sim_bringup '+('scan_lio_terrain.launch.py' if terrain else 'scan_lio.launch.py') if lio_navigation else
|
'br_sim_bringup '+('scan_lio_terrain.launch.py' if terrain else 'scan_lio.launch.py') if lio_navigation else
|
||||||
'br_sim_bringup mid360_sim.launch.py' if localization else
|
'br_sim_bringup mid360_sim.launch.py' if localization else
|
||||||
'br_sim_bringup '+('scan_terrain.launch.py' if terrain else 'scan_sim.launch.py') if navigation else
|
'br_sim_bringup '+('scan_terrain.launch.py' if terrain else 'scan_sim.launch.py') if navigation else
|
||||||
'r2027_robot_description robocon_robot.launch.py')
|
'br_sim_bringup robot_sim.launch.py')
|
||||||
options = ('gui:=%s' % ('true' if gui else 'false'))
|
options = ('gui:=%s' % ('true' if gui else 'false'))
|
||||||
if lio_navigation:
|
if lio_navigation:
|
||||||
options += ' sensor_profile:='+sensor_profile
|
options += ' sensor_profile:='+sensor_profile
|
||||||
|
if not terrain and not split:
|
||||||
|
options += ' with_rviz:=false'
|
||||||
if split:options += ' terrain:='+('true' if terrain else 'false')
|
if split:options += ' terrain:='+('true' if terrain else 'false')
|
||||||
elif localization:
|
elif localization:
|
||||||
options += ' with_lio:=true sensor_profile:='+sensor_profile
|
options += ' with_lio:=true sensor_profile:='+sensor_profile
|
||||||
@@ -294,10 +296,11 @@ class Sim(object):
|
|||||||
return False, 'launch 进程提前退出 code=%s' % self.proc.returncode
|
return False, 'launch 进程提前退出 code=%s' % self.proc.returncode
|
||||||
for p in proc_tree(self.proc.pid):
|
for p in proc_tree(self.proc.pid):
|
||||||
self.known[p] = _comm(p)
|
self.known[p] = _comm(p)
|
||||||
# The port/clock can become ready before spawn_entity finishes.
|
# The port/clock can become ready before the robot is spawned.
|
||||||
# All callers use the robot entry: require its actual spawn success
|
# Require explicit success from either the legacy or split spawn client.
|
||||||
# before allowing a state query/reset, independently of settling.
|
launch_log = self.log_text()
|
||||||
model_ready = 'Spawn status: SpawnEntity: Successfully spawned entity' in self.log_text()
|
model_ready = ('Spawn status: SpawnEntity: Successfully spawned entity' in launch_log
|
||||||
|
or '已生成机器人' in launch_log)
|
||||||
if model_ready and port_open(port=11355) and any(v == 'gzserver' for v in self.known.values()):
|
if model_ready and port_open(port=11355) and any(v == 'gzserver' for v in self.known.values()):
|
||||||
return True, 'gzserver 与模型生成均已就绪(%.1f s)' % (time.monotonic() - t0)
|
return True, 'gzserver 与模型生成均已就绪(%.1f s)' % (time.monotonic() - t0)
|
||||||
return False, '在 %.0f s 内未就绪' % timeout
|
return False, '在 %.0f s 内未就绪' % timeout
|
||||||
|
|||||||
Reference in New Issue
Block a user