@@ -105,7 +105,7 @@ def find_root_link(input_path):
105105 raise ValueError ("Could not determine root link. Check that the URDF contains valid joint definitions." )
106106
107107
108- def transform_urdf_to_macro (input_path , connector_link , no_prefix ):
108+ def transform_urdf_to_macro (input_path , connector_link , no_prefix , macro_name = None ):
109109 """Transform a URDF file into a Xacro macro with connector joint.
110110
111111 This function converts a URDF file into a reusable Xacro macro that can be
@@ -120,11 +120,13 @@ def transform_urdf_to_macro(input_path, connector_link, no_prefix):
120120 Name of link to connect to parent robot
121121 no_prefix : bool
122122 If True, don't add prefixes to element names
123+ macro_name : str, optional
124+ Name for the xacro macro. If None, uses the robot name from the URDF.
123125
124126 Returns
125127 -------
126128 tuple[lxml.etree.Element, str]
127- Tuple of (xacro_root_element, robot_name )
129+ Tuple of (xacro_root_element, final_macro_name )
128130 """
129131 XACRO_NS = "http://ros.org/wiki/xacro"
130132 NSMAP = {"xacro" : XACRO_NS }
@@ -155,9 +157,12 @@ def transform_urdf_to_macro(input_path, connector_link, no_prefix):
155157 # Provide a default empty string for the prefix.
156158 macro_params .insert (0 , "prefix:=''" )
157159
160+ # Use provided macro_name, otherwise fall back to the robot name
161+ final_macro_name = macro_name if macro_name else robot_name
162+
158163 # Create macro element
159164 macro = etree .Element ("{}macro" .format ("{" + XACRO_NS + "}" ))
160- macro .set ("name" , robot_name )
165+ macro .set ("name" , final_macro_name )
161166 macro .set ("params" , " " .join (macro_params ))
162167 xacro_root .append (macro )
163168
@@ -216,7 +221,7 @@ def transform_urdf_to_macro(input_path, connector_link, no_prefix):
216221 indent_element (xacro_root , level = 0 )
217222 xacro_root .tail = None # Ensure no tail text at the root level
218223
219- return xacro_root , robot_name
224+ return xacro_root , final_macro_name
220225
221226
222227def print_xacro_usage_instructions (output_path , robot_name , no_prefix = False ):
0 commit comments