"""face_track_servo.launch.py — Launch face-tracking head servo controller (Issue #279).

Usage:
  ros2 launch saltybot_social face_track_servo.launch.py
  ros2 launch saltybot_social face_track_servo.launch.py kp_pan:=2.0 pan_limit_deg:=60.0
"""

import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node


def generate_launch_description():
    pkg = get_package_share_directory("saltybot_social")
    cfg = os.path.join(pkg, "config", "face_track_servo_params.yaml")

    return LaunchDescription([
        DeclareLaunchArgument("kp_pan",         default_value="1.5",
                              description="Pan proportional gain (°/s per °)"),
        DeclareLaunchArgument("kp_tilt",        default_value="1.2",
                              description="Tilt proportional gain (°/s per °)"),
        DeclareLaunchArgument("pan_limit_deg",  default_value="90.0",
                              description="Mechanical pan limit ± (degrees)"),
        DeclareLaunchArgument("tilt_limit_deg", default_value="30.0",
                              description="Mechanical tilt limit ± (degrees)"),
        DeclareLaunchArgument("fov_h_deg",      default_value="60.0",
                              description="Camera horizontal FOV (degrees)"),
        DeclareLaunchArgument("fov_v_deg",      default_value="45.0",
                              description="Camera vertical FOV (degrees)"),

        Node(
            package="saltybot_social",
            executable="face_track_servo_node",
            name="face_track_servo_node",
            output="screen",
            parameters=[
                cfg,
                {
                    "kp_pan":         LaunchConfiguration("kp_pan"),
                    "kp_tilt":        LaunchConfiguration("kp_tilt"),
                    "pan_limit_deg":  LaunchConfiguration("pan_limit_deg"),
                    "tilt_limit_deg": LaunchConfiguration("tilt_limit_deg"),
                    "fov_h_deg":      LaunchConfiguration("fov_h_deg"),
                    "fov_v_deg":      LaunchConfiguration("fov_v_deg"),
                },
            ],
        ),
    ])
