import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node


def generate_launch_description():
    birdseye_share = get_package_share_directory('origincar_birdseye')
    camera_share = get_package_share_directory('car_usb_cam')
    default_birdseye_config = os.path.join(
        birdseye_share, 'config', 'birdseye_defaults.yaml')
    default_camera_config = os.path.join(
        camera_share, 'config', 'usb_camera.yaml')
    camera_launch = os.path.join(camera_share, 'launch', 'hobot_usb_cam.launch.py')

    return LaunchDescription([
        DeclareLaunchArgument(
            'camera_config',
            default_value=default_camera_config,
            description='Path passed unchanged to car_usb_cam'),
        DeclareLaunchArgument(
            'birdseye_config',
            default_value=default_birdseye_config,
            description='Birdseye node ROS parameter YAML'),
        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(camera_launch),
            launch_arguments={
                'camera_config': LaunchConfiguration('camera_config'),
            }.items()),
        Node(
            package='origincar_birdseye',
            executable='birdseye_node',
            name='birdseye_node',
            output='screen',
            parameters=[LaunchConfiguration('birdseye_config')]),
    ])
