-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPyNao.py
422 lines (370 loc) · 15.6 KB
/
PyNao.py
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
#!/usr/bin/python
# -*- encoding:utf-8 -*-
__author__ = 'erick'
has_pil = True
try:
from PIL import Image
except Exception as e:
print(e)
has_pil = False
import math
import sys
import time
import almath
from PyQt4 import QtCore, QtGui
from naoqi import ALProxy
import threading
import vision_definitions as vd
from mainWindowComplex import Ui_MainWindow
class Ventana(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.win = Ui_MainWindow()
self.win.setupUi(self)
self.win.textIP.setText("127.0.0.1")
self.win.textPORT.setText("9559")
self.win.excitedButton.setText("Macarena")
self.win.rockButton.setText("RockYou")
self.win.autonoModeButton.setText("STOP ALL!")
self.connect(self.win.volumeSlider, QtCore.SIGNAL('valueChanged(int)'), self.volumeControl)
self.connect(self.win.readSensorButton, QtCore.SIGNAL('clicked()'), self.leerSensores)
self.connect(self.win.AnySayButton, QtCore.SIGNAL('clicked()'), self.animatedSay)
self.connect(self.win.calmDownButton, QtCore.SIGNAL('clicked()'), self.Cool)
self.connect(self.win.excitedButton, QtCore.SIGNAL('clicked()'),
self.bailaMacarena)
self.connect(self.win.explicandoButton, QtCore.SIGNAL('clicked()'), self.Explain)
self.connect(self.win.rockButton, QtCore.SIGNAL('clicked()'),
self.RockYou)
self.connect(self.win.kongButton, QtCore.SIGNAL('clicked()'), self.kingKong)
self.connect(self.win.musclesButton, QtCore.SIGNAL('clicked()'), self.muscle)
self.connect(self.win.r2d2Button, QtCore.SIGNAL('clicked()'), self.arturito)
self.connect(self.win.nopeButton, QtCore.SIGNAL('clicked()'), self.Nope)
self.connect(self.win.yeahButton, QtCore.SIGNAL('clicked()'), self.runBehaviorDialog)
self.connect(self.win.vacuumButton, QtCore.SIGNAL('clicked()'), self.aspiradora)
self.connect(self.win.flyingButton, QtCore.SIGNAL('clicked()'), self.avioncito)
self.connect(self.win.hotspotButton, QtCore.SIGNAL('clicked()'), self.crearHotspot)
self.connect(self.win.turnFlButton, QtCore.SIGNAL('clicked()'), self.GiroFrenteIzquierda)
self.connect(self.win.turnFrButton, QtCore.SIGNAL('clicked()'), self.GiroFrenteDerecha)
self.connect(self.win.turnBlButton, QtCore.SIGNAL('clicked()'), self.GiroBackIzquierda)
self.connect(self.win.turnBrButton, QtCore.SIGNAL('clicked()'), self.GiroBackDerecha)
self.connect(self.win.batteryButton, QtCore.SIGNAL('clicked()'), self.batteryStatus)
self.connect(self.win.autonoModeButton, QtCore.SIGNAL('clicked()'),
self.stopAll)
self.connect(self.win.frontButton, QtCore.SIGNAL('clicked()'), self.avanza)
self.connect(self.win.backButton, QtCore.SIGNAL('clicked()'), self.retrocede)
self.connect(self.win.rightButton, QtCore.SIGNAL('clicked()'), self.derecha)
self.connect(self.win.leftButton, QtCore.SIGNAL('clicked()'), self.izquierda)
self.connect(self.win.sitButton, QtCore.SIGNAL('clicked()'), self.sentarse)
self.connect(self.win.sayButton, QtCore.SIGNAL('clicked()'), self.hablando)
self.connect(self.win.WakeButton, QtCore.SIGNAL('clicked()'), self.wakeUp)
self.connect(self.win.ConnectButton, QtCore.SIGNAL('clicked()'), self.Connect)
self.connect(self.win.RestButton, QtCore.SIGNAL('clicked()'), self.rest)
self.connect(self.win.pictureButton, QtCore.SIGNAL('clicked()'), self.videoCam)
self.connect(self.win.saludoButton, QtCore.SIGNAL('clicked()'), self.Saludar)
#self.connect(self.win.sayText, QtCore.SIGNAL('returnPressed()'), self.hablando)
#self.connect(self.win.textPORT, QtCore.SIGNAL('returnPressed()'), self.Connect)
def stopAll(self):
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
try:
bh = ALProxy("ALBehaviorManager", IP, PORT)
mv = ALProxy("ALMotion", IP, PORT)
pst = ALProxy("ALRobotPosture", IP, PORT)
bh.stopAllBehaviors()
mv.stopMove()
pst.goToPosture("Stand", 0.3)
mv.rest()
except Exception, e:
print(e)
def RockYou(self):
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
try:
bh = ALProxy("ALBehaviorManager", IP, PORT)
if bh.isBehaviorInstalled('User/wewillrockyouv6-22529a/RockYou'):
bh.runBehavior('User/wewillrockyouv6-22529a/RockYou')
except Exception, e:
print(e)
def runBehaviorDialog(self):
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
try:
bhProxy = ALProxy("ALBehaviorManager", IP, PORT)
bhProxy.startBehavior("User/holamundo-2a0070/behavior_1")
except Exception, e:
print(e)
def Rock(self):
print("Rock")
def Yeah(self):
print("Yeah!")
def Explain(self):
print("Explicando")
def Cool(self):
print("Calm Down")
def excited(self):
print("Excited")
def GiroFrenteIzquierda(self):
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
try:
motionProxy = ALProxy("ALMotion", IP, PORT)
postureProxy = ALProxy("ALRobotPosture", IP, PORT)
motionProxy.wakeUp()
postureProxy.goToPosture("StandInit", 0.5)
motionProxy.moveTo(0,0, math.pi/2.0)
except Exception, e:
print("Error")
print e
def GiroFrenteDerecha(self):
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
try:
motionProxy = ALProxy("ALMotion", IP, PORT)
postureProxy = ALProxy("ALRobotPosture", IP, PORT)
motionProxy.wakeUp()
postureProxy.goToPosture("StandInit", 0.5)
motionProxy.moveTo(0,0, -(math.pi/2.0))
except Exception, e:
print("Error")
print(e)
def GiroBackIzquierda(self):
print("Giro de reversaIzquierda")
def GiroBackDerecha(self):
print("Giro de reversaDerecha")
def crearHotspot(self):
print("Soy un AP")
try:
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
alconProxy = ALProxy("ALConnectionManager", IP, PORT)
alconProxy.enableTethering("wifi", "mynao", "naonaonao")
print "wifi", "mynao", "naonaonao"
except Exception as e:
print(e)
ttsProxy = ALProxy("ALTextToSpeech", IP, PORT)
ttsProxy.say("Soy un jotspod!")
def volumeControl(self):
print("Volume changed")
def animatedSay(self):
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
animatedProxy = ALProxy("ALAnimatedSpeech", IP, PORT)
ttsProxy = ALProxy("ALTextToSpeech", IP, PORT)
ttsProxy.setLanguage("Spanish")
text = "^mode(contextual)" #+ str(self.win.comboBox.currentText())
print type(self.win.AniSayText.text())
dialog = str(self.win.AniSayText.text())
animatedProxy.say(text + dialog)
def batteryStatus(self):
print("Checking Battery")
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
batteryProxy = ALProxy("ALBattery", IP, PORT)
carga = batteryProxy.getBatteryCharge()
self.win.batteryText.setText("%d por ciento" %(carga))
def aspiradora(self):
print("Vacuum")
try:
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
saludaProxy = ALProxy("ALAnimatedSpeech", IP, PORT)
saludaProxy.say("^start(animations/Stand/Waiting/Vacuum_1) ^wait(animations/Stand/Waiting/Vacuum_1)")
except:
print("No quiero")
def avioncito(self):
print("I believe...")
try:
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
motionProxy = ALProxy("ALMotion", IP, PORT)
motionProxy.setFallManagerEnabled(False)
saludaProxy = ALProxy("ALAnimatedSpeech", IP, PORT)
saludaProxy.say("^start(animations/Stand/Waiting/SpaceShuttle_1) ^wait(animations/Stand/Waiting/SpaceShuttle_1)")
except Exception, e:
print(e)
def muscle(self):
print("Muscles")
try:
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
saludaProxy = ALProxy("ALAnimatedSpeech", IP, PORT)
saludaProxy.say("^start(animations/Stand/Waiting/Fitness_3) ^wait(animations/Stand/Waiting/Fitness_3)")
except:
print("No puedo")
def arturito(self):
print("R2D2")
def kingKong(self):
print("KingKong")
def Nope(self):
print("Nope")
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
try:
bhProxy = ALProxy("ALBehaviorManager", IP, PORT)
#bhProxy.stop
except:
print("")
def leerSensores(self):
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
memoryProxy = ALProxy("ALMemory", IP, PORT)
sonarProxy = ALProxy("ALSonar", IP, PORT)
sonarProxy.subscribe("pynao")
AccX = memoryProxy.getData("Device/SubDeviceList/InertialSensor/AccX/Sensor/Value")
AccY = memoryProxy.getData("Device/SubDeviceList/InertialSensor/AccY/Sensor/Value")
AccZ = memoryProxy.getData("Device/SubDeviceList/InertialSensor/AccZ/Sensor/Value")
GyrX = memoryProxy.getData("Device/SubDeviceList/InertialSensor/GyrX/Sensor/Value")
GyrY = memoryProxy.getData("Device/SubDeviceList/InertialSensor/GyrY/Sensor/Value")
usL = memoryProxy.getData("Device/SubDeviceList/US/Left/Sensor/Value")
usR = memoryProxy.getData("Device/SubDeviceList/US/Right/Sensor/Value")
sonarProxy.unsubscribe("pynao")
print(type(AccX))
print(type(GyrX))
self.win.AccelXtext.setText("x: " + str(round(AccX, 2)))
self.win.AccelYtext.setText("y: " + str(round(AccY, 2)))
self.win.AccelZtext.setText("z: " + str(round(AccZ, 2)))
self.win.GyroXtext.setText("x: " + str(round(GyrX, 2)))
self.win.GyroYtext.setText("y: " + str(round(GyrY, 2)))
self.win.USLeftText.setText("%.2f m" %(usL))
self.win.USRightText.setText("%.2f m" %(usR))
def autonoMode(self):
print("Ya Soy Autonomo")
#Aquí acaba lo nuuevo, lo demás ahí está
def avanza(self):
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
try:
motionProxy = ALProxy("ALMotion", IP, PORT)
motionProxy.wakeUp()
motionProxy.moveTo(0.5, 0.0, 0)
except:
print("no puedo avanzar")
def retrocede(self):
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
try:
motionProxy = ALProxy("ALMotion", IP, PORT)
motionProxy.wakeUp()
motionProxy.moveTo(-0.5, 0.0, 0)
except:
print("no pude retroceder")
def derecha(self):
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
try:
motionProxy = ALProxy("ALMotion", IP, PORT)
motionProxy.wakeUp()
motionProxy.moveTo(0.0, -0.5, 0)
except:
print("no logro moverme a la derecha")
def izquierda(self):
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
try:
motionProxy = ALProxy("ALMotion", IP, PORT)
motionProxy.wakeUp()
motionProxy.moveTo(0.0, 0.5, 0)
except:
print("no logro moerme a la izquierda")
def sentarse(self):
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
try:
motionProxy = ALProxy("ALMotion", IP, PORT)
postureProxy = ALProxy("ALRobotPosture", IP, PORT)
motionProxy.wakeUp()
postureProxy.goToPosture("Sit", 1.0)
motionProxy.rest()
except:
print("Quizá esto no es así")
def Saludar(self):
try:
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
saludaProxy = ALProxy("ALAnimatedSpeech", IP, PORT)
saludaProxy.say("^start(animations/Stand/Gestures/Hey_1) ^wait(animations/Stand/Gestures/Hey_1)")
except:
print("No jaló la vida")
def hablando(self):
try:
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
sayProxy = ALProxy("ALTextToSpeech", IP, PORT)
texto = str(self.win.sayText.text())
sayProxy.say(texto)
print("Ahora sí se pudo")
except:
print("Ni pedo, no salió")
def videoCam(self):
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
try:
camProxy = ALProxy("ALVideoDevice", IP, PORT)
client = camProxy.subscribe("python_client", vd.kVGA, 11, 5)
momento = time.strftime("_%H%M%S_%d%m%y")
image = camProxy.getImageRemote(client)
camProxy.unsubscribe(client)
im = Image.frombytes("RGB", (image[0], image[1]), image[6])
im.save("selfie_%s.png" %momento, "PNG")
except:
print("Así no es chavo")
def turnHead(self):
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
angle = self.win.horizontalSlider.value()
angulo = angle*almath.TO_RAD
try:
motionProxy = ALProxy("ALMotion", IP, PORT)
motionProxy.setStiffnesses("Head", 1.0)
motionProxy.setAngles("HeadYaw", angulo, 0.2)
time.sleep(1.0)
motionProxy.setStiffnesses("Head", 0.0)
except:
print("Error al conectar con Head")
def rest(self):
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
try:
motionProxy = ALProxy("ALMotion", IP, PORT)
motionProxy.rest()
print("rest")
except:
print("Error Al Descansar")
def Connect(self):
print("Connect")
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
try:
ttsProxy = ALProxy("ALTextToSpeech", IP, PORT)
ttsProxy.say("Conexión establecida")
except:
print("Error de conexión")
def wakeUp(self):
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
try:
motionProxy = ALProxy("ALMotion", IP, PORT)
motionProxy.wakeUp()
robotPosture = ALProxy("ALRobotPosture", IP, PORT)
robotPosture.goToPosture("Stand", 0.7)
print("Awake")
except:
print("Error al despertar")
def bailaMacarena(self):
IP = str(self.win.textIP.text())
PORT = int(self.win.textPORT.text())
try:
bh = ALProxy("ALBehaviorManager", IP, PORT)
if bh.isBehaviorInstalled('User/macarena-566d69/Macarena'):
print("Pos sí estuvo la macarena")
bh.runBehavior("User/macarena-566d69/Macarena")
print("Ya acabé de bailar")
except Exception, e:
print(e)
def main():
app = QtGui.QApplication(sys.argv)
ventana = Ventana()
ventana.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()