"""
terrain_adaptation.launch.py — Launch the terrain adaptation node (Issue #142).

Usage
-----
  ros2 launch saltybot_terrain_adaptation terrain_adaptation.launch.py
  ros2 launch saltybot_terrain_adaptation terrain_adaptation.launch.py \
      odom_topic:=/saltybot/rover_odom control_rate:=50.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_share = get_package_share_directory("saltybot_terrain_adaptation")
    default_params = os.path.join(pkg_share, "config", "terrain_params.yaml")

    return LaunchDescription([
        DeclareLaunchArgument(
            "params_file",
            default_value=default_params,
            description="Path to terrain_params.yaml",
        ),
        DeclareLaunchArgument(
            "odom_topic",
            default_value="/saltybot/rover_odom",
            description="Odometry topic for wheel-slip detection",
        ),
        DeclareLaunchArgument(
            "control_rate",
            default_value="50.0",
            description="Control loop rate (Hz)",
        ),
        Node(
            package="saltybot_terrain_adaptation",
            executable="terrain_adaptation_node",
            name="terrain_adaptation",
            output="screen",
            parameters=[
                LaunchConfiguration("params_file"),
                {
                    "odom_topic":    LaunchConfiguration("odom_topic"),
                    "control_rate":  LaunchConfiguration("control_rate"),
                },
            ],
        ),
    ])
