Created
February 15, 2019 11:27
-
-
Save 4noha/4be0ed1f0dd89d51fe287fe24588e783 to your computer and use it in GitHub Desktop.
Python2.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| import sys | |
| import signal | |
| import socket as skt | |
| import math | |
| from naoqi import ALProxy | |
| class UDPServer(): | |
| PORT = 7000 | |
| RECV_TIMEOUT_MSEC = 300 | |
| @classmethod | |
| def responder(self, MotionSender): | |
| inst = skt.socket(skt.AF_INET, skt.SOCK_DGRAM) | |
| inst.bind(('', UDPServer.PORT)) | |
| inst.setblocking(0) | |
| while True: | |
| try: | |
| data, adr = inst.recvfrom(UDPServer.RECV_TIMEOUT_MSEC) | |
| except skt.error: | |
| pass | |
| else: | |
| data = data.rstrip('\n') | |
| data = data.rstrip('\r') | |
| data = data.rstrip('\n') | |
| # | |
| rep = data | |
| if rep is None: | |
| continue | |
| print("ret:", rep) | |
| MotionSender.msg = rep.encode('utf8') | |
| MotionSender.say() | |
| MotionSender.forword() | |
| MotionSender.right_turn() | |
| class MotionSender(): | |
| #IP = "localhost" | |
| IP = "192.168.11.11" | |
| #PORT = 58966 | |
| PORT = 9559 | |
| MOVE = 0.1 | |
| TURN = math.radians(45) | |
| print(TURN) | |
| def __init__(self): | |
| print("IP:", MotionSender.IP, " PORT:", MotionSender.PORT) | |
| self.tts = ALProxy("ALTextToSpeech",MotionSender.IP, MotionSender.PORT) | |
| self.motion = ALProxy("ALMotion", MotionSender.IP, MotionSender.PORT) | |
| signal.signal(signal.SIGINT, self.gracefully_close) | |
| UDPServer.responder(self) | |
| def say(self): | |
| self.tts.say(self.msg) | |
| def forword(self): | |
| self.motion.moveTo(MotionSender.MOVE, 0.0, 0.0) | |
| def behind(self): | |
| self.motion.moveTo(-MotionSender.MOVE, 0.0, 0.0) | |
| def left(self): | |
| self.motion.moveTo(0.0, MotionSender.MOVE, 0.0) | |
| def right(self): | |
| self.motion.moveTo(0.0, -MotionSender.MOVE, 0.0) | |
| def right_turn(self): | |
| self.motion.moveTo(0.0, 0.0, -MotionSender.TURN) | |
| def left_turn(self): | |
| self.motion.moveTo(0.0, 0.0, MotionSender.TURN) | |
| def look_back(self): | |
| self.motion.moveTo(0.0, 0.0, math.radians(180)) | |
| def gracefully_close(self, signal, frame): | |
| sys.exit(0) | |
| MotionSender() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment