"""gimbal.launch.py — Launch saltybot_gimbal node (Issue #548)."""

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() -> LaunchDescription:
    pkg = get_package_share_directory("saltybot_gimbal")

    serial_port_arg = DeclareLaunchArgument(
        "serial_port",
        default_value="/dev/ttyTHS1",
<<<<<<< HEAD
        description="JLINK serial port to ESP32 BALANCE",
=======
        description="JLINK serial port to ESP32-S3",
>>>>>>> 291dd68 (feat: remove all STM32/Mamba/BlackPill references — ESP32-S3 only)
    )
    pan_limit_arg = DeclareLaunchArgument(
        "pan_limit_deg",
        default_value="150.0",
        description="Pan soft limit ± degrees",
    )
    tilt_limit_arg = DeclareLaunchArgument(
        "tilt_limit_deg",
        default_value="45.0",
        description="Tilt soft limit ± degrees",
    )

    gimbal_node = Node(
        package="saltybot_gimbal",
        executable="gimbal_node",
        name="gimbal_node",
        output="screen",
        parameters=[
            os.path.join(pkg, "config", "gimbal_params.yaml"),
            {
                "serial_port":    LaunchConfiguration("serial_port"),
                "pan_limit_deg":  LaunchConfiguration("pan_limit_deg"),
                "tilt_limit_deg": LaunchConfiguration("tilt_limit_deg"),
            },
        ],
    )

    return LaunchDescription([
        serial_port_arg,
        pan_limit_arg,
        tilt_limit_arg,
        gimbal_node,
    ])
