Advertisement
Guest User

robot_state_publisher

a guest
May 14th, 2024
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 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.  
  11. rviz_config_file = os.path.join(bringup_dir, 'rviz', 'truck.rviz')
  12. truck_urdf_file = os.path.join(bringup_dir, 'urdf', 'arocs_truck.urdf')
  13. map_yaml_file = os.path.join(bringup_dir, 'maps', 'infinite_map.yaml')
  14.  
  15. # Load URDF file contents into a variable
  16. with open(truck_urdf_file, 'r') as urdf_file:
  17. robot_description_content = urdf_file.read()
  18.  
  19.  
  20. # Start RViz2
  21. start_rviz_cmd = ExecuteProcess(
  22. cmd=['rviz2', '-d', rviz_config_file],
  23. output='screen')
  24.  
  25. # Robot state publisher
  26. robot_state_publisher_cmd = Node(
  27. package='robot_state_publisher',
  28. executable='robot_state_publisher',
  29. name='robot_state_publisher',
  30. output='screen',
  31. parameters=[{'use_sim_time': False, 'robot_description': robot_description_content}])
  32.  
  33. # Map server node
  34. start_map_server_cmd = Node(
  35. package='nav2_map_server',
  36. executable='map_server',
  37. name='map_server',
  38. output='screen',
  39. parameters=[{'yaml_filename': map_yaml_file, 'use_sim_time': False}],
  40. )
  41.  
  42. # Lifecycle manager to handle lifecycle state transitions
  43. lifecycle_manager_cmd = Node(
  44. package='nav2_lifecycle_manager',
  45. executable='lifecycle_manager',
  46. name='lifecycle_manager',
  47. output='screen',
  48. parameters=[{
  49. 'use_sim_time': True,
  50. 'autostart': True,
  51. 'node_names': ['map_server']
  52. }]
  53. )
  54.  
  55. # Create the launch description and add actions
  56. ld = LaunchDescription()
  57. ld.add_action(start_rviz_cmd)
  58. ld.add_action(robot_state_publisher_cmd)
  59. #ld.add_action(start_map_server_cmd) # I am using rolling_window = True to avoid need of huge static maps on farm..not practical
  60. #ld.add_action(lifecycle_manager_cmd) # no previous map for farm.
  61.  
  62. return ld
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement