Example #1
0
def TurtleTurn(actions, x, y, heading, steps):
    """ Educational example, not actually useful.
    
    Equivalent roughly to the following python:
    (assuming x,y -> r, theta in polar coordinates)
    for i in xrange(steps):
        forward(r)
        right(theta)
    or logo:
    repeat steps: [fd r rt theta]
    
    How to use:
    >>> ApproachXY(actions, 100, 0, 3).onDone(pr("I'm done walking in circles!"))
    
    """
    remaining = [steps]

    def target_pos_callback():
        if remaining[0] <= 0:
            return None  # signals stopping
        else:
            remaining[0] -= 1
            return x, y, heading

    return Approacher(actions, lambda: succeed(target_pos_callback()))
Example #2
0
 def _sendRequest(self, o):
     """ sends a request, returns a Deferred, which you can do addCallback on.
     If this is in fact synchronous, your callback will be called immediately,
     otherwise it will be called upon availability of data from socket.
     """
     if self.s is None:
         self.s = socket.socket()
         self.s.connect((self._message_maker._host, self._message_maker._port))
     s = self.s
     tosend = self._message_maker.make(o, keepalive=True)
     if DEBUG:
         print "***     Sending:     ***\n%s" % tosend
     s.send(tosend)
     # get headers, read size, read the rest
     h = []
     c = None
     if DEBUG:
         print "receiving:"
     while c != '<':
         c = s.recv(1)
         if DEBUG:
             sys.stdout.write(c)
             sys.stdout.flush()
         h.append(c)
     if DEBUG:
         print
     headers = ''.join(h[:-1])
     content_length = self.contentLengthFromHeaders(headers)
     # Connection: close
     close_socket = self.closeSocketFromHeaders(headers)
     if close_socket and DEBUG_CLOSE:
         print "Will close socket"
     if DEBUG:
         print "expecting %s" % content_length
     # this loop is required for getting large stuff, like
     # getRemoteImage (1200000~ bytes for 640x480 RGB)
     rest = []
     left = content_length - 1
     while left > 0:
         rest.append(s.recv(content_length-1))
         left -= len(rest[-1])
     if DEBUG:
         print "memory = %s" % memory.memory()
     body = h[-1] + ''.join(rest)
     if DEBUG:
         print "***     Got:          ***\n%s" % compresstoprint(
                                             headers + body, 1000, 1000)
         print "*************************"
     if close_socket:
         self.s.close()
         self.s = None
     xml = minidom.parseString(body)
     soapbody = xml.documentElement.firstChild
     return succeed(soapbody)
Example #3
0
 def _onNormalQuit_playerStopDone(self):
     naoqi_ok = self._on_normal_quit__naoqi_ok
     self._eventmanager._removeAllPendingCallbacks()
     d = succeed(None)
     if self._actions:
         if burst.options.passive_ctrl_c:# or not self._world.connected_to_nao:
             info( "BasicMainLoop: exiting")
         else:
             if naoqi_ok:
                 info( "BasicMainLoop: sitting, removing stiffness and quitting.")
                 d = self._actions.sitPoseAndRelax_returnDeferred()
         self._world._gameController.shutdown() # in parallel to sitting
     self.__running_instance = None
     return d
Example #4
0
 def subscribeToCamera(self,
         resolution=vision_definitions.kQVGA,
         colorspace=vision_definitions.kYUV422InterlacedColorSpace,
         fps=15):
     """ Default parameters are exactly what nao-man (northern bites) use:
     YUV422 color space, 320x240 (Quarter VGA), and 15 fps
     """
     if self._subscribed_to_camera:
         return succeed(self._camera_name)
     self._camera_resolution = resolution
     self._camera_colorspace = colorspace
     if is_120:
         meth = self.CameraModule.register
     else:
         meth = self.CameraModule.subscribe
     d = meth(self._camera_name, resolution, colorspace, fps)
     d.addCallback(self._onRegisterToCamera)
     return d
Example #5
0
 def makeHelp(self):
     if self._has_docs:
         return succeed(None)
     d = self._getDocs()
     self._getting_docs = True
     return d