#!/usr/bin/env python3
"""
ROS2 launch file for eye_ros package

启动所有节点：
1. 人脸检测识别节点
2. ASR语音转文字节点
3. LLM智能交互节点
4. TTS语音合成节点
"""

from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration


def generate_launch_description():
    """生成启动描述"""
    # 声明启动参数
    image_topic_arg = DeclareLaunchArgument(
        'image_topic',
        default_value='/camera/camera/color/image_raw',
        description='彩色相机话题'
    )
    
    db_path_arg = DeclareLaunchArgument(
        'db_path',
        default_value='/home/ubuntu/eyes/src/eye_ros/face_database/face_database.pkl',
        description='人脸数据库路径'
    )
    
    model_name_arg = DeclareLaunchArgument(
        'model_name',
        default_value='buffalo_l',
        description='人脸识别模型名称'
    )
    
    demo_path_arg = DeclareLaunchArgument(
        'demo_path',
        default_value='/home/ubuntu/audio_check_demo',
        description='外部ASR程序路径'
    )

    action_topic_arg = DeclareLaunchArgument(
        'action_topic',
        default_value='/home/ubuntu/eyes/src/eye_ros/action_database/动作映射列表',
        description='动作库路径'
    )

    
    # 创建节点
    face_recognition_node = Node(
        package='eye_ros',
        executable='face_recognition_node.py',
        name='face_recognition_node',
        parameters=[
            {
                'image_topic': LaunchConfiguration('image_topic'),
                'db_path': LaunchConfiguration('db_path'),
                'model_name': LaunchConfiguration('model_name')
            }
        ],
        output='screen'
    )
    
    asr_node = Node(
        package='eye_ros',
        executable='asr_node.py',
        name='asr_node',
        parameters=[
            {
                'demo_path': LaunchConfiguration('demo_path')
            }
        ],
        output='screen'
    )
    
    llm_node = Node(
        package='eye_ros',
        executable='llm_node.py',
        name='llm_node',
        output='screen'
    )
    
    tts_node = Node(
        package='eye_ros',
        executable='tts_node.py',
        name='tts_node',
        output='screen'
    )
    
    wake_word_node = Node(
        package='eye_ros',
        executable='wake_word_node.py',
        name='wake_word_node',
        output='screen'
    )
    
    # 创建启动描述
    ld = LaunchDescription()
    
    # 添加启动参数
    ld.add_action(image_topic_arg)
    ld.add_action(db_path_arg)
    ld.add_action(model_name_arg)
    ld.add_action(demo_path_arg)
    ld.add_action(action_topic_arg)
    
    # 添加节点
    ld.add_action(wake_word_node) #唤醒词节点
    ld.add_action(face_recognition_node) #人脸识别节点
    ld.add_action(asr_node) #ASR语音转文字节点
    ld.add_action(llm_node) #LLM智能交互节点
    ld.add_action(tts_node) #TTS语音合成节点
    
    
    return ld
