Repository navigation
Expand file tree
/
Copy pathEddieDrive.py
More file actions
97 lines (73 loc) · 2.27 KB
/
Copy pathEddieDrive.py
File metadata and controls
97 lines (73 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
'''
This is a script to 'drive' Eddie via keyboard input
Usage:
> python EddieDrive.py
*** NOTE ***
This script does not work within the Enthought Canopy environment.
It must be run from the command line via: python EddieDrive.py
It is also currently only works on Windows too, sorry.
'''
# WARNING # - Getch is a Windows only function. Similar functionality
# is available on Linux/MacOS.
from msvcrt import getch, kbhit
import sys
from time import sleep
# This is the IP address for my Eddie, yours will probably be different
# OLD USAGE --> MyEddie = PyEddiePlus.EddiePlus("Edward","192.168.1.111")
import PyEddiePlus
MyEddie = PyEddiePlus.EddiePlus("Edward")
MyEddie.FindEddie()
MyEddie.InitializeEddie()
print "Use a,d,w & x to drive Eddie"
print "Press q to Quit"
print
sys.stdout.flush()
MaxSpeed = 10
MaxTurn = 6
SpeedVal = 0
TurnVal = 0
KeyPress = 's'
while KeyPress is not "q":
# Take keyboard input and issue appropriate commands to Eddie
if kbhit():
# If a new keystroke is waiting to be read
KeyPress = getch()
if KeyPress is 'a':
TurnVal -= 1
elif KeyPress is 'd':
TurnVal += 1
elif KeyPress is 'w':
SpeedVal += 1
elif KeyPress is 'x':
SpeedVal -= 1
elif KeyPress is 's':
SpeedVal = 0
TurnVal = 0
else:
# Do nothing
# Received a character other than an Eddie command
print "Key Received: {0}".format(KeyPress)
#pass
else:
# Increment Eddie's speed towards zero
if TurnVal > 0:
TurnVal = abs(TurnVal) - 1
elif TurnVal < 0:
TurnVal = - (abs(TurnVal) - 1)
if SpeedVal > 0:
SpeedVal = abs(SpeedVal) - 1
elif SpeedVal < 0:
SpeedVal = - (abs(SpeedVal) - 1)
# Limit the maximum speed
if SpeedVal > MaxSpeed:
SpeedVal = MaxSpeed
if TurnVal > MaxTurn:
TurnVal = MaxTurn
#print "Turn = {0}".format(TurnVal)
#print "Speed = {0}".format(SpeedVal)
MyEddie.Turn(TurnVal)
MyEddie.Drive(SpeedVal)
# Go through the loop at about 10Hz
sleep(.05)
MyEddie.Disconnect()
print "Eddie is tired, he needs to rest now."