2
2
import yaml
3
3
from ament_index_python .packages import get_package_share_directory
4
4
from launch import LaunchDescription
5
- from launch .actions import DeclareLaunchArgument
5
+ from launch .actions import DeclareLaunchArgument , OpaqueFunction
6
6
from launch_ros .actions import Node
7
7
from launch .conditions import LaunchConfigurationEquals
8
8
from launch .conditions import IfCondition
9
9
from launch .substitutions import LaunchConfiguration , PythonExpression
10
10
11
-
12
- def generate_launch_description ():
13
-
14
- # load crazyflies
15
- crazyflies_yaml = os .path .join (
16
- get_package_share_directory ('crazyflie' ),
17
- 'config' ,
18
- 'crazyflies.yaml' )
19
-
20
- with open (crazyflies_yaml , 'r' ) as ymlfile :
21
- crazyflies = yaml .safe_load (ymlfile )
11
+ def parse_yaml (context ):
12
+ # Load the crazyflies YAML file
13
+ crazyflies_yaml_file = LaunchConfiguration ('crazyflies_yaml_file' ).perform (context )
14
+ with open (crazyflies_yaml_file , 'r' ) as file :
15
+ crazyflies = yaml .safe_load (file )
22
16
23
17
# server params
24
18
server_yaml = os .path .join (
@@ -38,17 +32,17 @@ def generate_launch_description():
38
32
get_package_share_directory ('crazyflie' ),
39
33
'urdf' ,
40
34
'crazyflie_description.urdf' )
35
+
41
36
with open (urdf , 'r' ) as f :
42
-
43
37
robot_desc = f .read ()
38
+
44
39
server_yaml_content ["/crazyflie_server" ]["ros__parameters" ]["robot_description" ] = robot_desc
45
40
46
41
# construct motion_capture_configuration
47
42
motion_capture_yaml = os .path .join (
48
43
get_package_share_directory ('crazyflie' ),
49
44
'config' ,
50
45
'motion_capture.yaml' )
51
-
52
46
with open (motion_capture_yaml , 'r' ) as ymlfile :
53
47
motion_capture_content = yaml .safe_load (ymlfile )
54
48
@@ -73,12 +67,22 @@ def generate_launch_description():
73
67
with open ('tmp_motion_capture.yaml' , 'w' ) as outfile :
74
68
yaml .dump (motion_capture_content , outfile , default_flow_style = False , sort_keys = False )
75
69
70
+
71
+ def generate_launch_description ():
72
+ default_crazyflies_yaml_path = os .path .join (
73
+ get_package_share_directory ('crazyflie' ),
74
+ 'config' ,
75
+ 'crazyflies.yaml' )
76
+
76
77
telop_yaml_path = os .path .join (
77
78
get_package_share_directory ('crazyflie' ),
78
79
'config' ,
79
80
'teleop.yaml' )
80
-
81
+
81
82
return LaunchDescription ([
83
+ DeclareLaunchArgument ('crazyflies_yaml_file' ,
84
+ default_value = default_crazyflies_yaml_path ),
85
+ OpaqueFunction (function = parse_yaml ),
82
86
DeclareLaunchArgument ('backend' , default_value = 'cpp' ),
83
87
DeclareLaunchArgument ('debug' , default_value = 'False' ),
84
88
DeclareLaunchArgument ('rviz' , default_value = 'False' ),
0 commit comments