spawn_hexarob.launch.py 966 B

12345678910111213141516171819202122232425262728293031
  1. import os
  2. from launch import LaunchDescription
  3. from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, ExecuteProcess
  4. from launch.substitutions import LaunchConfiguration
  5. from launch.launch_description_sources import PythonLaunchDescriptionSource
  6. import launch_ros.actions
  7. def generate_launch_description():
  8. # Set the path to your URDF or SDF file
  9. model_path = os.path.join(
  10. os.getenv('HOME'), 'ros2_ws', 'src', 'hexarob_description', 'hexarob', 'robot.urdf'
  11. )
  12. # Ignition Gazebo world launch
  13. gazebo = ExecuteProcess(
  14. cmd=['ign', 'gazebo', '-r', '-v', '4', 'default.sdf'],
  15. output='screen'
  16. )
  17. # Spawn the robot in Ignition Gazebotouch spawn_hexarob.launch.py
  18. spawn_robot = ExecuteProcess(
  19. cmd=['ros2', 'run', 'ros_gz_sim', 'create', '-world', 'default', '-file', model_path],
  20. output='screen'
  21. )
  22. return LaunchDescription([
  23. gazebo,
  24. spawn_robot
  25. ])