ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
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 ...