"""Launch emergency stop server."""
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():
    package_dir = get_package_share_directory("saltybot_emergency_stop")
    config_dir = os.path.join(package_dir, "config")

    return LaunchDescription([
        DeclareLaunchArgument(
            "config_file",
            default_value=os.path.join(config_dir, "estop_config.yaml"),
            description="E-stop configuration file",
        ),
        DeclareLaunchArgument(
            "enable_estop",
            default_value="true",
            description="Enable emergency stop system",
        ),
        Node(
            package="saltybot_emergency_stop",
            executable="estop_server",
            name="estop_server",
            output="screen",
            parameters=[{
                "config_file": LaunchConfiguration("config_file"),
                "enable_estop": LaunchConfiguration("enable_estop"),
                "cmd_vel_zero_timeout_ms": 50,
                "cascade_timeout_ms": 500,
                "log_directory": "/home/seb/saltybot-data/estop",
            }],
        ),
    ])
