Day 1: Building the static model

Source

Sources for this tutorial can be found on GitHub

Setting up

  • ROS: Indigo
  • OS: Ubuntu 14.04
  • OS: Gazebo 7.0.0

Initialize the workspace

To create the basic skeleton of the directory structure, we begin with a workspace {WORKSPACE}_ws, where we set {WORKSPACE}=mybot.

  1. cd ~
  2. mkdir -p mybot_ws/src
  3. cd mybot_ws/src
  4. catkin_init_workspace
  5. cd ..
  6. catkin_make
  7. echo "source ~/mybot_ws/devel/setup.bash" >> ~/.bashrc # Adds workspace to search path

In the src folder are three main packages, {MODEL}_control{MODEL}_description{MODEL}_gazebo. We set {MODEL} = mybot. To create a package: catkin_create_pkg {PKG_NAME} {PKG_DEPENDENCIES}. In this case, we have no {PKG_DEPENDENCIES} = “”.

  1. cd ~/mybot_ws/src/
  2. catkin_create_pkg mybot_control
  3. catkin_create_pkg mybot_description
  4. catkin_create_pkg mybot_gazebo

Creating your own World

Let’s start with the gazebo package, go in there and create the following subfolders:

  1. roscd mybot_gazebo
  2. mkdir launch worlds

At first we want to create a world for our gazebo server. Therefore we switch to our worlds directory and create a new world file.

  1. cd worlds
  2. gedit mybot.world

A basic world file defines at least a name:

  1. <?xml version="1.0"?>
  2. <sdf version="1.4">
  3. <world name="myworld">
  4. </world>
  5. </sdf>

Here you could directly add models and object with their position. Also the laws of physics may be defined in a world. This is an important step to understand, because in this file you could also attach a specific plugin to an object. The plugin itself contains ROS and Gazebo specific code for more complex behaviors.

At first we just want to add some basic objects, like a ground and a basic illumination source inside the world tag.

  1. <include>
  2. <uri>model://sun</uri>
  3. </include>
  4.  
  5. <include>
  6. <uri>model://ground_plane</uri>
  7. </include>

Check your “~/.gazebo/models” directory, as this is a default path for saved models. If this path does not exist try to find /usr/share/gazebo/setup.sh where gazebo looks for models. Otherwise add it to your model path.

As the ground plane and the sun are basic models that are also on the gazebo server they will be downloaded on startup if they cannot be found locally. If you want to know which object are available on the gazebo server, take a look at Gazebo model database. To start the gazebo server there are several methods. As it is a good practice to use a launch file, we will create one now. This could later also be used for multiple nodes.

Change to the launch directory of your project:

  1. roscd mybot_gazebo/launch

Create a new file:

  1. gedit mybot_world.launch

and insert:

  1. <launch>
  2. <include file="$(find gazebo_ros)/launch/empty_world.launch">
  3. <arg name="world_name" value="$(find mybot_gazebo)/worlds/mybot.world"/>
  4. <arg name="gui" value="true"/>
  5. </include>
  6. </launch>

This launch file will just execute a default launch file provided by Gazebo, and tell it to load our world file and show the Gazebo client. You can launch it by doing:

  1. roslaunch mybot_gazebo mybot_world.launch

Now you should see the gazebo server and the gui starting with a world that contains a ground plane and a sun (which is not obviously visible without objects). If not, it can be that there are some connections problems with the server.

If that happens, start gazebo without the launch file, go to the models, you should find the one you want in the server. Click on them, they will be put in the cache. Now, if you close gazebo and start it again with the launch file, it should work.

If you would press “Save world as” in “File” in your gazebo client and save the world in a text file, you could investigate the full world description.

If you want to watch a more complex and beautiful world environment then add the following inside your world tag:

  1. <include>
  2. <uri>model://willowgarage</uri>
  3. </include>

This one shows you the office of Willow Garage, be careful, it’s huge and may make your simulation extremely slow.

Create the Robot Model (URDF)

In ~/mybot_ws/src/mybot_description/urdf, there will be four files:

  • mybot.xacro: primary file that loads the other three files and contains only URDF items like joints and links
  • mybot.gazebo: contains gazebo-specific labels that are wrapped within gaz
  • materials.xacro: maps strings to colors
  • macros.xacro: macros to help simplify

The more accurate you want to model your robot the more time you need to spend on the design. In the next image you see a developing process of a robot model, from a simple cube to a differential drive robot. You can also check the ROS tutorial about the robot.

We could put our model as a SDF file in the ~/.gazebo/models directory, this is the standard way when you work only with Gazebo. However with ROS we’ll prefer to use a URDF file generated by Xacro and put it the description package.

The Universal Robotic Description Format (URDF) is an XML file format used in ROS as the native format to describe all elements of a robot. Xacro (XML Macros) is an XML macro language. It is very useful to make shorter and clearer robot descriptions.

Ok so first we need to go into our description package and create the urdf subfolder and the description file:

  1. roscd mybot_description
  2. mkdir urdf
  3. cd urdf
  4. gedit mybot.xacro

XACRO CONCEPTS

  • xacro:include: Import the content from other file. We can divide the content in different xacros and merge them using xacro:include.
  • property: Useful to define constant values. Use it later using ${property_name}
  • xacro:macro: Macro with variable values. Later, we can use this macro from another xacro file, and we specify the required value for the variables. To use a macro, you have to include the file where the macro is, and call it using the macro’s name and filling the required values.

This file will be the main description of our robot. Let’s put some basic structure:

  1. <?xml version="1.0"?>
  2. <robot name="mybot" xmlns:xacro="http://www.ros.org/wiki/xacro">
  3. <!-- Put here the robot description -->
  4. </robot>

The structure is basic for a urdf file. The complete description (links, joints, transmission…) have to be within the robot tag. The xmlns:xacro="http://www.ros.org/wiki/xacro" specifies that this file will use xacro. If you want to use xacro you have to put this.

With xacro, you can define parameters. Once again, this make the file clearer. They are usually put at the beginning of the file (within the robot tag, of course).

Let’s define some physical properties for our robot, mainly the dimensions of the chassis, the caster wheel, the wheels and the camera:

  1. <xacro:property name="PI" value="3.1415926535897931"/>
  2.  
  3. <xacro:property name="chassisHeight" value="0.1"/>
  4. <xacro:property name="chassisLength" value="0.4"/>
  5. <xacro:property name="chassisWidth" value="0.2"/>
  6. <xacro:property name="chassisMass" value=""/>
  7.  
  8. <xacro:property name="casterRadius" value="0.05"/>
  9. <xacro:property name="casterMass" value=""/>
  10.  
  11. <xacro:property name="wheelWidth" value="0.05"/>
  12. <xacro:property name="wheelRadius" value="0.1"/>
  13. <xacro:property name="wheelPos" value="0.2"/>
  14. <xacro:property name="wheelMass" value=""/>
  15.  
  16. <xacro:property name="cameraSize" value="0.05"/>
  17. <xacro:property name="cameraMass" value="0.1"/>

‹arg name="gui" value="true"/›These parameters or properties can be used in all the file with ${property name}.

We will also include three files :

  1. <xacro:include filename="$(find mybot_description)/urdf/mybot.gazebo" />
  2. <xacro:include filename="$(find mybot_description)/urdf/materials.xacro" />
  3. <xacro:include filename="$(find mybot_description)/urdf/macros.xacro" />

These three correspond respectively to:

  • all the gazebo-specific aspects of our robot
  • definition of the materials used (mostly colors)
  • definitions of some macros for easier description of the robot

Every file has to contain the robot tag and everything we put in them should be in this tag.

Now we want to add a rectangular base for our robot. Insert this within the robot tag of mybot.xacro:

  1. <link name='chassis'>
  2. <collision>
  3. <origin xyz="0 0 ${wheelRadius}" rpy="0 0 0"/>
  4. <geometry>
  5. <box size="${chassisLength} ${chassisWidth} ${chassisHeight}"/>
  6. </geometry>
  7. </collision>
  8. <visual>
  9. <origin xyz="0 0 ${wheelRadius}" rpy="0 0 0"/>
  10. <geometry>
  11. <box size="${chassisLength} ${chassisWidth} ${chassisHeight}"/>
  12. </geometry>
  13. <material name="orange"/>
  14. </visual>
  15. <inertial>
  16. <origin xyz="0 0 ${wheelRadius}" rpy="0 0 0"/>
  17. <mass value="${chassisMass}"/>
  18. <box_inertia m="${chassisMass}" x="${chassisLength}" y="${chassisWidth}" z="${chassisHeight}"/>
  19. </inertial>
  20. </link>

We define a box with chassisLength x chassisWidth x chassisHeight meters and mass chassisMasskg.

As you can see, we have three tags for this one box, where one is used to the collision detection engine, one to the visual rendering engine and the last to the physic engine. Most of the time they are the same, except when you have complicated and beautiful visual meshes.

As they don’t need to be that complicated for collision detection you could use a simple model for the collision. The material element in the visual tag refer to a color that must be defined in the materials.xacro and refred to in the mybot.gazebo file, at least, in the structure we adopted.

Add this in “mybot.gazebo”, within the robot tag :

  1. <gazebo reference="chassis">
  2. <material>Gazebo/Orange</material>
  3. </gazebo>

And this in the “materials.xacro” :

  1. <material name="black">
  2. <color rgba="0.0 0.0 0.0 1.0"/>
  3. </material>
  4.  
  5. <material name="blue">
  6. <color rgba="0.0 0.0 0.8 1.0"/>
  7. </material>
  8.  
  9. <material name="green">
  10. <color rgba="0.0 0.8 0.0 1.0"/>
  11. </material>
  12.  
  13. <material name="grey">
  14. <color rgba="0.2 0.2 0.2 1.0"/>
  15. </material>
  16.  
  17. <material name="orange">
  18. <color rgba="${255/255} ${108/255} ${10/255} 1.0"/>
  19. </material>
  20.  
  21. <material name="brown">
  22. <color rgba="${222/255} ${207/255} ${195/255} 1.0"/>
  23. </material>
  24.  
  25. <material name="red">
  26. <color rgba="0.8 0.0 0.0 1.0"/>
  27. </material>
  28.  
  29. <material name="white">
  30. <color rgba="1.0 1.0 1.0 1.0"/>
  31. </material> 

As you can see, we add more than just the color we wanted, this is for convenience. Now, we can leave this file alone and use any color we want.

Another particular thing in the chassis link is the use of “box_inertia” in the inertial tag. This is a macro made with xacro. As you can see, when you use a macro, you can simply use the tag and specifies the parameters. Xacro will understand.

Add this in the macros.xacro file, within the robot tag :

  1. <macro name="cylinder_inertia" params="m r h">
  2. <inertia ixx="${m*(3*r*r+h*h)/12}" ixy = "" ixz = ""
  3. iyy="${m*(3*r*r+h*h)/12}" iyz = ""
  4. izz="${m*r*r/2}"
  5. />
  6. </macro>
  7.  
  8. <macro name="box_inertia" params="m x y z">
  9. <inertia ixx="${m*(y*y+z*z)/12}" ixy = "" ixz = ""
  10. iyy="${m*(x*x+z*z)/12}" iyz = ""
  11. izz="${m*(x*x+z*z)/12}"
  12. />
  13. </macro>
  14.  
  15. <macro name="sphere_inertia" params="m r">
  16. <inertia ixx="${2*m*r*r/5}" ixy = "" ixz = ""
  17. iyy="${2*m*r*r/5}" iyz = ""
  18. izz="${2*m*r*r/5}"
  19. />
  20. </macro>

Once again, we add more than we needed. We will use the others later. The inertia tag is a convention of the inertial tag in a link.

We have two small things to do before testing our model with gazebo.

The physic engine does not accept a base_link with inertia. It is then useful to add a simple link without inertia and make a joint between it and the chassis. Add this before the chassis link in the mybot.xacro file :

  1. <link name="footprint" />
  2.  
  3. <joint name="base_joint" type="fixed">
  4. <parent link="footprint"/>
  5. <child link="chassis"/>
  6. </joint>

In order to start gazebo with our model, we have to modify the previously created launch file mybot_world.launch by adding the following two tags in the launch tag:

  1. <!-- urdf xml robot description loaded on the Parameter Server, converting the xacro into a proper urdf file-->
  2. <param name="robot_description" command="$(find xacro)/xacro.py '$(find mybot_description)/urdf/mybot.xacro'" />
  3.  
  4. <!-- push robot_description to factory and spawn robot in gazebo -->
  5. <node name="mybot_spawn" pkg="gazebo_ros" type="spawn_model" output="screen"
  6. args="-urdf -param robot_description -model mybot" />

The first tag will first call the xacro script to convert of xacro description into an actual URDF. This URDF is then inserted into a ROS parameter called “robot_description” (this is a standard name used by many ROS tools).

The second tag launches a program from the gazebo_ros package that will load the URDF from the parameter “robot_description” and spawn the model into our Gazebo simulator

If you launch your project with this launch file, the gazebo client opens and the the chassis should be there. It should also fall because of the physic engine.

As a next step we add a caster wheel to the robot. This is the simplest wheel as we have no axis and no friction. We can simply approximate the caster wheel with a ball. Add this after the chassis link in the main urdf file :

  1. <joint name="fixed" type="fixed">
  2. <parent link="chassis"/>
  3. <child link="caster_wheel"/>
  4. </joint>
  5.  
  6. <link name="caster_wheel">
  7. <collision>
  8. <origin xyz="${casterRadius-chassisLength/2} 0 ${casterRadius-chassisHeight+wheelRadius}" rpy="0 0 0"/>
  9. <geometry>
  10. <sphere radius="${casterRadius}"/>
  11. </geometry>
  12. </collision>
  13.  
  14. <visual>
  15. <origin xyz="${casterRadius-chassisLength/2} 0 ${casterRadius-chassisHeight+wheelRadius}" rpy="0 0 0"/>
  16. <geometry>
  17. <sphere radius="${casterRadius}"/>
  18. </geometry>
  19. <material name="red"/>
  20. </visual>
  21.  
  22. <inertial>
  23. <origin xyz="${casterRadius-chassisLength/2} 0 ${casterRadius-chassisHeight+wheelRadius}" rpy="0 0 0"/>
  24. <mass value="${casterMass}"/>
  25. <sphere_inertia m="${casterMass}" r="${casterRadius}"/>
  26. </inertial>
  27. </link>

We attach this caster wheel to the chassis with a fixed joint. The two links will then always move together. We use the sphere_inertia macro we added earlier in the macros.xacro file. Also add a gazebo tag in the gazebo file for this link :

  1. <gazebo reference="caster_wheel">
  2. <mu1>0.0</mu1>
  3. <mu2>0.0</mu2>
  4. <material>Gazebo/Red</material>
  5. </gazebo>

As usual, we specify the color used in material. We also added mu1 and mu2, with value 0 to remove the friction.

Last but not least, we want to add some wheels to the robot. We could add the two links in the main file, but let’s make one macro to make it simple. In the macro file, add this :

  1. <macro name="wheel" params="lr tY">
  2.  
  3. <link name="${lr}_wheel">
  4. <collision>
  5. <origin xyz="0 0 0" rpy="0 ${PI/2} ${PI/2}" />
  6. <geometry>
  7. <cylinder length="${wheelWidth}" radius="${wheelRadius}"/>
  8. </geometry>
  9. </collision>
  10.  
  11. <visual>
  12. <origin xyz="0 0 0" rpy="0 ${PI/2} ${PI/2}" />
  13. <geometry>
  14. <cylinder length="${wheelWidth}" radius="${wheelRadius}"/>
  15. </geometry>
  16. <material name="black"/>
  17. </visual>
  18.  
  19. <inertial>
  20. <origin xyz="0 0 0" rpy="0 ${PI/2} ${PI/2}" />
  21. <mass value="${wheelMass}"/>
  22. <cylinder_inertia m="${wheelMass}" r="${wheelRadius}" h="${wheelWidth}"/>
  23. </inertial>
  24. </link>
  25.  
  26. <gazebo reference="${lr}_wheel">
  27. <mu1 value="1.0"/>
  28. <mu2 value="1.0"/>
  29. <kp value="10000000.0" />
  30. <kd value="1.0" />
  31. <fdir1 value="1 0 0"/>
  32. <material>Gazebo/Black</material>
  33. </gazebo>
  34.  
  35. <joint name="${lr}_wheel_hinge" type="continuous">
  36. <parent link="chassis"/>
  37. <child link="${lr}_wheel"/>
  38. <origin xyz="${-wheelPos+chassisLength/2} ${tY*wheelWidth/2+tY*chassisWidth/2} ${wheelRadius}" rpy="0 0 0" />
  39. <axis xyz="0 1 0" rpy="0 0 0" />
  40. <limit effort="" velocity=""/>
  41. <joint_properties damping="0.0" friction="0.0"/>
  42. </joint>
  43.  
  44. <transmission name="${lr}_trans">
  45. <type>transmission_interface/SimpleTransmission</type>
  46. <joint name="${lr}_wheel_hinge"/>
  47. <actuator name="${lr}Motor">
  48. <hardwareInterface>EffortJointInterface</hardwareInterface>
  49. <mechanicalReduction></mechanicalReduction>
  50. </actuator>
  51. </transmission>
  52.  
  53. </macro>

The parameters allows us to specify which wheel we are talking about. “lr” could have two values (left or right) and “tY”, for translation along the Y-axis, also (respectively 1 and -1). There is nothing new concerning the link part.

The gazebo tag is inserted here so that we don’t need to worry about it every time we add a wheel. This macro is thus self-sufficient. The joint type is continuous. This allows a rotation around one axis. This axis is y 0 1 0 and connects each wheel to the chassis of your robot.

What’s new is the transmission element. To use ros_control with your robot, you need to add some additional elements to your URDF. The element is used to link actuators to joints, see the spec for exact XML format. We’ll use them in a minute.

Now you can add the wheels to the main file :

  1. <wheel lr="left" tY=""/>
  2. <wheel lr="right" tY="-1"/>

As you see, the macro makes it very simple.

Now you can launch your simulation and the full robot should appear!

Run the Models

Load the Gazebo simulator in a terminal

  1. roslaunch mybot_gazebo mybot_world.launch

Version Control (recommended)

Initialize a new repo in github server, like making_my_robot_in_gazebo.

Save everythin in this new repo and set a new branch called "day1_static_model" by

  1. git push --set-upstream origin day1_static_model

Reference

  1. Robotic simulation scenarios with Gazebo and ROS

Making my own Autonomous Robot in ROS / Gazebo, Day 1: Building the static model的更多相关文章

  1. Making my own Autonomous Robot in ROS / Gazebo, Day 2: Enable the robot

    Day 2: Enable the robot Git Setting git checkout master git branch day2_enable_robot git push --set- ...

  2. Gazebo Ros入门

    教程代码 First step with gazebo and ros • setup a ROS workspace • create projects for your simulated rob ...

  3. Gazebo機器人仿真學習探索筆記(七)连接ROS

    中文稍后补充,先上官方原版教程.ROS Kinetic 搭配 Gazebo 7 附件----官方教程 Tutorial: ROS integration overview As of Gazebo 1 ...

  4. ROS常用三維機器人仿真工具Gazebo教程匯總

    參考網址: 1. http://gazebosim.org/tutorials 2. http://gazebosim.org/tutorials/browse Gazebo Tutorials Ga ...

  5. Robot Operating System (ROS)学习笔记2---使用smartcar进行仿真

    搭建环境:XMWare  Ubuntu14.04  ROS(indigo) 转载自古月居  转载连接:http://www.guyuehome.com/248 一.模型完善 文件夹urdf下,创建ga ...

  6. Gazebo與ROS版本說明

    使用哪种ROS / Gazebo版本的组合 介绍 本文档提供了有关将不同版本的ROS与不同版本的Gazebo结合使用的选项的概述.建议在安装Gazebo ROS包装之前阅读它.重要!简单的分析,快速和 ...

  7. 在ROS Kinetic和Gazebo 8中使用智能汽车仿真演示

    在ROS Kinetic和Gazebo 8中使用智能汽车仿真演示 智能车无人驾驶技术是目前人工智能和机器人技术的研究热点,有许多开源平台可以使我们零基础零成本入门无人驾驶技术.本文分享一下目前ROS官 ...

  8. getting started with building a ROS simulation platform for Deep Reinforcement Learning

    Apparently, this ongoing work is to make a preparation for futural research on Deep Reinforcement Le ...

  9. ROS机器人程序设计(原书第2版)补充资料 (捌) 第八章 导航功能包集入门 navigation

    ROS机器人程序设计(原书第2版)补充资料 (捌) 第八章 导航功能包集入门 navigation 书中,大部分出现hydro的地方,直接替换为indigo或jade或kinetic,即可在对应版本中 ...

随机推荐

  1. spring cloud的主要组成部分

    服务发现:Eureka断路器: Hystrix 客户端和控制面板客户端负载均衡: Ribbon声明式REST客户端: Feign外部化配置: Archaius路由和过滤器: Zuul RxJava w ...

  2. aischool 倒计时VIEW封装

    @implementation TWPaperTimeCountLabel { NSInteger miaoshu; dispatch_source_t _timer; } -(id)initWith ...

  3. SQL 一条SQL语句 统计 各班总人数,男女各总人数 ,各自 男女 比例 (转)

    select  sClass 班级,count(*)  班级学生总人数, sum(case when sGender=0 then 1 else 0 end) 女生人数, sum(case when ...

  4. Excel 同时打开2个或多个独立窗口

    首先win7版本点击[开始]菜单,在输入框里面输入"regedit.exe"打开注册表     然后定位找到该路径HKEY_CLASSES_ROOT \ Excel.Sheet.1 ...

  5. php 截取代码方法(140个字后的。)

    //截取摘要public static function mbsubstr($str){    $strleng = mb_strlen($str,"utf8");    $mbs ...

  6. hdu5219 Repeating

    后缀数组+莫比乌斯函数 #include <stdio.h> #include <string.h> #include<algorithm> using names ...

  7. Docker镜像的管理和创建

    1. Docker镜像和Docker容器:      Docker镜像实际上是一系列的文件系统,通常的Linux系统一般是两层文件系统,bootfs和rootfs,bootfs就是bootloader ...

  8. Java 获取两个日期之间的日期

    1.前期需求,两个日期,我们叫他startDate和endDate,然后获取到两个日期之间的日期 /** * 获取两个日期之间的日期 * @param start 开始日期 * @param end ...

  9. 上海有线通下载exe会302转发请求

    起因: 做的软件用的clickonce,在公网的clickonce下载exe时一直报错,在vpn环境下没问题.错误提示如下: + HTTP redirect is not allowed for ap ...

  10. Lucene热词显示并选择

    利用Jquery easyui里的autocomplete(1.10.0版本) 的异步请求(remot.html) 添加引用 <script src="~/Scripts/jquery ...