Player/Stage仿真学习(一)
ubuntu 16.04环境下,使用Player/stage进行简单的仿真,
提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
上一节player/stage安装记录中,我们运行了一个.cfg文件来测试player/stage是否安装成功。本小结我们测试一个简单的C++文件,该文件能参考接收到的机器人传感器信息,控制机器人的运行速度及转角度,从而进行简单的避障运动。更多内容可参考链接 https://player-stage-manual.readthedocs.io/en/latest/CONTROLLER_CPP/
一、使用步骤
1,文件下载
本小结的代码来源于链接 http://github.com/NickelsLab/Player-Stage-Manual/archive/v4.1.0.zip。点击进去即可下载文件包Player-Stage-Manual-4.1.0.zip。解压文件,注意文件路径不能包含中文,否则后续会出问题。
unzip Player-Stage-Manual-4.1.0.zip
文件夹内有code和docs两个文件夹,我们运行以下代码:
cd code/ch6.1
这里的6.1对应链接 https://player-stage-manual.readthedocs.io/en/latest/CONTROLLER_CPP/中的第6章。
观察发现,这个文件夹内有.inc,.cfg,.world,.cc等各类文件。
2.运行程序
我们运行以下代码,
~/work/stage/test/src$ player simple.cfg &
[1] 16288
ThinkCentre-M920t-N000:~/work/stage/test/src$ Registering driver
Player v.3.0.2
* Part of the Player/Stage/Gazebo Project [http://playerstage.sourceforge.net].
* Copyright (C) 2000 - 2009 Brian Gerkey, Richard Vaughan, Andrew Howard,
* Nate Koenig, and contributors. Released under the GNU General Public License.
* Player comes with ABSOLUTELY NO WARRANTY. This is free software, and you
* are welcome to redistribute it under certain conditions; see COPYING
* for details.
invoking player_driver_init()...
[Stage plugin] Stage driver init
** Stage plugin v4.3.0 **
* Part of the Player Project [http://playerstage.sourceforge.net]
* Copyright 2000-2013 Richard Vaughan, Brian Gerkey and contributors.
* Released under the GNU General Public License v2.
success
[Stage plugin] Loading world "simple.world"
[Loading ./simple.world][Include pioneer.inc][Include map.inc][Include sick.inc][Image "../bitmaps/cave.png"]
[Stage plugin] 6665.simulation.0 is "./simple.world"
[Stage plugin] 6665.position2d.0 is "r0"
[Stage plugin] 6665.ranger.0 is "r0.ranger:0"
[Stage plugin] 6665.ranger.1 is "r0.ranger:1"
listening on 6665
Listening on ports: 6665
然后会弹出一个stage仿真窗口,该窗口内有一个静止不动的小机器人。
新打开一个terminal,运行命令
g++ -o example0 `pkg-config --cflags playerc++` example0.cc `pkg-config --libs playerc++`
编译文件example.cc。terminal会弹出一个error和一个warning,内容如下:
:~/work/stage/test/src$ g++ -o example0 `pkg-config --cflags playerc++` example0.cc `pkg-config --libs playerc++`
In file included from /usr/local/include/player-3.0/libplayerc++/playerclient.h:66:0,
from /usr/local/include/player-3.0/libplayerc++/playerc++.h:61,
from example0.cc:30:
/usr/include/boost/signal.hpp:17:4: warning: #warning "Boost.Signals is no longer being maintained and is now deprecated. Please switch to Boost.Signals2. To disable this warning message, define BOOST_SIGNALS_NO_DEPRECATION_WARNING." [-Wcpp]
# warning "Boost.Signals is no longer being maintained and is
^
/usr/bin/ld: /tmp/cc6EdPya.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv'
//usr/lib/x86_64-linux-gnu/libboost_system.so.1.58.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
从网上查询以后发现,将命令修改成以下内容,即可消灭error。
g++ -o example0 `pkg-config --cflags playerc++` example0.cc `pkg-config --libs playerc++` -lboost_system
运行完程序,编译完example0.cc后,文件夹内生成了一个example0的可执行文件,运行该文件,理想情况下,机器人开始运动。
./example0
某些情况下,我们会遇到类似以下内容的error。
playerc error : failed to get response
这个问题困扰了我特别久,一度怀疑是否是软件安装不对。多番查询,找到解决办法如下:打开simple.world文件,搜索speedup,将其值修改成0或-1。这个指令的意思是使机器人经可能快地移动,更多内容可参考链接: link。
# set the multiple of real time that Stage should try to achieve. Default is 1.
# set to 0 to go as fast as possible.
speedup 0
修改完以后,运行以下代码
player simple.cfg &
g++ -o example0 `pkg-config --cflags playerc++` example0.cc `pkg-config --libs playerc++` -lboost_system
./example0
就可以看到机器人开始运动啦。
红色的点是机器人,周围花瓣一样的是laser的扫描范围。
总结
还可以使用Makefile进行编译,我们这例子很简单,就没用,感兴趣的同学可自行尝试。