ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I ended up solving this problem by running xacro in a subprocess from within python.

Here's the launch file:

<?xml version="1.0"?>
<launch>
  <rosparam command="load" file="$(find my_robot_bringup)/launch/dynamic_dimensions.yaml"/>
  <arg name="namespace" default=""/>
  <node name="my_robot_description_uploader" pkg="my_robot_description" type="load_robot_description.py" output="screen" respawn="false">
    <rosparam subst_value="True">
      namespace: "$(arg namespace)"
      model_filepath: "$(find my_robot_description)/urdf/my_robot.urdf.xacro"
    </rosparam>
  </node>
</launch>

And the python:

#!/usr/bin/env python
import sys
import rospy
import xacro
import subprocess

def load_robot_description():
    my_robot_dynamic_dimension_1 = rospy.get_param(
        '/my_robot_dynamic_dimension_1')
    namespace = rospy.get_param('~namespace')
    model_filepath = rospy.get_param('~model_filepath')

    try:
        command_string = "rosrun xacro xacro --inorder {} my_robot_dynamic_dimension_1:={}".format(model_filepath, my_robot_dynamic_dimension_1)
        robot_description = subprocess.check_output(
            command_string, shell=True, stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as process_error:
        rospy.logfatal('Failed to run xacro command with error: \n%s', process_error.output)
        sys.exit(1)

    rospy.set_param(namespace + "/robot_description", robot_description)

if __name__ == '__main__':
    try:
        rospy.init_node('load_robot_description', anonymous=True)
        load_robot_description()
    except rospy.ROSInterruptException:
        pass