robot.py
Go to the documentation of this file.
00001 
00002 #! /usr/bin/env python
00003 
00004 import socket
00005 import sys
00006 
00007 class RobotControlClient:
00008         # Constructor that initializes Robot's IP and port
00009         def __init__(self, host, port):
00010                 self.host = host;
00011                 self.port = port;
00012                 
00013         # Connect to the Robot
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         # Disconnect from the Robot
00028         def disconnect(self):
00029                 self.sock.close()
00030         
00031         # Move straight forward
00032         # @param speed meters / second
00033         def moveForward(self, speed):
00034                 self.sendData("SetSpeed %f 0" % speed);
00035                 
00036         # Move staight backward
00037         # @param speed meters / second
00038         def moveBackward(self, speed):
00039                 self.sendData("SetSpeed %f 0" % -speed);
00040                 
00041         # Turn in place couter clockwise
00042         # @param speed radians / second
00043         def turnLeft(self, speed):
00044                 self.sendData("SetSpeed 0 %f" % speed);
00045                 
00046         # Turn in place clockwise
00047         # @param speed radians / second
00048         def turnRight(self, speed):
00049                 self.sendData("SetSpeed 0 %f" % -speed);
00050 #               
00051 #       def mv(self,(x,y)):
00052 #               self.pos=(self.pos[0]+x,self.pos[1]+y,self.pos[2])
00053 
00054         # Custom movements
00055         # @param forwardSpeed in meters / second (negitive is reverse)
00056         # @yaw rotation in radians / second
00057         def customMovement(self, forwardSpeed, yaw):
00058                 self.sendData("SetSpeed %f %f" % (forwardSpeed, yaw));
00059                 
00060         # Stop the Robot
00061         def stop(self):
00062                 self.sendData("SetSpeed 0 0");
00063                 
00064         # Private Methods
00065         def sendData(self, dataString):
00066                 self.sock.send(chr(len(dataString)) + dataString)


tcp_command
Author(s): Hunter Allen
autogenerated on Mon Oct 6 2014 08:35:12