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

This might be what you're looking for:

import os
import xacro

def generate_launch_description():
  ...
  robot_urdf = os.path.join(get_package_share_directory(
        'awesome_description_pkg'), 'urdf', 'robot.xacro')
  robot_urdf = xacro.process_file(robot_urdf)
  robot_description = {'robot_description': robot_urdf.toxml()}
  robot_state_pub_node = Node(
      package='robot_state_publisher',
      executable='robot_state_publisher',
      output='screen',
      parameters=[robot_description]
  )

If not, robot state publisher can take urdf file as an argument, so you could process the xacro file with xacro python module, save it and pass that file name as argument. Something along the lines:

robot_state_pub_node = Node(
    package='robot_state_publisher',
    executable='robot_state_publisher',
    output='screen',
    arguments=[robot_urdf]
)

Where robot_urdf is preprocessed xacro file i.e. urdf description of the robot.