Pass a variable to XML(xacro) from CMake
Hi everyone. I'm using ROS2 Humble and Ubuntu 22.04
How can I pass a variable to XML file (robot.urdf.xacro)? I want to pass a variable from CMake to my urdf file so that I can choose model which I need.
URDF file
<xacro:property name="sim" value="${SIMULATION}"/>
<xacro:if value="${sim == 1}">
model description...
</xacro:if>
CMake
if (${AMENT_CMAKE_ARGS} ${SIMULATION})
set(SIMULATION ${AMENT_CMAKE_ARGS} ${SIMULATION})
else()
set(SIMULATION 0)
endif()
configure_file("urdf/robot.urdf.xacro" ${SIMULATION})
I tried to use the configure_file, but it can't parse the file.
Help me, please. Maybe I'm using the wrong command in CMake.
You probably need to use the @ONLY arg in configure_file and use @SIMULATION@ because it's trying to act on all your xacro expressions.
https://cmake.org/cmake/help/latest/c...
However, I wonder what you're trying to accomplish with build-time configuration in ROS? Is there a reason you aren't doing this at runtime when you load and publish your robot description?