How to do it…

We will complete the URDF file to introduce the robot model in Gazebo by defining a few more elements there. However, we will be using the .xacro file which is more complex, but more powerful for development. We can find the file with all its modifications at chapter6_tutorials/robot_description/urdf/robot_gazebo.xacro on GitHub (https://github.com/kbipin/Robot-Operating-System-Cookbook):

<link name="base_link"> 
               <visual> 
               <geometry> 
                           <box size="0.2 .3 .1"/> 
                     </geometry> 
               <origin rpy="0 0 1.54" xyz="0 0 0.05"/> 
               <material name="white"> 
                     <color rgba="1 1 1 1"/> 
               </material> 
               </visual> 
         <collision> 
               <geometry> 
                           <box size="0.2 .3 0.1"/> 
               </geometry> 
         </collision> 
         <xacro:default_inertial mass="10"/> 
</link> 

You may have noticed in the preceding code that collision and inertial sections are necessary to introduce the robot model to Gazebo, which is required by the physics engine for simulation.

We will also add visible textures in Gazebo by including the robot.gazebo file in robot_gazebo.xacro as follows:

<xacro:include filename="$(find robot_description)/urdf/robot.gazebo" /> 

In the preceding code, robot.gazebo has texture information, which is shown as follows; we can refer to the complete file in the chapter6_tutorials packages at GitHub (https://github.com/kbipin/Robot-Operating-System-Cookbook):

  <gazebo reference="base_link"> 
    <material>Gazebo/Orange</material> 
  </gazebo> 
 
 <gazebo reference="wheel_1"> 
        <material>Gazebo/Black</material> 
 </gazebo> 
 
 <gazebo reference="wheel_2"> 
        <material>Gazebo/Black</material> 
 </gazebo> 
 
 <gazebo reference="wheel_3"> 
        <material>Gazebo/Black</material> 
 </gazebo> 
 
 <gazebo reference="wheel_4"> 
        <material>Gazebo/Black</material> 
</gazebo>

Then, we will create an integrated launch file to launch all components with the name gazebo.launch in the chapter6_tutorials/robot_gazebo/launch/ folder and add the following code (refer to the code in the chapter6_tutorials packages at GitHub (https://github.com/kbipin/Robot-Operating-System-Cookbook)):

<launch> 
  <!-- these are the arguments you can pass this launch file, for example paused:=true --> 
  <arg name="paused" default="true" /> 
  <arg name="use_sim_time" default="false" /> 
  <arg name="gui" default="true" /> 
  <arg name="headless" default="false" /> 
  <arg name="debug" default="true" /> 
  <!-- We resume the logic in empty_world.launch, changing only the name of the world to be launched --> 
  <include file="$(find gazebo_ros)/launch/empty_world.launch"> 
    <arg name="world_name" value="$(find robot1_gazebo)/worlds/robot.world" /> 
    <arg name="debug" value="$(arg debug)" /> 
    <arg name="gui" value="$(arggui)" /> 
    <arg name="paused" value="$(arg paused)" /> 
    <arg name="use_sim_time" value="$(arg use_sim_time)" /> 
    <arg name="headless" value="$(arg headless)" /> 
  </include> 
  <!-- Load the URDF into the ROS Parameter Server --> 
  <arg name="model" /> 
  <param name="robot_description" command="$(find xacro)/xacro.py $(arg model)" /> 
  <!-- Run a python script to the send a service call to gazebo_ros to spawn a URDF robot --> 
  <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen" args="-urdf -model robot1 - paramrobot_description -z 0.05" /> 
</launch> 
 

We will launch the robot model with ROS and Gazebo by using the following command:

$ roslaunch robot_gazebo gazebo.launch model:="'rospack find robot1_description'/urdf/robot_gazebo.xacro"

Soon, we will be able to view the robot in Gazebo, as shown in the following screenshot. Here, the simulation is paused initially; we have to start it by clicking the Play button, which is at the bottom left of the display bar:

Robot model in the Gazebo virtual world

Welcome! This will be our first step into the virtual world.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.98.108