Compare commits

...

2 Commits

Author SHA1 Message Date
äHuang77 553dcc3081 update 2026-05-18 11:35:21 +00:00
äHuang77 2f9bcbb8ad update 2026-05-18 11:34:58 +00:00
5 changed files with 67 additions and 69 deletions

View File

@ -22,11 +22,9 @@
### 编译 ### 编译
```bash ```bash
cd /workspace
# pip install -r requirements.txt # pip install -r requirements.txt
cd /workspace
colcon build --symlink-install colcon build --symlink-install
source /opt/ros/humble/setup.bash
source install/setup.bash
``` ```
### 注意事项 ### 注意事项
@ -34,65 +32,64 @@ source install/setup.bash
```bash ```bash
source /opt/ros/humble/setup.bash source /opt/ros/humble/setup.bash
source install/setup.bash source /workspace/install/setup.bash
export TURTLEBOT3_MODEL=burger
export NAV2_MAP_PATH=/workspace/src/turtlebot3_simulations/turtlebot3_gazebo/map/office_map.yaml export NAV2_MAP_PATH=/workspace/src/turtlebot3_simulations/turtlebot3_gazebo/map/office_map.yaml
``` ```
为了方便,也可以写入 `~/.bashrc` ## 2. 启动仿真(后面每一个步骤都在新终端执行)
```bash
echo 'source /opt/ros/humble/setup.bash' >> ~/.bashrc
echo 'source /workspace/install/setup.bash' >> ~/.bashrc
echo 'export TURTLEBOT3_MODEL=burger' >> ~/.bashrc
echo 'export NAV2_MAP_PATH=/workspace/src/turtlebot3_simulations/turtlebot3_gazebo/map/office_map.yaml' >> ~/.bashrc
source ~/.bashrc
```
1. 启动仿真, Nav2导航栈 AMCL节点rviz
```bash ```bash
./gzsim_run.sh ./gzsim_run.sh
```
## 3. 启动 AMCL节点负责 “map_server + amcl”
```bash
ros2 launch nav2_rrtstar_planner bringup_localization_with_initial_pose.launch.py \ ros2 launch nav2_rrtstar_planner bringup_localization_with_initial_pose.launch.py \
use_sim_time:=true \ use_sim_time:=true \
map:=$NAV2_MAP_PATH map:=$NAV2_MAP_PATH \
params_file:=/workspace/src/TurtleBot-RRT-Star/nav2_params.yaml
```
## 4. 启动 Nav2导航栈负责 “RRT* 规划器 + controller + bt_navigator
```bash
ros2 launch nav2_bringup navigation_launch.py \ ros2 launch nav2_bringup navigation_launch.py \
use_sim_time:=True \ use_sim_time:=True \
params_file:=/workspace/src/TurtleBot-RRT-Star/nav2_params.yaml \ params_file:=/workspace/src/TurtleBot-RRT-Star/nav2_params.yaml
map:=$NAV2_MAP_PATH ```
## 5. 打开rviz
```bash
export __NV_PRIME_RENDER_OFFLOAD=1 export __NV_PRIME_RENDER_OFFLOAD=1
export __GLX_VENDOR_LIBRARY_NAME=nvidia export __GLX_VENDOR_LIBRARY_NAME=nvidia
ros2 run rviz2 rviz2 -d /opt/ros/humble/share/nav2_bringup/rviz/nav2_default_view.rviz --ros-args -p use_sim_time:=true ros2 run rviz2 rviz2 -d /opt/ros/humble/share/nav2_bringup/rviz/nav2_default_view.rviz --ros-args -p use_sim_time:=true
``` ```
2. 新开终端执行环境生效后启动vlm_perception_pkg的语义检测节点开始目标语义标注并构建语义记忆库在机器人导航过程中节点实时检测环境中的目标并生成语义标注结果保存JSON 格式的语义记忆库到指定路径。
新开终端执行环境生效后启动vlm_perception_pkg的语义检测节点开始目标语义标注并构建语义记忆库在机器人导航过程中节点实时检测环境中的目标并生成语义标注结果保存JSON 格式的语义记忆库到指定路径。
## 6. 启动目标检测节点
```bash ```bash
ros2 run vlm_perception_pkg vlm_detection --ros-args -p use_sim_time:=true ros2 run vlm_perception_pkg vlm_detection --ros-args -p use_sim_time:=true
# 默认:启动时加载历史 JSON同一个语义记忆库文件 # 默认:启动时加载历史 JSON同一个语义记忆库文件可选启动时重置语义记忆库避免历史最高分长期不更新
# 可选:启动时重置语义记忆库,避免历史最高分长期不更新
# ros2 run vlm_perception_pkg vlm_detection --ros-args -p use_sim_time:=true -p reset_records_on_startup:=true # ros2 run vlm_perception_pkg vlm_detection --ros-args -p use_sim_time:=true -p reset_records_on_startup:=true
``` ```
3. 加载生成的语义记忆库文件in /workspace/src/vlm_nav_pkg/config通过 CLIP 将语义标签编码为shared embedding space当用户输入自然语言查询时系统匹配最接近的已知目标提取其坐标并发送至 Nav2实现基于自然语言的语义导航。以下是验证步骤 ### 导航建议
4. 重新启动仿真, Nav2导航栈 AMCL节点rviz - TurtleBot3 机身较矮,相机视角较低,高目标物体适合较远距离观测。
- 建议在机器人低速或短暂停止时运行检测,以提高 RGB-D 与 TF 的稳定性。
- 建议目标距离相机约 1~3 米,可以多角度对目标进行观察。
- 本项目保存的是“最高分对应的目标坐标”,适合用于导航到目标附近,不保证是物体几何中心。
检测完成后可查看目标标注结果in /workspace/src/vlm_nav_pkg/config带时间戳加载生成的语义记忆库文件通过 CLIP 将语义标签编码为shared embedding space当用户输入自然语言查询时系统匹配最接近的已知目标提取其坐标并发送至 Nav2实现基于自然语言的语义导航。
## 7. 启动目标检测节点
```bash ```bash
# 关闭检测节点后
./gzsim_run.sh # pip3 install "numpy<2"
ros2 launch nav2_rrtstar_planner bringup_localization_with_initial_pose.launch.py \
use_sim_time:=true \
map:=$NAV2_MAP_PATH
ros2 launch nav2_bringup navigation_launch.py \
use_sim_time:=True \
params_file:=/workspace/src/TurtleBot-RRT-Star/nav2_params.yaml \
map:=$NAV2_MAP_PATH
ros2 run rviz2 rviz2 -d /opt/ros/humble/share/nav2_bringup/rviz/nav2_default_view.rviz --ros-args -p use_sim_time:=true
pip3 install "numpy<2"
ros2 run vlm_nav_pkg semantic_nav ros2 run vlm_nav_pkg semantic_nav
``` ```
节点启动后,在终端输入自然语言语义目标(如 “water dispenser”“sofa”系统将自动完成语义查询与shared embedding space匹配提取目标对应的地图坐标并向 Nav2 发送导航目标位姿然后机器人自主规划路径并导航至语义目标位置RViz2 中实时可视化规划路径与导航过程 节点启动后,在终端输入自然语言语义目标(如 “water dispenser”“sofa”系统将自动完成语义查询与shared embedding space匹配提取目标对应的地图坐标并向 Nav2 发送导航目标位姿然后机器人自主规划路径并导航至语义目标位置RViz2 中实时可视化规划路径与导航过程。当前导航会默认在目标周围生成多个候选接近点,并优先选择距离当前机器人最近的可行点,避免直接撞向物体中心点。候选点会先经过 `/map` 自由空间筛选,再逐个试算全局路径,只在“有路径”的候选点里选最优目标。
![图7](assets/picture07.png)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 230 KiB

After

Width:  |  Height:  |  Size: 377 KiB

View File

@ -79,10 +79,6 @@ install(DIRECTORY launch/
DESTINATION share/${PROJECT_NAME}/launch DESTINATION share/${PROJECT_NAME}/launch
) )
install(DIRECTORY scripts/
DESTINATION share/${PROJECT_NAME}/scripts
)
if(BUILD_TESTING) if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED) find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies() ament_lint_auto_find_test_dependencies()

View File

@ -1,7 +1,7 @@
{ {
"Refrigerator": { "Refrigerator": {
"highest_score": 0.301513671875, "highest_score": 0.271240234375,
"last_detected": "2026-05-18T14:13:25.085735", "last_detected": "2026-05-18T10:25:26.258502",
"position": { "position": {
"x": -1.3181, "x": -1.3181,
"y": 0.5165, "y": 0.5165,
@ -9,39 +9,39 @@
} }
}, },
"water dispenser": { "water dispenser": {
"highest_score": 0.316162109375, "highest_score": 0.31689453125,
"last_detected": "2026-05-18T14:15:56.440127", "last_detected": "2026-05-18T10:26:11.990891",
"position": { "position": {
"x": -1.6292, "x": -1.4587,
"y": -1.7906, "y": -1.8551,
"z": 0.661 "z": 0.6153
} }
}, },
"sofa": { "sofa": {
"highest_score": 0.307861328125, "highest_score": 0.311767578125,
"last_detected": "2026-05-18T14:17:27.585956", "last_detected": "2026-05-18T10:26:51.065460",
"position": { "position": {
"x": 1.4535, "x": 1.6362,
"y": -0.4709, "y": 0.2425,
"z": 0.5445 "z": 0.4759
} }
}, },
"white toilet": { "white toilet": {
"highest_score": 0.269287109375, "highest_score": 0.2568359375,
"last_detected": "2026-05-18T14:13:07.308074", "last_detected": "2026-05-18T10:25:18.120319",
"position": { "position": {
"x": -4.3598, "x": -4.4027,
"y": -1.1593, "y": -1.2225,
"z": 0.3363 "z": 0.1715
} }
}, },
"office chair with wheels": { "office chair with wheels": {
"highest_score": 0.3037109375, "highest_score": 0.302734375,
"last_detected": "2026-05-18T14:12:39.416197", "last_detected": "2026-05-18T10:26:35.889506",
"position": { "position": {
"x": -2.8461, "x": -2.9779,
"y": 2.6732, "y": 2.3836,
"z": 0.4811 "z": 0.4007
} }
} }
} }

View File

@ -55,7 +55,12 @@ class ClipDetectionNode(Node):
# CLIP + Faster R-CNN # CLIP + Faster R-CNN
self.clip_model, self.clip_preprocess = clip.load("ViT-B/32", device=self.device) self.clip_model, self.clip_preprocess = clip.load("ViT-B/32", device=self.device)
self.frcnn_model = torchvision.models.detection.fasterrcnn_resnet50_fpn_v2(weights="DEFAULT").eval() self.frcnn_model = torchvision.models.detection.fasterrcnn_resnet50_fpn_v2(
weights="DEFAULT"
).to(self.device).eval()
self.get_logger().info(
f"Detection models initialized on device={self.device}"
)
# Labels and score tracking # Labels and score tracking
self.labels = ["Refrigerator","water dispenser", "sofa", "white toilet", "office chair with wheels"] self.labels = ["Refrigerator","water dispenser", "sofa", "white toilet", "office chair with wheels"]
@ -208,7 +213,7 @@ class ClipDetectionNode(Node):
depth_img = self.latest_depth.copy() depth_img = self.latest_depth.copy()
frame_stamp = self.latest_depth_stamp frame_stamp = self.latest_depth_stamp
camera_info = self.camera_info camera_info = self.camera_info
image_tensor = transforms.ToTensor()(cv_img) image_tensor = transforms.ToTensor()(cv_img).to(self.device)
frcnn_min_score = self.get_parameter( frcnn_min_score = self.get_parameter(
'frcnn_min_score' 'frcnn_min_score'
).get_parameter_value().double_value ).get_parameter_value().double_value