12 DEFAULT_MOVE_TIME = 1.5
15 FORWARD_ALIAS =
'forward' 16 BACKWARD_ALIAS =
'backward' 29 rospy.init_node(
'teleop')
30 roslib.load_manifest(
'pioneer_teleop')
32 if (len(sys.argv) > 1):
33 port = int(sys.argv[1])
39 if (len(sys.argv) > 2):
40 speed = float(sys.argv[2])
45 elif (speed > MAX_SPEED):
48 if (len(sys.argv) > 3):
49 moveTime = float(sys.argv[3])
53 moveTime = DEFAULT_MOVE_TIME
58 serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
59 serverSocket.bind((
'',port))
60 serverSocket.listen(queue)
62 print " - Listening for network communications in port " + str(port) +
"...\n" 65 print " - Waiting for client...\n" 66 clientSocket, address = serverSocket.accept()
67 command = clientSocket.recv(bufferSize)
68 if (command ==
'forward')
or (command == FORWARD_ALIAS):
69 print " >> Command recieved: move forward\n" 70 os.system(
"rosrun pioneer_teleop commandline_teleop.py forward " + str(speed) +
" " + str(moveTime))
71 elif (command ==
'backward')
or (command == BACKWARD_ALIAS):
72 print " >> Command recieved: move backward\n" 73 os.system(
"rosrun pioneer_teleop commandline_teleop.py backward " + str(speed) +
" " + str(moveTime))
74 elif (command ==
'right')
or (command == RIGHT_ALIAS):
75 print " >> Command recieved: move right\n" 76 os.system(
"rosrun pioneer_teleop commandline_teleop.py right " + str(speed) +
" " + str(moveTime))
77 elif (command ==
'left')
or (command == LEFT_ALIAS):
78 print " >> Command recieved: move left\n" 79 os.system(
"rosrun pioneer_teleop commandline_teleop.py left " + str(speed) +
" " + str(moveTime))
81 print " >> Error: Command '" + command +
"' not recognized !\n" 82 print " Please use " + str(FORWARD_ALIAS) +
"," + str(BACKWARD_ALIAS) +
"," + str(LEFT_ALIAS) +
" or " + str(RIGHT_ALIAS) +
"."