slim71 / SpartanLIFT

MSc thesis regarding the application of a teleoperated multi-UAV system for cooperative payload transport.
Apache License 2.0
1 stars 1 forks source link

Setting environment to correctly use URI in a .sdf model #1

Closed slim71 closed 1 year ago

slim71 commented 1 year ago

The drone models I've found are using multiple <uri> tags (like <uri>model://X3/meshes/led.dae</uri>) to load meshes and other stuff from the same folder in which the main model.sdf is located.

I can start Ignition with no problem, loading the desired world with the spawn_world.launch.py file from package reach. I then use x3_spawn.launch.py from package pelican to load the model, which is indeed found and loaded into Ignition but without meshes, as the terminal issues multiple lines like

Unable to find file with URI [model://X3/meshes/x3.dae]
Could not resolve file [model://X3/meshes/x3.dae]
Unable to find file[model://X3/meshes/x3.dae]
Mesh manager can't find mesh named [model://X3/meshes/x3.dae]
Cannot load null mesh [model://X3/meshes/x3.dae]
Failed to get Ogre item for [model://X3/meshes/x3.dae]
Failed to load geometry for visual: base_link_inertia_visual

and so on.

It's not working.

I've seen multiple posts (like this one) from which I gathered that I need

<gazebo_ros gazebo_model_path="${prefix}" />
<gazebo_ros gazebo_media_path="${prefix}" />

inside the <export> tag in the package.xml file (where also adding <exec_depend>gazebo_ros</exec_depend> is needed) and to install the directory in the package's share folder, using something like

install(
    DIRECTORY config description launch
    DESTINATION share/${PROJECT_NAME}
)

in the CMakeLists.txt file.

More investigation is needed.

slim71 commented 1 year ago

I've found an "alternate" solution, or the real one maybe.

I've seen something like this stuff about environment variables. The relevant part is

Gazebo will find your model as long as its parent path is listed on the environment variable GAZEBO_MODEL_PATH

Since I'm using Ignition Fortress, the right variables is IGN_GAZEBO_RESOURCE_PATH (it can be found by executing ign help gazebo or similar, depending on the Gazebo/Ignition version).

So in the end I've used environment hooks, found in this GitHub issue. In the package pelican I added a folder env-hooks with a file pelican.dsv.in, in which I've put

prepend-non-duplicate;IGN_GAZEBO_RESOURCE_PATH;share/@PROJECT_NAME@/models
prepend-non-duplicate;IGN_GAZEBO_RESOURCE_PATH;share/@PROJECT_NAME@/worlds
prepend-non-duplicate;IGN_GAZEBO_RESOURCE_PATH;share/@PROJECT_NAME@/description

Then I made sure to hook it up adding

ament_environment_hooks("${CMAKE_CURRENT_SOURCE_DIR}/env-hooks/${PROJECT_NAME}.dsv.in")

I'll just have to be sure to re-use this structure for any other package and with the appropriate folder structure.


For reference, everything is also explained in the issue above, which points at this and this as examples. I bit of explanation on environment hooks is here, with more in depth explanations in the ColCon docs.

slim71 commented 1 year ago

Relevant lines: https://github.com/slim71/SpartanLIFT/blob/f582d47a54d694a344a55e53e42eece246e98a9f/thesis_ws/src/pelican/CMakeLists.txt#L31 https://github.com/slim71/SpartanLIFT/blob/f582d47a54d694a344a55e53e42eece246e98a9f/thesis_ws/src/pelican/env-hooks/pelican.dsv.in#L1-L3