"""
rover_driver.launch.py — Launch the SaltyRover ESC motor driver node.

Usage:
    ros2 launch saltybot_rover_driver rover_driver.launch.py
    ros2 launch saltybot_rover_driver rover_driver.launch.py serial_port:=/dev/ttyACM1
    ros2 launch saltybot_rover_driver rover_driver.launch.py four_wheel:=false
"""

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_share = get_package_share_directory("saltybot_rover_driver")
    params_file = os.path.join(pkg_share, "config", "rover_params.yaml")

    serial_port_arg = DeclareLaunchArgument(
        "serial_port",
        default_value="/dev/ttyUSB_rover",
        description="Serial port for ESC controller",
    )
    four_wheel_arg = DeclareLaunchArgument(
        "four_wheel",
        default_value="true",
        description="Enable 4WD skid-steer (true) or 2WD differential (false)",
    )

    rover_driver = Node(
        package="saltybot_rover_driver",
        executable="rover_driver_node",
        name="rover_driver",
        parameters=[
            params_file,
            {
                "serial_port": LaunchConfiguration("serial_port"),
                "four_wheel":  LaunchConfiguration("four_wheel"),
            },
        ],
        output="screen",
        emulate_tty=True,
    )

    return LaunchDescription([
        serial_port_arg,
        four_wheel_arg,
        rover_driver,
    ])
