import os
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, ExecuteProcess
from launch.substitutions import LaunchConfiguration
from launch.launch_description_sources import PythonLaunchDescriptionSource
import launch_ros.actions

def generate_launch_description():
    # Set the path to your URDF or SDF file
    model_path = os.path.join(
        os.getenv('HOME'), 'ros2_ws', 'src', 'hexarob_description', 'hexarob', 'robot.urdf'
    )

    # Ignition Gazebo world launch
    gazebo = ExecuteProcess(
        cmd=['ign', 'gazebo', '-r', '-v', '4', 'default.sdf'],
        output='screen'
    )

    # Spawn the robot in Ignition Gazebotouch spawn_hexarob.launch.py

    spawn_robot = ExecuteProcess(
        cmd=['ros2', 'run', 'ros_gz_sim', 'create', '-world', 'default', '-file', model_path],
        output='screen'
    )

    return LaunchDescription([
        gazebo,
        spawn_robot
    ])
