コード例 #1
0
ファイル: node.py プロジェクト: hfz-Nick/ROS
    def __init__(self,
                 node_name,
                 *,
                 cli_args=None,
                 namespace=None,
                 use_global_arguments=True):
        self._handle = None
        self.publishers = []
        self.subscriptions = []
        self.clients = []
        self.services = []
        self.timers = []
        self.guards = []
        self._default_callback_group = MutuallyExclusiveCallbackGroup()

        namespace = namespace or ''
        if not ok():
            raise NotInitializedException('cannot create node')
        try:
            self._handle = _rclpy.rclpy_create_node(node_name, namespace,
                                                    cli_args,
                                                    use_global_arguments)
        except ValueError:
            # these will raise more specific errors if the name or namespace is bad
            validate_node_name(node_name)
            # emulate what rcl_node_init() does to accept '' and relative namespaces
            if not namespace:
                namespace = '/'
            if not namespace.startswith('/'):
                namespace = '/' + namespace
            validate_namespace(namespace)
            # Should not get to this point
            raise RuntimeError('rclpy_create_node failed for unknown reason')
        self._logger = get_logger(
            _rclpy.rclpy_get_node_logger_name(self.handle))
コード例 #2
0
def spin(node):
    # imported locally to avoid loading extensions on module import
    from rclpy.executors import SingleThreadedExecutor
    executor = SingleThreadedExecutor()
    try:
        executor.add_node(node)
        while ok():
            executor.spin_once()
    finally:
        executor.shutdown()
コード例 #3
0
ファイル: node.py プロジェクト: hemantku/rclpy
    def __init__(self,
                 node_name,
                 *,
                 cli_args=None,
                 namespace=None,
                 use_global_arguments=True,
                 start_parameter_services=True):
        self._handle = None
        self._parameters = {}
        self.publishers = []
        self.subscriptions = []
        self.clients = []
        self.services = []
        self.timers = []
        self.guards = []
        self._default_callback_group = MutuallyExclusiveCallbackGroup()
        self._parameters_callback = None

        namespace = namespace or ''
        if not ok():
            raise NotInitializedException('cannot create node')
        try:
            self._handle = _rclpy.rclpy_create_node(node_name, namespace,
                                                    cli_args,
                                                    use_global_arguments)
        except ValueError:
            # these will raise more specific errors if the name or namespace is bad
            validate_node_name(node_name)
            # emulate what rcl_node_init() does to accept '' and relative namespaces
            if not namespace:
                namespace = '/'
            if not namespace.startswith('/'):
                namespace = '/' + namespace
            validate_namespace(namespace)
            # Should not get to this point
            raise RuntimeError('rclpy_create_node failed for unknown reason')
        self._logger = get_logger(
            _rclpy.rclpy_get_node_logger_name(self.handle))

        # Clock that has support for ROS time.
        # TODO(dhood): use sim time if parameter has been set on the node.
        self._clock = ROSClock()
        self._time_source = TimeSource(node=self)
        self._time_source.attach_clock(self._clock)

        self.__executor_weakref = None

        if start_parameter_services:
            self._parameter_service = ParameterService(self)
コード例 #4
0
def spin(node):
    """
    Execute work blocking until the library is shutdown.

    Callbacks will be executed in a SingleThreadedExecutor until shutdown() is called.
    This method blocks.

    :param node: A node to add to the executor to check for work.
    :return: Always returns None regardless whether work executes or timeout expires.
    :rtype: None
    """
    executor = get_global_executor()
    try:
        executor.add_node(node)
        while ok():
            executor.spin_once()
    finally:
        executor.remove_node(node)
コード例 #5
0
ファイル: executors.py プロジェクト: hfz-Nick/ROS
 def spin_until_future_complete(self, future):
     """Execute until a given future is done."""
     while ok() and not future.done():
         self.spin_once()
コード例 #6
0
ファイル: executors.py プロジェクト: hfz-Nick/ROS
 def spin(self):
     """Execute callbacks until shutdown."""
     while ok():
         self.spin_once()