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

Creating custom Gazebo world files from sdf's/dae's for use with roslaunch

asked 2014-10-20 15:05:48 -0600

BrettHemes gravatar image

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., <mesh><uri>file://mesh_name.dae</uri></mesh>). 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

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
1

answered 2014-10-21 01:25:40 -0600

andreasBihlmaier gravatar image

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. <include> in a .world file) or add it through GUI or ROS topics ...

edit flag offensive delete link more
3

answered 2020-07-17 12:00:32 -0600

teshansj gravatar image

updated 2020-07-17 12:01:27 -0600

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>
edit flag offensive delete link more

Comments

1

Thank you. After looking around for a day this finally worked for me.

shlock gravatar image shlock  ( 2020-11-19 00:40:51 -0600 )edit
1

answered 2017-11-26 12:31:58 -0600

updated 2017-11-26 12:35:05 -0600

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" />
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-10-20 15:05:48 -0600

Seen: 8,277 times

Last updated: Jul 17 '20