ROS(indigo) 安装和使用更新版本的Gazebo,本文以7为例。
Gazebo7支持更多新的功能,如果使用下面命令安装ROS(indigo):
~$ sudo apt-get install ros-indigo-desktop-full
那么配套安装的是Gazebo2,如何在ROS(indigo)中使用更新版本的Gazebo呢?
首先,需要卸载ros-indigo-desktop-full等,如下:
sudo apt-get remove ros-indigo-desktop-full
然后,依次输入下面命令:
sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
可以用:cat /etc/apt/sources.list.d/gazebo-stable.list ,查看,如下:

添加秘钥:
~$ wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
--2016-11-24 12:39:26-- http://packages.osrfoundation.org/gazebo.key
Resolving packages.osrfoundation.org (packages.osrfoundation.org)... 54.193.183.180
Connecting to packages.osrfoundation.org (packages.osrfoundation.org)|54.193.183.180|:80... [sudo] password for relaybot: connected.
HTTP request sent, awaiting response... 200 OK
Length: 1772 (1.7K) [application/pgp-keys]
Saving to: ‘STDOUT’
100%[======================================>] 1,772 --.-K/s in 0s
2016-11-24 12:39:26 (7.08 MB/s) - written to stdout [1772/1772]
OK

完成后,更新:
sudo apt-get update
这时,在终端输入gazebo和libgazebo,并用tab键查看:
sudo apt-get install gazebo
gazebo2 gazebo5-plugin-base-prerelease
gazebo2-dbg gazebo5-prerelease
gazebo3 gazebo6
gazebo3-common gazebo6-common
gazebo3-dbg gazebo6-common-prerelease
gazebo3-doc gazebo6-dbg
gazebo3-plugin-base gazebo6-dbg-prerelease
gazebo4 gazebo6-doc
gazebo4-common gazebo6-doc-prerelease
gazebo4-common-prerelease gazebo6-plugin-base
gazebo4-dbg gazebo6-plugin-base-prerelease
gazebo4-dbg-prerelease gazebo6-prerelease
gazebo4-doc gazebo6-robocup3ds
gazebo4-doc-prerelease gazebo6-robocup3ds-common
gazebo4-plugin-base gazebo7
gazebo4-plugin-base-prerelease gazebo7-common
gazebo4-prerelease gazebo7-dbg
gazebo5 gazebo7-doc
gazebo5-build-deps gazebo7-haptix
gazebo5-common gazebo7-haptix-common
gazebo5-common-prerelease gazebo7-haptix-dbg
gazebo5-dbg gazebo7-haptix-doc
gazebo5-dbg-prerelease gazebo7-haptix-plugin-base
gazebo5-doc gazebo7-plugin-base
gazebo5-doc-prerelease gazebo7-robocup3ds
gazebo5-plugin-base gazebo7-robocup3ds-common
~$ sudo apt-get install libgazebo
libgazebo3 libgazebo6-dev
libgazebo4 libgazebo6-dev-prerelease
libgazebo4-dev libgazebo6-prerelease
libgazebo4-dev-prerelease libgazebo6-robocup3ds
libgazebo4-prerelease libgazebo7
libgazebo5 libgazebo7-dev
libgazebo5-dbg libgazebo7-haptix
libgazebo5-dev libgazebo7-haptix-dev
libgazebo5-dev-prerelease libgazebo7-robocup3ds
libgazebo5-prerelease libgazebo-dev
libgazebo6
如果需要开发gazebo,需安装libgazebo*-dev,如果只是使用,安装gazebo*,如下:
sudo apt-get install gazebo7
安装完毕后,在终端输入gazebo,查看:
gazebo

但是到这里只是安装了Gazebo的新版,需要重新安装ROS。
sudo apt-get install ros-indigo-desktop
注意不要安装full版,Gazebo2不能与更新版本的Gazebo共存,需要单独安装所需功能包即可。
然后,安装ros-gazebo接口库等,以7为例如下:
:~$ sudo apt-get install ros-indigo-gazebo7-
ros-indigo-gazebo7-msgs ros-indigo-gazebo7-ros-control
ros-indigo-gazebo7-plugins ros-indigo-gazebo7-ros-pkgs
ros-indigo-gazebo7-ros
安装完毕后,ROS(indigo)就可以和Gazebo7一起使用了。
这里,以ROS机器人程序设计(原书第2版)的第7章214页的示例,测试键盘控制Gazebo7.4中小车的移动:
第一步,如下:
~$ roslaunch robot1_gazebo gazebo_wg.launch
... logging to /home/relaybot/.ros/log/247f85e8-b203-11e6-85e0-0811968dc4b0/roslaunch-relay-ThinkPad-T420s-4397.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.
started roslaunch server http://relay-ThinkPad-T420s:59553/
SUMMARY
========
PARAMETERS
* /robot_description: <?xml version="1....
* /rosdistro: indigo
* /rosversion: 1.11.20
* /use_sim_time: True
NODES
/
gazebo (gazebo_ros/gzserver)
gazebo_gui (gazebo_ros/gzclient)
robot_state_publisher (robot_state_publisher/state_publisher)
urdf_spawner (gazebo_ros/spawn_model)
auto-starting new master
process[master]: started with pid [4412]
ROS_MASTER_URI=http://localhost:11311
setting /run_id to 247f85e8-b203-11e6-85e0-0811968dc4b0
process[rosout-1]: started with pid [4425]
started core service [/rosout]
process[gazebo-2]: started with pid [4432]
process[gazebo_gui-3]: started with pid [4441]
process[robot_state_publisher-4]: started with pid [4449]
process[urdf_spawner-5]: started with pid [4457]
spawn_model script started
[ INFO] [1479963726.738918650]: Finished loading Gazebo ROS API Plugin.
[ INFO] [1479963726.740184907]: waitForService: Service [/gazebo/set_physics_properties] has not been advertised, waiting...
[INFO] [WallTime: 1479963726.793513] [0.000000] Loading model xml from ros parameter
[INFO] [WallTime: 1479963726.796361] [0.000000] Waiting for service /gazebo/spawn_urdf_model
[INFO] [WallTime: 1479963727.401217] [0.000000] Calling service /gazebo/spawn_urdf_model
[ INFO] [1479963727.884869698, 0.001000000]: Camera Plugin (robotNamespace = /), Info: Using the 'robotNamespace' param: '/'
[ INFO] [1479963727.891392402, 0.001000000]: Laser Plugin (robotNamespace = /), Info: Using the 'robotNamespace' param: '/'
[ INFO] [1479963727.891614468, 0.001000000]: Starting Laser Plugin (ns = /)!
[INFO] [WallTime: 1479963727.899568] [0.001000] Spawn status: SpawnModel: Successfully spawned model
[ INFO] [1479963727.910095653, 0.001000000]: Camera Plugin (ns = /) <tf_prefix_>, set to ""
[ INFO] [1479963727.915187439, 0.001000000]: Laser Plugin (ns = /) <tf_prefix_>, set to ""
[ INFO] [1479963727.948279641, 0.001000000]: Loading gazebo_ros_control plugin
[ INFO] [1479963727.948487708, 0.001000000]: Starting gazebo_ros_control plugin in namespace: /robot
[ INFO] [1479963727.950724362, 0.001000000]: gazebo_ros_control plugin is waiting for model URDF in parameter [/robot_description] on the ROS param server.
[urdf_spawner-5] process has finished cleanly
log file: /home/relaybot/.ros/log/247f85e8-b203-11e6-85e0-0811968dc4b0/urdf_spawner-5*.log
[ INFO] [1479963728.200219231, 0.001000000]: Loaded gazebo_ros_control.
[ INFO] [1479963728.205156602, 0.001000000]: Starting GazeboRosSkidSteerDrive Plugin (ns = /)!
[ INFO] [1479963728.242052698, 0.022000000]: waitForService: Service [/gazebo/set_physics_properties] is now available.
[ INFO] [1479963728.346945001, 0.110000000]: Physics dynamic reconfigure ready

第二步,如下:
~$ rosrun teleop_twist_keyboard teleop_twist_keyboard.py
Reading from the keyboard and Publishing to Twist!
---------------------------
Moving around:
u i o
j k l
m , .
For Holonomic mode (strafing), hold down the shift key:
---------------------------
U I O
J K L
M < >
t : up (+z)
b : down (-z)
anything else : stop
q/z : increase/decrease max speeds by 10%
w/x : increase/decrease only linear speed by 10%
e/c : increase/decrease only angular speed by 10%
CTRL-C to quit
currently: speed 0.5 turn 1
使用键盘控制小车在环境中运动,也可以查看其他数据,如小车摄像头等,利用rviz和rqt_image_view,如下:

翻车后:

补充与巩固:
编译并运行,https://github.com/nubot-nudt/simatch:
中国机器人大赛中型组仿真比赛
China Robot Competition Middle Size Simulation League (With English User Manual)
-End-
附,需要请阅读:
中国机器人大赛中型组仿真比赛 China Robot Competition Middle Size Simulation League (With English User Manual)
演示视频 Demo Video
Two options:
1. 优酷Youku
2. Youtube
说明
该软件包包括了robot_code模块,gazebo_visual模块,coach4sim模块,common模块以及auto_referee模块,其中,参赛选手主要注重robot_code模块,里面包含的是控制机器人运动的相关程序。各个模块的介绍如下:
- robot_code: 机器人的感知、规划、运动控制等方面,由NuBot队伍的机器人代码改造而成,其中主要的策略等(在nubot_control软件包中)部分已经删除,选手应自行编写,其余部分可以直接沿用,也可随意改动。
- gazebo_visual: Gazebo仿真平台,除基本的设置(在sim_config文件中)外,不应做其他改动。最终使用版本以比赛时的版本为准。
- coach4sim: 用于仿真的coach,发送比赛开始、暂停、站位等指令。
- common: 包含cmake、手柄驱动等。选手不必做改动。
- auto_referee: 自动裁判盒,模拟refbox以及裁判的功能,自动进行比赛。
请先学习ROS、C++,作为基本技能和知识,然后对机器人策略等方面有一定了解,再进行robot_code的多机器人协同程序的编写。由于目前仿真中可以直接得到准确的全局信息,所以选手可能会倾向于集中式控制,但是,建议选手用分布式机器人控制。在未来会在仿真中增加更多的现实因素,比如考虑单个机器人所能获取信息的局限性等;
可能增加或改变的规则(最终以比赛时为准)
比赛规则参考2016年RoboCup中型组比赛的规则,但是由于仿真比赛的特殊性,不会完全按照里面的所有规则,比如说:
1. 比赛不分上下半场,一共15分钟左右;
2. 任何利用自动裁判盒(auto_referee)的漏洞获取比赛中的优势将视为作弊行为,比赛成绩无效;
3. 比赛时候可能会对gazebo_visual部分作一定的改动,比如根据真实机器人的一般情况限制机器人的平移速度、旋转速度等,这些改动将通知到每一个队伍。所以请参赛队伍记住自己的代码也要考虑真实世界的情况,不要太理想;
4. 比赛过程中是否对机器人获取的信息加入适当的噪声以及加入多少看比赛情况而定,会及时通知参赛队伍;
5. 比赛前可能会有一次“热身”,主要看看本次比赛参赛队伍的整体水平从而或许对规则作相应的改动,最终目的在于促进机器人技术的发展,鼓励大家积极参与;
6. 机器人不得恶意碰撞其他机器人,需要考虑避障;
目前auto_referee中可以检测的规则
- 单个机器人带球不能超过3m,需要传球才可以;
2. 单个机器人带球不能从己方半场过中线到对方半场,必须传球过中线才可以; - 球出界或者射门得分;
- 除了守门员以外其他机器人不得进入小禁区,除了守门员以外在大禁区的机器人数量最多1个;
- 发球时机器人离球距离的限制,具体如下:
(1) 如果是THROWIN,GOALKICK,CORNERKICK或者FREEKICK的情况时,对方机器人离球要超过3m,己方机器人除了开球机器人以外其他机器人要离球超过2m;
(2) 如果是KICKOFF的情况时,除了发球机器人外其余机器人都必须在自己的半场,且对方机器人离球要超过3m,己方机器人除了开球机器人以外其他机器人要离球超过2m;
(3) 如果是DROPBALL的情况时,所有机器人离球必须超过1m,但是如果在自己的大禁区则不受此距离限制;
(4) 如果是比赛过程中的PENALTY情况时,除了守门员外其余机器人不得在大禁区内且除了准备点球的那个机器人外其余机器人必须离球超过3m;
auto_referee即将添加的规则
- 考虑发球等待时延;
- 检测进球无效情况(机器人射门得分前必须有至少一次传球(传球不成功也算),否则得分无效);
比赛流程
假设服务器(即运行Gazebo的由比赛方提供的主机)的IP地址为IpA,主机名(hostname)为hostA; cyan方参赛队主机的IP地址为IpB,主机名为hostB; magenta方参赛队主机的IP地址为IpC,主机名为hostC,那么相应的配置如下:
参赛队主机的配置(由参赛选手完成)
主机只需要运行自己的机器人代码,即robot_code的部分,禁止运行gazebo_visual,auto_refereeoach4sim。比赛过程如非特何人操作参赛主机,否则视为作弊,除非征得裁判和对方队员同意。
服务器的配置(由辅助裁判完成)
- 将所有参赛队伍的IP地址和主机名加入服务器的/etc/hosts文件中;(赛事负责人将提前将每个队伍的参赛主机名以及参赛队伍名称收集好,其中IP地址将固定分配给每个队伍)。
- 在sim_config文件中更改cyan/prefix以及magenta/prefix的值为参赛双方的队伍名字;
- 打开Gazebo,即
$ roslaunch nubot_gazebo game_ready.launch - 待双方参赛队伍机器人代码运行后,开启自动裁判盒开始比赛,即
$ rosrun auto_referee auto_referee -1代表cyan发球
或者$ rosrun auto_referee auto_referee 1代表magenta发球 - 到下一组比赛的时候,重复步骤2,3,4
共同开发
欢迎大家积极共同完善该仿真平台,我们将感谢每一个人的贡献。
本软件使用git作为版本控制,托管于GitHub网站。如果想共同开发该软件包,请fork一下该软件包(首先你要注册一个GitHub帐号),然后git clone到自己的电脑去,改进完代码后,可以git push上来,然后再在GitHub里面发一个pull request。
需要的基本技能和知识:
- 软件编程:
- robot_code: ROS, C++
- gazebo_visual: ROS, C++, Gazebo插件以及编程实现
- coach4sim: ROS, C++, Qt
- 配置文件: Linux bash或其他
- 其他方面
- 使用说明: txt,Markdown
- 软件文档: Doxygen或其他
为了方便大家交流,请大家把遇到的问题发到这里https://github.com/nubot-nudt/simatch/issues,我会抽时间回答,别人能回答的话也帮忙回答。建议所有人都注册一个github帐号,对这个simatch版本库fork一下。fork的目的在于你对它的修改可以提交给我,然后我审批过后就可以融合进来。目前希望大家能够将自己在使用过程终于遇到的问题以及解决办法写到README.md文件,然后提交给我。如果有参考价值,那么我就把它融合进来,这样所有人都能看到,也是对这个软件的一个贡献。
步骤
- 按下图中的fork就行了(前提是你已经登陆了github帐号),这样在你的帐号里就有了simatch。

2. 然后点进README.md文件,就可以编辑了。把自己遇到的问题和解决部分写在这里questions & answers如下图:

3. 最后创建一个pull request如下图所示,这样我就能够审批通过你的编辑了
联系
软件维护者(Maitainer): abcgarden@126.com
Nubot队伍(RoboCup team): nubot.nudt@outlook.com
用户手册 User manual
NOTE: If you want to have a basic understanding of how Gazebo and ROS combines to work for robots, it is recommended to check out the repository 'single_nubot_gazebo'.This contains how to configure the environment, how to run the simulation, and how the robot is simulated. You could run the ROS tool 'rqt_graph' tounderstand the basic messages and service flow.
Package Summary
- Maintainer status: maintained
- Maintainer: Weijia Yao abcgarden@126.com
- Author: NuBot Team
- License: Apache
- Bug / feature tracker: https://github.com/nubot-nudt/simatch/issues
- Source: git https://github.com/nubot-nudt/simatch (branch: master)
Recommended Operating Environment
- Ubuntu 14.04;
- ROS Indigo or ROS Jade. (It is recommended to install ROS Jade)
- Gazebo 5.0 or above;
- gazebo_ros_pkgs; (please read the NOTE below for more information)
- If you decide to use coach4sim with a GUI, you should make sure you have installed Qt5. The recommended install place is /opt. Other versions of Ubuntu, ROS or Gazebo may also work, but we have not tested yet.
NOTE: Concerning how to install appropriate gazebo_ros_pkgs, please read the following according to your own situation:
- 1. If you decide to use ROS Indigo, please read the following:
If you choose "desktop-full" install of ROS Indigo, there is a Gazebo 2.0 included initially. In order to install Gazebo 5.0/5.1, you should first remove Gazebo 2.0 by running:
(The following command is dangerous; it might delete the whole ROS, so please do it carefully or you may find other ways to delete gazebo2)$ sudo apt-get remove gazebo2*
Then you should be able to install Gazebo 5.0 now. To install gazebo_ros_pkgs compatible with Gazebo5.0/5.1, run this command:$ sudo apt-get install ros-indigo-gazebo5-ros-pkgs ros-indigo-gazebo5-ros-control
HOWEVER, if the above command does now work, these packages may be moved to other places. You can check out gazebo_ros and download and install the correct version. - 2. If you decide to use ROS Jade with gazebo 5.0 or 5.1, read the following
ROS Jade has gazebo_ros_pkgs with it; so you don't have to install gazebo_ros_pkgs again.
However, you should do the following steps to fix some of the bugs in ROS Jade related to Gazebo:- (a)
$ sudo gedit /opt/ros/jade/lib/gazebo_ros/gazebo
In this file, go to line 24 and delete the last '/'. Sosetup_path=$(pkg-config --variable=prefix gazebo)/share/gazebo/
is changed tosetup_path=$(pkg-config --variable=prefix gazebo)/share/gazebo
You can read this link for more information - (b) Install Gazebo 5.
$ sudo apt-get install gazebo5
If this fails, try to run the 'gazebo5_install.sh'(obtained from Gazebo's official website).
Read for more information - (c) Optional: copy resource files to the new gazebo folder.
$ sudo cp -r /usr/share/gazebo-5.0/* /usr/share/gazebo-5.1
- (a)
- 3. If you decide to use ROS Jade with gazebo 7.1, read the following,
- (1) Install gazebo 7.0 by running gazebo7_install.sh(obtained from Gazebo's official website);
- (2) Then run this in the terminal:
-
$ sudo apt-get install ros-jade-gazebo7-ros-pkgs
- (1) Install gazebo 7.0 by running gazebo7_install.sh(obtained from Gazebo's official website);
Compile
Since auto_referee depends on ncurses, if you would like to use it to debug your code, please run this command:
1. sudo apt-get update
2. sudo apt-get install libncurses5-dev
And then you are good to compile as follows:
1. $ sudo chmod +x configure
2. $ ./configure
3. $ catkin_make
Compile Error Solution:
1) Cannot find cmake file related to Qt and therefore cannot complie coach4sim.
- Explanation: This means it cannot find the cmake file to Qt. Since coach4sim uses Qt to draw its GUI, we need Qt to compile the program successfully(solution 1). However, since the function of coach4sim is only to send game commands, you could do this manually by sending approriate ROS messages without using coach4sim(solution 2).
- Solution 1: You should first install Qt and then add the location to CMAKE_PREFIX_PATH. In this case, go to src/coach4sim/CMakeLists.txt and add the path to line 5. The final result would look like this:
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "/opt/Qt5.3.2/5.3/gcc_64/lib/cmake/Qt5Widgets/") - Solution 2: In another terminal, input the following to send a game command:
rostopic pub -r 1 /nubot/receive_from_coach nubot_common/CoachInfo "
MatchMode: 10
MatchType: 0"
Indeed, when you input until nubot_common/CoachInfo, you could press 'Tab' twice and then the whole definition of the message would show up. Then you could fill up the message. However, you only need to fill in two fields: 'MatchMode' and 'MatchType', where 'MatchMode' is the current game command, 'MatchType' is the previous game command. The coding of the game commands is in core.hpp. For quick reference:
enum MatchMode {
STOPROBOT = 0,
OUR_KICKOFF = 1,
OPP_KICKOFF = 2,
OUR_THROWIN = 3,
OPP_THROWIN = 4,
OUR_PENALTY = 5,
OPP_PENALTY = 6,
OUR_GOALKICK = 7 ,
OPP_GOALKICK = 8,
OUR_CORNERKICK = 9,
OPP_CORNERKICK = 10,
OUR_FREEKICK = 11,
OPP_FREEKICK = 12,
DROPBALL = 13,
STARTROBOT = 15,
PARKINGROBOT = 25,
TEST = 27
};
2) When catkin_make, if it shows "fatal error: Eigen/Eigen: No such file or directory"
- Solution 1: Change all 'Eigen3' to 'Eigen' in CMakeLists.txt of world_model package in robot_code module
- Solution 2: look at /usr/include/eigen3/Eigen, if this folder exists, it means you have already installed Eigen;
Input this command:$ sudo ln -s /usr/include/eigen3/Eigen /usr/include/Eigen
3) if you come across other problems, you could refer to doc/ folder.
Run
You could run the robot_code, gazebo_visal and coach4sim in one computer. However, the simulation speed would be low. So you could also run them with several computers to decrease the burden of one single computer.
With one computer
Assuming you are in the root directory of 'simatch',
If you want to run those modules in one launch, you could
1 $ source devel/setup.bash
You could write this line into ~/.bashrc file so that you don't have to source it every time you open a terminal.
2 $ roslaunch simatch_cyan.launch or $ roslaunch simatch_magenta.launch
If you want to run those modules seperatly, you could
1 $ source devel/setup.bash
You could write this line into ~/.bashrc file so that you don't have to source it every time you open a terminal.
2 To run gazebo_visual,$ roslaunch nubot_gazebo game_ready.launch
3 To run robot_code for cyan or magenta robots:$ rosrun nubot_common cyan_robot.sh or $ rosrun nubot_common magenta_robot.sh
4 To run coach4sim,rosrun coach4sim cyan_coach.sh or rosrun coach4sim magenta_coach.sh
NOTE:
1. You could change some parameters in sim_config(see "Change game parameters" part below) file and relaunch all modules again.
2. You might not watch the robots doing anything because the movement part in 'nubot_control' package is removed. You might need to write some codes by yourself.
With several computers
Configuration of computer A and computer B
The recommended way to run simulation is with two computers running nubot_ws and gazebo_visual seperately.
For example,computer A runs gazebo_visual to display the movement of robots. Computer B runs nubot_ws to calculate and send movement commands to robots. In addition, computer B should also run coach to send game command such as game start.
The communication between computer A and computer B is via ROS master. The following is the configuration steps:
- In computer A, add computer B's IP address in /etc/hosts; and in computer B, add computer A's IP address in /etc/hostse.g. In computer A,
$ sudo gedit /etc/hosts and add "192.168.8.100 Maggie"In computer B,$ sudo gedit /etc/hosts and add "192.168.8.101 Bart" - In computer A, run gazebo_visual; In computer B, before you run nubot_ws, you should export ROS_MASTER_URI.e.g. In computer B,
$ export ROS_MASTER_URI=http://Bart:11311 - In computer B, run coach and send game command
Change game parameters
You could change some parameters in "sim_config", which is a symbolic link to global_config.yaml. The content of this file is:
# Uses ISO units. For example, use 'm' for length. general: dribble_distance_thres: 0.47 # theshold distance between nubot and football below which dribble ball dribble_angle_thres: 15.0 # kicking mechanism aligning with football; allowed maximum angle error in degrees noise_scale: 0.00 # the scale of gaussian noise (m) noise_rate: 0.01 # how frequent the noise is generated cyan: prefix: "nubot" # Nubot name prefix. num: 3 magenta: prefix: "rival" # Rival name prefix. num: 3 field: length: 18 # Use integer! used in spawn_model_script width: 12 # Use integer! used in spawn_model_script football: name: "football" # football model name chassis_link: "football::chassis" # football body link name
更多文章请关注《万象专栏》
转载请注明出处:https://www.wanxiangsucai.com/read/cv12481

