Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Fixed writing urdf file to package folder #255

Open
wants to merge 1 commit into
base: foxy-devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 3 additions & 26 deletions launch/driver.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')]
Expand Down Expand Up @@ -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(
Expand All @@ -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"))),
])
])