Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from ament_index_python.packages import get_package_share_path
- from launch import LaunchDescription
- from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription
- from launch.conditions import IfCondition, UnlessCondition
- from launch.launch_description_sources import PythonLaunchDescriptionSource
- from launch.substitutions import Command, LaunchConfiguration, PythonExpression
- from launch_ros.actions import Node
- from launch_ros.parameter_descriptions import ParameterValue
- def generate_launch_description():
- gazebo_ros_pkg = get_package_share_path('gazebo_ros')
- gantry_pkg_path = get_package_share_path('gantry_controller')
- model_path = os.path.join(gantry_pkg_path, 'urdf/gantry.xacro')
- rviz_config_path = os.path.join(gantry_pkg_path, 'rviz/urdf.rviz')
- # TODO: Add world sdf file location and file name.
- # Launch configuration variables. Commands to declare these follow
- # below.
- model = LaunchConfiguration('model')
- rviz_config_file = LaunchConfiguration('rviz_config_file')
- gui = LaunchConfiguration('gui')
- headless = LaunchConfiguration('headless')
- use_robot_state_pub = LaunchConfiguration('use_robot_state_pub')
- use_rviz = LaunchConfiguration('use_rviz')
- use_sim_time = LaunchConfiguration('use_sim_time')
- use_simulator = LaunchConfiguration('use_simulator')
- # Commands to define the launch arguments.
- declare_model_cmd = DeclareLaunchArgument(
- name='model',
- default_value=str(model_path),
- description='Absolute path to robot URDF file')
- declare_rviz_config_file_cmd = DeclareLaunchArgument(
- name='rviz_config_file',
- default_value=str(rviz_config_path),
- description='Absolute path to rviz config file')
- declare_gui_cmd = DeclareLaunchArgument(
- name='gui',
- default_value='True',
- choices=['True', 'False'],
- description='Flag to enable joint_state_publisher_gui')
- declare_headless_cmd = DeclareLaunchArgument(
- name='headless',
- default_value='False',
- choices=['True', 'False'],
- description='Whether to execute gzclient')
- declare_use_robot_state_pub_cmd = DeclareLaunchArgument(
- name='use_robot_state_pub',
- default_value='True',
- choices=['True', 'False'],
- description='Flag to enable robot_state_publisher')
- declare_user_rviz_cmd = DeclareLaunchArgument(
- name='use_rviz',
- default_value='True',
- choices=['True', 'False'],
- description='Whether to start RVIZ')
- declare_use_sim_time_cmd = DeclareLaunchArgument(
- name='use_sim_time',
- default_value='True',
- choices=['True', 'False'],
- description='Flag to use Gazebo simulation clock')
- declare_use_simulator_cmd = DeclareLaunchArgument(
- name='use_simulator',
- default_value='True',
- choices=['True', 'False'],
- description='Flag to start the simulator')
- # Specify the launch actions.
- # Start the gazebo server.
- # TODO: Add world to load: launch_arguments={'world': world}.items())
- # TODO: Is there are cleaner way to launch gazebo? (launch files?)
- gazebo_launch_cmd = ExecuteProcess(
- cmd=['gazebo',
- '--verbose',
- '-s', 'libgazebo_ros_init.so',
- '-s', 'libgazebo_ros_factory.so'],
- output='screen')
- # Robot state publisher
- robot_description = ParameterValue(Command(['xacro ', model]), value_type=str)
- robot_state_publisher_node = Node(
- condition=IfCondition(use_robot_state_pub),
- package='robot_state_publisher',
- executable='robot_state_publisher',
- parameters=[{'use_sim_time': use_sim_time,
- 'robot_description': robot_description}],
- arguments=[model_path])
- # Spawn the robot.
- spawn_entity = Node(
- package='gazebo_ros',
- executable='spawn_entity.py',
- arguments=['-entity', 'gantry', '-topic', 'robot_description'],
- output='screen')
- # Launch RViz
- # rviz_node = Node(
- # condition=IfCondition(use_rviz),
- # package='rviz2',
- # executable='rviz2',
- # name='rviz2',
- # output='screen',
- # arguments=['-d', rviz_config_file])
- return LaunchDescription([
- # Set up launch arguments.
- declare_model_cmd,
- declare_rviz_config_file_cmd,
- declare_gui_cmd,
- declare_headless_cmd,
- declare_use_robot_state_pub_cmd,
- declare_user_rviz_cmd,
- declare_use_sim_time_cmd,
- declare_use_simulator_cmd,
- # Startup actions.
- gazebo_launch_cmd,
- robot_state_publisher_node,
- spawn_entity,
- # rviz_node,
- ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement