Advertisement
marcusvini178

Launch file

Mar 28th, 2023
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.56 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.    
  17.     joint_state_publisher_node = launch_ros.actions.Node(
  18.         package='joint_state_publisher',
  19.         executable='joint_state_publisher',
  20.         name='joint_state_publisher',
  21.         condition=launch.conditions.UnlessCondition(LaunchConfiguration('gui'))
  22.     )
  23.     joint_state_publisher_gui_node = launch_ros.actions.Node(
  24.         package='joint_state_publisher_gui',
  25.         executable='joint_state_publisher_gui',
  26.         name='joint_state_publisher_gui',
  27.         condition=launch.conditions.IfCondition(LaunchConfiguration('gui'))
  28.     )
  29.     rviz_node = launch_ros.actions.Node(
  30.         package='rviz2',
  31.         executable='rviz2',
  32.         name='rviz2',
  33.         output='screen',
  34.         arguments=['-d', LaunchConfiguration('rvizconfig')],
  35.     )
  36.  
  37.     spawn_entity = launch_ros.actions.Node(
  38.         package='gazebo_ros',
  39.         executable='spawn_entity.py',
  40.         arguments=['-entity', 'sam_bot', '-topic', 'robot_description'],
  41.         output='screen'
  42.     )
  43.  
  44.     return launch.LaunchDescription([
  45.         launch.actions.DeclareLaunchArgument(name='gui', default_value='True',
  46.                                             description='Flag to enable joint_state_publisher_gui'),
  47.         launch.actions.DeclareLaunchArgument(name='model', default_value=default_model_path,
  48.                                             description='Absolute path to robot urdf file'),
  49.         launch.actions.DeclareLaunchArgument(name='rvizconfig', default_value=default_rviz_config_path,
  50.                                             description='Absolute path to rviz config file'),
  51.         launch.actions.ExecuteProcess(cmd=['gazebo', '--verbose', '-s', 'libgazebo_ros_init.so', '-s', 'libgazebo_ros_factory.so'], output='screen'),
  52.  
  53.  
  54.         joint_state_publisher_node,
  55.         joint_state_publisher_gui_node,
  56.         robot_state_publisher_node,
  57.         spawn_entity,
  58.         rviz_node
  59.     ])
  60.  
Tags: launch file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement