import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
from launch_ros.parameter_descriptions import ParameterValue  # Import this!

def generate_launch_description():
    ####### DATA INPUT ##########
    urdf_file = 'robot.urdf'
    package_description = "hexarob_description"
    ####### DATA INPUT END ##########
    
    print("Fetching URDF ==>")
    robot_desc_path = os.path.join(
        get_package_share_directory(package_description), "hexarob", urdf_file
    )

    # Read the URDF file content
    with open(robot_desc_path, 'r') as file:
        urdf_content = file.read()

    # Robot State Publisher
    robot_state_publisher_node = Node(
        package='robot_state_publisher',
        executable='robot_state_publisher',
        name='robot_state_publisher_node',
        emulate_tty=True,
        parameters=[{'use_sim_time': True, 'robot_description': ParameterValue(urdf_content, value_type=str)}],
        output="screen"
    )

    return LaunchDescription([robot_state_publisher_node])
