forked from mintforpeople/robobo.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting_example.py
More file actions
185 lines (144 loc) · 5.27 KB
/
testing_example.py
File metadata and controls
185 lines (144 loc) · 5.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
from utils.Wheels import Wheels
from utils.IR import IR
from utils.Sounds import Sounds
from utils.Emotions import Emotions
from utils.LED import LED
from utils.Color import Color
from utils.StatusFrequency import StatusFrequency
from Robobo import Robobo
def testMoveWheels():
rob.moveWheelsByTime(10,10,2,wait=False)
rob.movePanTo(60,20)
rob.wait(1)
rob.moveWheelsByTime(10, 10, 1)
rob.movePanTo(90,20)
rob.wait(1)
rob.moveWheelsByDegrees(Wheels.BOTH,90,10)
rob.movePanTo(0, 20)
rob.wait(1)
posL = rob.readWheelPosition(Wheels.L)
print ("PosL: " + str(posL))
posR = rob.readWheelPosition(Wheels.R)
print ("PosR: " + str(posR))
def testLeds():
rob.sayText("Testing my leds")
rob.setLedColorTo(LED.All, Color.RED)
rob.wait(0.5)
rob.setLedColorTo(LED.All, Color.OFF)
rob.wait(0.5)
rob.setLedColorTo(LED.FrontC, Color.MAGENTA)
rob.wait(0.5)
rob.setLedColorTo(LED.FrontC, Color.OFF)
rob.wait(0.5)
rob.setLedColorTo(LED.FrontLL, Color.MAGENTA)
rob.wait(0.5)
rob.setLedColorTo(LED.FrontLL, Color.OFF)
rob.wait(0.5)
rob.setLedColorTo(LED.FrontL, Color.MAGENTA)
rob.wait(0.5)
rob.setLedColorTo(LED.FrontL, Color.OFF)
rob.wait(0.5)
rob.setLedColorTo(LED.FrontR, Color.MAGENTA)
rob.wait(0.5)
rob.setLedColorTo(LED.FrontR, Color.OFF)
rob.wait(0.5)
rob.setLedColorTo(LED.FrontRE, Color.MAGENTA)
rob.wait(0.5)
rob.setLedColorTo(LED.FrontRE, Color.OFF)
rob.wait(0.5)
rob.setLedColorTo(LED.BackL, Color.MAGENTA)
rob.wait(0.5)
rob.setLedColorTo(LED.BackL, Color.OFF)
rob.wait(0.5)
rob.setLedColorTo(LED.BackR, Color.MAGENTA)
rob.wait(0.5)
rob.setLedColorTo(LED.BackR, Color.OFF)
rob.wait(0.5)
rob.sayText("Finished!")
def testIRAndLeds():
closeIRValue = 100
mediumIRValue = 20
farIRValue = 5
speed = 1
rob.setLedColorTo(LED.All,Color.OFF)
rob.moveWheels(speed,speed)
print(rob.readAllIRSensor())
while (rob.readIRSensor(IR.FrontC) < farIRValue)and(rob.readIRSensor(IR.FrontRR) < farIRValue)and(rob.readIRSensor(IR.FrontLL) < farIRValue):
rob.wait(0.1)
print(rob.readAllIRSensor())
rob.setLedColorTo(LED.All,Color.GREEN)
while (rob.readIRSensor(IR.FrontC) < mediumIRValue)and(rob.readIRSensor(IR.FrontRR) < mediumIRValue)and(rob.readIRSensor(IR.FrontLL) < mediumIRValue):
rob.wait(0.1)
print(rob.readAllIRSensor())
rob.setLedColorTo(LED.All,Color.MAGENTA)
while (rob.readIRSensor(IR.FrontC) < closeIRValue)and(rob.readIRSensor(IR.FrontRR) < closeIRValue)and(rob.readIRSensor(IR.FrontLL) < closeIRValue):
rob.wait(0.1)
rob.stopMotors()
rob.setLedColorTo(LED.All,Color.RED)
rob.setEmotionTo(Emotions.SURPRISED)
rob.playSound(Sounds.DISCOMFORT)
#rob.moveWheelsByTime(speed*-1,speed*-1,1)
rob.setLedColorTo(LED.All,Color.BLUE)
rob.setEmotionTo(Emotions.SURPRISED)
def flingDetectedCallback():
rob.sayText("Fling detected!")
def tapDetectedCallback():
rob.stopMotors()
print("--> TAP detected: "+str(rob.readTapSensor()))
def faceDetectedCallback():
face = rob.readFaceSensor()
print("--> New face detected. Distance: " + str(face.distance) + ", (x,y): " + str(face.posx) + ", "+str(face.posy))
def faceLostCallback():
print("--> Face Lost !!")
def newColorBlobDetectedCallback():
rob.sayText("Blob detected")
def anewQRCodeDetectedCallback():
qr = rob.readQR()
rob.sayText("New QR detected")
print("--> New QR detected: " + str(qr))
def aQRCodeDetectedCallBack():
qr = rob.readQR()
rob.sayText("QR detected")
print("--> QR detected: " + str(qr))
def clapDetectedCallBack():
print("--> CLAP DETECTED!!")
if __name__ == '__main__':
rob = Robobo("10.113.36.177")
rob.connect()
rob.changeStatusFrequency(StatusFrequency.Max)
# rob.setEmotionTo(Emotions.NORMAL)
# rob.setActiveBlobs(True, True, False, False)
# rob.moveTiltTo(75,20,wait=False)
# rob.movePanTo(0,20)
# rob.wait(1)
#
# rob.whenAFlingIsDetected(flingDetectedCallback)
rob.whenATapIsDetected(tapDetectedCallback)
# rob.whenANewFaceIsDetected(faceDetectedCallback)
# rob.whenAFaceIsLost(faceLostCallback())
# #rob.whenANewColorBlobIsDetected(newColorBlobDetectedCallback)
# rob.whenANewQRCodeIsDetected(anewQRCodeDetectedCallback)
# #rob.whenAQRCodeIsDetected(aQRCodeDetectedCallBack)
# rob.whenClapIsDetected(clapDetectedCallBack())
#testLeds()
#testIRAndLeds()
testMoveWheels()
# rob.playNote(55, 1)
# rob.playNote(60, 1)
#
# print("Last Note --> " + str(rob.readLastNote()))
while (True):
print()
irsensors = rob.readAllIRSensor()
print("IR Sensor values: " + str(rob.readAllIRSensor()))
print("IR Blob values: ")
blobs = rob.readAllColorBlobs()
for key in blobs:
print("-->" + str(blobs[key]))
print("Brightness: " + str(rob.readBrightnessSensor()))
print("Phone battery level: " + str(rob.readBatteryLevel("phone")))
print("Base battery level: "+ str(rob.readBatteryLevel("base")))
print("Orientation sensor:" + str(rob.readOrientationSensor()))
print("Acceleration sensor: " + str(rob.readAccelerationSensor()))
print()
rob.wait(0.1)