ros2_office_vlm/README.md

97 lines
4.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

* 语义推理与导航
智能语义推理框架包含两个核心模块:
语义目标标注:利用 VLM识别物体
语义导航:机器人借助已保存的物体记忆,通过语义路标完成导航。
语义标注模块将 Faster R-CNN 与 CLIP 结合,实现零样本目标检测。
给定一个物体列表(例如:["Refrigerator", "water dispenser", "sofa", "white toilet", "office chair with wheels"]),由 Faster R-CNN 从 RGB 图像帧中生成候选区域。
随后,使用 CLIP 将每个候选区域进行特征编码,并与文本标签做余弦相似度对比,为区域分配最可能的类别标签。
点击 RViz2 中Nav2 Goal在地图上选择目标位置调整箭头设置机器人到达后的朝向确认后机器人将自主导航在探索过程中系统会结合 RGB-D 数据 记录物体的中心坐标,并将置信度分数与位置信息存入 JSON 文件。
只有当检测到更高置信度的结果时,才会更新原有记录。
## 1. 环境要求
- Ubuntu 22.04
- ROS2 Humble
- Gazebo Sim Harmonic
---
### 编译
```bash
cd /workspace
# pip install -r requirements.txt
colcon build --symlink-install
source /opt/ros/humble/setup.bash
source install/setup.bash
```
### 注意事项
之后每打开一个新终端,都建议先执行:
```bash
source /opt/ros/humble/setup.bash
source install/setup.bash
export TURTLEBOT3_MODEL=burger
export NAV2_MAP_PATH=/workspace/src/turtlebot3_simulations/turtlebot3_gazebo/map/office_map.yaml
```
为了方便,也可以写入 `~/.bashrc`
```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
./gzsim_run.sh
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
export __NV_PRIME_RENDER_OFFLOAD=1
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
```
2. 新开终端执行环境生效后启动vlm_perception_pkg的语义检测节点开始目标语义标注并构建语义记忆库在机器人导航过程中节点实时检测环境中的目标并生成语义标注结果保存JSON 格式的语义记忆库到指定路径。
```bash
ros2 run vlm_perception_pkg vlm_detection
# 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
```bash
./gzsim_run.sh
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
```
节点启动后,在终端输入自然语言语义目标(如 “water dispenser”“sofa”系统将自动完成语义查询与shared embedding space匹配提取目标对应的地图坐标并向 Nav2 发送导航目标位姿然后机器人自主规划路径并导航至语义目标位置RViz2 中实时可视化规划路径与导航过程