コード例 #1
0
import time
import random
from pointer import Pointer

print("Starting")
def randpan():
    return random.randrange(1400, 1600)

def randtilt():
    return random.randrange(1800, 2000)

def randsleep():
    time.sleep(random.uniform(0.5, 3))

pointer = Pointer()
try:
    while True:
        pointer.position(randpan(), randtilt())
        randsleep()
except KeyboardInterrupt:
    pass # it's ok
finally:
    print("Clean up and exit.")
    pointer.cleanup()

print("Done")
コード例 #2
0
	(pan, tilt) = q.pop()
	if (pan, tilt) in visited:
		continue

	visited.add((pan, tilt))
	p.position(pan, tilt)
	time.sleep(DELAY)
	xy = c.detect_pointer()

	if not xy:
		continue

	(x, y) = xy
	datamap[(x, y)] = (pan, tilt)
	for pp in [pan - STEP, pan + STEP]:
		for tt in [tilt - STEP, tilt + STEP]:
			if (pp, tt) not in visited:
				print("enqueue ", (pp, tt))
				q.append((pp, tt))
			else:
				print("ignore ", (pp, tt))

print("Done scanning. Collected entries: ", len(datamap))
print("Saving to ", FILE)
with open(FILE, 'wb') as file:
	pickle.dump(datamap, file)

print("Done")
c.cleanup()
p.cleanup()
コード例 #3
0
ファイル: web_server.py プロジェクト: pshabunia/experimental
        self.send_response(200)
        self.send_header('Content-Type', 'text/html')
        self.end_headers()
        self.wfile.write(bytearray(f.read(), 'utf-8'))
        f.close()

    def position(self):
        query_params = parse_qs(urlparse(self.path).query)
        x = int(query_params['x'][0])
        y = int(query_params['y'][0])
        (pan, tilt) = SERVO_MAP.query(x, y)
        POINTER.position(pan, tilt)
        self.send_response(200)
        self.end_headers()
        self.wfile.write(b'Ok')

    def not_found(self):
        self.send_error(404, 'Robots not found')


if __name__ == '__main__':
    httpd = HTTPServer((HOSTNAME, PORT), RequestHandler)
    print('Server Starts - {}:{}'.format(HOSTNAME, PORT))
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        pass
    POINTER.cleanup()
    httpd.server_close()
    print('Server Stops - {}:{}'.format(HOSTNAME, PORT))