def wait_for(node, namespace=None, timeout=None): """ Wait for ROS node up. @param node: node name @type node: str """ from rospy.names import canonicalize_name node = canonicalize_name(node) def is_node_up(node): try: node_up = any([node in upnode for upnode in rosnode.get_node_names(namespace)]) return node_up except Exception: return False if not is_node_up(node): if timeout is not None: timeout_t = time.time() + timeout while not is_node_up(node): time.sleep(0.1) if time.time() >= timeout_t: raise rospy.exceptions.ROSException("timeout exceeded while waiting for node %s" % node) else: while not is_node_up(node): time.sleep(0.1)
def test_canonicalize_name(self): from rospy.names import canonicalize_name tests = [ ('', ''), ('/', '/'), ('foo', 'foo'), ('/foo', '/foo'), ('/foo/', '/foo'), ('/foo/bar', '/foo/bar'), ('/foo/bar/', '/foo/bar'), ('/foo/bar//', '/foo/bar'), ('/foo//bar', '/foo/bar'), ('//foo/bar', '/foo/bar'), ('foo/bar', 'foo/bar'), ('foo//bar', 'foo/bar'), ('foo/bar/', 'foo/bar'), ('/foo/bar', '/foo/bar'), ] for t, v in tests: self.assertEquals(v, canonicalize_name(t))
def test_canonicalize_name(self): from rospy.names import canonicalize_name tests = [ ("", ""), ("/", "/"), ("foo", "foo"), ("/foo", "/foo"), ("/foo/", "/foo"), ("/foo/bar", "/foo/bar"), ("/foo/bar/", "/foo/bar"), ("/foo/bar//", "/foo/bar"), ("/foo//bar", "/foo/bar"), ("//foo/bar", "/foo/bar"), ("foo/bar", "foo/bar"), ("foo//bar", "foo/bar"), ("foo/bar/", "foo/bar"), ("/foo/bar", "/foo/bar"), ] for t, v in tests: self.assertEquals(v, canonicalize_name(t))