Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 MAX_SPEED = 0.4
00012 DEFAULT_MOVE_TIME = 1.5
00013 DEFAULT_PORT = 50001
00014
00015 FORWARD_ALIAS = 'forward'
00016 BACKWARD_ALIAS = 'backward'
00017 LEFT_ALIAS = 'left'
00018 RIGHT_ALIAS = 'right'
00019
00020
00021
00022
00023
00024 import roslib
00025 import rospy
00026 import socket
00027 import sys
00028 import os
00029 rospy.init_node('teleop')
00030 roslib.load_manifest('pioneer_teleop')
00031
00032 if (len(sys.argv) > 1):
00033 port = int(sys.argv[1])
00034 if (port <= 0):
00035 port = DEFAULT_PORT
00036 else:
00037 port = DEFAULT_PORT
00038
00039 if (len(sys.argv) > 2):
00040 speed = float(sys.argv[2])
00041 else:
00042 speed = 0
00043 if (speed <= 0):
00044 speed = 0.2
00045 elif (speed > MAX_SPEED):
00046 speed = MAX_SPEED
00047
00048 if (len(sys.argv) > 3):
00049 moveTime = float(sys.argv[3])
00050 else:
00051 moveTime = 0.0
00052 if (moveTime <= 0):
00053 moveTime = DEFAULT_MOVE_TIME
00054
00055 host = ''
00056 queue = 5
00057 bufferSize = 256
00058 serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00059 serverSocket.bind(('',port))
00060 serverSocket.listen(queue)
00061
00062 print " - Listening for network communications in port " + str(port) + "...\n"
00063
00064 while 1:
00065 print " - Waiting for client...\n"
00066 clientSocket, address = serverSocket.accept()
00067 command = clientSocket.recv(bufferSize)
00068 if (command == 'forward') or (command == FORWARD_ALIAS):
00069 print " >> Command recieved: move forward\n"
00070 os.system("rosrun pioneer_teleop commandline_teleop.py forward " + str(speed) + " " + str(moveTime))
00071 elif (command == 'backward') or (command == BACKWARD_ALIAS):
00072 print " >> Command recieved: move backward\n"
00073 os.system("rosrun pioneer_teleop commandline_teleop.py backward " + str(speed) + " " + str(moveTime))
00074 elif (command == 'right') or (command == RIGHT_ALIAS):
00075 print " >> Command recieved: move right\n"
00076 os.system("rosrun pioneer_teleop commandline_teleop.py right " + str(speed) + " " + str(moveTime))
00077 elif (command == 'left') or (command == LEFT_ALIAS):
00078 print " >> Command recieved: move left\n"
00079 os.system("rosrun pioneer_teleop commandline_teleop.py left " + str(speed) + " " + str(moveTime))
00080 else:
00081 print " >> Error: Command '" + command + "' not recognized !\n"
00082 print " Please use " + str(FORWARD_ALIAS) + "," + str(BACKWARD_ALIAS) + "," + str(LEFT_ALIAS) + " or " + str(RIGHT_ALIAS) + "."
00083 clientSocket.close()