Robotics StackExchange | Archived questions

What's the correct way to load mesh files in Gazebo and Rviz?

I want to load a URDF model that uses mesh files into Gazebo and Rviz2. For this I have created a package that I have called "abb" and added a folder "meshes" to store the mesh files. The problem is that I can't load a mesh file named "base_link.stl" in Gazebo or Rviz2 when I use the folloging format in the xacro file:

<mesh filename="package://abb/meshes/base_link.stl"/>

I have checked the file exists in the meshes folder. I don't understand why it doesn't work, because it follows the format package://<packagename>/<path> that is indicated in http://wiki.ros.org/urdf/XML/link and I have seen in many examples on the web.

However if I use the following line in the xacro file it load the mesh file in Gazebo and Rviz2:

<mesh filename="file://$(find abb)/meshes/base_link.stl"/>

Although I can solve the problem using this way I would like to know why it doesn't work when using "package://". I would be very grateful if someone could tell me what I am doing wrong.

Best regards.

Asked by joseecm on 2022-07-30 06:59:43 UTC

Comments

I had the same problem and your work around solved the error. But I will wait for better explanation of the problem

Asked by mateussmenezes on 2022-11-12 22:14:37 UTC

Answers

I found that GAZEBO_MODEL_PATH should include the path that locates mars_robot. You need to add "export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:(path to mars_robot)" in ~/.bashrc file and source ~/.bashrc .

Asked by ichdich on 2023-02-13 04:52:12 UTC

Comments

You can reference the path to the mesh file in several ways.

This works with RVIZ and GAZEBO:

<mesh filename="file://$(find my_package)/meshes/mesh_file"/>

This work with RVIZ but not for GAZEBO:

<mesh filename="package://my_package/meshes/mesh_file"/>

For GAZEBO other way is including the path in the environment variable GAZEBO_MODEL_PATH. For that you can use the EXPORT command in the command line or include the following code to your launch file.

import os
from ament_index_python import get_package_prefix

pkg_share_path = os.pathsep + os.path.join(get_package_prefix(package_name), 'share')
if 'GAZEBO_MODEL_PATH' in os.environ:
    os.environ['GAZEBO_MODEL_PATH'] += pkg_share_path
else:
    os.environ['GAZEBO_MODEL_PATH'] =  pkg_share_path

See this post I wrote for more information.

Asked by joseecm on 2023-02-14 09:35:24 UTC

Comments