PX4与仿真入门教程-dronedoc-使用 Gazebo 插件创建地图(gazebo plugin)
PX4与仿真入门教程-dronedoc-使用 Gazebo 插件创建地图(gazebo plugin)
说明:
- 介绍如何使用collision_map_creator_plugin来创建地图
- collision_map_creator_plugin插件使用Google protobuf messages作为消息通信渠道
步骤:
- 安装依赖
sudo apt-get install protobuf-compiler
- 下载和编译插件
cd ~/tools/dronedoc/
git clone https://github.com/osrf/collision_map_creator_plugin
cd collision_map_creator_plugin
mkdir build
cd build
cmake ../
make
- 编译完成之后,如果就这样执行会提示错误
[libprotobuf ERROR google/protobuf/descriptor_database.cc:57] File already exists in database: vector2d.proto
解决方法参考:点击查看
我们修改
set (msgs
collision_map_request.proto
${PROTOBUF_IMPORT_DIRS}/vector2d.proto
${PROTOBUF_IMPORT_DIRS}/header.proto
${PROTOBUF_IMPORT_DIRS}/time.proto
)
- 更改为
set (msgs
collision_map_request.proto
)
- 再重新编译一次就可以
测试:
- 新开终端,打开gazebo
cd ~/tools/dronedoc/
source load_environment.sh
export GAZEBO_PLUGIN_PATH=$GAZEBO_PLUGIN_PATH:~/tools/dronedoc/collision_map_creator_plugin/build
gazebo ~/tools/dronedoc/collision_map_creator_plugin/map_creator.world --verbose
- 指定--verbose,显示启动的详细信息,了解加载插件
- 新开终端,请求建图
cd ~/tools/dronedoc/
source load_environment.sh
export GAZEBO_PLUGIN_PATH=$GAZEBO_PLUGIN_PATH:~/tools/dronedoc/collision_map_creator_plugin/build
~/tools/dronedoc/collision_map_creator_plugin/build/request_publisher "(-50,50)(50,50)(50,-50)(-50,-50)" 50 0.01 ~/map.png
- 在gazebo的终端,就会显示生成地图的进度,生成的文件在用户根目录下,文件名为map.png
- 运行效果如下:
$ ~/tools/dronedoc/collision_map_creator_plugin/build/request_publisher "(-50,50)(50,50)(50,-50)(-50,-50)" 50 0.01 ~/map.png
Request: UL.x: -50 UL.y: 50 UR.x: 50 UR.y: 50 LR.x: 50 LR.y: -50 LL.x: -50 LL.y: -50 Height: 50 Resolution: 0.01 Filename: /home/ubuntu/map.png Threshold: 255
$ rosrun px4_sim_pkg request_publisher "(-50,50)(50,50)(50,-50)(-50,-50)" 50 0.01 ~/map.png 255
[ INFO] [1634199833.591290409]:
Request Start
[ INFO] [1634199833.596139683]:
Request:
UL.x: -50.000000 UL.y: 50.000000
UR.x: 50.000000 UR.y: 50.000000
LR.x: 50.000000 LR.y: -50.000000
LL.x: -50.000000 LL.y: -50.000000
Height: 50.000000
Resolution: 0.010000
Filename: /home/ubuntu/map.png
Threshold: 255
- 效果如下:
参考:
- http://gazebosim.org/tutorials?tut=custom_messages
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号