import os
from launch import LaunchDescription
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
from launch.substitutions import PathJoinSubstitution


def generate_launch_description():
    config_dir = PathJoinSubstitution(
        [FindPackageShare('saltybot_battery_speed_limiter'), 'config']
    )
    config_file = PathJoinSubstitution([config_dir, 'battery_limiter_config.yaml'])

    battery_limiter = Node(
        package='saltybot_battery_speed_limiter',
        executable='battery_speed_limiter_node',
        name='battery_speed_limiter',
        output='screen',
        parameters=[config_file],
        remappings=[
            ('/saltybot/battery_state', '/saltybot/battery_state'),
            ('/saltybot/speed_limit_factor', '/saltybot/speed_limit_factor'),
        ],
    )

    return LaunchDescription([
        battery_limiter,
    ])