Advertisement
Guest User

launch file

a guest
Apr 4th, 2023
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.06 KB | Source Code | 0 0
  1. import launch
  2. from launch.substitutions import Command, LaunchConfiguration
  3. import launch_ros
  4. import os
  5.  
  6. def generate_launch_description():
  7.     pkg_share = launch_ros.substitutions.FindPackageShare(package='sam_bot_description').find('sam_bot_description')
  8.     default_model_path = os.path.join(pkg_share, 'src/description/aroc_truck_description.urdf')
  9.     default_rviz_config_path = os.path.join(pkg_share, 'rviz/urdf_config.rviz')
  10.  
  11.     robot_state_publisher_node = launch_ros.actions.Node(
  12.         package='robot_state_publisher',
  13.         executable='robot_state_publisher',
  14.         parameters=[{'robot_description': Command(['xacro ', LaunchConfiguration('model')])}]
  15.     )
  16.     joint_state_publisher_node = launch_ros.actions.Node(
  17.         package='joint_state_publisher',
  18.         executable='joint_state_publisher',
  19.         name='joint_state_publisher',
  20.         condition=launch.conditions.UnlessCondition(LaunchConfiguration('gui'))
  21.     )
  22.     joint_state_publisher_gui_node = launch_ros.actions.Node(
  23.         package='joint_state_publisher_gui',
  24.         executable='joint_state_publisher_gui',
  25.         name='joint_state_publisher_gui',
  26.         condition=launch.conditions.IfCondition(LaunchConfiguration('gui'))
  27.     )
  28.     rviz_node = launch_ros.actions.Node(
  29.         package='rviz2',
  30.         executable='rviz2',
  31.         name='rviz2',
  32.         output='screen',
  33.         arguments=['-d', LaunchConfiguration('rvizconfig')],
  34.     )
  35.  
  36.     spawn_entity = launch_ros.actions.Node(
  37.         package='gazebo_ros',
  38.         executable='spawn_entity.py',
  39.         arguments=['-entity', 'sam_bot', '-topic', 'robot_description'],
  40.         output='screen'
  41.     )
  42.  
  43.     robot_localization_node = launch_ros.actions.Node(
  44.        package='robot_localization',
  45.        executable='ekf_node',
  46.        name='ekf_filter_node',
  47.        output='screen',
  48.        parameters=[os.path.join(pkg_share, 'config/ekf.yaml'), {'use_sim_time': LaunchConfiguration('use_sim_time')}]
  49. )
  50.  
  51.     return launch.LaunchDescription([
  52.         launch.actions.DeclareLaunchArgument(name='gui', default_value='True',
  53.                                             description='Flag to enable joint_state_publisher_gui'),
  54.         launch.actions.DeclareLaunchArgument(name='model', default_value=default_model_path,
  55.                                             description='Absolute path to robot urdf file'),
  56.         launch.actions.DeclareLaunchArgument(name='rvizconfig', default_value=default_rviz_config_path,
  57.                                             description='Absolute path to rviz config file'),
  58.         launch.actions.ExecuteProcess(cmd=['gazebo', '--verbose', '-s', 'libgazebo_ros_init.so', '-s', 'libgazebo_ros_factory.so'], output='screen'),
  59.         launch.actions.DeclareLaunchArgument(name='use_sim_time', default_value='True',
  60.                                             description='Flag to enable use_sim_time'),
  61.         joint_state_publisher_node,
  62.         joint_state_publisher_gui_node,
  63.         robot_state_publisher_node,
  64.         spawn_entity,
  65.         robot_localization_node,
  66.         rviz_node
  67.     ])
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement