Search code examples
rosgazebo-simu

How to fixate to models to each other in Gazebo?


I have a project, in which I want to include two models a mir (https://github.com/DFKI-NI/mir_robot) and a ur10 (https://github.com/ros-industrial/universal_robot).

My goal is, to fixate the ur10 on top of the mir.

What I have done so far:

Now, in my workspace I have the descriptions of the mir and the ur10, as well as the launch and world files for Gazebo.

I was easily able to position the ur10-arm on top of the mir, but of course it is not fixated. While researching this, I found that the suggested method is to add a fixed joint between them.

So, in my world file I added

<sdf version='1.7'>
   <world name='default'>
      <-- sun, ground plane etc. -->
      <model name='mir'>
         <-- all the specification for the mir robot I obtained from the demo -->
         <joint name='connecting_joint' type='fixed'>
            <parent>base_footprint</parent>
            <child>ur10::base</child>
            <pose> 0 0 0 0 0 0</pose>
         </joint>
      </model>
      <model name='ur10'>
      <-- all the specification for the ur10 robot -->
      </model>
   </world>
</sdf>

When I now open Gazebo, this joint appears in the list of joints for the mir robot. But the fixation does not work, the ur10 still falls of.

I then turned to the model editor in Gazebo. But since I cannot edit both of my models at the same time, I cannot add a joint between them. When I added a box and added the fixed joint between it and the mir, it worked flawlessly.

I have also read about model nesting, but this seems to only apply to Gazebo Classic. In addition, if fixed joint is the correct way to do this, I would like to do it this way.

If anyone can tell, what I have done wrong or what needs to be done additionally to make this work, I would be grateful.


Solution

  • It looks like your URDF/SDF composition is correct. However, the joint that you added to the world file needs to be included in the robot URDF description itself.

    The world file is not the right place to define the joint, because it doesn't know about the models you define with URDF. The world file in Gazebo is used to specify how objects, models, physics parameters, light source etc. should be initially loaded in the simulation. On the other hand, URDF (XML) format is used to represent a robot model in ROS.

    That being said, you need to add that joint into the URDF file such that you specify connection between mir and ur10.

    Here is a simple example how to do it in the URDF.xml:

    <robot name="mir_ur10">
      <include filename="$(find mir_description)/urdf/mir.urdf.xacro"/>
      <include filename="$(find ur_description)/urdf/ur10.urdf.xacro"/>
    
      <link name="base_footprint"/>
      <link name="world"/>
    
      <joint name='connecting_joint' type='fixed'>
        <origin xyz="0.5 0 0.36" rpy="0 0 0"/> <!--Adjust the origin as per your need-->
        <parent link="base_footprint"/> <!--Parent link-->
        <child link="ur10::base"/> <!--Child link-->
      </joint>
    </robot>
    

    This example assumes that the mir robot's URDF is named mir.urdf.xacro and located in a package named mir_description, and that the ur10 robot's URDF is named ur10.urdf.xacro and located in a package named ur_description. Make sure to replace these values with actual names and locations as per your setup.

    Then, you´ll need to load this combined URDF into ROS parameter server and spawn it in Gazebo.

    Here is an example on how to do it:

    <?xml version="1.0"?>
    <launch>
       <param name="robot_description" 
              command="$(find xacro)/xacro --inorder $(find your_package)/urdf/mir_ur10.urdf.xacro"
       />
    
       <node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" 
          args="-param robot_description -urdf -model mir_ur10"
       />
    </launch>
    

    This launch file first reads the mir_ur10.urdf.xacro and loads it into the ROS parameter server under a parameter named "robot_description". Then it uses gazebo_ros's spawn_model node to spawn your robot model into Gazebo.