"""
sidewalk_segmentation.launch.py — Launch semantic sidewalk segmentation node.

Usage:
  ros2 launch saltybot_segmentation sidewalk_segmentation.launch.py
  ros2 launch saltybot_segmentation sidewalk_segmentation.launch.py publish_debug_image:=true
  ros2 launch saltybot_segmentation sidewalk_segmentation.launch.py engine_path:=/custom/model.engine
"""

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_segmentation")
    cfg = os.path.join(pkg, "config", "segmentation_params.yaml")

    return LaunchDescription([
        DeclareLaunchArgument("engine_path",
            default_value="/mnt/nvme/saltybot/models/bisenetv2_cityscapes_512x256.engine",
            description="Path to TensorRT .engine file"),
        DeclareLaunchArgument("onnx_path",
            default_value="/mnt/nvme/saltybot/models/bisenetv2_cityscapes_512x256.onnx",
            description="Path to ONNX fallback model"),
        DeclareLaunchArgument("process_every_n", default_value="1",
            description="Run inference every N frames (1=every frame)"),
        DeclareLaunchArgument("publish_debug_image", default_value="false",
            description="Publish colour-coded debug image on /segmentation/debug_image"),
        DeclareLaunchArgument("unknown_as_obstacle", default_value="false",
            description="Treat unknown pixels as lethal obstacles"),
        DeclareLaunchArgument("costmap_range_m", default_value="5.0",
            description="Forward look-ahead range for costmap projection (m)"),
        DeclareLaunchArgument("camera_pitch_deg", default_value="5.0",
            description="Camera downward pitch angle (degrees)"),

        Node(
            package="saltybot_segmentation",
            executable="sidewalk_seg",
            name="sidewalk_seg",
            output="screen",
            parameters=[
                cfg,
                {
                    "engine_path":          LaunchConfiguration("engine_path"),
                    "onnx_path":            LaunchConfiguration("onnx_path"),
                    "process_every_n":      LaunchConfiguration("process_every_n"),
                    "publish_debug_image":  LaunchConfiguration("publish_debug_image"),
                    "unknown_as_obstacle":  LaunchConfiguration("unknown_as_obstacle"),
                    "costmap_range_m":      LaunchConfiguration("costmap_range_m"),
                    "camera_pitch_deg":     LaunchConfiguration("camera_pitch_deg"),
                },
            ],
        ),
    ])
