def generate_launch_description(): executable = ExecutableInPackage(package='tf2_ros', executable='static_transform_publisher') exec_sick_scan2 = ExecutableInPackage(package='sick_scan2', executable='sick_generic_caller') ############################################################################################ # # modify your settings here: # print( "##########################################################################" ) print( "# ROS2 Driver for SICK SCANNER (SET YOUR SETTING ACCORDING TO YOUR SETUP!" ) print( "##########################################################################" ) print("Your Settings:") hostname = '192.168.0.71' port = "2112" name = "sick_tim_5xx" print("hostname [IP-address of scanner ]: " + hostname) print("port [IP-port of scanner ]: " + port) print("name [to identify scanner type]: " + name) print( "##########################################################################" ) print("# STARTING NODE") print( "##########################################################################" ) # TODO(wjwwood): Use a substitution to find share directory once this is implemented in launch urdf = os.path.join(get_package_share_directory('sick_scan2'), 'launch', 'single_rrbot.urdf') yamlFileName = os.path.join(get_package_share_directory('sick_scan2'), 'launch', 'sick_tim_5xx.yaml') # Yaml-File reserved for future use ... return LaunchDescription([ LogInfo(msg=['Try to start world <-> laser']), launch.actions.ExecuteProcess( cmd=[executable, '0', '0', '0', '0', '0', '0', 'world', 'laser'], output='screen'), # # YAML-File support seems to be buggy. ros2 param crashes ... # launch.actions.ExecuteProcess( # cmd=[exec_sick_scan2, '__params:='+yamlFileName], output='screen'), launch.actions.ExecuteProcess(cmd=[ exec_sick_scan2, '__hostname:=' + hostname + " __port:=" + port + " __name:=" + name ], output='screen') ])
def generate_launch_description(): x = LaunchConfiguration('x', default='0.0') y = LaunchConfiguration('y', default='0.0') z = LaunchConfiguration('z', default='1.0') urdf_file = PathJoinSubstitution( [FindPackageShare('rexrov2_description'), 'robots', 'rexrov2_default.xacro']) gazebo = ExecuteProcess( cmd=['gazebo', '--verbose', '-s', 'libgazebo_ros_factory.so'], output='screen') rsp = Node( package='robot_state_publisher', executable='robot_state_publisher', name='robot_state_publisher', output='screen', parameters=[{ 'robot_description': Command([ ExecutableInPackage(package='xacro', executable='xacro'), ' ', urdf_file ]) }]) spawn_entity = Node( package='gazebo_ros', executable='spawn_entity.py', arguments=[ '-entity', 'rexrov2', '-topic', '/robot_description', '-x', x, '-y', y, '-z', z], output='screen') return LaunchDescription([ gazebo, rsp, spawn_entity, ])
def generate_launch_description(): executable = ExecutableInPackage(package='topic_monitor', executable='data_publisher') return LaunchDescription([ launch.actions.ExecuteProcess( cmd=[executable, 'sensor', '--best-effort'], output='screen'), launch.actions.ExecuteProcess( cmd=[executable, 'critical'], output='screen'), ])
def apply( self, context: LaunchContext, node_descriptions: List[SandboxedNode] ) -> Action: """Apply the policy any launches the ROS2 nodes in the sandbox.""" user = self.run_as pw_record = pwd.getpwuid(user.uid) env = os.environ.copy() env['HOME'] = pw_record.pw_dir env['LOGNAME'] = pw_record.pw_name env['USER'] = pw_record.pw_name self.__logger.debug('Running as: {}'.format(pw_record.pw_name)) self.__logger.debug('\tuid: {}'.format(user.uid)) self.__logger.debug('\tgid: {}'.format(user.gid)) self.__logger.debug('\thome: {}'.format(pw_record.pw_dir)) def set_user() -> None: """Set the current user.""" os.setgid(user.gid) os.setuid(user.uid) for description in node_descriptions: package_name = perform_substitutions( context, description.package ) executable_name = perform_substitutions( context, description.node_executable ) # TODO: support node namespace and node name # TODO: support parameters # TODO: support remappings cmd = [ExecutableInPackage( package=package_name, executable=executable_name ).perform(context)] self.__logger.info('Running: {}'.format(cmd)) subprocess.Popen( cmd, preexec_fn=set_user, env=env ) # TODO: handle events for process # TODO: LaunchAsUser is currently NO-OP due to all sandboxing logic being handled here. return LoadRunAsNodes()
def generate_launch_description(): # Initialize launch description launch_description = LaunchDescription() # Declare arguments launch_description.add_action( DeclareLaunchArgument(name='xacro_file', description='Target xacro file.')) launch_description.add_action( DeclareLaunchArgument(name='rviz_config', description='Rviz config file.', default_value=PathJoinSubstitution([ FindPackageShare('xacro_live'), 'rviz/view_robot.rviz' ]))) # Add nodes launch_description.add_action( Node(package='xacro_live', executable='xacro_live', name='xacro_live', output='screen', parameters=[{ 'xacro_file': LaunchConfiguration('xacro_file') }])) launch_description.add_action( Node(package='robot_state_publisher', executable='robot_state_publisher', name='robot_state_publisher', output='screen', parameters=[{ 'robot_description': Command([ ExecutableInPackage(package='xacro', executable='xacro'), ' ', LaunchConfiguration('xacro_file') ]) }])) launch_description.add_action( Node( package='joint_state_publisher_gui', executable='joint_state_publisher_gui', name='joint_state_publisher_gui', output='screen', ), ) launch_description.add_action( Node(package='rviz2', executable='rviz2', name='rviz', output='screen', arguments=['-d', LaunchConfiguration('rviz_config')]), ) return launch_description
def create_data_publisher_action(size, depth): name = '{0}_depth_{1}'.format(size, depth) payload = 0 if size == 'small' else 100000 executable = ExecutableInPackage(package='topic_monitor', executable='data_publisher') return launch.actions.ExecuteProcess( cmd=[ executable, name, '--depth', str(depth), '--payload-size', str(payload) ], output='screen', )
def generate_launch_description(): executable = ExecutableInPackage(package='topic_monitor', executable='data_publisher') return LaunchDescription([ launch.actions.ExecuteProcess( cmd=[executable, 'small', '--payload-size', '1', '--period', '4'], output='screen'), launch.actions.ExecuteProcess( cmd=[executable, 'medium', '--payload-size', '50000', '--period', '4'], output='screen'), launch.actions.ExecuteProcess( cmd=[executable, 'large', '--payload-size', '100000', '--period', '4'], output='screen'), launch.actions.ExecuteProcess( cmd=[executable, 'xlarge', '--payload-size', '150000', '--period', '4'], output='screen'), ])
def __init__(self, *, package: SomeSubstitutionsType, node_executable: SomeSubstitutionsType, node_name: Optional[SomeSubstitutionsType] = None, node_namespace: SomeSubstitutionsType = '', parameters: Optional[SomeParameters] = None, remappings: Optional[SomeRemapRules] = None, arguments: Optional[Iterable[SomeSubstitutionsType]] = None, **kwargs) -> None: """ Construct an Node action. Many arguments are passed eventually to :class:`launch.actions.ExecuteProcess`, so see the documentation of that class for additional details. However, the `cmd` is not meant to be used, instead use the `node_executable` and `arguments` keyword arguments to this function. This action, once executed, delegates most work to the :class:`launch.actions.ExecuteProcess`, but it also converts some ROS specific arguments into generic command line arguments. The launch_ros.substitutions.ExecutableInPackage substitution is used to find the executable at runtime, so this Action also raise the exceptions that substituion can raise when the package or executable are not found. If the node_name is not given (or is None) then no name is passed to the node on creation and instead the default name specified within the code of the node is used instead. The node_namespace can either be absolute (i.e. starts with /) or relative. If absolute, then nothing else is considered and this is passed directly to the node to set the namespace. If relative, the namespace in the 'ros_namespace' LaunchConfiguration will be prepended to the given relative node namespace. If no node_namespace is given, then the default namespace `/` is assumed. The parameters are passed as a list, with each element either a yaml file that contains parameter rules (string or pathlib.Path to the full path of the file), or a dictionary that specifies parameter rules. Keys of the dictionary can be strings or an iterable of Substitutions that will be expanded to a string. Values in the dictionary can be strings, integers, floats, or tuples of Substitutions that will be expanded to a string. Additionally, values in the dictionary can be lists of the aforementioned types, or another dictionary with the same properties. A yaml file with the resulting parameters from the dictionary will be written to a temporary file, the path to which will be passed to the node. Multiple dictionaries/files can be passed: each file path will be passed in in order to the node (where the last definition of a parameter takes effect). :param: package the package in which the node executable can be found :param: node_executable the name of the executable to find :param: node_name the name of the node :param: node_namespace the ros namespace for this Node :param: parameters list of names of yaml files with parameter rules, or dictionaries of parameters. :param: remappings ordered list of 'to' and 'from' string pairs to be passed to the node as ROS remapping rules :param: arguments list of extra arguments for the node """ cmd = [ ExecutableInPackage(package=package, executable=node_executable) ] cmd += [] if arguments is None else arguments # Reserve space for ros specific arguments. # The substitutions will get expanded when the action is executed. cmd += ['--ros-args' ] # Prepend ros specific arguments with --ros-args flag if node_name is not None: cmd += [ '-r', LocalSubstitution("ros_specific_arguments['name']", description='node name') ] if parameters is not None: ensure_argument_type(parameters, (list), 'parameters', 'Node') # All elements in the list are paths to files with parameters (or substitutions that # evaluate to paths), or dictionaries of parameters (fields can be substitutions). i = 0 for param in parameters: cmd += [ LocalSubstitution( "ros_specific_arguments['params'][{}]".format(i), description='parameter {}'.format(i)) ] i += 1 normalized_params = normalize_parameters(parameters) if remappings is not None: i = 0 for remapping in normalize_remap_rules(remappings): k, v = remapping cmd += [ '-r', LocalSubstitution( "ros_specific_arguments['remaps'][{}]".format(i), description='remapping {}'.format(i)) ] i += 1 super().__init__(cmd=cmd, **kwargs) self.__package = package self.__node_executable = node_executable self.__node_name = node_name self.__node_namespace = node_namespace self.__parameters = [] if parameters is None else normalized_params self.__remappings = [] if remappings is None else remappings self.__arguments = arguments self.__expanded_node_name = '<node_name_unspecified>' self.__expanded_node_namespace = '' self.__final_node_name = None # type: Optional[Text] self.__expanded_parameter_files = None # type: Optional[List[Text]] self.__expanded_remappings = None # type: Optional[List[Tuple[Text, Text]]] self.__substitutions_performed = False self.__logger = launch.logging.get_logger(__name__)
def __init__(self, *, executable: Optional[SomeSubstitutionsType] = None, node_executable: Optional[SomeSubstitutionsType] = None, package: Optional[SomeSubstitutionsType] = None, name: Optional[SomeSubstitutionsType] = None, namespace: Optional[SomeSubstitutionsType] = None, node_name: Optional[SomeSubstitutionsType] = None, node_namespace: SomeSubstitutionsType = None, exec_name: Optional[SomeSubstitutionsType] = None, parameters: Optional[SomeParameters] = None, remappings: Optional[SomeRemapRules] = None, arguments: Optional[Iterable[SomeSubstitutionsType]] = None, **kwargs) -> None: """ Construct an Node action. Many arguments are passed eventually to :class:`launch.actions.ExecuteProcess`, so see the documentation of that class for additional details. However, the `cmd` is not meant to be used, instead use the `executable` and `arguments` keyword arguments to this function. This action, once executed, delegates most work to the :class:`launch.actions.ExecuteProcess`, but it also converts some ROS specific arguments into generic command line arguments. The launch_ros.substitutions.ExecutableInPackage substitution is used to find the executable at runtime, so this Action also raise the exceptions that substituion can raise when the package or executable are not found. If the name is not given (or is None) then no name is passed to the node on creation and instead the default name specified within the code of the node is used instead. The namespace can either be absolute (i.e. starts with /) or relative. If absolute, then nothing else is considered and this is passed directly to the node to set the namespace. If relative, the namespace in the 'ros_namespace' LaunchConfiguration will be prepended to the given relative node namespace. If no namespace is given, then the default namespace `/` is assumed. The parameters are passed as a list, with each element either a yaml file that contains parameter rules (string or pathlib.Path to the full path of the file), or a dictionary that specifies parameter rules. Keys of the dictionary can be strings or an iterable of Substitutions that will be expanded to a string. Values in the dictionary can be strings, integers, floats, or tuples of Substitutions that will be expanded to a string. Additionally, values in the dictionary can be lists of the aforementioned types, or another dictionary with the same properties. A yaml file with the resulting parameters from the dictionary will be written to a temporary file, the path to which will be passed to the node. Multiple dictionaries/files can be passed: each file path will be passed in in order to the node (where the last definition of a parameter takes effect). .. deprecated:: Foxy Parameters `node_executable`, `node_name`, and `node_namespace` are deprecated. Use `executable`, `name`, and `namespace` instead. :param: executable the name of the executable to find if a package is provided or otherwise a path to the executable to run. :param: node_executable (DEPRECATED) the name of the executable to find if a package is provided or otherwise a path to the executable to run. :param: package the package in which the node executable can be found :param: name the name of the node :param: namespace the ROS namespace for this Node :param: exec_name the label used to represent the process. Defaults to the basename of node executable. :param: node_name (DEPRECATED) the name of the node :param: node_namespace (DEPRECATED) the ros namespace for this Node :param: parameters list of names of yaml files with parameter rules, or dictionaries of parameters. :param: remappings ordered list of 'to' and 'from' string pairs to be passed to the node as ROS remapping rules :param: arguments list of extra arguments for the node """ if node_executable is not None: warnings.warn( "The parameter 'node_executable' is deprecated, use 'executable' instead", stacklevel=2) if executable is not None: raise RuntimeError( "Passing both 'node_executable' and 'executable' parameters. " "Only use 'executable'") executable = node_executable if package is not None: cmd = [ExecutableInPackage(package=package, executable=executable)] else: cmd = [executable] cmd += [] if arguments is None else arguments # Reserve space for ros specific arguments. # The substitutions will get expanded when the action is executed. cmd += ['--ros-args' ] # Prepend ros specific arguments with --ros-args flag if node_name is not None: warnings.warn( "The parameter 'node_name' is deprecated, use 'name' instead", stacklevel=2) if name is not None: raise RuntimeError( "Passing both 'node_name' and 'name' parameters. Only use 'name'." ) cmd += [ '-r', LocalSubstitution("ros_specific_arguments['name']", description='node name') ] name = node_name if name is not None: cmd += [ '-r', LocalSubstitution("ros_specific_arguments['name']", description='node name') ] if node_namespace: warnings.warn( "The parameter 'node_namespace' is deprecated, use 'namespace' instead" ) if namespace: raise RuntimeError( "Passing both 'node_namespace' and 'namespace' parameters. " "Only use 'namespace'.") namespace = node_namespace if parameters is not None: ensure_argument_type(parameters, (list), 'parameters', 'Node') # All elements in the list are paths to files with parameters (or substitutions that # evaluate to paths), or dictionaries of parameters (fields can be substitutions). normalized_params = normalize_parameters(parameters) # Forward 'exec_name' as to ExecuteProcess constructor kwargs['name'] = exec_name super().__init__(cmd=cmd, **kwargs) self.__package = package self.__node_executable = executable self.__node_name = name self.__node_namespace = namespace self.__parameters = [] if parameters is None else normalized_params self.__remappings = [] if remappings is None else list( normalize_remap_rules(remappings)) self.__arguments = arguments self.__expanded_node_name = self.UNSPECIFIED_NODE_NAME self.__expanded_node_namespace = self.UNSPECIFIED_NODE_NAMESPACE self.__expanded_parameter_arguments = None # type: Optional[List[Tuple[Text, bool]]] self.__final_node_name = None # type: Optional[Text] self.__expanded_remappings = None # type: Optional[List[Tuple[Text, Text]]] self.__substitutions_performed = False self.__logger = launch.logging.get_logger(__name__)
def generate_launch_description(): #executable = ExecutableInPackage(package='tf2_ros', executable='static_transform_publisher') exec_sick_scan2 = ExecutableInPackage(package='sick_scan2', executable='sick_generic_caller') exec_sick_scan2_gdb = ExecutableInPackage(package='sick_scan2', executable='gdb') ############################################################################################ # # modify your settings here: # # TODO(wjwwood): Use a substitution to find share directory once this is implemented in launch urdf = os.path.join(get_package_share_directory('sick_scan2'), 'launch', 'single_rrbot.urdf') yamlFileName = os.path.join(get_package_share_directory('sick_scan2'), 'launch', 'sick_lms_5xx.yaml') with open(yamlFileName, 'r') as stream: try: yamlConf = yaml.load(stream) print(yaml.safe_load(stream)) except yaml.YAMLError as exc: print(exc) print( "##########################################################################" ) print( "# ROS2 Driver for SICK SCANNER (SET YOUR SETTING ACCORDING TO YOUR SETUP!" ) print( "##########################################################################" ) print("Your Settings:") #hostname = '192.168.0.151' #port = "2112"; #name = "sick_lms_5xx" #frameId = "laser" print(yaml.dump(yamlConf)) #print ("hostname [IP-address of scanner ]: " + hostname) #print ("port [IP-port of scanner ]: " + port) #print ("name [to identify scanner type]: " + name) print( "##########################################################################" ) print("# STARTING NODE") print( "##########################################################################" ) # Yaml-File reserved for future use ... return LaunchDescription([ #LogInfo(msg=[ # 'Try to start world <-> laser' #]), #launch.actions.ExecuteProcess( #cmd=[executable, '0','0','0','0','0','0','world','laser'], output='screen'), # # YAML-File support seems to be buggy. ros2 param crashes ... launch_ros.actions.Node(name='sick_lms_5xx', package='sick_scan2', executable='sick_generic_caller', parameters=[yamlFileName], output='screen') # __hostname:=192.168.0.151 __frame_id:=laser __port:=2112 --ros-args --remap __name:=sick_lms_5xx #launch.actions.ExecuteProcess( # cmd=[exec_sick_scan2, '__hostname:='+hostname ," __port:=" + port , " __frame_id:=" + frameId , "--ros-args --remap __name:=" + name], output='screen') # launch.actions.ExecuteProcess( # cmd=[exec_sick_scan2_gdb, '--args sick_generic_caller __hostname:='+hostname+ " __port:=" + port + " __frame_id:=" + frameId + " --ros-args --remap __name:=" + name], output='screen') ])
def __init__(self, *, package: SomeSubstitutionsType, node_executable: SomeSubstitutionsType, node_name: Optional[SomeSubstitutionsType] = None, node_namespace: Optional[SomeSubstitutionsType] = None, remappings: Optional[Iterable[Tuple[ SomeSubstitutionsType, SomeSubstitutionsType]]] = None, arguments: Optional[Iterable[SomeSubstitutionsType]] = None, **kwargs) -> None: """ Construct an Node action. Many arguments are passed eventually to :class:`launch.actions.ExecuteProcess`, so see the documentation of that class for additional details. However, the `cmd` is not meant to be used, instead use the `node_executable` and `arguments` keyword arguments to this function. This action, once executed, delegates most work to the :class:`launch.actions.ExecuteProcess`, but it also converts some ROS specific arguments into generic command line arguments. The launch_ros.substitutions.ExecutableInPackage substitution is used to find the executable at runtime, so this Action also raise the exceptions that substituion can raise when the package or executable are not found. If the node_name is not given (or is None) then no name is passed to the node on creation and instead the default name specified within the code of the node is used instead. The node_namespace can either be absolute (i.e. starts with /) or relative. If absolute, then nothing else is considered and this is passed directly to the node to set the namespace. If relative, the namespace in the 'ros_namespace' LaunchConfiguration will be prepended to the given relative node namespace. If no node_namespace is given, then the default namespace `/` is assumed. :param: package the package in which the node executable can be found :param: node_executable the name of the executable to find :param: node_name the name of the node :param: node_namespace the ros namespace for this Node :param: remappings ordered list of 'to' and 'from' string pairs to be passed to the node as ROS remapping rules :param: arguments list of extra arguments for the node """ cmd = [ ExecutableInPackage(package=package, executable=node_executable) ] cmd += [] if arguments is None else arguments # Reserve space for ros specific arguments. # The substitutions will get expanded when the action is executed. ros_args_index = 0 if node_name is not None: cmd += [ LocalSubstitution( 'ros_specific_arguments[{}]'.format(ros_args_index)) ] ros_args_index += 1 if node_namespace is not None: cmd += [ LocalSubstitution( 'ros_specific_arguments[{}]'.format(ros_args_index)) ] ros_args_index += 1 if remappings is not None: for k, v in remappings: cmd += [ LocalSubstitution( 'ros_specific_arguments[{}]'.format(ros_args_index)) ] ros_args_index += 1 super().__init__(cmd=cmd, **kwargs) self.__package = package self.__node_executable = node_executable self.__node_name = node_name self.__node_namespace = node_namespace self.__remappings = [] if remappings is None else remappings self.__arguments = arguments self.__expanded_node_name = '<node_name_unspecified>' self.__expanded_node_namespace = '/' self.__final_node_name = None # type: Optional[Text] self.__expanded_remappings = None # type: Optional[Dict[Text, Text]] self.__substitutions_performed = False