def generate_launch_description(): set_tty_launch_config_action = launch.actions.SetLaunchConfiguration( "emulate_tty", "True") # Launch Description ld = launch.LaunchDescription() # Watchdog node watchdog_node = LifecycleNode(package='sw_watchdog', node_executable='simple_watchdog', node_namespace='', node_name='simple_docker_watchdog', output='screen', arguments=['220', '--publish', '--activate'] #arguments=['__log_level:=debug'] ) # Make the Watchdog node take the 'activate' transition watchdog_activate_trans_event = EmitEvent(event=ChangeState( lifecycle_node_matcher=launch.events.matches_action(watchdog_node), transition_id=lifecycle_msgs.msg.Transition.TRANSITION_ACTIVATE, )) # When the watchdog reaches the 'inactive' state from 'active', log message # and restart monitored entity (via docker) watchdog_inactive_handler = RegisterEventHandler( OnStateTransition( target_lifecycle_node=watchdog_node, start_state='deactivating', goal_state='inactive', entities=[ # Log LogInfo(msg="Watchdog transitioned to 'INACTIVE' state."), # Restart the monitored entity OpaqueFunction(function=docker_restart), # Change state event (inactive -> active) watchdog_activate_trans_event, ], )) # When Shutdown is requested, clean up docker shutdown_handler = RegisterEventHandler( OnShutdown( on_shutdown=[ # Log LogInfo(msg="watchdog_in_docker was asked to shutdown."), # Clean up docker OpaqueFunction(function=docker_stop), ], )) # Add the actions to the launch description. # The order they are added reflects the order in which they will be executed ld.add_action(set_tty_launch_config_action) ld.add_action(OpaqueFunction(function=docker_run)) ld.add_action(watchdog_node) ld.add_action(watchdog_inactive_handler) ld.add_action(shutdown_handler) return ld
def generate_launch_description(): ld = launch.LaunchDescription() ld.add_action( launch.actions.DeclareLaunchArgument("type", default_value="simulation")) ld.add_action(OpaqueFunction(function=prepare_rviz)) ld.add_action(OpaqueFunction(function=launch_rviz)) return ld
def generate_test_description(executable, ready_fn): command = [executable] # Execute python files using same python used to start this test env = dict(os.environ) if command[0][-3:] == '.py': command.insert(0, sys.executable) env['PYTHONUNBUFFERED'] = '1' launch_description = LaunchDescription() test_context = {} for replacement_name, (replacement_value, cli_argument) in TEST_CASES.items(): random_string = '%d_%s' % (random.randint( 0, 9999), time.strftime('%H_%M_%S', time.gmtime())) launch_description.add_action( ExecuteProcess(cmd=command + [cli_argument.format(**locals())], name='name_maker_' + replacement_name, env=env)) test_context[replacement_name] = replacement_value.format(**locals()) launch_description.add_action( OpaqueFunction(function=lambda context: ready_fn())) return launch_description, test_context
def generate_launch_description(): def add_launch_arg(name: str, default_value=None): return DeclareLaunchArgument(name, default_value=default_value) return launch.LaunchDescription([ add_launch_arg("input_pointcloud", "/sensing/lidar/no_ground/pointcloud"), add_launch_arg("input_map", "/map/pointcloud_map"), add_launch_arg("output_clusters", "clusters"), add_launch_arg("use_pointcloud_map", "false"), add_launch_arg( "voxel_grid_param_path", [ FindPackageShare("euclidean_cluster"), "/config/voxel_grid.param.yaml" ], ), add_launch_arg( "euclidean_param_path", [ FindPackageShare("euclidean_cluster"), "/config/euclidean_cluster.param.yaml" ], ), OpaqueFunction(function=launch_setup), ])
def generate_launch_description(): """Generate launch description with multiple components.""" container = ComposableNodeContainer( node_name='my_container', node_namespace='my_namespace', package='rclcpp_components', node_executable='component_container', composable_node_descriptions=[ ComposableNode(package='demo_nodes_cpp', node_plugin='demo_nodes_cpp::Talker', node_name='talker'), ComposableNode(package='sw_watchdog', node_plugin='sw_watchdog::SimpleHeartbeat', node_name='heartbeat', parameters=[{ 'period': 200 }], extra_arguments=[{ 'use_intra_process_comms': True }]), ], output='screen') # When Shutdown is requested (launch), clean up all child processes shutdown_handler = RegisterEventHandler( OnShutdown( on_shutdown=[ # Log LogInfo(msg="heartbeat_composition was asked to shutdown."), # Clean up OpaqueFunction(function=group_stop), ], )) return launch.LaunchDescription([container, shutdown_handler])
def generate_test_description(rmw_implementation, ready_fn): path_to_action_server_executable = os.path.join( os.path.dirname(__file__), 'fixtures', 'fibonacci_action_server.py' ) return LaunchDescription([ # Always restart daemon to isolate tests. ExecuteProcess( cmd=['ros2', 'daemon', 'stop'], name='daemon-stop', on_exit=[ ExecuteProcess( cmd=['ros2', 'daemon', 'start'], name='daemon-start', on_exit=[ ExecuteProcess( cmd=[sys.executable, path_to_action_server_executable], additional_env={'RMW_IMPLEMENTATION': rmw_implementation} ), OpaqueFunction(function=lambda context: ready_fn()) ], additional_env={'RMW_IMPLEMENTATION': rmw_implementation} ) ] ), ])
def generate_launch_description(): ## arguments argument_teleopmode = DeclareLaunchArgument( 'teleop_mode', default_value='joy', description='joy or keyboard', ) ## nodes node_turtlesim = Node( package='turtlesim', node_executable='turtlesim_node', name='turtlesim_node1', ) ## including launch files def func_launch_teleop_node(context): if context.launch_configurations['teleop_mode'] == 'joy': return [ IncludeLaunchDescription( PythonLaunchDescriptionSource([ os.path.join( get_package_share_directory('turtlesim_teleop'), 'launch'), '/teleop-joy.launch.py' ]), ) ] launch_teleop_node = OpaqueFunction(function=func_launch_teleop_node) ld = LaunchDescription() ld.add_action(argument_teleopmode) ld.add_action(node_turtlesim) ld.add_action(launch_teleop_node) return ld
def test_execute_process_with_on_exit_behavior(): """Test a process' on_exit callback and actions are processed.""" def on_exit_callback(event, context): on_exit_callback.called = True on_exit_callback.called = False executable_with_on_exit_callback = ExecuteLocal( process_description=Executable(cmd=[sys.executable, '-c', "print('callback')"]), output='screen', on_exit=on_exit_callback ) assert len(executable_with_on_exit_callback.get_sub_entities()) == 0 def on_exit_function(context): on_exit_function.called = True on_exit_function.called = False on_exit_action = OpaqueFunction(function=on_exit_function) executable_with_on_exit_action = ExecuteLocal( process_description=Executable(cmd=[sys.executable, '-c', "print('callback')"]), output='screen', on_exit=[on_exit_action] ) assert executable_with_on_exit_action.get_sub_entities() == [on_exit_action] ld = LaunchDescription([ executable_with_on_exit_callback, executable_with_on_exit_action ]) ls = LaunchService() ls.include_launch_description(ld) assert 0 == ls.run() assert on_exit_callback.called assert on_exit_function.called
def generate_test_description(rmw_implementation, ready_fn): path_to_echo_server_script = os.path.join(os.path.dirname(__file__), 'fixtures', 'echo_server.py') additional_env = {'RMW_IMPLEMENTATION': rmw_implementation} return LaunchDescription([ # Always restart daemon to isolate tests. ExecuteProcess( cmd=['ros2', 'daemon', 'stop'], name='daemon-stop', on_exit=[ ExecuteProcess( cmd=['ros2', 'daemon', 'start'], name='daemon-start', on_exit=[ # Add test fixture actions. Node( node_executable=sys.executable, arguments=[path_to_echo_server_script], node_name='echo_server', node_namespace='my_ns', additional_env=additional_env, ), Node( node_executable=sys.executable, arguments=[path_to_echo_server_script], node_name='_hidden_echo_server', node_namespace='my_ns', remappings=[('echo', '_echo')], additional_env=additional_env, ), OpaqueFunction(function=lambda context: ready_fn()) ], additional_env=additional_env) ]), ])
def generate_launch_description(): declare_lidar = DeclareLaunchArgument( 'lidar', default_value='lds', description='LiDAR: lds only, for now.') mouse_node = LifecycleNode( node_name='raspimouse', package='raspimouse', node_executable='raspimouse', output='screen', parameters=[ os.path.join( get_package_share_directory('raspimouse_ros2_examples'), 'config', 'mouse.yml') ]) def func_launch_lidar_node(context): if context.launch_configurations['lidar'] == 'lds': return [ IncludeLaunchDescription( PythonLaunchDescriptionSource([ os.path.join( get_package_share_directory('hls_lfcd_lds_driver'), 'launch'), '/hlds_laser.launch.py' ]), ) ] launch_lidar_node = OpaqueFunction(function=func_launch_lidar_node) ld = LaunchDescription() ld.add_action(declare_lidar) ld.add_action(mouse_node) ld.add_action(launch_lidar_node) return ld
def generate_launch_description(): launch = RandomTestRunnerLaunch() launch.collect_random_test_launch_configuration() launch_description_list = [OpaqueFunction(function=launch.launch_setup)] launch_description_list.extend( launch.generate_launch_arguments_declarations()) return LaunchDescription(launch_description_list)
def generate_launch_description(): spawner_dir = get_package_share_directory('robot_spawner_pkg') declare_n_robots_cmd = DeclareLaunchArgument('n_robots', default_value='2') declare_robots_file_cmd = DeclareLaunchArgument('robots_file', default_value=os.path.join( spawner_dir, 'robots.yaml')) declare_base_frame_cmd = DeclareLaunchArgument('base_frame', default_value='base_link') # Define commands for launching the navigation instances simulator = IncludeLaunchDescription(PythonLaunchDescriptionSource( os.path.join(spawner_dir, 'simulator.launch.py')), launch_arguments={}.items()) # Create the launch description and populate ld = LaunchDescription() # Add declarations for launch file arguments ld.add_action(declare_n_robots_cmd) ld.add_action(declare_robots_file_cmd) ld.add_action(declare_base_frame_cmd) # Add the actions to start gazebo, robots and simulations ld.add_action(simulator) # The opaque function is neccesary to resolve the context of the launch file and read the LaunchDescription param at runtime ld.add_action(OpaqueFunction(function=initialize_robots)) return ld
def generate_launch_description(): return LaunchDescription( [ DeclareLaunchArgument("use_sim_time", default_value="false"), OpaqueFunction(function=launch_setup), ] )
def test_launch_service_emit_event(): """ Test the emitting of events in the LaunchService class. Also covers basic tests for include_launch_description(), run(), and shutdown(). """ ls = LaunchService(debug=True) assert ls._LaunchService__context._event_queue.qsize() == 0 from launch.actions import OpaqueFunction from launch.actions import RegisterEventHandler from launch.event_handler import EventHandler handled_events = queue.Queue() ld = LaunchDescription([ RegisterEventHandler(EventHandler( matcher=lambda event: True, entities=OpaqueFunction( function=lambda context: handled_events.put(context.locals.event), ), )) ]) ls.include_launch_description(ld) assert ls._LaunchService__context._event_queue.qsize() == 1 class MockEvent: name = 'Event' ls.emit_event(MockEvent()) assert ls._LaunchService__context._event_queue.qsize() == 2 assert handled_events.qsize() == 0 t = threading.Thread(target=ls.run, kwargs={'shutdown_when_idle': False}) t.start() # First event (after including description of event handler). handled_events.get(block=True, timeout=5.0) # Emit and then check for a second event. ls.emit_event(MockEvent()) handled_events.get(block=True, timeout=5.0) # Shutdown (generates a third event) and join the thread. ls.shutdown() t.join() # Check that the shutdown event was handled. handled_events.get(block=False) assert handled_events.qsize() == 0 ls.emit_event(MockEvent()) assert handled_events.qsize() == 0 assert ls.run(shutdown_when_idle=True) == 0 handled_events.get(block=False)
def generate_launch_description(): sim_arg = DeclareLaunchArgument('sim', default_value='False') fake_walk_arg = DeclareLaunchArgument('fake_walk', default_value='False') sim_ns_arg = DeclareLaunchArgument( 'sim_ns', default_value=TextSubstitution(text='/')) robot_type_arg = DeclareLaunchArgument( 'robot_type', default_value=TextSubstitution(text='wolfgang')) return LaunchDescription([ sim_arg, fake_walk_arg, sim_ns_arg, robot_type_arg, OpaqueFunction(function=launch_setup) ])
def generate_test_description(ready_fn): node_env = os.environ.copy() node_env["PYTHONUNBUFFERED"] = "1" return LaunchDescription([ Node(package='apex_rostest', node_executable='echo_node', env=node_env), RegisterEventHandler( StdoutReadyListener( "echo_node", "ready", actions=[OpaqueFunction(function=lambda context: ready_fn())])) ])
def generate_test_description(ready_fn): polly_server = Node(package='tts', node_executable='polly_server', additional_env={'PYTHONUNBUFFERED': '1'}, output='screen') synthesizer_server = Node(package='tts', node_executable='synthesizer_server', additional_env={'PYTHONUNBUFFERED': '1'}, output='screen') launch_description = LaunchDescription([ polly_server, synthesizer_server, OpaqueFunction(function=lambda context: ready_fn()), ]) return launch_description, locals()
def generate_test_description(ready_fn): launch_description = LaunchDescription() # Set the output format to a "verbose" format that is expected by the executable output os.environ['RCUTILS_CONSOLE_OUTPUT_FORMAT'] = \ '[{severity}] [{name}]: {message} ({function_name}() at {file_name}:{line_number})' executable = os.path.join(os.getcwd(), 'test_logging_long_messages') if os.name == 'nt': executable += '.exe' process_name = 'test_logging_long_messages' launch_description.add_action( ExecuteProcess(cmd=[executable], name=process_name, output='screen')) launch_description.add_action( OpaqueFunction(function=lambda context: ready_fn())) return launch_description, {'process_name': process_name}
def generate_test_description(ready_fn): return LaunchDescription([ # Always restart daemon to isolate tests. ExecuteProcess( cmd=['ros2', 'daemon', 'stop'], name='daemon-stop', on_exit=[ ExecuteProcess( cmd=['ros2', 'daemon', 'start'], name='daemon-start', on_exit=[ OpaqueFunction(function=lambda context: ready_fn()) ], ) ]) ])
def generate_test_description(ready_fn): package_name = 'ifm3d_ros2' node_exe = 'camera_standalone' namespace = NS_ nodename = NN_ exe = os.path.join(get_package_prefix(package_name), 'lib', package_name, node_exe) return launch.LaunchDescription([ ExecuteProcess( cmd=[exe, '__ns:=%s' % namespace, '__node:=%s' % nodename], log_cmd=True, output='screen'), OpaqueFunction(function=lambda context: ready_fn()), ])
def generate_launch_description(): return launch.LaunchDescription([ # arguments #launch.actions.DeclareLaunchArgument('global_ns', default_value = ['crs']), launch.actions.DeclareLaunchArgument('sim_robot', default_value=['True']), launch.actions.DeclareLaunchArgument('gazebo_gui', default_value=['False']), launch.actions.DeclareLaunchArgument( 'xacro', default_value=[ os.path.join( get_package_share_directory('fanuc_r2000ic_support'), 'urdf', 'r2000ic165f.xacro') ]), launch.actions.DeclareLaunchArgument( 'srdf', default_value=[ os.path.join( get_package_share_directory('fanuc_r2000ic_support'), 'urdf', 'fanuc_r2000ic165f.srdf') ]), launch.actions.DeclareLaunchArgument( 'motion_planning_cfg', default_value=[ os.path.join(get_package_share_directory('crs_application'), 'config/motion_planning', 'fanuc_MP_config.yaml') ]), launch.actions.DeclareLaunchArgument( 'gazebo_world', default_value=[ os.path.join(get_package_share_directory('crs_support'), 'worlds', 'crs.world') ]), launch.actions.DeclareLaunchArgument( 'urdf_preview_path', default_value=[ os.path.join(get_package_share_directory('crs_support'), 'urdf', 'crs_preview.urdf') ], description= 'The path where the launch file will generate the urdf for preview purposes' ), OpaqueFunction(function=launch_setup) ])
def generate_launch_description(): # TODO Try LaunchContext ? return LaunchDescription([ DeclareLaunchArgument('debug', default_value='0'), DeclareLaunchArgument('x', default_value='0'), DeclareLaunchArgument('y', default_value='0'), DeclareLaunchArgument('z', default_value='-20'), DeclareLaunchArgument('roll', default_value='0.0'), DeclareLaunchArgument('pitch', default_value='0.0'), DeclareLaunchArgument('yaw', default_value='0.0'), DeclareLaunchArgument('mode', default_value='default'), DeclareLaunchArgument('namespace', default_value='rexrov'), DeclareLaunchArgument('use_ned_frame', default_value='false'), # DeclareLaunchArgument('use_sim_time', default_value='true'), OpaqueFunction(function=launch_setup) ])
def generate_launch_description(): ld = LaunchDescription() use_sim_time_arg = DeclareLaunchArgument( 'use_sim_time', default_value='true', description='Use simulation (Gazebo) clock if true') urdf_path_arg = DeclareLaunchArgument('urdf_path', default_value='robot.urdf', description='urdf_path') ld.add_action(urdf_path_arg) ld.add_action(use_sim_time_arg) ld.add_action(OpaqueFunction(function=launch_setup)) return ld
def generate_launch_description(): spawner_dir = get_package_share_directory('robot_spawner_pkg') declare_robots_file_cmd = DeclareLaunchArgument( 'robots_file', default_value=os.path.join(spawner_dir, 'tb3_swarmlab_arena.yaml')) declare_base_frame_cmd = DeclareLaunchArgument( 'base_frame', default_value='base_footprint') # Create the launch description and populate ld = LaunchDescription() # Add declarations for launch file arguments ld.add_action(declare_robots_file_cmd) ld.add_action(declare_base_frame_cmd) # The opaque function is neccesary to resolve the context of the launch file and read the LaunchDescription param at runtime ld.add_action(OpaqueFunction(function=initialize_robots)) return ld
def generate_launch_description(): multi_robot_launch = IncludeLaunchDescription( PythonLaunchDescriptionSource( os.path.join(get_package_share_directory('robot_spawner_pkg'), 'multi_robot.launch.py')), launch_arguments={ 'behaviour': 'false', 'world': 'face.world', 'map': os.path.join(get_package_share_directory('robot_spawner_pkg'), 'maps', 'face.yaml'), }.items()) ld = LaunchDescription() ld.add_action(multi_robot_launch) ld.add_action(OpaqueFunction(function=controller_spawning)) return ld
def test_wait_for_ready(self): data = [] self.launch_description.add_entity( RegisterEventHandler( StdoutReadyListener( node_name="terminating_node", ready_txt="Ready", actions=[ OpaqueFunction( function=lambda context: data.append('ok')) ]))) launch_service = LaunchService() launch_service.include_launch_description(self.launch_description) launch_service.run() # If the StdoutReadyListener worked, we should see 'ok' in the data self.assertIn('ok', data)
def test_wait_for_wrong_message(self): data = [] self.launch_description.add_entity( RegisterEventHandler( StdoutReadyListener( node_name="different_node", ready_txt="not_ready", actions=[ OpaqueFunction( function=lambda context: data.append('ok')) ]))) launch_service = LaunchService() launch_service.include_launch_description(self.launch_description) launch_service.run() # We should not get confused by output that doesn't match the ready_txt self.assertNotIn('ok', data)
def generate_launch_description(): system_monitor_path = os.path.join( get_package_share_directory("system_launch"), "config", "system_monitor") return launch.LaunchDescription([ DeclareLaunchArgument( "cpu_monitor_config_file", default_value=os.path.join(system_monitor_path, "cpu_monitor.param.yaml"), ), DeclareLaunchArgument( "hdd_monitor_config_file", default_value=os.path.join(system_monitor_path, "hdd_monitor.param.yaml"), ), DeclareLaunchArgument( "mem_monitor_config_file", default_value=os.path.join(system_monitor_path, "mem_monitor.param.yaml"), ), DeclareLaunchArgument( "net_monitor_config_file", default_value=os.path.join(system_monitor_path, "net_monitor.param.yaml"), ), DeclareLaunchArgument( "ntp_monitor_config_file", default_value=os.path.join(system_monitor_path, "ntp_monitor.param.yaml"), ), DeclareLaunchArgument( "process_monitor_config_file", default_value=os.path.join(system_monitor_path, "process_monitor.param.yaml"), ), DeclareLaunchArgument( "gpu_monitor_config_file", default_value=os.path.join(system_monitor_path, "gpu_monitor.param.yaml"), ), OpaqueFunction(function=launch_setup), ])
def generate_test_description(ready_fn): velodyne_cloud_node = Node( package="velodyne_nodes", node_executable="velodyne_cloud_node_exe", node_name="vlp16_driver_node", node_namespace="lidar_front", parameters=[ os.path.join(get_package_share_directory("velodyne_nodes"), "param/test.param.yaml") ], arguments=["--model", "vlp16"]) context = {'vel_node': velodyne_cloud_node} return LaunchDescription([ velodyne_cloud_node, # Start tests right away - no need to wait for anything OpaqueFunction(function=lambda context: ready_fn()) ]), context
def execute(self, context): """ Execute the action. Delegated to :meth:`launch.actions.ExecuteProcess.execute`. """ actions = super().execute(context) if not self.__timeout: return actions self.__timer = TimerAction(period=self.__timeout, actions=[ OpaqueFunction( function=self._shutdown_process, kwargs={'send_sigint': True}) ]) on_process_exit_event = OnProcessExit(on_exit=self.__on_process_exit, target_action=self) context.register_event_handler(on_process_exit_event) if not actions: return [self.__timer] return actions.append(self.__timer)