ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

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

asked 2022-07-30 06:59:43 -0500

joseecm gravatar image

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 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.

edit retag flag offensive close merge delete


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

mateussmenezes gravatar image mateussmenezes  ( 2022-11-12 21:14:37 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2023-02-14 08:35:24 -0500

joseecm gravatar image

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
    os.environ['GAZEBO_MODEL_PATH'] =  pkg_share_path

See this post I wrote for more information.

edit flag offensive delete link more

answered 2023-02-13 03:52:12 -0500

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 .

edit flag offensive delete link more

Question Tools



Asked: 2022-07-30 06:59:43 -0500

Seen: 1,339 times

Last updated: Feb 14 '23