Pass a variable to XML(xacro) from CMake

asked 2023-04-13 02:08:03 -0500

sharp-0000ff gravatar image

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.

image description

Help me, please. Maybe I'm using the wrong command in CMake.

edit retag flag offensive close merge delete

Comments

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?

danzimmerman gravatar image danzimmerman  ( 2023-04-16 08:41:54 -0500 )edit