def test_if_condition(): """Test IfCondition class.""" class MockLaunchContext: def perform_substitution(self, substitution): return substitution.perform(self) lc = MockLaunchContext() test_cases = [ ('true', True), ('True', True), ('TRUE', True), ('1', True), ('false', False), ('False', False), ('FALSE', False), ('0', False), ] for string, expected in test_cases: assert IfCondition([TextSubstitution(text=string) ]).evaluate(lc) is expected with pytest.raises(InvalidConditionExpressionError): IfCondition([TextSubstitution(text='')]).evaluate(lc) with pytest.raises(InvalidConditionExpressionError): IfCondition([TextSubstitution(text='typo')]).evaluate(lc)
def generate_launch_description(): urdf1 = os.path.join(get_package_share_directory('ros2_dorna_description'), 'urdf', 'dorna.urdf') rviz_config_file = os.path.join( get_package_share_directory('ros2_dorna_bringup'), 'config', 'dorna.rviz') return LaunchDescription([ DeclareLaunchArgument(name="gui", default_value="True", description="Launch GUI?"), DeclareLaunchArgument(name="rviz", default_value="True", description="Launch RViz?"), Node(package='ros2_dorna_state_publisher', node_executable='ros2_dorna_state_publisher', output='screen', arguments=[urdf1]), Node(package='ros2_dorna_simulator', node_executable='ros2_dorna_simulator', output='screen'), Node(package='ros2_dorna_gui', node_executable='ros2_dorna_gui', output='screen', condition=IfCondition(LaunchConfiguration("gui"))), Node(package='ros2_dorna_utilities', node_executable='ros2_dorna_utilities', output='screen'), Node(package='rviz2', node_executable='rviz2', arguments=['-d', rviz_config_file], output='screen', condition=IfCondition(LaunchConfiguration("rviz"))) ])
def generate_launch_description(): executable = "executable" if ROS_DISTRO == ROS_DISTRO_FOXY else "node_executable" pkg_share = get_package_share_directory("tennis_court") gazebo_ros_share = get_package_share_directory("gazebo_ros") # Gazebo Server gzserver_launch_file = os.path.join(gazebo_ros_share, "launch", "gzserver.launch.py") world_file = os.path.join(pkg_share, "worlds", "court.world") gzserver_launch = IncludeLaunchDescription( PythonLaunchDescriptionSource(gzserver_launch_file), launch_arguments={ "world": world_file, "verbose": "false", "pause": LaunchConfiguration("paused") }.items()) # Gazebo Client gzclient_launch_file = os.path.join(gazebo_ros_share, "launch", "gzclient.launch.py") gzclient_launch = IncludeLaunchDescription( PythonLaunchDescriptionSource(gzclient_launch_file), condition=IfCondition(LaunchConfiguration("gui"))) static_tf_node = Node(package="tf2_ros", arguments=[ "0", "0", "8", "3.14159", "1.57079", "3.14159", "map", "zenith_camera_link" ], **{executable: "static_transform_publisher"}) # Ball Manager ball_manager_node = Node(package="tennis_court", condition=IfCondition( LaunchConfiguration("manager")), parameters=[{ "use_sim_time": True }], output="screen", emulate_tty=True, **{executable: "ball_manager.py"}) # Rviz rviz_config_file = os.path.join(pkg_share, "config", "config.rviz") rviz_node = Node(package="rviz2", arguments=["-d", rviz_config_file], condition=IfCondition(LaunchConfiguration("rviz")), parameters=[{ "use_sim_time": True }], **{executable: "rviz2"}) return LaunchDescription([ DeclareLaunchArgument(name="gui", default_value="true"), DeclareLaunchArgument(name="paused", default_value="false"), DeclareLaunchArgument(name="rviz", default_value="false"), DeclareLaunchArgument(name="manager", default_value="true"), gzserver_launch, gzclient_launch, static_tf_node, ball_manager_node, rviz_node ])
def generate_launch_description(): log_level = 'info' if (os.getenv('ROS_DISTRO') == "dashing") or (os.getenv('ROS_DISTRO') == "eloquent"): return LaunchDescription(declare_configurable_parameters(configurable_parameters) + [ # Realsense launch_ros.actions.Node( condition=IfCondition(PythonExpression([LaunchConfiguration('config_file'), " == ''"])), package='realsense2_camera', node_namespace=LaunchConfiguration("camera_name"), node_name=LaunchConfiguration("camera_name"), node_executable='realsense2_camera_node', prefix=['stdbuf -o L'], parameters=[set_configurable_parameters(configurable_parameters) ], output='screen', arguments=['--ros-args', '--log-level', LaunchConfiguration('log_level')], ), launch_ros.actions.Node( condition=IfCondition(PythonExpression([LaunchConfiguration('config_file'), " != ''"])), package='realsense2_camera', node_namespace=LaunchConfiguration("camera_name"), node_name=LaunchConfiguration("camera_name"), node_executable='realsense2_camera_node', prefix=['stdbuf -o L'], parameters=[set_configurable_parameters(configurable_parameters) , PythonExpression([LaunchConfiguration("config_file")]) ], output='screen', arguments=['--ros-args', '--log-level', LaunchConfiguration('log_level')], ), ]) else: return LaunchDescription(declare_configurable_parameters(configurable_parameters) + [ # Realsense launch_ros.actions.Node( condition=IfCondition(PythonExpression([LaunchConfiguration('config_file'), " == ''"])), package='realsense2_camera', namespace=LaunchConfiguration("camera_name"), name=LaunchConfiguration("camera_name"), executable='realsense2_camera_node', parameters=[set_configurable_parameters(configurable_parameters) ], output='screen', arguments=['--ros-args', '--log-level', LaunchConfiguration('log_level')], emulate_tty=True, ), launch_ros.actions.Node( condition=IfCondition(PythonExpression([LaunchConfiguration('config_file'), " != ''"])), package='realsense2_camera', namespace=LaunchConfiguration("camera_name"), name=LaunchConfiguration("camera_name"), executable='realsense2_camera_node', parameters=[set_configurable_parameters(configurable_parameters) , PythonExpression([LaunchConfiguration("config_file")]) ], output='screen', arguments=['--ros-args', '--log-level', LaunchConfiguration('log_level')], emulate_tty=True, ), ])
def generate_launch_description(): omnivelma_dir = get_package_share_directory('omnivelma_navigation_2') bringup_dir = get_package_share_directory('nav2_bringup') launch_dir = os.path.join(bringup_dir, 'launch') map_location = os.path.join(omnivelma_dir, 'maps', 'willow_garage.yaml') nav_params_dir = os.path.join(omnivelma_dir, 'params', 'nav2_params.yaml') slam = LaunchConfiguration('use_slam') nav_params_cmd = launch.actions.DeclareLaunchArgument( name='nav_params_file', default_value=nav_params_dir, description="Navigation parameters file") map_cmd = launch.actions.DeclareLaunchArgument(name='map_file', default_value=map_location, description="Map file") use_slam_cmd = DeclareLaunchArgument(name='use_slam', default_value='False', description="SLAM or localization") slam_cmd = IncludeLaunchDescription( launch.launch_description_sources.PythonLaunchDescriptionSource( os.path.join(omnivelma_dir, 'launch/slam_launch.py')), condition=IfCondition(slam), launch_arguments={ # 'params_file': launch.substitutions.LaunchConfiguration('nav_params_file'), }.items(), ) amcl_cmd = IncludeLaunchDescription( launch.launch_description_sources.PythonLaunchDescriptionSource( os.path.join(launch_dir, 'localization_launch.py')), condition=IfCondition(PythonExpression(['not ', slam])), launch_arguments={ 'params_file': launch.substitutions.LaunchConfiguration('nav_params_file'), 'map': launch.substitutions.LaunchConfiguration('map_file') }.items(), ) # Create the launch description and populate ld = LaunchDescription() ld.add_action(use_slam_cmd) ld.add_action(nav_params_cmd) ld.add_action(map_cmd) ld.add_action(amcl_cmd) ld.add_action(slam_cmd) return ld
def launch_setup(context): configs_dir = os.path.join(get_package_share_directory("ov_msckf"), "config") available_configs = os.listdir(configs_dir) config = LaunchConfiguration("config").perform(context) if not config in available_configs: return [ LogInfo( msg= "ERROR: unknown config: '{}' - Available configs are: {} - not starting OpenVINS" .format(config, ", ".join(available_configs))) ] config_path = os.path.join( get_package_share_directory("ov_msckf"), "config", config, "estimator_config.yaml", ) node1 = Node( package="ov_msckf", executable="run_subscribe_msckf", condition=IfCondition(LaunchConfiguration("ov_enable")), namespace=LaunchConfiguration("namespace"), parameters=[ { "verbosity": LaunchConfiguration("verbosity") }, { "use_stereo": LaunchConfiguration("use_stereo") }, { "max_cameras": LaunchConfiguration("max_cameras") }, { "config_path": config_path }, ], ) node2 = Node( package="rviz2", executable="rviz2", condition=IfCondition(LaunchConfiguration("rviz_enable")), arguments=[ "-d" + os.path.join(get_package_share_directory("ov_msckf"), "launch", "display_ros2.rviz"), "--ros-args", "--log-level", "warn", ], ) return [node1, node2]
def generate_launch_description(): declare_sitl_world_cmd = DeclareLaunchArgument( 'sitl_world', default_value='yosemite', description='World [yosemite, mcmillan, ksql, baylands]') sitl_world = ReplaceWorldString( sitl_world=launch.substitutions.LaunchConfiguration('sitl_world')) included_launch = launch.actions.IncludeLaunchDescription( launch.launch_description_sources.PythonLaunchDescriptionSource( sitl_world)) use_rviz = LaunchConfiguration('use_rviz') declare_use_rviz_cmd = DeclareLaunchArgument( 'use_rviz', default_value='True', description='Whether to start RVIZ') use_qgroundcontrol = LaunchConfiguration('use_qgroundcontrol') declare_use_qgroundcontrol_cmd = DeclareLaunchArgument( 'use_qgroundcontrol', default_value='True', description='Whether to start QGroundcontrol') include_nodes = [included_launch] sitl_launcher_dir = get_package_share_directory('sitl_launcher') start_rviz_cmd = Node(condition=IfCondition(use_rviz), package='rviz2', node_executable='rviz2', node_name='rviz2', arguments=[ '-d', sitl_launcher_dir + "/rviz/rviz.rviz", "--ros-args", "-p", "use_sim_time:=True" ], output='screen') start_qgroundcontrol_cmd = Node(condition=IfCondition(use_qgroundcontrol), package='qgroundcontrol', node_executable='qgroundcontrol-start.sh', node_name='qgroundcontrol', output='screen') ld = LaunchDescription(include_nodes) ld.add_action(declare_use_rviz_cmd) ld.add_action(start_rviz_cmd) ld.add_action(declare_use_qgroundcontrol_cmd) ld.add_action(start_qgroundcontrol_cmd) ld.add_action(declare_sitl_world_cmd) return ld
def test_shutdown_execute_conditional(): """Test the conditional execution (or visit) of the Shutdown class.""" true_action = Shutdown(condition=IfCondition('True')) false_action = Shutdown(condition=IfCondition('False')) context = LaunchContext() assert context._event_queue.qsize() == 0 assert false_action.visit(context) is None assert context._event_queue.qsize() == 0 assert true_action.visit(context) is None assert context._event_queue.qsize() == 1 event = context._event_queue.get_nowait() assert isinstance(event, ShutdownEvent)
def generate_launch_description(): world_file = os.path.join(get_package_share_directory('crane_plus_gazebo'), 'worlds', 'table.world') declare_arg_gui = DeclareLaunchArgument( 'gui', default_value='true', description='Set to "false" to run headless.') declare_arg_server = DeclareLaunchArgument( 'server', default_value='true', description='Set to "false" not to run gzserver.') gzserver = IncludeLaunchDescription( PythonLaunchDescriptionSource([ get_package_share_directory('gazebo_ros'), '/launch/gzserver.launch.py' ]), condition=IfCondition(LaunchConfiguration('server')), launch_arguments={'world': world_file}.items(), ) gzclient = IncludeLaunchDescription(PythonLaunchDescriptionSource([ get_package_share_directory('gazebo_ros'), '/launch/gzclient.launch.py' ]), condition=IfCondition( LaunchConfiguration('gui'))) move_group = IncludeLaunchDescription( PythonLaunchDescriptionSource([ get_package_share_directory('crane_plus_moveit_config'), '/launch/run_move_group.launch.py' ]), ) spawn_entity = Node(package='gazebo_ros', executable='spawn_entity.py', arguments=[ '-entity', 'crane_plus', '-x', '0', '-y', '0', '-z', '1.02', '-topic', '/robot_description' ], output='screen') return LaunchDescription([ declare_arg_gui, declare_arg_server, gzserver, gzclient, move_group, spawn_entity, ])
def generate_rviz_launch_description(namespace="robot"): # Get the launch directory titan_dir = get_package_share_directory("titan") rviz_config_file = os.path.join(titan_dir, "rviz", "namespaced_view.rviz") use_namespace = "true" namespaced_rviz_config_file = ReplaceString( source_file=rviz_config_file, replacements={"<robot_namespace>": ("/", namespace)}, ) start_namespaced_rviz_cmd = Node( condition=IfCondition(use_namespace), package="rviz2", executable="rviz2", name="rviz2", namespace=namespace, # TODO: FIX onload MUTEX ERROR # arguments=['-d', namespaced_rviz_config_file], output="screen", remappings=[ ("/tf", "tf"), ("/tf_static", "tf_static"), ("/goal_pose", "goal_pose"), ("/clicked_point", "clicked_point"), ("/initialpose", "initialpose"), ], ) exit_event_handler_namespaced = RegisterEventHandler( condition=IfCondition(use_namespace), event_handler=OnProcessExit( target_action=start_namespaced_rviz_cmd, on_exit=EmitEvent(event=Shutdown(reason="rviz exited")), ), ) # Create the launch description and populate ld = LaunchDescription() # Add any conditioned actions ld.add_action(start_namespaced_rviz_cmd) # Add other nodes and processes we need ld.add_action(exit_event_handler_namespaced) return ld
def generate_launch_description(): use_sim_time = LaunchConfiguration('use_sim_time', default='true') world_file_name = 'dolly_empty.world' world = os.path.join(get_package_share_directory('dolly_gazebo'), 'worlds', world_file_name) launch_file_dir = os.path.join(get_package_share_directory('dolly_gazebo'), 'launch') pkg_dolly_description= get_package_share_directory('dolly_description') # RViz rviz = Node( package='rviz2', executable='rviz2', arguments=['-d', os.path.join(pkg_dolly_description, 'rviz', 'dolly_gazebo.rviz')], condition=IfCondition(LaunchConfiguration('rviz')) ) return LaunchDescription([ ExecuteProcess( cmd=['gazebo', '--verbose', world, '-s', 'libgazebo_ros_init.so'], output='screen'), IncludeLaunchDescription( PythonLaunchDescriptionSource([launch_file_dir, '/robot_state_publisher.launch.py']), launch_arguments={'use_sim_time': use_sim_time}.items(), ), DeclareLaunchArgument('rviz', default_value='true', description='Open RViz.'), ])
def generate_launch_description(): # Path nb2_launch_dir = os.path.join( get_package_share_directory('neuronbot2_bringup'), 'launch') autodock_launch_dir = os.path.join( get_package_share_directory('apriltag_docking'), 'launch') rviz_path = os.path.join( get_package_share_directory('napp_apriltag_docking'), 'rviz', 'default_tag_bot.rviz') open_rviz = LaunchConfiguration('open_rviz', default='True') neuron_app_bringup = GroupAction([ DeclareLaunchArgument('open_rviz', default_value='true', description='Launch Rviz?'), IncludeLaunchDescription(PythonLaunchDescriptionSource( os.path.join(nb2_launch_dir, 'bringup_launch.py')), launch_arguments={'use_camera': 'top'}.items()), IncludeLaunchDescription( PythonLaunchDescriptionSource( os.path.join(autodock_launch_dir, 'autodock_neuronbot.launch.py'))), Node(package='rviz2', executable='rviz2', name='rviz2', arguments=['-d', rviz_path], condition=IfCondition(LaunchConfiguration("open_rviz"))), ]) ld = LaunchDescription() ld.add_action(neuron_app_bringup) return ld
def generate_launch_description(): xacro_path = os.path.join(get_package_share_directory('robot_runtime'), 'urdf', 'homey.urdf.xacro') urdf_file = render_xacro(xacro_path) return LaunchDescription([ DeclareLaunchArgument('use_sim_time', default_value='false'), DeclareLaunchArgument('publish_frequency', default_value='5.0'), DeclareLaunchArgument('joint_states', default_value='false'), Node( package='robot_state_publisher', executable='robot_state_publisher', name='robot_state_publisher', output='screen', parameters=[{ 'publish_frequency': LaunchConfiguration('publish_frequency'), 'use_sim_time': LaunchConfiguration('use_sim_time'), }], arguments=[urdf_file.name], ), Node( package='joint_state_publisher', executable='joint_state_publisher', name='joint_state_publisher', output='screen', arguments=[urdf_file.name], parameters=[{ 'use_sim_time': LaunchConfiguration('use_sim_time'), }], condition=IfCondition(LaunchConfiguration('joint_states')), ), ])
def generate_launch_description(): # Get gazebo_ros package path gazebo_ros_share_path = get_package_share_directory('gazebo_ros') lobot_desc_share_path = get_package_share_directory('lobot_description') zero_g_world_path = os.path.join(lobot_desc_share_path, 'worlds/zero_g_world.sdf') # Launch gzserver gzserver = IncludeLaunchDescription(PythonLaunchDescriptionSource( os.path.join(gazebo_ros_share_path, 'launch', 'gzserver.launch.py')), launch_arguments={ 'extra_gazebo_args': '__log_level:=info', 'world': zero_g_world_path, 'pause': 'true' }.items()) return LaunchDescription([ DeclareLaunchArgument( 'gui', default_value='True', description= 'Bool to specify if gazebo should be launched with GUI or not'), gzserver, IncludeLaunchDescription(PythonLaunchDescriptionSource( os.path.join(gazebo_ros_share_path, 'launch', 'gzclient.launch.py')), condition=IfCondition( LaunchConfiguration('gui'))), ])
def generate_launch_description(): ld = LaunchDescription() launchturtle = LaunchConfiguration('launchturtle') #declare this argument in the LaunchDescription class declareturtle = DeclareLaunchArgument( 'launchturtle', default_value='false', description= 'true would launch turtlesim. false would launch the turtle teleop key' ) run_teleop = Node(condition=UnlessCondition(launchturtle), package='turtlesim', executable='turtle_teleop_key', name='turtle_teleop_key', output='screen') run_turtlesim = Node(condition=IfCondition(launchturtle), package='turtlesim', executable='turtlesim_node', name='turtlesim_node', output='screen') ld.add_action(declareturtle) ld.add_action(run_teleop) ld.add_action(run_turtlesim) return ld
def generate_launch_description(): declare_use_remappings_cmd = DeclareLaunchArgument( 'use_remappings', default_value='false', description='Arguments to pass to all nodes launched by the file') declare_rviz_config_file_cmd = DeclareLaunchArgument( 'rviz_config_file', description='Full path to the RVIZ config file to use') start_rviz_cmd = Node( package='rviz2', node_executable='rviz2', node_name='rviz2', arguments=['-d', LaunchConfiguration('rviz_config_file')], output='log', use_remappings=IfCondition(LaunchConfiguration('use_remappings')), remappings=[('/tf', 'tf'), ('/tf_static', 'tf_static'), ('goal_pose', 'goal_pose'), ('/clicked_point', 'clicked_point'), ('/initialpose', 'initialpose')]) # Create the launch description and populate ld = LaunchDescription() # Declare the launch options ld.add_action(declare_use_remappings_cmd) ld.add_action(declare_rviz_config_file_cmd) # Add any conditioned actions ld.add_action(start_rviz_cmd) return ld
def generate_launch_description(): # ROS packages pkg_mammoth_description = get_package_share_directory( 'mammoth_description') # launch arguments use_sim_time = LaunchConfiguration('use_sim_time', default='true') use_rviz = LaunchConfiguration('use_rviz', default='true') # Nodes rviz = Node(package='rviz2', executable='rviz2', arguments=[ '-d', os.path.join(pkg_mammoth_description, 'rviz', 'mammoth_gazebo.rviz') ], condition=IfCondition(use_rviz)) return LaunchDescription([ # Launch Arguments DeclareLaunchArgument('use_rviz', default_value='false', description='Use simulation time if true'), # Node rviz, ])
def group(self, ns=None, if_arg=None, unless_arg=None): ''' Group the next nodes / entities into - another namespace - a if / unless condition depending on some argument ''' # save current entity index prev_index = self.index self.entities.append([]) self.index = len(self.entities) - 1 if ns is not None: self.entities[-1].append(PushRosNamespace(ns)) try: yield self finally: new_entities = self.entities[self.index] # restore state self.index = prev_index condition = None # get condition if if_arg is not None: condition = IfCondition(self.arg(if_arg)) elif unless_arg is not None: condition = UnlessCondition(self.arg(unless_arg)) # add new entities as sub-group self.entity(GroupAction(new_entities, condition=condition))
def generate_launch_description(): bringup_cmd_group = GroupAction([ Node(package='apriltag_docking', executable='controller', name='autodock_controller', output='screen', parameters=[config]), Node(package='rviz2', executable='rviz2', name='rviz2', arguments=['-d', rviz_config_dir], condition=IfCondition(open_rviz)), IncludeLaunchDescription(PythonLaunchDescriptionSource( os.path.join(tag_launch_dir, 'tag_realsense.launch.py')), launch_arguments={ 'image_topic': image_topic, 'camera_name': camera_name }.items()) ]) ld = LaunchDescription() ld.add_action(bringup_cmd_group) return ld
def generate_launch_description(): # ROS packages pkg_mammoth_gazebo = get_package_share_directory('mammoth_gazebo') # Config waypoints = os.path.join(pkg_mammoth_gazebo, 'config/waypoints', 'single-I.csv') # Launch arguments use_sim_time = LaunchConfiguration('use_sim_time', default='false') follow_waypoints = LaunchConfiguration('follow_waypoints', default='true') # Nodes waypoint_publisher = Node(package='waypoint', executable='waypoint', name='waypoint', output='screen', parameters=[{ 'filename': waypoints }, { 'use_sim_time': use_sim_time }], condition=IfCondition(follow_waypoints)) return LaunchDescription([ # Launch Arguments DeclareLaunchArgument('use_sim_time', default_value='false', description='Use simulation time if true'), DeclareLaunchArgument('follow_waypoints', default_value='true', description='Follow waypoints if true'), # Nodes waypoint_publisher, ])
def generate_launch_description(): # Webots webots = WebotsLauncher( #world=os.path.join(get_package_share_directory('robotis_mini_description'), 'worlds', 'ros_example.wbt') world=os.path.join('./worlds', 'empty.wbt')) # Controller node # synchronization = launch.substitutions.LaunchConfiguration('synchronization', default=False) # controller = ControllerLauncher( # package='head_node', # executable='head_publisher', # parameters=[{'synchronization': synchronization}], # output='screen' #) # urdf for state publisher robot_description_filename = 'robotis_mini.urdf.xacro' print("robot_description_filename : {}".format(robot_description_filename)) xacro = os.path.join( get_package_share_directory('robotis_mini_description'), 'urdf', robot_description_filename) print("xacro : {}".format(xacro)) use_sim_time = LaunchConfiguration('use_sim_time', default='false') xacro_path = LaunchConfiguration('xacro_path', default='{}'.format(xacro)) print("xacro_path : {}".format(xacro_path)) gui = LaunchConfiguration('gui', default='true') return launch.LaunchDescription([ webots, DeclareLaunchArgument( 'use_sim_time', default_value='false', description='Use simulation (Gazebo) clock if true'), Node(package='robot_state_publisher', executable='robot_state_publisher', name='robot_state_publisher', output='screen', parameters=[{ 'use_sim_time': use_sim_time, 'robot_description': Command(['xacro', ' ', xacro_path]) }]), Node(condition=UnlessCondition(gui), package='joint_state_publisher', executable='joint_state_publisher', name='joint_state_publisher', output='screen'), Node(condition=IfCondition(gui), package='joint_state_publisher_gui', executable='joint_state_publisher_gui', name='joint_state_publisher_gui'), launch.actions. RegisterEventHandler(event_handler=launch.event_handlers.OnProcessExit( target_action=webots, on_exit=[launch.actions.EmitEvent(event=launch.events.Shutdown())], )), ])
def generate_launch_description(): ld = LaunchDescription([ DeclareLaunchArgument( 'gazebo_model_path_env_var', description='GAZEBO_MODEL_PATH environment variable'), DeclareLaunchArgument( 'gazebo_plugin_path_env_var', description='GAZEBO_PLUGIN_PATH environment variable'), DeclareLaunchArgument( 'headless', default_value='False', description='Whether to execute gzclient'), DeclareLaunchArgument( 'world_model_file', description='Full path to world model file to load'), DeclareLaunchArgument( 'robot_gt_urdf_file', description='Full path to robot urdf model file to load'), DeclareLaunchArgument( 'robot_realistic_urdf_file', description='Full path to robot urdf model file to load'), SetEnvironmentVariable('RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1'), SetEnvironmentVariable('GAZEBO_MODEL_PATH', LaunchConfiguration('gazebo_model_path_env_var')), SetEnvironmentVariable('GAZEBO_PLUGIN_PATH', LaunchConfiguration('gazebo_plugin_path_env_var')), ExecuteProcess( cmd=['gzserver', '--verbose', '-s', 'libgazebo_ros_init.so', LaunchConfiguration('world_model_file')], output='screen'), ExecuteProcess( condition=IfCondition(PythonExpression(['not ', LaunchConfiguration('headless')])), cmd=['gzclient'], output='log'), Node( package='robot_state_publisher', node_executable='robot_state_publisher', node_name='robot_state_publisher_gt', output='log', parameters=[{'use_sim_time': True}], arguments=[LaunchConfiguration('robot_gt_urdf_file')]), Node( package='tf2_ros', node_executable='static_transform_publisher', node_name='gt_odom_static_transform_publisher', output='log', parameters=[{'use_sim_time': True}], arguments=["0", "0", "0", "0", "0", "0", "map", "odom"]), # odom is actually the ground truth, because currently (Eloquent) odom and base_link are hardcoded in the navigation stack (recoveries and controller) >:C Node( package='robot_state_publisher', node_executable='robot_state_publisher', node_name='robot_state_publisher_realistic', output='log', parameters=[{'use_sim_time': True}], arguments=[LaunchConfiguration('robot_realistic_urdf_file')]), ]) return ld
def generate_launch_description(): # ROS packages pkg_lawnbot_description = get_package_share_directory( 'lawnbot_description') # Launch arguments use_sim_time = LaunchConfiguration('use_sim_time', default='true') use_rviz = LaunchConfiguration('use_rviz', default='true') robot_desc, urdf_file = generate_robot_model(pkg_lawnbot_description) # Nodes robot_state_publisher = Node(package='robot_state_publisher', executable='robot_state_publisher', name='robot_state_publisher', output='screen', parameters=[{ 'use_sim_time': use_sim_time, 'robot_description': robot_desc, }]) joint_state_publisher = Node(package='joint_state_publisher', executable='joint_state_publisher', name='joint_state_publisher', output='screen', parameters=[{ 'use_sim_time': use_sim_time }]) rviz = Node(package='rviz2', executable='rviz2', arguments=[ '-d', os.path.join(pkg_lawnbot_description, 'rviz', 'lawnbot.rviz') ], condition=IfCondition(use_rviz), parameters=[{ 'use_sim_time': use_sim_time }]) return LaunchDescription([ # Launch Arguments DeclareLaunchArgument( 'use_sim_time', default_value='true', description='Use simulation (Gazebo) clock if true'), DeclareLaunchArgument('use_rviz', default_value='true', description='Open rviz if true'), # Nodes robot_state_publisher, joint_state_publisher, rviz, ])
def generate_launch_description(): return LaunchDescription([ DeclareLaunchArgument('gui', default_value='true', description='Set to "false" to run headless.'), DeclareLaunchArgument( 'server', default_value='true', description='Set to "false" not to run gzserver.'), IncludeLaunchDescription(PythonLaunchDescriptionSource( [ThisLaunchFileDir(), '/gzserver.launch.py']), condition=IfCondition( LaunchConfiguration('server'))), IncludeLaunchDescription(PythonLaunchDescriptionSource( [ThisLaunchFileDir(), '/gzclient.launch.py']), condition=IfCondition( LaunchConfiguration('gui'))), ])
def generate_launch_description(): # Get gazebo_ros package path gazebo_ros_share_path = get_package_share_directory('gazebo_ros') lobot_desc_share_path = get_package_share_directory('lobot_description') sim_share_path = get_package_share_directory('arm_simulation') gym_zero_g_world_path = os.path.join(lobot_desc_share_path, "worlds/gym_zero_g_world.sdf") zero_g_world_path = os.path.join(lobot_desc_share_path, "worlds/zero_g_world.sdf") cmd = [ '"', gym_zero_g_world_path, '"', ' if "', LaunchConfiguration('gym'), '" == "True" ', 'else ', '"', zero_g_world_path, '"' ] # The expression above expression is evaluated to something like this: # <some_path>/gym_zero_g_world.sdf if "<LaunchConfig evaluation result>" == "True" else <some_path>/zero_g_world.sdf py_cmd = PythonExpression(cmd) # Launch gzserver gzserver = IncludeLaunchDescription(PythonLaunchDescriptionSource( os.path.join(gazebo_ros_share_path, 'launch', 'gzserver.launch.py')), launch_arguments={ 'extra_gazebo_args': '__log_level:=info', 'pause': 'true', 'world': py_cmd }.items()) spawn_entity = IncludeLaunchDescription( PythonLaunchDescriptionSource( os.path.join(sim_share_path, 'launch', 'spawn_entity.launch.py')), ) # Launch gzclient gzclient = IncludeLaunchDescription(PythonLaunchDescriptionSource( os.path.join(gazebo_ros_share_path, 'launch', 'gzclient.launch.py')), condition=IfCondition( LaunchConfiguration('gui'))) return LaunchDescription([ DeclareLaunchArgument( 'gym', default_value='False', description= 'Bool to specify if the simulation is to be ran with openai gym training' ), DeclareLaunchArgument( 'gui', default_value='True', description= 'Bool to specify if gazebo should be launched with GUI or not'), gzserver, spawn_entity, gzclient, ])
def generate_launch_description(): hexapod_path = get_package_share_path('hexapod_desc') default_model_path = hexapod_path / 'urdf/hexapod.urdf' default_rviz_config_path = hexapod_path / 'rviz/urdf.rviz' gui_arg = DeclareLaunchArgument( name='gui', default_value='true', choices=['true', 'false'], description='Flag to enable joint_state_publisher_gui') model_arg = DeclareLaunchArgument( name='model', default_value=str(default_model_path), description='Absolute path to robot urdf file') rviz_arg = DeclareLaunchArgument( name='rvizconfig', default_value=str(default_rviz_config_path), description='Absolute path to rviz config file') robot_description = ParameterValue(Command( ['xacro ', LaunchConfiguration('model')]), value_type=str) robot_state_publisher_node = Node(package='robot_state_publisher', executable='robot_state_publisher', parameters=[{ 'robot_description': robot_description }]) # Depending on gui parameter, either launch joint_state_publisher or joint_state_publisher_gui joint_state_publisher_node = Node(package='joint_state_publisher', executable='joint_state_publisher', condition=UnlessCondition( LaunchConfiguration('gui'))) joint_state_publisher_gui_node = Node( package='joint_state_publisher_gui', executable='joint_state_publisher_gui', condition=IfCondition(LaunchConfiguration('gui'))) rviz_node = Node( package='rviz2', executable='rviz2', name='rviz2', output='screen', arguments=['-d', LaunchConfiguration('rvizconfig')], ) return LaunchDescription([ gui_arg, model_arg, rviz_arg, joint_state_publisher_node, joint_state_publisher_gui_node, robot_state_publisher_node, rviz_node ])
def include_launch( package: str, name: str, cond: Optional[str] = None, **kwargs, ): share = get_package_share_directory(package) launch_path = os.path.join(share, 'launch', name) return IncludeLaunchDescription( PythonLaunchDescriptionSource(launch_path), condition=IfCondition(LaunchConfiguration(cond)) if cond else None, **kwargs )
def generate_launch_description(): return LaunchDescription( declare_configurable_parameters(configurable_parameters) + [ # Realsense launch_ros.actions.Node( condition=IfCondition( PythonExpression( ["'", LaunchConfiguration('config_file'), "' == ''"])), package='realsense2_camera', namespace=LaunchConfiguration("camera_name"), name=LaunchConfiguration("camera_name"), executable='realsense2_camera_node', parameters=[ set_configurable_parameters(configurable_parameters) ], output='screen', emulate_tty=True, ), launch_ros.actions.Node( condition=IfCondition( PythonExpression( ["'", LaunchConfiguration('config_file'), "' != ''"])), package='realsense2_camera', namespace=LaunchConfiguration("camera_name"), name=LaunchConfiguration("camera_name"), executable='realsense2_camera_node', parameters=[ set_configurable_parameters(configurable_parameters), {LaunchConfiguration("config_file")} ], output='screen', emulate_tty=True, ), ])
def generate_launch_description(): pkg_gazebo_ros = get_package_share_directory('gazebo_ros') pkg_dolly_gazebo = get_package_share_directory('dolly_gazebo') # Gazebo launch gazebo = IncludeLaunchDescription( PythonLaunchDescriptionSource( os.path.join(pkg_gazebo_ros, 'launch', 'gazebo.launch.py'), )) # Follow node follow = Node(package='dolly_follow', executable='dolly_follow', output='screen', remappings=[('cmd_vel', '/dolly/cmd_vel'), ('laser_scan', '/dolly/laser_scan')]) # Teleop node teleop = Node(package='dolly_teleop', executable='dolly_teleop_node', output='screen', prefix=["konsole -e"], remappings=[('cmd_vel', '/dolly/cmd_vel')]) # RViz rviz = Node(package='rviz2', executable='rviz2', arguments=[ '-d', os.path.join(pkg_dolly_gazebo, 'rviz', 'dolly_gazebo.rviz') ], condition=IfCondition(LaunchConfiguration('rviz'))) return LaunchDescription([ DeclareLaunchArgument('world', default_value=[ os.path.join(pkg_dolly_gazebo, 'worlds', 'dolly_empty.world'), '' ], description='SDF world file'), DeclareLaunchArgument('rviz', default_value='true', description='Open RViz.'), gazebo, #follow, teleop, rviz ])
def test_launch_description_get_launch_arguments(): """Test the get_launch_arguments() method of the LaunchDescription class.""" ld = LaunchDescription([]) assert len(ld.get_launch_arguments()) == 0 ld = LaunchDescription([DeclareLaunchArgument('foo')]) la = ld.get_launch_arguments() assert len(la) == 1 assert la[0]._conditionally_included is False ld = LaunchDescription( [DeclareLaunchArgument('foo', condition=IfCondition('True'))]) la = ld.get_launch_arguments() assert len(la) == 1 assert la[0]._conditionally_included is True ld = LaunchDescription([ IncludeLaunchDescription( LaunchDescriptionSource( LaunchDescription([ DeclareLaunchArgument('foo'), ]))), ]) la = ld.get_launch_arguments() assert len(la) == 1 assert la[0]._conditionally_included is False this_dir = os.path.dirname(os.path.abspath(__file__)) ld = LaunchDescription([ IncludeLaunchDescription( PythonLaunchDescriptionSource( os.path.join(this_dir, 'launch_file_with_argument.launch.py'))), ]) la = ld.get_launch_arguments() assert len(la) == 1 assert la[0]._conditionally_included is False ld = LaunchDescription([ IncludeLaunchDescription( PythonLaunchDescriptionSource([ # This will prevent loading of this launch file to find arguments in it. ThisLaunchFileDir(), 'launch_file_with_argument.launch.py', ])), ]) la = ld.get_launch_arguments() assert len(la) == 0