def grab_cup(): """ After reaching the cup intersection, the robot should turn around and go backwards until it reaches he intersection again, the robot should then pickup a cup. """ value = follow_line_with_gyro_recorded() forward_adjust() robot.stop() time.sleep(0.1) robot.rotate_by_degree_special(target=value + 178) robot.stop() #lift down a bit less so the grabber clears the stand robot.lift_down(position_offset=285, blocking=False) robot.set_ramp_value(7000) backwards_moving_using_gyro(value + 178) robot.reset_ramp_value() robot.stop() robot.close_grabber(long=True) robot.lift_up() robot.straight_line_moving(duration=1100) time.sleep(1.2) try: client_socket.send('X') except: pass
def grab_cup(): """ After reaching the cup intersection, the robot should turn around and go backwards until it reaches he intersection again, the robot should then pickup a cup. """ value = follow_line_with_gyro_recorded() print(value) # robot.straight_line_moving(speed = 150, duration = 2000) # time.sleep(2) forward_adjust() robot.rotate_by_degree_special(target = value + 140, speed = 250) robot.rotate_by_degree_special(target = value + 170, speed = 100) robot.stop() #turn_around(direction='right', slow_end = True) #lift down a bit less so the grabber clears the stand robot.lift_down(position_offset = 285) backwards_moving_using_gyro(value + 180) #backwards_until_intersection() robot.stop() robot.close_grabber() robot.lift_up() robot.straight_line_moving(duration = 1000) time.sleep(1) try: client_socket.send('X') except: pass
def proxy_handler(client_socket, remote_host, remote_port, receive_first): # connect to the remote host remote_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) remote_socket.connect((remote_host, remote_port)) # remote data from the remote end if necessary if receive_first: remote_buffer = receive_from(remote_socket) hexdump(remote_buffer) # send it our response proxy_handler remote_buffer = response_handler(remote_buffer) # if we have data to send out local cliente, send it if len(remote_buffer): print('[<==] sending %d bytes to localhost' % len(remote_buffer)) client_socket.send(remote_buffer) # now lets loop and read from localhost # send to remote, send to local # rinse,wash, repeat while True: # read from local local host local_buffer = receive_from(client_socket) if len(local_buffer): print('[==>] Received %d butes from localhost.' % len(local_buffer)) hexdump(local_buffer) # send it to our request handler local_buffer = request_handler(local_buffer) # send off the data to the remote local_host remote_socket.send(local_buffer) print('[==>] Sent to remote') # receive back the response remote_buffer = receiver_from(remote_socket) if len(remote_buffer): print('[<==] Received %d bytes from remote' % len(remote_buffer)) hexdump(remote_buffer) # send to our response proxy_handler remote_buffer = response_handler(remote_buffer) # send the response to tha local socket client_socket.send(remote_buffer) print('[<==] Sent to localhost') # if no more data on eiteher side, close the connections if no len(local_buffer) or not len(remote_buffer): client_socket.close() remote_socket.close() print('[*] No more data. Closing connections') break
def handle_client(client_socket): request = client_socket.recv(1024) try: text_file = open("output.txt", "a") # append instead of w = write text_file.write("Received: %s" % request) text_file.close() except: print("Error while receiving") print "[*] Received: %s" % request client_socket.send("ACK!") client_socket.close()
def run(self): send(localPicPath, self.generatePicName()) # 图片发送成功之后就要开始开始等待新的图片了到来了,这里要开启一个定时器,因为定时向服务器请求图片是否处理成功 self.startWaitRePicFla.emit()