{"id":2571,"date":"2015-02-26T09:56:36","date_gmt":"2015-02-26T08:56:36","guid":{"rendered":"http:\/\/www.generationrobots.com\/blog\/?p=2571"},"modified":"2023-03-29T12:17:41","modified_gmt":"2023-03-29T10:17:41","slug":"robotic-simulation-scenarios-with-gazebo-and-ros","status":"publish","type":"post","link":"https:\/\/www.generationrobots.com\/blog\/en\/robotic-simulation-scenarios-with-gazebo-and-ros\/","title":{"rendered":"Robotic simulation scenarios with Gazebo and ROS"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"h-gazebo-robotics-simulator-with-ros\">Gazebo robotics simulator with ROS<\/h2>\n\n\n\n<p>This tutorial is intended for roboticists that want to have realistic simulations of their robotic scenarios. Gazebo is a 3D simulator, while ROS serves as the interface for the robot. Combining both results in a powerful robot simulator.<\/p>\n\n\n\n<p>With Gazebo you are able to create a 3D scenario on your computer with robots, obstacles and many other objects. Gazebo also uses a physical engine for illumination, gravity, inertia, etc. You can evaluate and test your robot in difficult or dangerous scenarios without any harm to your robot. Most of the time it is faster to run a simulator instead of starting the whole scenario on your real robot.<\/p>\n\n\n\n<p>Originally Gazebo was designed to evaluate algorithms for robots. For many applications it is essential to test your robot application, like error handling, battery life, localization, navigation and grasping. As there was a need for a multi-robot simulator Gazebo was developed and improved.<\/p>\n\n\n\n<p><strong>This Tutorial was tested with an Ubuntu 12.10 with ROS Hydro and Gazebo-1.9.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-sources\">Sources<\/h3>\n\n\n\n<p>Sources for this tutorial can be found on <a class=\"catalogue\" title=\"Gazebo with ROS sources\" href=\"https:\/\/github.com\/HumaRobotics\/mybot_gazebo_tutorial\" target=\"_blank\" rel=\"noopener noreferrer\">GitHub<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-installation-of-gazebo\">Installation of Gazebo<\/h3>\n\n\n\n<p>For Gazebo there are also multiple options for installation. As I use an Ubuntu I selected the installation with precompiled binaries. Make sure you can launch \u00ab\u00a0gzserver\u00a0\u00bb and \u00ab\u00a0gzclient\u00a0\u00bb after the installation of Gazebo.<\/p>\n\n\n\n<p>Gazebo is split up in two parts. The server part computes all the physics and world, while the client is the graphical frontent for gazebo. So if you want to save performance on your computer you could also execute all tests without the graphical interface. Although it looks very nice, it consumes a lot of resources.<\/p>\n\n\n\n<p><strong>Your Gazebo should be installed in:<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>\/usr\/bin\/gzserver<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/usb\/bin\/gzclient<\/code><\/pre>\n<\/blockquote>\n\n\n\n<p>or<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>\/usr\/local\/bin\/gzserver<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/usr\/local\/bin\/gzclient<\/code><\/pre>\n<\/blockquote>\n\n\n\n<p><strong>if you installed Gazebo from sources.<\/strong><\/p>\n\n\n\n<p>After Gazebo and ROS have been installed it is time to install the bridge between them. With this bridge you can launch gazebo within ROS and dynamically add models to Gazebo. Depending on your Gazebo installation, there are different methods to continue.<\/p>\n\n\n\n<p>If you have ROS Hydro you probably want to follow this guide to install the ROS Packages for Gazebo and look at the &lsquo;Install Pre-Built Debians&rsquo; section.<\/p>\n\n\n\n<p>If you do not have the ROS Version \u00ab\u00a0Hydro\u00a0\u00bb installed, you have to manually \u00ab\u00a0git clone\u00a0\u00bb the \u00ab\u00a0gazebo_ros_pkgs\u00a0\u00bb. The git url can be found on http:\/\/www.ros.org\/wiki\/gazebo_ros_pkgs. If git is not installed:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>sudo apt-get install git<\/code><\/pre>\n<\/blockquote>\n\n\n\n<p>If you have some missing dependencies, the following two packages may help<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>sudo apt-get install ros-hydro-pcl-conversions<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install ros-hydro-control-msgs<\/code><\/pre>\n<\/blockquote>\n\n\n\n<p>If the cmake_modules are missing, \u00ab\u00a0git clone\u00a0\u00bb them in the sources of your catkin directory.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>git clone https:\/\/github.com\/ros\/cmake_modules<\/code><\/pre>\n<\/blockquote>\n\n\n\n<p>If everything worked you should be able to start Gazebo and ROS with (remember to source your environment):<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>roscore &amp; rosrun gazebo_ros gazebo<\/code><\/pre>\n<\/blockquote>\n\n\n\n<p>You could also start them individually with gzserver and gzclient. If Gazebo is properly connected to ROS you should be able to the some published topics. Just type<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>rostopic list<\/code><\/pre>\n<\/blockquote>\n\n\n\n<p>in one of your favorite terminals to see, if there are some gazebo topics if the gzserver is running.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code class=\"bash\">\/gazebo\/link_states<\/code><code class=\"bash\">\/gazebo\/model_states<\/code><code class=\"bash\">\/gazebo\/parameter_descriptions<\/code><code class=\"bash\">\/gazebo\/parameter_updates<\/code><code class=\"bash\">\/gazebo\/set_link_state<\/code><code class=\"bash\">\/gazebo\/set_model_state<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-first-steps-with-gazebo-and-ros\">First Steps with Gazebo and ROS<\/h2>\n\n\n\n<p>You should have previously installed Gazebo and ROS. Now you are ready to discover the fascinating world of simulation. In <a name=\"TOC\"><\/a>this tutorial we are going to:<\/p>\n\n\n\n<p><a href=\"#SetupWorkspace\">\u2022setup a ROS workspace<br \/><\/a> <a href=\"#PROJECTS\">\u2022create projects for your simulated robot<br \/><\/a><a href=\"#create a Gazebo world\">\u2022create a Gazebo world<br \/><\/a><a href=\"#create your own robot model\">\u2022create your own robot model<br \/><\/a><a href=\"#connect your robot model to ROS\">\u2022connect your robot model to ROS<br \/><\/a><a href=\"#use a teleoperation node to control your robot\">\u2022use a teleoperation node to control your robot<br \/><\/a><a href=\"#add a camera to your robot\">\u2022add a camera to your robot<br \/><\/a><a href=\"#use Rviz to vizualize all the robot information\">\u2022use Rviz to vizualize all the robot information<br \/><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-setup-a-new-workspace\">Setup a new workspace<\/h2>\n\n\n\n<p>We&rsquo;ll assume that you start from scratch and need to create a new workspace for your project. Let&rsquo;s first source our ROS Hydro environment:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>source \/opt\/ros\/hydro\/setup.bash<\/code><\/pre>\n\n\n\n<p>Now let&rsquo;s create the folder that will contain our workspace and the &lsquo;src&rsquo; subfolder.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p ~\/catkin_ws\/src<\/code><\/pre>\n\n\n\n<p>Go into the source and initialize the workspace:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ~\/catkin_ws\/src<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>catkin_init_workspace<\/code><\/pre>\n\n\n\n<p>Lets do a first build of your (empty) workspace just to generate the proper setup files<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ..<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>catkin_make<\/code><\/pre>\n\n\n\n<p>From now on, each time we&rsquo;ll have to start ROS commands that imply using our packages, we&rsquo;ll have to source the workspace environment in each terminal:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>source ~\/catkin_ws\/devel\/setup.bash<\/code><\/pre>\n\n\n\n<p><a href=\"#TOC\">Back to the table of contents<\/a><\/p>\n\n\n\n<p><a name=\"PROJECTS\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-create-projects-for-your-simulated-robot\">Create projects for your simulated robot<\/h2>\n\n\n\n<p>The ROS community has established some conventions for packages that define robots, their ROS bindings and the Gazebo integration. We&rsquo;ll try to follow these conventions for this simple robot. Let&rsquo;s assume our robot will be called mybot. We are going to create 3 packages:<\/p>\n\n\n\n<p>mybot_gazebo: provides launch files and worlds for easy starting of simulation mybot_description: provides the 3D model of the robot and the description of joints and sensors mybot_control: configures the ROS interface to our robot&rsquo;s joints Ok let&rsquo;s create these, first make sure you&rsquo;ve sourced your workspace environment and go into the &lsquo;src&rsquo; subfolder:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ~\/catkin_ws\/src<\/code><\/pre>\n\n\n\n<p>Let&rsquo;s create the three packages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>catkin_create_pkg mybot_gazebo gazebo_ros<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>catkin_create_pkg mybot_description<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>catkin_create_pkg mybot_control<\/code><\/pre>\n\n\n\n<p><a href=\"#TOC\">Back to the table of contents<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-creating-your-own-world\"><a name=\"create a Gazebo world\"><\/a>Creating your own World<\/h2>\n\n\n\n<p>Let&rsquo;s start with the gazebo package, go in there and create the following subfolders:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>roscd mybot_gazebo <\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir launch worlds<\/code><\/pre>\n\n\n\n<p>At first we want to create a world for our gazebo server. Therefore we switch to our worlds directory of our turtlebot project and create a new world file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd worlds<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>gedit mybot.world<\/code><\/pre>\n\n\n\n<p>A basic world file defines at least a name:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\"?&gt;\n&lt;sdf version=\"1.4\"&gt;\n&lt;world name=\"myworld\"&gt;\n&lt;\/world&gt;\n&lt;\/sdf&gt;<\/code><\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>At first we just want to add some basic objects, like a ground and a basic illumination source inside the world tag.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\t&lt;include&gt;\n\t\t&lt;uri&gt;model:\/\/sun&lt;\/uri&gt;\n\t&lt;\/include&gt;\n\n\t&lt;include&gt;\n\t\t&lt;uri&gt;model:\/\/ground_plane&lt;\/uri&gt;\n\t&lt;\/include&gt;\n<\/code><\/pre>\n\n\n\n<p>Check your \u00ab\u00a0~\/.gazebo\/models\u00a0\u00bb directory, as this is a default path for saved models. If this path does not exist try to find <code>\/usr\/share\/gazebo\/setup.sh<\/code> where gazebo looks for models. Otherwise add it to your model path.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Change to the launch directory of your project:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>roscd mybot_gazebo\/launch<\/code><\/pre>\n\n\n\n<p>Create a new file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gedit mybot_world.launch<\/code><\/pre>\n\n\n\n<p>and insert:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;launch&gt;\t  \n\t&lt;include file=\"$(find gazebo_ros)\/launch\/empty_world.launch\"&gt;\t    \n\t\t&lt;arg name=\"world_name\" value=\"$(find mybot_gazebo)\/worlds\/mybot.world\"\/&gt;\t    \n\t\t&lt;arg name=\"gui\" value=\"true\"\/&gt;\t  \n\t&lt;\/include&gt;\t\n&lt;\/launch&gt;<\/code><\/pre>\n\n\n\n<p>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:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>roslaunch mybot_gazebo mybot_world.launch<\/code><\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>If you would press \u00ab\u00a0Save world as\u00a0\u00bb in \u00ab\u00a0File\u00a0\u00bb in your gazebo client and save the world in a text file, you could investigate the full world description.<\/p>\n\n\n\n<p>If you want to watch a more complex and beautiful world environment then add the following inside your world tag:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  \t&lt;include&gt;\n\t\t&lt;uri&gt;model:\/\/willowgarage&lt;\/uri&gt;\t\n\t&lt;\/include&gt;\n<\/code><\/pre>\n\n\n\n<p>This one shows you the office of Willow Garage, be careful, it&rsquo;s huge and may make your simulation extremely slow.<\/p>\n\n\n\n<p><a href=\"#TOC\">Back to the table of contents<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-creating-your-own-model\"><a name=\"&quot;create\"><\/a>Creating your own Model<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/img\/products\/Create%20your%20own%20model.jpg\" alt=\"Create your model with ROS Gazebo\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>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&rsquo;ll prefer to use a URDF file generated by Xacro and put it the description package.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Ok so first we need to go into our description package and create the urdf subfolder and the description file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>roscd mybot_description<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir urdf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>cd urdf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>gedit mybot.xacro<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-xacro-concepts\">XACRO CONCEPTS<\/h3>\n\n\n\n<p>\u2022 <strong>xacro:include:<\/strong> Import the content from other file. We can divide the content in different xacros and merge them using xacro:include.<br \/>\u2022 <strong>property:<\/strong> Useful to define constant values. Use it later using <code>${property_name}<\/code><br \/>\u2022 <strong>xacro:macro:<\/strong> 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&rsquo;s name and filling the required values.<\/p>\n\n\n\n<p>This file will be the main description of our robot. Let&rsquo;s put some basic structure:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\"?&gt;\n&lt;robot name=\"mybot\" xmlns:xacro=\"http:\/\/www.ros.org\/wiki\/xacro\"&gt;\n        &lt;!-- Put here the robot description --&gt;\n&lt;\/robot&gt;\n<\/code><\/pre>\n\n\n\n<p>The structure is basic for a urdf file. The complete description (links, joints, transmission&#8230;) have to be within the robot tag. The <code>xmlns:xacro=\"http:\/\/www.ros.org\/wiki\/xacro\"<\/code> specifies that this file will use xacro. If you want to use xacro you have to put this.<\/p>\n\n\n\n<p>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).<\/p>\n\n\n\n<p>Let&rsquo;s define some physical properties for our robot, mainly the dimensions of the chassis, the caster wheel, the wheels and the camera:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n&lt;xacro:property name=\"PI\" value=\"3.1415926535897931\"\/&gt;\n\n&lt;xacro:property name=\"chassisHeight\" value=\"0.1\"\/&gt;\n&lt;xacro:property name=\"chassisLength\" value=\"0.4\"\/&gt;\n&lt;xacro:property name=\"chassisWidth\" value=\"0.2\"\/&gt;\n&lt;xacro:property name=\"chassisMass\" value=\"50\"\/&gt;\n\n&lt;xacro:property name=\"casterRadius\" value=\"0.05\"\/&gt;\n&lt;xacro:property name=\"casterMass\" value=\"5\"\/&gt;\n\n&lt;xacro:property name=\"wheelWidth\" value=\"0.05\"\/&gt;\n&lt;xacro:property name=\"wheelRadius\" value=\"0.1\"\/&gt;\n&lt;xacro:property name=\"wheelPos\" value=\"0.2\"\/&gt;\n&lt;xacro:property name=\"wheelMass\" value=\"5\"\/&gt;\n\n&lt;xacro:property name=\"cameraSize\" value=\"0.05\"\/&gt;\n&lt;xacro:property name=\"cameraMass\" value=\"0.1\"\/&gt;\n<\/code><\/pre>\n\n\n\n<p><code class=\"bash\">\u2039arg name=\"gui\" value=\"true\"\/\u203a<\/code>These parameters or properties can be used in all the file with ${property name}.<\/p>\n\n\n\n<p>We will also include three files :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> &lt;xacro:include filename=\"$(find mybot_description)\/urdf\/mybot.gazebo\" \/&gt;\n &lt;xacro:include filename=\"$(find mybot_description)\/urdf\/materials.xacro\" \/&gt;\n &lt;xacro:include filename=\"$(find mybot_description)\/urdf\/macros.xacro\" \/&gt;\n<\/code><\/pre>\n\n\n\n<p>These three correspond respectively to:<\/p>\n\n\n\n<p>\u2022 all the gazebo-specific aspects of our robot<br \/>\u2022 definition of the materials used (mostly colors)<br \/>\u2022 definitions of some macros for easier description of the robot<\/p>\n\n\n\n<p>Every file has to contain the robot tag and everything we put in them should be in this tag.<\/p>\n\n\n\n<p>Now we want to add a rectangular base for our robot. Insert this within the robot tag of mybox.xacro:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;link name='chassis'&gt;\n  &lt;collision&gt; \n    &lt;origin xyz=\"0 0 ${wheelRadius}\" rpy=\"0 0 0\"\/&gt; \n    &lt;geometry&gt; \n      &lt;box size=\"${chassisLength} ${chassisWidth} ${chassisHeight}\"\/&gt; \n    &lt;\/geometry&gt; \n  &lt;\/collision&gt;\n  &lt;visual&gt; \n    &lt;origin xyz=\"0 0 ${wheelRadius}\" rpy=\"0 0 0\"\/&gt; \n    &lt;geometry&gt; \n      &lt;box size=\"${chassisLength} ${chassisWidth} ${chassisHeight}\"\/&gt; \n    &lt;\/geometry&gt; \n    &lt;material name=\"orange\"\/&gt;\n  &lt;\/visual&gt;\n  &lt;inertial&gt; \n    &lt;origin xyz=\"0 0 ${wheelRadius}\" rpy=\"0 0 0\"\/&gt; \n    &lt;mass value=\"${chassisMass}\"\/&gt; \n    &lt;box_inertia m=\"${chassisMass}\" x=\"${chassisLength}\" y=\"${chassisWidth}\" z=\"${chassisHeight}\"\/&gt;\n  &lt;\/inertial&gt;\n&lt;\/link&gt;\n<\/code><\/pre>\n\n\n\n<p>We define a box with <code>chassisLength<\/code> x <code>chassisWidth<\/code> x <code>chassisHeight<\/code> meters and mass <code>chassisMasskg<\/code>.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>As they don&rsquo;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.<\/p>\n\n\n\n<p>Add this in \u201cmybot.gazebo\u201d, within the robot tag :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;gazebo reference=\"chassis\"&gt;\n  &lt;material&gt;Gazebo\/Orange&lt;\/material&gt;\n&lt;\/gazebo&gt;\n<\/code><\/pre>\n\n\n\n<p>And this in the \u201cmaterials.xacro\u201d :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;material name=\"black\"&gt;\n  &lt;color rgba=\"0.0 0.0 0.0 1.0\"\/&gt;\n&lt;\/material&gt;\n\n&lt;material name=\"blue\"&gt;\n  &lt;color rgba=\"0.0 0.0 0.8 1.0\"\/&gt;\n&lt;\/material&gt;\n\n&lt;material name=\"green\"&gt;\n  &lt;color rgba=\"0.0 0.8 0.0 1.0\"\/&gt;\n&lt;\/material&gt;\n\n&lt;material name=\"grey\"&gt;\n  &lt;color rgba=\"0.2 0.2 0.2 1.0\"\/&gt;\n&lt;\/material&gt;\n\n&lt;material name=\"orange\"&gt;\n  &lt;color rgba=\"${255\/255} ${108\/255} ${10\/255} 1.0\"\/&gt;\n&lt;\/material&gt;\n\n&lt;material name=\"brown\"&gt;\n  &lt;color rgba=\"${222\/255} ${207\/255} ${195\/255} 1.0\"\/&gt;\n&lt;\/material&gt;\n\n&lt;material name=\"red\"&gt;\n  &lt;color rgba=\"0.8 0.0 0.0 1.0\"\/&gt;\n&lt;\/material&gt;\n\n&lt;material name=\"white\"&gt;\n  &lt;color rgba=\"1.0 1.0 1.0 1.0\"\/&gt;\n&lt;\/material&gt;\n<\/code><\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Another particular thing in the chassis link is the use of \u201cbox_inertia\u201d 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.<\/p>\n\n\n\n<p>Add this in the macros.xacro file, within the robot tag :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;macro name=\"cylinder_inertia\" params=\"m r h\"&gt;\n  &lt;inertia  ixx=\"${m*(3*r*r+h*h)\/12}\" ixy = \"0\" ixz = \"0\"\n    iyy=\"${m*(3*r*r+h*h)\/12}\" iyz = \"0\"\n    izz=\"${m*r*r\/2}\"\n  \/&gt;\n&lt;\/macro&gt;\n\n&lt;macro name=\"box_inertia\" params=\"m x y z\"&gt;\n  &lt;inertia  ixx=\"${m*(y*y+z*z)\/12}\" ixy = \"0\" ixz = \"0\"\n    iyy=\"${m*(x*x+z*z)\/12}\" iyz = \"0\"\n    izz=\"${m*(x*x+z*z)\/12}\"\n  \/&gt;\n&lt;\/macro&gt;\n\n&lt;macro name=\"sphere_inertia\" params=\"m r\"&gt;\n  &lt;inertia  ixx=\"${2*m*r*r\/5}\" ixy = \"0\" ixz = \"0\"\n    iyy=\"${2*m*r*r\/5}\" iyz = \"0\"\n    izz=\"${2*m*r*r\/5}\"\n  \/&gt;\n&lt;\/macro&gt;\n<\/code><\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>We have two small things to do before testing our model with gazebo.<\/p>\n\n\n\n<p>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 :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;link name=\"footprint\" \/&gt;\n\n&lt;joint name=\"base_joint\" type=\"fixed\"&gt;\n  &lt;parent link=\"footprint\"\/&gt;\n  &lt;child link=\"chassis\"\/&gt;\n&lt;\/joint&gt;\n<\/code><\/pre>\n\n\n\n<p>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:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- urdf xml robot description loaded on the Parameter Server, converting the xacro into a proper urdf file--&gt;\n&lt;param name=\"robot_description\" command=\"$(find xacro)\/xacro.py '$(find mybot_description)\/urdf\/mybot.xacro'\" \/&gt;\n\n&lt;!-- push robot_description to factory and spawn robot in gazebo --&gt;\n&lt;node name=\"mybot_spawn\" pkg=\"gazebo_ros\" type=\"spawn_model\" output=\"screen\"\n args=\"-urdf -param robot_description -model mybot\" \/&gt;\n <\/code><\/pre>\n\n\n\n<p>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 \u201crobot_description\u201d (this is a standard name used by many ROS tools).<\/p>\n\n\n\n<p>The second tag launches a program from the gazebo_ros package that will load the URDF from the parameter \u201crobot_description\u201d and spawn the model into our Gazebo simulator<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/img\/products\/CreateYourOwnModel2_680.jpg\" alt=\"model chassis created with ROS Gazebo\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>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 :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;joint name=\"fixed\" type=\"fixed\"&gt;\n  &lt;parent link=\"chassis\"\/&gt;\n  &lt;child link=\"caster_wheel\"\/&gt;\n&lt;\/joint&gt;\n\n&lt;link name=\"caster_wheel\"&gt;\n  &lt;collision&gt;\n    &lt;origin xyz=\"${casterRadius-chassisLength\/2} 0 ${casterRadius-chassisHeight+wheelRadius}\" rpy=\"0 0 0\"\/&gt;\n    &lt;geometry&gt;\n      &lt;sphere radius=\"${casterRadius}\"\/&gt;\n    &lt;\/geometry&gt;\n  &lt;\/collision&gt;\n  \n  &lt;visual&gt;\n    &lt;origin xyz=\"${casterRadius-chassisLength\/2} 0 ${casterRadius-chassisHeight+wheelRadius}\" rpy=\"0 0 0\"\/&gt;\n    &lt;geometry&gt;\n      &lt;sphere radius=\"${casterRadius}\"\/&gt;\n    &lt;\/geometry&gt;\n    &lt;material name=\"red\"\/&gt;\n  &lt;\/visual&gt;\n\n  &lt;inertial&gt;\n    &lt;origin xyz=\"${casterRadius-chassisLength\/2} 0 ${casterRadius-chassisHeight+wheelRadius}\" rpy=\"0 0 0\"\/&gt;\n    &lt;mass value=\"${casterMass}\"\/&gt;\n    &lt;sphere_inertia m=\"${casterMass}\" r=\"${casterRadius}\"\/&gt;\n  &lt;\/inertial&gt;\n&lt;\/link&gt;<\/code><\/pre>\n\n\n\n<p>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 :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;gazebo reference=\"caster_wheel\"&gt;\n  &lt;mu1&gt;0.0&lt;\/mu1&gt;\n  &lt;mu2&gt;0.0&lt;\/mu2&gt;\n  &lt;material&gt;Gazebo\/Red&lt;\/material&gt;\n&lt;\/gazebo&gt;\n<\/code><\/pre>\n\n\n\n<p>As usual, we specify the color used in material. We also added mu1 and mu2, with value 0 to remove the friction.<\/p>\n\n\n\n<p>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&rsquo;s make one macro to make it simple. In the macro file, add this :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;macro name=\"wheel\" params=\"lr tY\"&gt;\n\n&lt;link name=\"${lr}_wheel\"&gt;\n  &lt;collision&gt;\n    &lt;origin xyz=\"0 0 0\" rpy=\"0 ${PI\/2} ${PI\/2}\" \/&gt;\n    &lt;geometry&gt;\n      &lt;cylinder length=\"${wheelWidth}\" radius=\"${wheelRadius}\"\/&gt;\n    &lt;\/geometry&gt;\n  &lt;\/collision&gt;\n\n  &lt;visual&gt;\n    &lt;origin xyz=\"0 0 0\" rpy=\"0 ${PI\/2} ${PI\/2}\" \/&gt;\n    &lt;geometry&gt;\n      &lt;cylinder length=\"${wheelWidth}\" radius=\"${wheelRadius}\"\/&gt;\n    &lt;\/geometry&gt;\n    &lt;material name=\"black\"\/&gt;\n  &lt;\/visual&gt;\n\n  &lt;inertial&gt;\n    &lt;origin xyz=\"0 0 0\" rpy=\"0 ${PI\/2} ${PI\/2}\" \/&gt;\n    &lt;mass value=\"${wheelMass}\"\/&gt;\n    &lt;cylinder_inertia m=\"${wheelMass}\" r=\"${wheelRadius}\" h=\"${wheelWidth}\"\/&gt;\n  &lt;\/inertial&gt;\n&lt;\/link&gt;\n\n&lt;gazebo reference=\"${lr}_wheel\"&gt;\n  &lt;mu1 value=\"1.0\"\/&gt;\n  &lt;mu2 value=\"1.0\"\/&gt;\n  &lt;kp  value=\"10000000.0\" \/&gt;\n  &lt;kd  value=\"1.0\" \/&gt;\n  &lt;fdir1 value=\"1 0 0\"\/&gt;\n  &lt;material&gt;Gazebo\/Black&lt;\/material&gt;\n&lt;\/gazebo&gt;\n\n\n&lt;joint name=\"${lr}_wheel_hinge\" type=\"continuous\"&gt;\n  &lt;parent link=\"chassis\"\/&gt;\n  &lt;child link=\"${lr}_wheel\"\/&gt;\n&lt;origin xyz=\"${-wheelPos+chassisLength\/2} ${tY*wheelWidth\/2+tY*chassisWidth\/2} ${wheelRadius}\" rpy=\"0 0 0\" \/&gt;\n  &lt;axis xyz=\"0 1 0\" rpy=\"0 0 0\" \/&gt;\n  &lt;limit effort=\"100\" velocity=\"100\"\/&gt;\n  &lt;joint_properties damping=\"0.0\" friction=\"0.0\"\/&gt;\n&lt;\/joint&gt;\n\n\n&lt;transmission name=\"${lr}_trans\"&gt;\n  &lt;type&gt;transmission_interface\/SimpleTransmission&lt;\/type&gt;\n  &lt;joint name=\"${lr}_wheel_hinge\"\/&gt;\n  &lt;actuator name=\"${lr}Motor\"&gt;\n    &lt;hardwareInterface&gt;EffortJointInterface&lt;\/hardwareInterface&gt;\n    &lt;mechanicalReduction&gt;10&lt;\/mechanicalReduction&gt;\n  &lt;\/actuator&gt;\n&lt;\/transmission&gt;\n\n&lt;\/macro&gt;\n<\/code><\/pre>\n\n\n\n<p>The parameters allows us to specify which wheel we are talking about. \u201clr\u201d could have two values (left or right) and \u201ctY\u201d, for translation along the Y-axis, also (respectively 1 and -1). There is nothing new concerning the link part.<\/p>\n\n\n\n<p>The gazebo tag is inserted here so that we don&rsquo;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.<\/p>\n\n\n\n<p>What&rsquo;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&rsquo;ll use them in a minute.<\/p>\n\n\n\n<p>Now you can add the wheels to the main file :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;wheel lr=\"left\" tY=\"1\"\/&gt;\n&lt;wheel lr=\"right\" tY=\"-1\"\/&gt;\n<\/code><\/pre>\n\n\n\n<p>As you see, the macro makes it very simple.<\/p>\n\n\n\n<p>Now you can launch your simulation and the full robot should appear!<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/img\/products\/CreateYourOwnModel3_680.jpg\" alt=\"Robot model created with ROS and Gazebo\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><a href=\"#TOC\">Back to the table of contents<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-connect-your-robot-to-ros\"><a name=\"connect your robot model to ROS\"><\/a>Connect your robot to ROS<\/h3>\n\n\n\n<p>Alright, our robot is all nice and has this new car smell, but we can&rsquo;t do anything with it yet as it has no connection with ROS. In order to add this connection we need to add gazebeo plugins to our model. There are different kinds of plugins:<\/p>\n\n\n\n<p>\u2022 World: Dynamic changes to the world, e.g. Physics, like illumination or gravity, inserting models<br \/>\u2022 Model: Manipulation of models (robots), e.g. move the robots<br \/>\u2022 Sensor: Feedback from virtual sensor, like camera, laser scanner<br \/>\u2022 System: Plugins that are loaded by the GUI, like saving images<\/p>\n\n\n\n<p>First of all we&rsquo;ll use a plugin to provide access to the joints of the wheels. The transmission tags in our URDF will be used by this plugin the define how to link the joints to controllers. To activate the plugin, add the following to mybot.gazebo:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;gazebo&gt;\n  &lt;plugin name=\"gazebo_ros_control\" filename=\"libgazebo_ros_control.so\"&gt;\n    &lt;robotNamespace&gt;\/mybot&lt;\/robotNamespace&gt;\n  &lt;\/plugin&gt;\n&lt;\/gazebo&gt;\n<\/code><\/pre>\n\n\n\n<p>Look at this tutorial for more information on how this plugin works.<\/p>\n\n\n\n<p>With this plugin, we will be able to control the joints, however we need to provide some extra configuration and explicitely start controllers for the joints. In order to do so, we&rsquo;ll use the package mybot_control that we have defined before. Let&rsquo;s first create the configuration file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>roscd mybot_control<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir config<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>cd config<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>gedit mybot_control.yaml<\/code><\/pre>\n\n\n\n<p>This file will define three controllers: one for each wheel, connections to the joint by the transmission tag, one for publishing the joint states. It also defined the PID gains to use for this controller:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mybot:\n  # Publish all joint states -----------------------------------\n  joint_state_controller:\n    type: joint_state_controller\/JointStateController\n    publish_rate: 50  \n  \n\n  # Effort Controllers ---------------------------------------\n  leftWheel_effort_controller:\n    type: effort_controllers\/JointEffortController\n    joint: left_wheel_hinge\n    pid: {p: 100.0, i: 0.1, d: 10.0}\n  rightWheel_effort_controller:\n    type: effort_controllers\/JointEffortController\n    joint: right_wheel_hinge\n    pid: {p: 100.0, i: 0.1, d: 10.0}\n<\/code><\/pre>\n\n\n\n<p>Now we need to create a launch file to start the controllers. For this let&rsquo;s do:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>roscd mybot_control<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir launch<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>cd launch<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>gedit mybot_control.launch<\/code><\/pre>\n\n\n\n<p>In this file we&rsquo;ll put two things. First we&rsquo;ll load the configuration and the controllers, and we&rsquo;ll also start a node that will provide 3D transforms (tf) of our robot. This is not mandatory but that makes the simulation more complete:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;launch&gt;\n\n  &lt;!-- Load joint controller configurations from YAML file to parameter server --&gt;\n  &lt;rosparam file=\"$(find mybot_control)\/config\/mybot_control.yaml\" command=\"load\"\/&gt;\n\n  &lt;!-- load the controllers --&gt;\n  &lt;node name=\"controller_spawner\"\n    pkg=\"controller_manager\"\n    type=\"spawner\" respawn=\"false\"\n    output=\"screen\" ns=\"\/mybot\"\n    args=\"joint_state_controller\n      rightWheel_effort_controller\n      leftWheel_effort_controller\"\n  \/&gt;\n\n\n  &lt;!-- convert joint states to TF transforms for rviz, etc --&gt;\n  &lt;node name=\"robot_state_publisher\" pkg=\"robot_state_publisher\" type=\"robot_state_publisher\" respawn=\"false\" output=\"screen\"&gt;\n    &lt;param name=\"robot_description\" command=\"$(find xacro)\/xacro.py '$(find mybot_description)\/urdf\/mybot.xacro'\" \/&gt;\n    &lt;remap from=\"\/joint_states\" to=\"\/mybot\/joint_states\" \/&gt;\n  &lt;\/node&gt;\n\n&lt;\/launch&gt;\n<\/code><\/pre>\n\n\n\n<p>We could launch our model on gazebo and then launch the controller, but to save some time (and terminals), we&rsquo;ll start the controllers automatically by adding a line to the \u201cmybot_world.launch\u201d in the mybot_gazebo package :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- ros_control mybot launch file --&gt;\n&lt;include file=\"$(find mybot_control)\/launch\/mybot_control.launch\" \/&gt;\n<\/code><\/pre>\n\n\n\n<p>Now launch your simulations. In a separate terminal, if you do a \u201crostopic list\u201d you should see the topics corresponding to your controllers. You can send commands manually to your robot:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n  rostopic pub -1 \/mybot\/leftWheel_effort_controller\/command std_msgs\/Float64 \"data: 1.5\"\n  rostopic pub -1 \/mybot\/rightWheel_effort_controller\/command std_msgs\/Float64 \"data: 1.0\"<\/code><\/pre>\n\n\n\n<p>The robot should start moving. Congratulations, you can now control your joints through ROS ! You can also monitor the joint states by doing :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n  rostopic echo \/mybot\/joint_states<\/code><\/pre>\n\n\n\n<p><a href=\"#TOC\">Back to the table of contents<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-teleoperation-of-your-robot\"><a name=\"use a teleoperation node to control your robot\"><\/a>Teleoperation of your robot<\/h2>\n\n\n\n<p>Ok you can control joints individually, but that&rsquo;s not so convenient when you want to make your mobile robot move around. Let&rsquo;s use another plugin called differential drive to make it easier. Add this in the gazebo file of your model :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;gazebo&gt;\n  &lt;plugin name=\"differential_drive_controller\" filename=\"libgazebo_ros_diff_drive.so\"&gt;\n    &lt;alwaysOn&gt;true&lt;\/alwaysOn&gt;\n    &lt;updateRate&gt;100&lt;\/updateRate&gt;\n    &lt;leftJoint&gt;left_wheel_hinge&lt;\/leftJoint&gt;\n    &lt;rightJoint&gt;right_wheel_hinge&lt;\/rightJoint&gt;\n    &lt;wheelSeparation&gt;${chassisWidth+wheelWidth}&lt;\/wheelSeparation&gt;\n    &lt;wheelDiameter&gt;${2*wheelRadius}&lt;\/wheelDiameter&gt;\n    &lt;torque&gt;20&lt;\/torque&gt;\n    &lt;commandTopic&gt;mybot\/cmd_vel&lt;\/commandTopic&gt;\n    &lt;odometryTopic&gt;mybot\/odom_diffdrive&lt;\/odometryTopic&gt;\n    &lt;odometryFrame&gt;odom&lt;\/odometryFrame&gt;\n    &lt;robotBaseFrame&gt;footprint&lt;\/robotBaseFrame&gt;\n  &lt;\/plugin&gt;\n&lt;\/gazebo&gt;\n<\/code><\/pre>\n\n\n\n<p>This plugin will subscribe to the cmd_vel topic specified with the \u00ab commandTopic \u00bb tag and convert the messages to the proper commands on the wheels. It also provides some odometry data.<\/p>\n\n\n\n<p>Now, you can start gazebo with the usual launch file.<\/p>\n\n\n\n<p>To teleoperate your robot with the keybord you can use a teleoperation node as provided in turtlesim or turtlebot packages. We just need to remap the topic name to connect it to our robot :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\trosrun turtlesim turtle_teleop_key \/turtle1\/cmd_vel:=\/mybot\/cmd_vel\n\trosrun turtlebot_teleop turtlebot_teleop_key \/turtlebot_teleop\/cmd_vel:=\/mybot\/cmd_vel<\/code><\/pre>\n\n\n\n<p>Enjoy the ride !<\/p>\n\n\n\n<p><a href=\"#TOC\">Back to the table of contents<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-adding-a-camera\"><a name=\"add a camera to your robot\"><\/a>Adding a camera<\/h2>\n\n\n\n<p>Let&rsquo;s add some sensors to our robot. If you already created some environment, you can now see what it is, with the eyes of your robot. For this we have to add a camera plugin to our robot model. For that, two things are necessary, a link and the actual plugin.<\/p>\n\n\n\n<p>Add the link to your main model file :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;link name=\"camera\"&gt;\n  &lt;collision&gt;\n    &lt;origin xyz=\"0 0 0\" rpy=\"0 0 0\"\/&gt;\n    &lt;geometry&gt;\n      &lt;box size=\"${cameraSize} ${cameraSize} ${cameraSize}\"\/&gt;\n    &lt;\/geometry&gt;\n  &lt;\/collision&gt;\n\n  &lt;visual&gt;\n    &lt;origin xyz=\"0 0 0\" rpy=\"0 0 0\"\/&gt;\n    &lt;geometry&gt;\n      &lt;box size=\"${cameraSize} ${cameraSize} ${cameraSize}\"\/&gt;\n    &lt;\/geometry&gt;\n    &lt;material name=\"blue\"\/&gt;\n  &lt;\/visual&gt;\n\n  &lt;inertial&gt;\n    &lt;mass value=\"${cameraMass}\" \/&gt;\n    &lt;origin xyz=\"0 0 0\" rpy=\"0 0 0\"\/&gt;\n    &lt;box_inertia m=\"${cameraMass}\" x=\"${cameraSize}\" y=\"${cameraSize}\" z=\"${cameraSize}\" \/&gt;\n  &lt;\/inertial&gt;\n&lt;\/link&gt;\n<\/code><\/pre>\n\n\n\n<p>And now add the plugin to the gazebo file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;gazebo reference=\"camera\"&gt;\n&nbsp; &lt;material&gt;Gazebo\/Blue&lt;\/material&gt;\n&nbsp; &lt;sensor type=\"camera\" name=\"camera1\"&gt;\n&nbsp; &nbsp; &lt;update_rate&gt;30.0&lt;\/update_rate&gt;\n&nbsp; &nbsp; &lt;camera name=\"head\"&gt;\n&nbsp; &nbsp; &nbsp; &lt;horizontal_fov&gt;1.3962634&lt;\/horizontal_fov&gt;\n&nbsp; &nbsp; &nbsp; &lt;image&gt;\n&nbsp; &nbsp; &nbsp; &nbsp; &lt;width&gt;800&lt;\/width&gt;\n&nbsp; &nbsp; &nbsp; &nbsp; &lt;height&gt;800&lt;\/height&gt;\n&nbsp; &nbsp; &nbsp; &nbsp; &lt;format&gt;R8G8B8&lt;\/format&gt;\n&nbsp; &nbsp; &nbsp; &lt;\/image&gt;\n&nbsp; &nbsp; &nbsp; &lt;clip&gt;\n&nbsp; &nbsp; &nbsp; &nbsp; &lt;near&gt;0.02&lt;\/near&gt;\n&nbsp; &nbsp; &nbsp; &nbsp; &lt;far&gt;300&lt;\/far&gt;\n&nbsp; &nbsp; &nbsp; &lt;\/clip&gt;\n&nbsp; &nbsp; &lt;\/camera&gt;\n&nbsp; &nbsp; &lt;plugin name=\"camera_controller\" filename=\"libgazebo_ros_camera.so\"&gt;\n&nbsp; &nbsp; &nbsp; &lt;alwaysOn&gt;true&lt;\/alwaysOn&gt;\n&nbsp; &nbsp; &nbsp; &lt;updateRate&gt;0.0&lt;\/updateRate&gt;\n&nbsp; &nbsp; &nbsp; &lt;cameraName&gt;mybot\/camera1&lt;\/cameraName&gt;\n&nbsp; &nbsp; &nbsp; &lt;imageTopicName&gt;image_raw&lt;\/imageTopicName&gt;\n&nbsp; &nbsp; &nbsp; &lt;cameraInfoTopicName&gt;camera_info&lt;\/cameraInfoTopicName&gt;\n&nbsp; &nbsp; &nbsp; &lt;frameName&gt;camera_link&lt;\/frameName&gt;\n&nbsp; &nbsp; &nbsp; &lt;hackBaseline&gt;0.07&lt;\/hackBaseline&gt;\n&nbsp; &nbsp; &nbsp; &lt;distortionK1&gt;0.0&lt;\/distortionK1&gt;\n&nbsp; &nbsp; &nbsp; &lt;distortionK2&gt;0.0&lt;\/distortionK2&gt;\n&nbsp; &nbsp; &nbsp; &lt;distortionK3&gt;0.0&lt;\/distortionK3&gt;\n&nbsp; &nbsp; &nbsp; &lt;distortionT1&gt;0.0&lt;\/distortionT1&gt;\n&nbsp; &nbsp; &nbsp; &lt;distortionT2&gt;0.0&lt;\/distortionT2&gt;\n&nbsp; &nbsp; &lt;\/plugin&gt;\n&nbsp; &lt;\/sensor&gt;\n &lt;\/gazebo&gt;Adding a camera\n\nLet's add some sensors to our robot. If you already created some environment, you can now see what it is, with the eyes of your robot. \n<\/code><\/pre>\n\n\n\n<p>Launch your simulation, and add some object in front of the robot. You can obtain the camera image as with any ROS compatible camera, by subscribing to the image topic. You can use the image_view tool to visualize it directly:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rosrun image_view image_view image:=\/mybot\/camera1\/image_raw<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/img\/products\/AddingaCamera.jpg\" alt=\"Image view Tool ROS Gazebo\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><a href=\"#TOC\">Back to the table of contents<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-visualisation-with-rviz\"><a name=\"use Rviz to vizualize all the robot information\"><\/a>Visualisation with RViz<\/h2>\n\n\n\n<p>Rviz is one of these fantastic tools that will make you love ROS. It&rsquo;s capable of visualizing many different kind of information in the same interface. To start rviz:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rosrun rviz rviz<\/code><\/pre>\n\n\n\n<p>At the bottom left of the window there is an \u201cadd\u201d button which allows you to load visualization plugins. In the parameters of these plugins you generally have to define the topic name to which the plugin subscribes, this should be fairly straightforward. A Rviz configuration file is provided with the sources and started by default in the launch file.<\/p>\n\n\n\n<p>Here is an example visualization with plugins for: the robot model, the 3D transforms TF, the camera Image, the odometry:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/img\/products\/VisualizationWithRviz_680.jpg\" alt=\"Rviz visualisation with ROS Gazebo\"\/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Gazebo robotics simulator with ROS This tutorial is intended for roboticists that want to have realistic simulations of their robotic scenarios. Gazebo is a 3D simulator, while ROS serves as the interface for the robot. Combining both results in a powerful robot simulator. With Gazebo you are able to create a 3D scenario on your[&#8230;]<br \/> <a class=\"button\" href=\"https:\/\/www.generationrobots.com\/blog\/en\/robotic-simulation-scenarios-with-gazebo-and-ros\/\" style=\"float:right;\">Read this article &gt;&gt;<\/a><\/p>\n","protected":false},"author":188,"featured_media":2572,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10535],"tags":[],"class_list":["post-2571","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guides-and-tutorials"],"_links":{"self":[{"href":"https:\/\/www.generationrobots.com\/blog\/wp-json\/wp\/v2\/posts\/2571","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.generationrobots.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.generationrobots.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.generationrobots.com\/blog\/wp-json\/wp\/v2\/users\/188"}],"replies":[{"embeddable":true,"href":"https:\/\/www.generationrobots.com\/blog\/wp-json\/wp\/v2\/comments?post=2571"}],"version-history":[{"count":3,"href":"https:\/\/www.generationrobots.com\/blog\/wp-json\/wp\/v2\/posts\/2571\/revisions"}],"predecessor-version":[{"id":12381,"href":"https:\/\/www.generationrobots.com\/blog\/wp-json\/wp\/v2\/posts\/2571\/revisions\/12381"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.generationrobots.com\/blog\/wp-json\/wp\/v2\/media\/2572"}],"wp:attachment":[{"href":"https:\/\/www.generationrobots.com\/blog\/wp-json\/wp\/v2\/media?parent=2571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.generationrobots.com\/blog\/wp-json\/wp\/v2\/categories?post=2571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.generationrobots.com\/blog\/wp-json\/wp\/v2\/tags?post=2571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}