看完初级的tutorials,掌握了基本概念,但是对ROS控制机器人没概念,那么首先从一个模拟器开始会比较直观,这里选择PR2模拟器
ROS真正的吸引力不在于它自己发布或订阅的中间件,而在于ROS为世界各地的开发者提供了一种标准机制来分享他们的代码。
大量现成可用的程序包(packages)已经势不可挡。
要会仿真,首先要知道怎么用仿真器,那么先学习simulator_gazebo
首先是安装,看教程输入sudo apt-get install ros-kinetic-simulator-gazebo,但是提示下面的错误,搜索网络上
root@ben-virtual-machine:~# sudo apt-get install ros-kinetic-simulator-gazebo
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package ros-kinetic-simulator-gazebo 报错
root@ben-virtual-machine:~# sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
root@ben-virtual-machine:~# sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
Executing: /tmp/tmp.FPVwaFiywx/gpg.1.sh --keyserver
hkp://ha.pool.sks-keyservers.net:80
--recv-key
421C365BD9FF1F717815A3895523BAEEB01FA116
gpg: requesting key B01FA116 from hkp server ha.pool.sks-keyservers.net
gpg: key B01FA116: "ROS Builder
gpg: Total number processed: 1
gpg: unchanged: 1
root@ben-virtual-machine:~# sudo apt-get update
需要输入上面的三句,尝试以后,发现还是不行,
查看了ros安装部分,查看可获取的packet , 用下面的指令
apt-cache search ros-kinetic 发现了仿真器的名字可能不对
修改名字后,看起来正常。
root@ben-virtual-machine:~# sudo apt-get install ros-kinetic-simulators
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be upgraded:
ros-kinetic-simulators
1 upgraded, 0 newly installed, 0 to remove and 413 not upgraded.
Need to get 1,746 B of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://packages.ros.org/ros/ubuntu xenial/main amd64 ros-kinetic-simulators amd64 1.3.2-0xenial-20200122-153539+0000 [1,746 B]
Fetched 1,746 B in 9s (187 B/s)
(Reading database ... 319409 files and directories currently installed.)
Preparing to unpack .../ros-kinetic-simulators_1.3.2-0xenial-20200122-153539+0000_amd64.deb ...
Unpacking ros-kinetic-simulators (1.3.2-0xenial-20200122-153539+0000) over (1.3.2-0xenial-20180810-032425-0800) ...
Setting up ros-kinetic-simulators (1.3.2-0xenial-20200122-153539+0000) ...
root@ben-virtual-machine:~#
安装完成后 打开软件
roslaunch gazebo_ros empty_world.launch
出现界面,但是一直卡住,通过百度,发现是因为启动的时候需要加载库,所以慢
运行:
cd ~/.gazebo/
ls
mkdir -p models
ls
cd ~/.gazebo/models/
wget http://file.ncnynl.com/ros/gazebo_models.txt
ls
输出:
gazebo_models.txt
运行:
wget -i gazebo_models.txt
ls model.tar.g* | xargs -n1 tar xzvf
全部模型有170M,但在线下载速度非常慢,我下了一天一夜才下完。不过现在小伙伴已经将其共享至网盘,可直接下载,然后将其解压至~/.gazebo/models里。
链接:http://pan.baidu.com/s/1pKaeg0F 密码:cmxc (来自rosclub.cn)
或是下载https://bitbucket.org/osrf/gazebo_models/downloads/ (ExBot ROS专区,网友提醒)
确实在线下载太慢了,直接从第二个网站下载了,然后解压,注意解压的时候不能有上一级目录,否则无法找到。必须在这个目录~/.gazebo/models里
重新打开,终于看到对应的界面。
但是突然报了错误
百度一下,发现说是之前没有完全关闭
需要killall gzserver && killall gzclient,执行完了再次打开,还是有问题,说明这个方式不对
再次百度,虚拟机需要将下面这个设置一下
export SVGA_VGPU10=0
如果要长久设置,需要echo "export SVGA_VGPU10=0" >> ~/.bashrc
结果再次打开gazebo就可以了,然后按照例程生产一个box,注意该版本要使用gazebo_ros才可以。
这里empty_world.launch是类似一个模板,一般使用这个就可以。
在增加一个桌子,由于没有table.launch,自己添加一个,参考empty world的路径添加
另外还没有table.urdf.xacro,所以也自己创建,路径要配合table.launch中的路径
table.launch改为下面这样,黑体是修改的地方,这里黑体只是为了清楚的显示哪里改动。
调用指令roslaunch gazebo_ros table.launch打印信息如下,不清楚对错,但是桌子确实出现了
root@ben-virtual-machine:~/gazebo_exercise# roslaunch gazebo_ros table.launch
... logging to /root/.ros/log/4cd217b6-4ba4-11ea-bfb4-000c29917a0b/roslaunch-ben-virtual-machine-9704.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
xacro: Traditional processing is deprecated. Switch to --inorder processing!
To check for compatibility of your document, use option --check-order.
For more infos, see http://wiki.ros.org/xacro#Processing_Order
deprecated: xacro tags should be prepended with 'xacro' xml namespace.
Use the following script to fix incorrect usage:
find . -iname "*.xacro" | xargs sed -i 's#<\([/]\?\)\(if\|unless\|include\|arg\|property\|macro\|insert_block\)#<\1xacro:\2#g'
when processing file: /opt/ros/kinetic/share/gazebo_ros/objects/table.urdf.xacro
xacro.py is deprecated; please use xacro instead
started roslaunch server http://ben-virtual-machine:35593/
SUMMARY
========
PARAMETERS
* /rosdistro: kinetic
* /rosversion: 1.12.13
* /table_description:
NODES
/
spawn_table (gazebo_ros/spawn_model)
ROS_MASTER_URI=http://localhost:11311
process[spawn_table-1]: started with pid [9724]
SpawnModel script started
[INFO] [1581307141.449040, 0.000000]: Loading model XML from ros parameter
[INFO] [1581307141.462754, 0.000000]: Waiting for service /gazebo/spawn_urdf_model
[INFO] [1581307141.465401, 0.000000]: Calling service /gazebo/spawn_urdf_model
[INFO] [1581307141.593709, 2425.108000]: Spawn status: SpawnModel: Successfully spawned entity
[spawn_table-1] process has finished cleanly
log file: /root/.ros/log/4cd217b6-4ba4-11ea-bfb4-000c29917a0b/spawn_table-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete
done
注意,这是在之前的打开的empty wold基础上,再次执行roslaunch,可能有重叠,如果先打开table,并没有启动gazebo。但是再次打开empty world,桌子还是显示的。
具体原因不详,但是至少gazebo创建了对象。继续学习
wiki中说gazebo作为单独的学习。目前我还是先按照ros中的tutorial学习。