Go to the documentation of this file.00001
00002
00003
00004 import socket
00005 import sys
00006
00007 class RobotControlClient:
00008
00009 def __init__(self, host, port):
00010 self.host = host;
00011 self.port = port;
00012
00013
00014 def connect(self):
00015 try:
00016 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00017 except socket.error, msg:
00018 print("[ERROR] %s\n" % msg)
00019 sys.exit(1)
00020
00021 try:
00022 self.sock.connect((self.host, self.port))
00023 except socket.error, msg:
00024 print("[ERROR] %s\n" % msg)
00025 sys.exit(2)
00026
00027
00028 def disconnect(self):
00029 self.sock.close()
00030
00031
00032
00033 def moveForward(self, speed):
00034 self.sendData("SetSpeed %f 0" % speed);
00035
00036
00037
00038 def moveBackward(self, speed):
00039 self.sendData("SetSpeed %f 0" % -speed);
00040
00041
00042
00043 def turnLeft(self, speed):
00044 self.sendData("SetSpeed 0 %f" % speed);
00045
00046
00047
00048 def turnRight(self, speed):
00049 self.sendData("SetSpeed 0 %f" % -speed);
00050
00051
00052
00053
00054
00055
00056
00057 def customMovement(self, forwardSpeed, yaw):
00058 self.sendData("SetSpeed %f %f" % (forwardSpeed, yaw));
00059
00060
00061 def stop(self):
00062 self.sendData("SetSpeed 0 0");
00063
00064
00065 def sendData(self, dataString):
00066 self.sock.send(chr(len(dataString)) + dataString)