From 0b807b03d018951d94761152f83a91d6a0c8e354 Mon Sep 17 00:00:00 2001 From: Aris Synodinos Date: Mon, 5 Sep 2022 20:14:00 +0200 Subject: [PATCH] Fixed writing urdf file to package folder (which fails if installed in /opt) --- launch/driver.launch.py | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/launch/driver.launch.py b/launch/driver.launch.py index 711b4cf3..bbb23377 100644 --- a/launch/driver.launch.py +++ b/launch/driver.launch.py @@ -2,34 +2,15 @@ # Licensed under the MIT License. import os -import xacro from ament_index_python.packages import get_package_share_directory from launch import LaunchDescription, conditions from launch.actions import (DeclareLaunchArgument, GroupAction) -from launch.substitutions import LaunchConfiguration, Command +from launch.substitutions import LaunchConfiguration, Command, FindExecutable import launch.actions import launch_ros.actions -def to_urdf(xacro_path, urdf_path=None): - """Convert the given xacro file to URDF file. - * xacro_path -- the path to the xacro file - * urdf_path -- the path to the urdf file - """ - # If no URDF path is given, use a temporary file - if urdf_path is None: - urdf_path = os.path.join( - get_package_share_directory("azure_kinect_ros_driver"), - "urdf", - "azure_kinect.urdf") - # open and process file - doc = xacro.process_file(xacro_path) - # open the output file - out = xacro.open_output(urdf_path) - out.write(doc.toprettyxml(indent=' ')) - - return urdf_path # Return path to the urdf file def generate_launch_description(): # Note: tf_prefix is not supported as an argument to the xacro file for robot/joint state publishers @@ -40,9 +21,7 @@ def generate_launch_description(): "azure_kinect.urdf.xacro") print("Robot description xacro_file : {}".format(xacro_file)) - urdf_path = to_urdf(xacro_file) # convert, xacro to urdf - urdf = open(urdf_path).read() - print("Robot description urdf_path : {}".format(urdf_path)) + urdf = Command([FindExecutable(name='xacro'), ' ', xacro_file]) # Variable used for the flag to publish a standalone azure_description instead of the default robot_description parameter remappings = [('robot_description', 'azure_description')] @@ -173,7 +152,6 @@ def generate_launch_description(): package='joint_state_publisher', executable='joint_state_publisher', name='joint_state_publisher', - arguments=[urdf_path], condition=conditions.IfCondition(launch.substitutions.LaunchConfiguration("overwrite_robot_description"))), # If flag overwrite_robot_description is not set: launch_ros.actions.Node( @@ -187,7 +165,6 @@ def generate_launch_description(): package='joint_state_publisher', executable='joint_state_publisher', name='joint_state_publisher', - arguments=[urdf_path], remappings=remappings, condition=conditions.UnlessCondition(launch.substitutions.LaunchConfiguration("overwrite_robot_description"))), - ]) \ No newline at end of file + ])