Skip to content

Commit

Permalink
Use OpaqueFunction to load string path of custom user-defined crazyfl…
Browse files Browse the repository at this point in the history
…ies yaml file
  • Loading branch information
llanesc committed Jun 25, 2024
1 parent 5a8bdb4 commit d1537eb
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions crazyflie/launch/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@
import yaml
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.actions import DeclareLaunchArgument, OpaqueFunction
from launch_ros.actions import Node
from launch.conditions import LaunchConfigurationEquals
from launch.conditions import IfCondition
from launch.substitutions import LaunchConfiguration, PythonExpression


def generate_launch_description():

# load crazyflies
crazyflies_yaml = os.path.join(
get_package_share_directory('crazyflie'),
'config',
'crazyflies.yaml')

with open(crazyflies_yaml, 'r') as ymlfile:
crazyflies = yaml.safe_load(ymlfile)
def parse_yaml(context):
# Load the crazyflies YAML file
crazyflies_yaml_file = LaunchConfiguration('crazyflies_yaml_file').perform(context)
with open(crazyflies_yaml_file, 'r') as file:
crazyflies = yaml.safe_load(file)

# server params
server_yaml = os.path.join(
Expand All @@ -38,17 +32,17 @@ def generate_launch_description():
get_package_share_directory('crazyflie'),
'urdf',
'crazyflie_description.urdf')

with open(urdf, 'r') as f:

robot_desc = f.read()

server_yaml_content["/crazyflie_server"]["ros__parameters"]["robot_description"] = robot_desc

# construct motion_capture_configuration
motion_capture_yaml = os.path.join(
get_package_share_directory('crazyflie'),
'config',
'motion_capture.yaml')

with open(motion_capture_yaml, 'r') as ymlfile:
motion_capture_content = yaml.safe_load(ymlfile)

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


def generate_launch_description():
default_crazyflies_yaml_path = os.path.join(
get_package_share_directory('crazyflie'),
'config',
'crazyflies.yaml')

telop_yaml_path = os.path.join(
get_package_share_directory('crazyflie'),
'config',
'teleop.yaml')

return LaunchDescription([
DeclareLaunchArgument('crazyflies_yaml_file',
default_value=default_crazyflies_yaml_path),
OpaqueFunction(function=parse_yaml),
DeclareLaunchArgument('backend', default_value='cpp'),
DeclareLaunchArgument('debug', default_value='False'),
DeclareLaunchArgument('rviz', default_value='False'),
Expand Down

0 comments on commit d1537eb

Please sign in to comment.