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

Revision history [back]

We struggled for 1 week with this, here is our solution to contribute back to the community:

if your run rosrun gazebo_ros spawn_model -h you notice there is a flag called:

-package_to_model - optional: convert urdf <mesh filename="package://..." to <mesh filename="model://..."

This allows you to transform during runtime your urdf file so that your meshes are loaded from gazebo model folder located under /home/user/.gazebo/models , all that is left is to add some installs in your my_robot_description pkg.

Edit your my_robot_description -> CMakeLists.txt file, e.g.

roscd my_robot_description && gedit CMakeLists.txt

Add the following lines at the bottom:

# the place where gazebo puts the models by default
set(GAZEBO_MODEL_PATH $ENV{HOME}/.gazebo/models)

# to create folder : /home/user/.gazebo/models/my_robot_description
add_custom_target(COMMAND cmake -E make_directory ${GAZEBO_MODEL_PATH}/${PROJECT_NAME})

# copy my_robot meshes to gazebo models folder
install(DIRECTORY meshes
  DESTINATION ${GAZEBO_MODEL_PATH}/${PROJECT_NAME}
  FILES_MATCHING PATTERN "*.dae"
  PATTERN "*.png"
)

make sure to compile your my_robot_description pkg with the right flag:

catkin build --this --make-args install

We struggled for 1 week with this, here is our solution to contribute back to the community:

if your run rosrun gazebo_ros spawn_model -h you notice there is a flag called:

-package_to_model - optional: convert urdf <mesh filename="package://..." to <mesh filename="model://..."

This allows you to transform during runtime your urdf file so that your meshes are loaded from gazebo model folder located under /home/user/.gazebo/models , all that is left is to add some installs in your my_robot_description pkg.

Edit your my_robot_description -> CMakeLists.txt file, e.g.

roscd my_robot_description && gedit CMakeLists.txt

Add the following lines at the bottom:

# the place where gazebo puts the models by default
set(GAZEBO_MODEL_PATH $ENV{HOME}/.gazebo/models)

# to create folder : /home/user/.gazebo/models/my_robot_description
add_custom_target(COMMAND cmake -E make_directory ${GAZEBO_MODEL_PATH}/${PROJECT_NAME})

# copy my_robot meshes to gazebo models folder
install(DIRECTORY meshes
  DESTINATION ${GAZEBO_MODEL_PATH}/${PROJECT_NAME}
  FILES_MATCHING PATTERN "*.dae"
  PATTERN "*.png"
)

make sure to compile your my_robot_description pkg with the right flag:

catkin build --this --make-args install

And finally of course, spawn your model in gazebo with the above mentioned flag, e.g.

<!-- spawn your robot (in a certain position) -->
    <node pkg="gazebo_ros" type="spawn_model" name="mbot_spawner"
          args="-package_to_model -urdf -model mbot -param robot_description -x 0.5 -y 0.5 -z 0.01" />