0
$\begingroup$

Rosanswers logo

Hi,

I have been trying to figure this out for a couple of days now and am having trouble. Basically I want to create a world file to be launched via roslaunch that is composed of number of model sdf's that reference local meshes from within my package (e.g., file://mesh_name.dae). I then want to spawn one or more robots into said world using 'gazebo_ros spawn_model'.

When using roslaunch Gazebo can't seem to find any files outside of the .gazebo folder and I get the following errors:

Error [SystemPaths.cc:371] File or path does not exist[""]

Error [Visual.cc:2072] No mesh specified

I have read over the tutorials about making custom worlds at gazebosim.org but all of the tutorials use models from the Gazebo model data base (i.e., < uri>model://pioneer2dx/meshes/chassis.dae< /uri>). There is also text on how to use spawn_model with urdf's but not collada's?

What is the best way to do this while keeping the models local to a package? I seem to remember seeing someone mention using Gazebo's environment variables but this seems like an awkward solution.

Thanks, Brett


Originally posted by BrettHemes on ROS Answers with karma: 525 on 2014-10-20

Post score: 0

$\endgroup$

3 Answers 3

0
$\begingroup$

Rosanswers logo

I use a combination of converting .urdf to .sdf and custom cmake targets. From the CMakeLists.txt

install(DIRECTORY meshes/
    DESTINATION $ENV{HOME}/.gazebo/models/lwr_description/meshes
)
set(lwrs
  lwr1
  lwr2
)

foreach(lwr ${lwrs})
  set(dir ${CMAKE_CURRENT_SOURCE_DIR}/models/${lwr})
  install(DIRECTORY ${dir} DESTINATION $ENV{HOME}/.gazebo/models)

  add_custom_command(
    OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/urdf/${lwr}.urdf
    COMMAND rosrun
    ARGS xacro xacro ${CMAKE_CURRENT_SOURCE_DIR}/urdf/${lwr}.xacro > ${CMAKE_CURRENT_SOURCE_DIR}/urdf/${lwr}.urdf
      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/urdf/lwr_macro.xacro ${CMAKE_CURRENT_SOURCE_DIR}/urdf/${lwr}.xacro ${CMAKE_CURRENT_SOURCE_DIR}/urdf/lwrFRI1.gazebo
  )

  add_custom_command(
    OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/models/${lwr}/model.sdf
    COMMAND gz
    ARGS sdf --print ${CMAKE_CURRENT_SOURCE_DIR}/urdf/${lwr}.urdf > ${CMAKE_CURRENT_SOURCE_DIR}/models/${lwr}/model.sdf
      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/urdf/${lwr}.urdf ${CMAKE_CURRENT_BINARY_DIR}/${lwr}.urdf.checked
  )

  add_custom_command(
      OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${lwr}.urdf.checked
    COMMAND check_urdf
      ARGS ${CMAKE_CURRENT_SOURCE_DIR}/urdf/${lwr}.urdf > ${CMAKE_CURRENT_BINARY_DIR}/${lwr}.urdf.checked
      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/urdf/${lwr}.urdf
  )

  add_custom_target("${lwr}sdf" ALL DEPENDS urdf/${lwr}.urdf models/${lwr}/model.sdf)
endforeach()

Inside the .urdf (or .xacro) the meshes are referenced as

<mesh filename="package://lwr_description/meshes/link0_mq_dh.dae"/>

which results in the following inside the .sdf (as converted by gz sdf --print):

<uri>model://lwr_description/meshes/convex/link0_lq_dh.dae</uri>

This way you do not have to model anything twice and can add everything through the usual gazebo mechanisms (i.e. in a .world file) or add it through GUI or ROS topics ...


Originally posted by andreasBihlmaier with karma: 56 on 2014-10-21

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

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" />

Originally posted by Oscar Lima with karma: 831 on 2017-11-26

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

For anyone having a similar problem and coming across this after 6 years, you can make gazebo look in the package directory for models using the package.xml. In the below example, you can put your models into <your/package/directory>/models/ and use them from the world file without copying them into the default gazebo model directory (This might not have been available in 2014 when the question was asked)

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

Here {prefix} is evaluated to the package path

In the world file, now you can do this

<geometry>
    <mesh><uri>model://your_mesh.dae</uri></mesh>
</geometry>

Originally posted by teshansj with karma: 168 on 2020-07-17

This answer was NOT ACCEPTED on the original site

Post score: 3


Original comments

Comment by shlock on 2020-11-19:
Thank you. After looking around for a day this finally worked for me.

$\endgroup$

Your Answer

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