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

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

2 Answers

Sort by ยป oldest newest most voted
1

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

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
0

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

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 3,434 times

Last updated: Nov 26 '17