Advertisement
marcusvini178

mapping_world.launch.py

May 18th, 2023
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.90 KB | Source Code | 0 0
  1. import launch
  2. from launch.substitutions import Command, LaunchConfiguration
  3. import launch_ros
  4. import os
  5. import sys
  6. from ament_index_python.packages import get_package_share_directory
  7.  
  8.  
  9. def generate_launch_description():
  10.     pkg_share = launch_ros.substitutions.FindPackageShare(package='aroc_truck_description').find('aroc_truck_description')
  11.     default_model_path = os.path.join(pkg_share, 'src/description/aroc_truck_description.urdf')
  12.     default_rviz_config_path = os.path.join(pkg_share, 'rviz/urdf_config.rviz')
  13.     #world_file_name = 'winding_valley.sdf' #Fix wheel displacemente at rough terrains first...
  14.     world_file_name = 'turtlebot.world'  #'test_world.sdf'
  15.     world = os.path.join(pkg_share, 'world', world_file_name)
  16.     #world = os.path.join('/home/autoware-auto-ros1/nav2_ws/src/aroc_truck_description/aroc_truck_description/world', world_file_name)
  17.  
  18.  
  19.     robot_state_publisher_node = launch_ros.actions.Node(
  20.         package='robot_state_publisher',
  21.         executable='robot_state_publisher',
  22.         parameters=[{'robot_description': Command(['xacro ', LaunchConfiguration('model')])}]
  23.     )
  24.     joint_state_publisher_node = launch_ros.actions.Node(
  25.         package='joint_state_publisher',
  26.         executable='joint_state_publisher',
  27.         name='joint_state_publisher',
  28.         parameters=[{
  29.             'source_list': ['joint_states']
  30.         }],
  31.         condition=launch.conditions.UnlessCondition(LaunchConfiguration('gui'))
  32.     )
  33.     joint_state_publisher_gui_node = launch_ros.actions.Node(
  34.         package='joint_state_publisher_gui',
  35.         executable='joint_state_publisher_gui',
  36.         name='joint_state_publisher_gui',
  37.         parameters=[{'rate': 30.0}],  # Set the update rate of the GUI node (in Hz)
  38.         condition=launch.conditions.IfCondition(LaunchConfiguration('gui'))
  39.     )
  40.  
  41.     # I have added a custom publisher for the truck's intermediate wheels, since the Ackermann plugin don't include more than frontal and rear wheels (or modify this plugin later to optimize)
  42.     #Or I need to set the joints of these wheels as static otherwise joint_states won't recognize them. Or must have the joint_state_publisher_gui active to publishe these joints values. However
  43.     #if let it active it is going to overhead CPU and the transform from Odom to base_link will be delayed "Old TF transform"
  44.     intermediate_joint_state_publisher_node = launch_ros.actions.Node(
  45.         package='aroc_truck_description',
  46.         executable=sys.executable,
  47.         arguments=[os.path.join(get_package_share_directory('aroc_truck_description'), 'aroc_truck_python', 'intermediate_joint_state_publisher.py')],
  48.         name='intermediate_joint_state_publisher',
  49.         remappings=[('joint_states', 'joint_states')],
  50.         parameters=[{
  51.             'joint_names': ['middle_left_wheel_joint', 'middle_right_wheel_joint',
  52.                             'middle_rear_left_wheel_joint', 'middle_rear_right_wheel_joint',],
  53.             'publish_rate': 30
  54.         }]
  55.     )
  56.     rviz_node = launch_ros.actions.Node(
  57.         package='rviz2',
  58.         executable='rviz2',
  59.         name='rviz2',
  60.         output='screen',
  61.         arguments=['-d', LaunchConfiguration('rvizconfig')],
  62.     )
  63.  
  64.     spawn_entity = launch_ros.actions.Node(
  65.         package='gazebo_ros',
  66.         executable='spawn_entity.py',
  67.         arguments=['-entity', 'aroc_truck', '-topic', 'robot_description',
  68.         ],
  69.         output='screen'
  70.     )
  71.  
  72. #     robot_localization_node = launch_ros.actions.Node(
  73. #        package='robot_localization',
  74. #        executable='ekf_node',
  75. #        name='ekf_filter_node',
  76. #        output='screen',
  77. #        parameters=[os.path.join(pkg_share, 'config/ekf.yaml'), {'use_sim_time': LaunchConfiguration('use_sim_time')}]
  78. # )
  79.  
  80.     return launch.LaunchDescription([
  81.         launch.actions.DeclareLaunchArgument(name='gui', default_value='True',
  82.                                             description='Flag to enable joint_state_publisher_gui'),
  83.         launch.actions.DeclareLaunchArgument(name='model', default_value=default_model_path,
  84.                                             description='Absolute path to robot urdf file'),
  85.         launch.actions.DeclareLaunchArgument(name='rvizconfig', default_value=default_rviz_config_path,
  86.                                             description='Absolute path to rviz config file'),
  87.         launch.actions.DeclareLaunchArgument(name='use_sim_time', default_value='True',
  88.                                             description='Flag to enable use_sim_time'),
  89.         launch.actions.ExecuteProcess(cmd=['gazebo', '--verbose', '-s', 'libgazebo_ros_init.so', '-s', 'libgazebo_ros_factory.so', world], output='screen'),
  90.  
  91.  
  92.  
  93.         joint_state_publisher_node,
  94.         intermediate_joint_state_publisher_node,
  95.         joint_state_publisher_gui_node,
  96.         robot_state_publisher_node,
  97.         spawn_entity,
  98.         #robot_localization_node,
  99.         rviz_node
  100.     ])
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement