"""Launch file for VESC CAN telemetry node."""

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_dir = get_package_share_directory("saltybot_vesc_telemetry")
    config_file = os.path.join(pkg_dir, "config", "vesc_telemetry_params.yaml")

    return LaunchDescription([
        DeclareLaunchArgument(
            "config_file",
            default_value=config_file,
            description="Path to vesc_telemetry_params.yaml",
        ),
        DeclareLaunchArgument(
            "can_interface",
            default_value="can0",
            description="SocketCAN interface (e.g. can0, vcan0 for testing)",
        ),
        DeclareLaunchArgument(
            "poll_rate_hz",
            default_value="20",
            description="Telemetry publish + GET_VALUES poll rate (10-50 Hz)",
        ),
        Node(
            package="saltybot_vesc_telemetry",
            executable="vesc_telemetry_node",
            name="vesc_telemetry",
            output="screen",
            parameters=[
                LaunchConfiguration("config_file"),
                {
                    "can_interface": LaunchConfiguration("can_interface"),
                    "poll_rate_hz":  LaunchConfiguration("poll_rate_hz"),
                },
            ],
        ),
    ])
