0
$\begingroup$

I'm trying to include another sdf with , I can load it properly with an absolute path to the file but I want to make it a relative path. Structure is as follows:

  • package
    • src
    • models
    • worlds
      • model_1.sdf
      • model_2.sdf

For example I want to load model 2 inside of model 1. I can only find examples which are outdated, if anybody can point me in the right direction, that would be appreciated.

Using ROS2 humble with gazebo fortress

Thanks.

$\endgroup$
1
  • $\begingroup$ You wrote: "I'm trying to include another sdf with ," so... with what? $\endgroup$
    – cst0
    Oct 2, 2023 at 12:59

3 Answers 3

0
$\begingroup$

as I am not able to comment, I am writing my suggestion in answer section.

I am assuming that you want to add the same model in the sdf. You can include the models using the merge tag in sdf. Just for an example:

<!-- <include>
  <uri>
    https://fuel.gazebosim.org/1.0/OpenRobotics/models/Coke Can
  </uri>
</include>

<include>
  <merge>true</merge>
  <name>my_can</name>
  <uri>
    https://fuel.gazebosim.org/1.0/OpenRobotics/models/Coke Can
  </uri>
  <pose>0 0 1 0 0 0 </pose>
</include> -->

You can refer the sdformat documentation and different tags information here: http://sdformat.org/spec?ver=1.10&elem=model

$\endgroup$
0
$\begingroup$

To include models in the SDF file, you need to write the models directory path to the environment variable IGN_GAZEBO_RESOURCE_PATH, which would allow it to be visible. After which, you can reference models in your SDF with the following syntax:

<include>
   <uri>model://aws_robomaker_warehouse_RoofB_01</uri>
</include>

Note: Your models have to be well-defined with a config file. For reference example you can check out this repository. It includes models defined in the repository in its world SDF.

$\endgroup$
0
$\begingroup$

you can post refer to this Post, if u need any help, let me know. I was able to do it.

Steps to Follow:

1.Create a Models Folder in your Directory(package file) and store the sdf file there. I have created a single Folder named Box inside the Models File

  • Models
    • Box
      • model.config
      • model.sdf
      • meshes(folder)
        • mesh1.dae
        • mesh2.stl
        • mesh3.stl

below is the info inside present in the all the files.

a. Model.config file

  <?xml version="1.0"?>
  <model>
    <name>Box</name>
    <version>1.0</version>
    <sdf version='1.6'>model.sdf</sdf>
 <author>
<name>name</name>
<email>[email protected]</email>
</author>
<description>This is a box</description>
b. model.sdf
<?xml version="1.0" ?>
<sdf version="1.5">
<model name="Box">
<pose>0 0 0 0 0 0</pose>
<static>true</static>
<link name="link">
  <collision name="collision">
    <geometry>
      <mesh>
        <uri>model://box/meshes/mesh1.dae</uri>
        <scale>0.25 0.25 0.25</scale>
      </mesh>
    </geometry>
  </collision>
  <visual name="visual">
    <geometry>
      <mesh>
        <uri>model://box/meshes/mesh1.dae</uri>
        <scale>0.25 0.25 0.25</scale>
      </mesh>
    </geometry>
  </visual>
</link>

c. How to use the Launch File in python

spawn_entity = Node(package='gazebo_ros',
                    executable='spawn_entity.py',
                    name="spawn_sdf_entity",
                    arguments=[ '-entity','Box','-file', LaunchConfiguration('sdf_model'),
                                '-x','1.0',
                                '-y','1.0',
                                '-z', '0.0',
                                '-R','0.0',
                                '-P','0.0',
                                '-Y','0.0'
                                ], output='screen')


return LaunchDescription([
    sdf_model,
    spawn_entity,
])

I hope this will be useful for everyone!!

$\endgroup$
3
  • $\begingroup$ Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. $\endgroup$
    – Community Bot
    Nov 2, 2023 at 9:02
  • $\begingroup$ While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review $\endgroup$ Nov 2, 2023 at 12:58
  • $\begingroup$ I will add it below as an Answer $\endgroup$
    – Kedar
    Nov 3, 2023 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.