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

from launch import LaunchDescription
from launch_ros.actions import Node
from launch.substitutions import LaunchConfiguration
from launch.actions import DeclareLaunchArgument
import os
from ament_index_python.packages import get_package_share_directory


def generate_launch_description():
    """Generate launch description for VESC CAN driver."""
    pkg_dir = get_package_share_directory("saltybot_vesc_driver")
    config_file = os.path.join(pkg_dir, "config", "vesc_params.yaml")

    return LaunchDescription(
        [
            DeclareLaunchArgument(
                "config_file",
                default_value=config_file,
                description="Path to configuration YAML file",
            ),
            Node(
                package="saltybot_vesc_driver",
                executable="velocity_smoother_node",
                name="velocity_smoother",
                output="screen",
                parameters=[LaunchConfiguration("config_file")],
            ),
            Node(
                package="saltybot_vesc_driver",
                executable="vesc_driver_node",
                name="vesc_can_driver",
                output="screen",
                parameters=[LaunchConfiguration("config_file")],
            ),
        ]
    )
