"""Launch file for pan/tilt servo control node."""

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


def generate_launch_description():
    """Generate launch description."""
    # Declare arguments
    port_arg = DeclareLaunchArgument(
        "port",
        default_value="/dev/ttyUSB0",
        description="Serial port for servo bus"
    )
    baudrate_arg = DeclareLaunchArgument(
        "baudrate",
        default_value="1000000",
        description="Serial baudrate (1Mbps for SCS protocol)"
    )

    # Create node
    pan_tilt_node = Node(
        package="saltybot_pan_tilt",
        executable="pan_tilt_node",
        name="pan_tilt",
        parameters=[
            {"port": LaunchConfiguration("port")},
            {"baudrate": LaunchConfiguration("baudrate")},
            {"image_width": 848},
            {"image_height": 480},
            {"fov_h_deg": 87.0},
            {"fov_v_deg": 58.0},
            {"max_pan_speed": 100},
            {"max_tilt_speed": 100},
            {"pan_center": 2048},
            {"tilt_center": 2048},
            {"pan_min": 0},
            {"pan_max": 4095},
            {"tilt_min": 1024},
            {"tilt_max": 3072},
        ],
        output="screen",
    )

    return LaunchDescription([
        port_arg,
        baudrate_arg,
        pan_tilt_node,
    ])
