Advertisement
Guest User

simulation.launch

a guest
Feb 6th, 2024
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. import os
  2. from ament_index_python.packages import get_package_share_directory
  3. from launch import LaunchDescription
  4. from launch.actions import ExecuteProcess
  5. from launch_ros.actions import Node
  6.  
  7. def generate_launch_description():
  8. # Define paths
  9. bringup_dir = get_package_share_directory('nav2_bringup')
  10. world_file = os.path.join(bringup_dir, 'worlds', 'empty_ground.world') # EMPTY WORLD
  11. #world_file = os.path.join(bringup_dir, 'worlds', 'raceway.world') #SONOMA Raceway world # Friction is too high truck does not move
  12. rviz_config_file = os.path.join(bringup_dir, 'rviz', 'truck.rviz')
  13. truck_urdf_file = os.path.join(bringup_dir, 'urdf', 'arocs_truck.urdf')
  14. map_yaml_file = os.path.join(bringup_dir, 'maps', 'infinite_map.yaml')
  15.  
  16. # Load URDF file contents into a variable
  17. with open(truck_urdf_file, 'r') as urdf_file:
  18. robot_description_content = urdf_file.read()
  19.  
  20. # Start Gazebo server with the custom world that includes the truck model
  21. start_gazebo_server_cmd = ExecuteProcess(
  22. cmd=['gzserver', '--verbose', world_file, '-s', 'libgazebo_ros_init.so'],
  23. output='screen')
  24.  
  25. # Start Gazebo client
  26. start_gazebo_client_cmd = ExecuteProcess(
  27. cmd=['gzclient'],
  28. output='screen')
  29.  
  30. # Start RViz2
  31. start_rviz_cmd = ExecuteProcess(
  32. cmd=['rviz2', '-d', rviz_config_file],
  33. output='screen')
  34.  
  35. # Robot state publisher
  36. robot_state_publisher_cmd = Node(
  37. package='robot_state_publisher',
  38. executable='robot_state_publisher',
  39. name='robot_state_publisher',
  40. output='screen',
  41. parameters=[{'use_sim_time': True, 'robot_description': robot_description_content}])
  42.  
  43. # Map server node
  44. start_map_server_cmd = Node(
  45. package='nav2_map_server',
  46. executable='map_server',
  47. name='map_server',
  48. output='screen',
  49. parameters=[{'yaml_filename': map_yaml_file, 'use_sim_time': True}],
  50. )
  51.  
  52. # Lifecycle manager to handle lifecycle state transitions
  53. lifecycle_manager_cmd = Node(
  54. package='nav2_lifecycle_manager',
  55. executable='lifecycle_manager',
  56. name='lifecycle_manager',
  57. output='screen',
  58. parameters=[{
  59. 'use_sim_time': True,
  60. 'autostart': True,
  61. 'node_names': ['map_server'] # List of lifecycle nodes to manage
  62. }]
  63. )
  64.  
  65. # Create the launch description and add actions
  66. ld = LaunchDescription()
  67. ld.add_action(start_gazebo_server_cmd)
  68. ld.add_action(start_gazebo_client_cmd)
  69. ld.add_action(start_rviz_cmd)
  70. ld.add_action(robot_state_publisher_cmd)
  71. ld.add_action(start_map_server_cmd)
  72. ld.add_action(lifecycle_manager_cmd) # Add the lifecycle manager
  73.  
  74. return ld
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement