25
25
from ament_index_python .packages import get_package_share_directory
26
26
from launch import LaunchDescription
27
27
from launch_ros .actions import Node
28
- from launch .actions import DeclareLaunchArgument
29
- from launch .substitutions import LaunchConfiguration
28
+ from launch .actions import DeclareLaunchArgument , OpaqueFunction
29
+ from launch .substitutions import LaunchConfiguration , Command
30
+ from launch_ros .parameter_descriptions import ParameterValue
31
+
32
+
33
+ def load_urdf (context , * args , ** kwargs ):
34
+ # Get the URDF file name from context
35
+ urdf_file_name = context .launch_configurations ['urdf_file_name' ]
36
+
37
+ # Get package directory
38
+ pkg_dir = get_package_share_directory ('go2_robot_sdk' )
39
+
40
+ # Create full path to URDF
41
+ urdf_file_path = os .path .join (pkg_dir , 'urdf' , urdf_file_name )
42
+
43
+ # Robot state publisher node
44
+ robot_state_publisher_node = Node (
45
+ package = 'robot_state_publisher' ,
46
+ executable = 'robot_state_publisher' ,
47
+ name = 'robot_state_publisher' ,
48
+ output = 'screen' ,
49
+ parameters = [{
50
+ 'robot_description' : ParameterValue (
51
+ Command (['cat ' , urdf_file_path ]),
52
+ value_type = str
53
+ )
54
+ }],
55
+ )
56
+
57
+ return [robot_state_publisher_node ]
30
58
31
59
32
60
def generate_launch_description ():
@@ -37,14 +65,6 @@ def generate_launch_description():
37
65
urdf_file_name = LaunchConfiguration ('urdf_file_name' , default = 'go2.urdf' )
38
66
send_buffer_limit = LaunchConfiguration ('send_buffer_limit' , default = '100000000' )
39
67
40
- pkg_dir = get_package_share_directory ('go2_robot_sdk' )
41
- urdf_path = os .path .join (pkg_dir , 'urdf' )
42
-
43
- # Read URDF content before LaunchDescription
44
- default_urdf_path = os .path .join (urdf_path , 'go2.urdf' )
45
- with open (default_urdf_path , 'r' ) as infp :
46
- robot_desc = infp .read ()
47
-
48
68
return LaunchDescription ([
49
69
# Declare launch arguments
50
70
DeclareLaunchArgument (
@@ -63,17 +83,6 @@ def generate_launch_description():
63
83
description = 'Name of the URDF file'
64
84
),
65
85
66
- # Robot state publisher for URDF
67
- Node (
68
- package = 'robot_state_publisher' ,
69
- executable = 'robot_state_publisher' ,
70
- name = 'robot_state_publisher' ,
71
- output = 'screen' ,
72
- parameters = [{
73
- 'robot_description' : robot_desc
74
- }],
75
- ),
76
-
77
86
# Go2 driver node with minimal parameters
78
87
Node (
79
88
package = 'go2_robot_sdk' ,
@@ -122,4 +131,6 @@ def generate_launch_description():
122
131
'send_buffer_limit' : send_buffer_limit
123
132
}],
124
133
),
134
+
135
+ OpaqueFunction (function = load_urdf ),
125
136
])
0 commit comments