Skip to content

Commit 62c2040

Browse files
authored
Merge pull request #533 from llanesc/pr-crazyflies-yaml-launch-upgrade
Use OpaqueFunction to load string path of custom user-defined crazyfl…
2 parents d622047 + d1537eb commit 62c2040

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

crazyflie/launch/launch.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,17 @@
22
import yaml
33
from ament_index_python.packages import get_package_share_directory
44
from launch import LaunchDescription
5-
from launch.actions import DeclareLaunchArgument
5+
from launch.actions import DeclareLaunchArgument, OpaqueFunction
66
from launch_ros.actions import Node
77
from launch.conditions import LaunchConfigurationEquals
88
from launch.conditions import IfCondition
99
from launch.substitutions import LaunchConfiguration, PythonExpression
1010

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)
2216

2317
# server params
2418
server_yaml = os.path.join(
@@ -38,17 +32,17 @@ def generate_launch_description():
3832
get_package_share_directory('crazyflie'),
3933
'urdf',
4034
'crazyflie_description.urdf')
35+
4136
with open(urdf, 'r') as f:
42-
4337
robot_desc = f.read()
38+
4439
server_yaml_content["/crazyflie_server"]["ros__parameters"]["robot_description"] = robot_desc
4540

4641
# construct motion_capture_configuration
4742
motion_capture_yaml = os.path.join(
4843
get_package_share_directory('crazyflie'),
4944
'config',
5045
'motion_capture.yaml')
51-
5246
with open(motion_capture_yaml, 'r') as ymlfile:
5347
motion_capture_content = yaml.safe_load(ymlfile)
5448

@@ -73,12 +67,22 @@ def generate_launch_description():
7367
with open('tmp_motion_capture.yaml', 'w') as outfile:
7468
yaml.dump(motion_capture_content, outfile, default_flow_style=False, sort_keys=False)
7569

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+
7677
telop_yaml_path = os.path.join(
7778
get_package_share_directory('crazyflie'),
7879
'config',
7980
'teleop.yaml')
80-
81+
8182
return LaunchDescription([
83+
DeclareLaunchArgument('crazyflies_yaml_file',
84+
default_value=default_crazyflies_yaml_path),
85+
OpaqueFunction(function=parse_yaml),
8286
DeclareLaunchArgument('backend', default_value='cpp'),
8387
DeclareLaunchArgument('debug', default_value='False'),
8488
DeclareLaunchArgument('rviz', default_value='False'),

0 commit comments

Comments
 (0)