ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
It is possible to generate URDF files at compile time thanks to the add_custom_command
and add_custom_target
CMake commands.
add_custom_command(
OUTPUT
${CMAKE_CURRENT_SOURCE_DIR}/urdf/robot.urdf
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/urdf/box_line_macro.xacro
${CMAKE_CURRENT_SOURCE_DIR}/urdf/box_macro.xacro
${CMAKE_CURRENT_SOURCE_DIR}/urdf/robot.xacro
COMMAND
xacro --inorder robot.xacro -o robot.urdf
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/urdf/
COMMENT
"Generating robot URDF"
VERBATIM
)
This creates a command that will generate your URDF file, using DEPENDS
makes sure that everytime one of the XACRO file is changed the URDF will be generated.
This means that URDFs are generated only if necessary as long as you list all dependencies correctly. You can multiply this command block to generate multiple URDF files.
add_custom_target(
URDFs_files
ALL
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/urdf/robot.urdf
)
This command creates a CMake target that is built when "make all" is invoked and that depends on the URDF files. This ensures that the custom command will be called. You should list here all your generated URDF files.
In your launch file instead of something like:
<param name="robot_description" command="$(find xacro)/xacro --inorder $(find xacro_urdf_cmake)/urdf/robot.xacro" />
You now should use:
<param name="robot_description" textfile="$(find xacro_urdf_cmake)/urdf/robot.urdf" />
Instead of generating the URDF at run-time (in the launch file), you can now use the URDF generated at compile time.
($find xacro_urdf_cmake)
because xacro
is invoked by CMake and does not source the workspace you are working in. Use relative paths!URDFs_files
target.gitignore
fileA demonstration package is available at xacro_urdf_cmake. Checkout the pipeline to see what is does!
2 | No.2 Revision |
It is possible to generate URDF files at compile time thanks to the add_custom_command
and add_custom_target
CMake commands.
add_custom_command(
OUTPUT
${CMAKE_CURRENT_SOURCE_DIR}/urdf/robot.urdf
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/urdf/box_line_macro.xacro
${CMAKE_CURRENT_SOURCE_DIR}/urdf/box_macro.xacro
${CMAKE_CURRENT_SOURCE_DIR}/urdf/robot.xacro
COMMAND
xacro --inorder robot.xacro -o robot.urdf
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/urdf/
COMMENT
"Generating ${PROJECT_NAME} robot URDF"
VERBATIM
)
This creates a command that will generate your URDF file, using DEPENDS
makes sure that everytime one of the XACRO file is changed the URDF will be generated.
This means that URDFs are generated only if necessary as long as you list all dependencies correctly. You can multiply this command block to generate multiple URDF files.
add_custom_target(
URDFs_files
${PROJECT_NAME}_URDFs_files
ALL
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/urdf/robot.urdf
)
This command creates a CMake target that is built when "make all" is invoked and that depends on the URDF files. This ensures that the custom command will be called. You should list here all your generated URDF files.
In your launch file instead of something like:
<param name="robot_description" command="$(find xacro)/xacro --inorder $(find xacro_urdf_cmake)/urdf/robot.xacro" />
You now should use:
<param name="robot_description" textfile="$(find xacro_urdf_cmake)/urdf/robot.urdf" />
Instead of generating the URDF at run-time (in the launch file), you can now use the URDF generated at compile time.
($find xacro_urdf_cmake)
because xacro
is invoked by CMake and does not source the workspace you are working in. Use relative paths!URDFs_files${PROJECT_NAME}_URDFs_files
target.gitignore
fileA demonstration package is available at xacro_urdf_cmake. Checkout the pipeline to see what is does!
3 | No.3 Revision |
As Gijs pointed out, there is already a CMake macro for that: http://wiki.ros.org/xacro#Building_from_CMakeLists.txt
It is possible to generate URDF files at compile time thanks to the add_custom_command
and add_custom_target
CMake commands.
add_custom_command(
OUTPUT
${CMAKE_CURRENT_SOURCE_DIR}/urdf/robot.urdf
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/urdf/box_line_macro.xacro
${CMAKE_CURRENT_SOURCE_DIR}/urdf/box_macro.xacro
${CMAKE_CURRENT_SOURCE_DIR}/urdf/robot.xacro
COMMAND
xacro --inorder robot.xacro -o robot.urdf
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/urdf/
COMMENT
"Generating ${PROJECT_NAME} robot URDF"
VERBATIM
)
This creates a command that will generate your URDF file, using DEPENDS
makes sure that everytime one of the XACRO file is changed the URDF will be generated.
This means that URDFs are generated only if necessary as long as you list all dependencies correctly. You can multiply this command block to generate multiple URDF files.
add_custom_target(
${PROJECT_NAME}_URDFs_files
ALL
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/urdf/robot.urdf
)
This command creates a CMake target that is built when "make all" is invoked and that depends on the URDF files. This ensures that the custom command will be called. You should list here all your generated URDF files.
In your launch file instead of something like:
<param name="robot_description" command="$(find xacro)/xacro --inorder $(find xacro_urdf_cmake)/urdf/robot.xacro" />
You now should use:
<param name="robot_description" textfile="$(find xacro_urdf_cmake)/urdf/robot.urdf" />
Instead of generating the URDF at run-time (in the launch file), you can now use the URDF generated at compile time.
($find xacro_urdf_cmake)
because xacro
is invoked by CMake and does not source the workspace you are working in. Use relative paths!${PROJECT_NAME}_URDFs_files
target.gitignore
fileA demonstration package is available at xacro_urdf_cmake. Checkout the pipeline to see what is does!
4 | No.4 Revision |
As Gijs pointed out, there is already a CMake macro for that: http://wiki.ros.org/xacro#Building_from_CMakeLists.txt
It is possible to generate URDF files at compile time thanks to the add_custom_command
and add_custom_target
CMake commands.
add_custom_command(
OUTPUT
${CMAKE_CURRENT_SOURCE_DIR}/urdf/robot.urdf
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/urdf/box_line_macro.xacro
${CMAKE_CURRENT_SOURCE_DIR}/urdf/box_macro.xacro
${CMAKE_CURRENT_SOURCE_DIR}/urdf/robot.xacro
COMMAND
xacro --inorder robot.xacro -o robot.urdf
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/urdf/
COMMENT
"Generating ${PROJECT_NAME} robot URDF"
VERBATIM
)
This creates a command that will generate your URDF file, using DEPENDS
makes sure that everytime one of the XACRO file is changed the URDF will be generated.
This means that URDFs are generated only if necessary as long as you list all dependencies correctly. You can multiply this command block to generate multiple URDF files.
add_custom_target(
${PROJECT_NAME}_URDFs_files
ALL
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/urdf/robot.urdf
)
This command creates a CMake target that is built when "make all" is invoked and that depends on the URDF files. This ensures that the custom command will be called. You should list here all your generated URDF files.
In your launch file instead of something like:
<param name="robot_description" command="$(find xacro)/xacro --inorder $(find xacro_urdf_cmake)/urdf/robot.xacro" />
You now should use:
<param name="robot_description" textfile="$(find xacro_urdf_cmake)/urdf/robot.urdf" />
Instead of generating the URDF at run-time (in the launch file), you can now use the URDF generated at compile time.
($find xacro_urdf_cmake)
because xacro
is invoked by CMake and does not source the workspace you are working in. Use relative paths!${PROJECT_NAME}_URDFs_files
target.gitignore
fileA demonstration package is available at xacro_urdf_cmake. Checkout the pipeline to see what is does!
5 | No.5 Revision |
As Gijs pointed out, there is already a CMake macro for that: http://wiki.ros.org/xacro#Building_from_CMakeLists.txt
The macro is here: https://github.com/ros/xacro/blob/kinetic-devel/cmake/
It is possible to generate URDF files at compile time thanks to the add_custom_command
and add_custom_target
CMake commands.
add_custom_command(
OUTPUT
${CMAKE_CURRENT_SOURCE_DIR}/urdf/robot.urdf
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/urdf/box_line_macro.xacro
${CMAKE_CURRENT_SOURCE_DIR}/urdf/box_macro.xacro
${CMAKE_CURRENT_SOURCE_DIR}/urdf/robot.xacro
COMMAND
xacro --inorder robot.xacro -o robot.urdf
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/urdf/
COMMENT
"Generating ${PROJECT_NAME} robot URDF"
VERBATIM
)
This creates a command that will generate your URDF file, using DEPENDS
makes sure that everytime one of the XACRO file is changed the URDF will be generated.
This means that URDFs are generated only if necessary as long as you list all dependencies correctly. You can multiply this command block to generate multiple URDF files.
add_custom_target(
${PROJECT_NAME}_URDFs_files
ALL
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/urdf/robot.urdf
)
This command creates a CMake target that is built when "make all" is invoked and that depends on the URDF files. This ensures that the custom command will be called. You should list here all your generated URDF files.
In your launch file instead of something like:
<param name="robot_description" command="$(find xacro)/xacro --inorder $(find xacro_urdf_cmake)/urdf/robot.xacro" />
You now should use:
<param name="robot_description" textfile="$(find xacro_urdf_cmake)/urdf/robot.urdf" />
Instead of generating the URDF at run-time (in the launch file), you can now use the URDF generated at compile time.
($find xacro_urdf_cmake)
because xacro
is invoked by CMake and does not source the workspace you are working in. Use relative paths!${PROJECT_NAME}_URDFs_files
target.gitignore
fileA demonstration package is available at xacro_urdf_cmake. Checkout the pipeline to see what is does!