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


def generate_launch_description():
    package_share = get_package_share_directory('openarm_joint_sensor')
    default_params_file = os.path.join(
        package_share,
        'config',
        'joint_sensor_zero_offsets.yaml',
    )

    params_file_arg = DeclareLaunchArgument(
        'params_file',
        default_value=default_params_file,
        description='Path to the YAML parameter file for joint_sensor_can node.',
    )

    joint_sensor_node = Node(
        package='openarm_joint_sensor',
        executable='joint_sensor_can',
        name='joint_sensor_node',
        output='screen',
        parameters=[LaunchConfiguration('params_file')],
    )

    return LaunchDescription([
        params_file_arg,
        joint_sensor_node,
    ])
