Advertisement
Guest User

totototototottotodsfgvfg

a guest
Jun 13th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.37 KB | None | 0 0
  1. from naoqi import ALProxy
  2. import scipy.io.wavfile as wave
  3. from numpy import NaN, Inf, arange, isscalar, asarray, array, size
  4. import time
  5. import sys
  6. import os
  7. import pysftp
  8. import numpy
  9.  
  10.  
  11. #record = ALProxy("ALAudioRecorder", "169.254.28.144", 9559)
  12. #record = None
  13.  
  14. def soundRecord(robot_IP, robot_PORT=9559, temp=5):
  15. global record
  16. record = ALProxy("ALAudioRecorder", "169.254.28.144", 9559)
  17. record_path = '/home/nao/danseavec.wav'
  18. record.stopMicrophonesRecording()
  19. record.startMicrophonesRecording(record_path, 'wav', 16000, (1,0,0,0))
  20. time.sleep(temp)
  21. record.stopMicrophonesRecording()
  22.  
  23. def peakdet(v, delta, x = None):
  24.  
  25. maxtab = []
  26. mintab = []
  27.  
  28. if x is None:
  29. x = arange(len(v))
  30.  
  31. v = asarray(v)
  32.  
  33. if len(v) != len(x):
  34. sys.exit('Input vectors v and x must have same length')
  35.  
  36. if not isscalar(delta):
  37. sys.exit('Input argument delta must be a scalar')
  38.  
  39. if delta <= 0:
  40. sys.exit('Input argument delta must be positive')
  41.  
  42. mn, mx = Inf, -Inf
  43. mnpos, mxpos = NaN, NaN
  44.  
  45. lookformax = True
  46.  
  47. for i in arange(len(v)):
  48. this = v[i]
  49. if this > mx:
  50. mx = this
  51. mxpos = x[i]
  52. if this < mn:
  53. mn = this
  54. mnpos = x[i]
  55.  
  56. if lookformax:
  57. if this < mx-delta:
  58. maxtab.append((mxpos, mx))
  59. mn = this
  60. mnpos = x[i]
  61. lookformax = False
  62.  
  63. else:
  64. if this > mn+delta:
  65. mintab.append((mnpos, mn))
  66. mx = this
  67. mxpos = x[i]
  68. lookformax = True
  69.  
  70. return array(maxtab)
  71.  
  72. def moveUp(T, N, givenPos):
  73. names = ['RShoulderPitch', 'LShoulderPitch','RShoulderRoll', 'LShoulderRoll', 'RElbowRoll','LElbowRoll', 'RElbowYaw', 'LElbowYaw', 'RWristYaw', 'LWristYaw', 'RHand', 'LHand', 'RHipYawPitch', 'LHipYawPitch', 'RHipRoll', 'LHipRoll', 'RHipPitch', 'LHipPitch', 'RKneePitch', 'LKneePitch', 'RAnklePitch', 'LAnklePitch', 'RAnkleRoll', 'LAnkleRoll', 'HeadPitch','HeadYaw']
  74. nbPoses = len(givenPos)
  75. nbMoteur = len(names)
  76. temps = list()
  77. tableTemps = list()
  78. for i in range (N):
  79. temps.append((i+1)*T)
  80. for i in range(nbMoteur):
  81. tableTemps.append(temps)
  82. allPos = list()
  83. j=0
  84. for i in range(N):
  85. if j == nbPoses:
  86. j = 0
  87. allPos.append(givenPos[j])
  88. j = j+1
  89. allPos = zip(*allPos)
  90. motionProxy.angleInterpolationBezier(names, tableTemps, allPos)
  91. pass
  92.  
  93. def debout():
  94. f = open("/home/nao/deboutDegre.txt", "r")
  95. lignes = f.readlines()
  96. pos = list()
  97. for L in lignes[1:]:
  98. L = L.split(',')
  99. for i in range(len(L)):
  100. L[i] = float(L[i])*(pi/180)
  101. pos.append(L)
  102. f.close()
  103. moveUp(p,1,pos)
  104. pass
  105.  
  106. def analyseSon(ipp, port, temp=5):
  107. soundRecord(ipp, port, temp)
  108.  
  109. curdir = os.getcwd()
  110. dir = curdir + '/audio/danseavec.wav'
  111. with pysftp.Connection('169.254.28.144', username = 'nao', password = 'stark') as sftp :
  112. sftp.get('/home/nao/danseavec.wav', dir)
  113.  
  114. rate,data = wave.read('/home/eleve/Bureau/audio/danseavec.wav')
  115. #print rate
  116. #print data
  117. if len(data) != size(data) :
  118. data=data[:,0]
  119.  
  120.  
  121. Debut = 0
  122. duree = 5
  123. N = duree*rate
  124. zzrot = data[ Debut : N + Debut]
  125.  
  126. fvi = numpy.fft.fft(zzrot, n=2*N)
  127. acf = numpy.real( numpy.fft.ifft( fvi * numpy.conjugate(fvi) )[:N] )
  128. acf = acf/N
  129.  
  130.  
  131. acfcarre=acf*acf
  132.  
  133.  
  134. moy = 2000
  135.  
  136. rate1 = rate / moy
  137. ajf = []
  138. count = 0
  139. ajfa = 0
  140. while size(ajf) != size (acfcarre) / moy :
  141. for it in range (moy) :
  142. ajfa = acfcarre[it+count*moy] + ajfa
  143. ajf = ajf + [ajfa]
  144.  
  145. ajfa = 0
  146. count = count + 1
  147.  
  148.  
  149. ajf=ajf/ajf[0] * 100
  150. axex = numpy.arange(size(ajf))/rate1
  151. Npic=len(peakdet(ajf, 0.1, axex))
  152. TPP = Npic / duree
  153. return TPP
  154.  
  155.  
  156. while True :
  157. ipp = "169.254.28.144"
  158. port = 9559
  159. temp = 5
  160. TPP = analyseSon(ipp, port, temp)
  161. print TPP
  162.  
  163. if len(sys.argv) < 2:
  164. print("veuillez passer une ip en cli")
  165. sys.exit(1)
  166.  
  167. ip = sys.argv[1]
  168. postureProxy = ALProxy("ALRobotPosture", ipp, port)
  169. postureProxy.goToPosture("Stand", 0.5)
  170. motionProxy = ALProxy ("ALMotion", ipp, port)
  171.  
  172. TPP= analyseSon(ipp, port)
  173.  
  174. motionProxy=ALProxy("ALMotion")
  175. self.framemanager = ALProxy("ALFrameManager")
  176.  
  177. #0 0
  178. #-1 1
  179. #1 -1
  180. #1 -1
  181. #1 1
  182. #f = open("C:\Users\comte\Documents\ISEP\Cours\NaoDance\NaoDanceMouvement\balanceTete.txt", "r")
  183.  
  184.  
  185. f = open("/home/nao/poseStable1degre.txt", "r")
  186. lignes = f.readlines()
  187. pos = list()
  188. for L in lignes[1:]:
  189. L = L.split(',')
  190. for i in range(len(L)):
  191. L[i] = float(L[i])*(pi/180)
  192. pos.append(L)
  193. f.close()
  194. moveUp(TPP,4,pos)
  195. debout()
  196.  
  197. TPP= analyseSon(ipp, port)
  198.  
  199. f = open("/home/nao/poseStable2degre.txt", "r")
  200. lignes = f.readlines()
  201. pos = list()
  202. for L in lignes[1:]:
  203. L = L.split(',')
  204. for i in range(len(L)):
  205. L[i] = float(L[i])*(pi/180)
  206. pos.append(L)
  207. f.close()
  208. moveUp(TPP,4,pos)
  209. debout()
  210.  
  211. TPP= analyseSon(ipp, port)
  212.  
  213. f = open("/home/nao/hanches.txt", "r")
  214. lignes = f.readlines()
  215. pos = list()
  216. for L in lignes[1:]:
  217. L = L.split(',')
  218. for i in range(len(L)):
  219. L[i] = float(L[i])#*(pi/180)
  220. pos.append(L)
  221. f.close()
  222. moveUp(TPP,4,pos)
  223. debout()
  224.  
  225. TPP= analyseSon(ipp, port)
  226.  
  227. f = open("/home/nao/discodegre.txt", "r")
  228. lignes = f.readlines()
  229. pos = list()
  230. for L in lignes[1:]:
  231. L = L.split(',')
  232. for i in range(len(L)):
  233. L[i] = float(L[i])#*(pi/180)
  234. pos.append(L)
  235. f.close()
  236. moveUp(TPP,4,pos)
  237. debout()
  238.  
  239.  
  240.  
  241. # ##COUDES EN L'AIR GAUCHE
  242. #
  243. # names = ['RElbowRoll' ,'RShoulderRoll','LShoulderRoll','LElbowRoll','RShoulderPitch','LShoulderPitch','RElbowYaw', 'LElbowYaw', 'HeadYaw', 'HeadPitch']
  244. # times = [[x],[x],[x],[x],[x],[x],[x],[x],[x],[x]]
  245. #
  246. # for i in range (4):
  247. # motionProxy.angleInterpolation(names,[1.15,-1.13,1.17,-1.18,1.6,1.6,0.13,-0.13,1.45,-0.28],times, True)
  248. # motionProxy.angleInterpolation(names,[0.045,-0.045,-0.06,-0.04537,1.6,1.6,0.13,-0.13,1.45,0.21],times, True)
  249. #
  250. #
  251. #
  252. # ##COUDES EN L'AIR DROITE
  253. #
  254. #
  255. # names = ['RElbowRoll' ,'RShoulderRoll','LShoulderRoll','LElbowRoll','RShoulderPitch','LShoulderPitch','RElbowYaw', 'LElbowYaw', 'HeadYaw', 'HeadPitch']
  256. # times = [[x],[x],[x],[x],[x],[x],[x],[x],[x],[x]]
  257. #
  258. # for i in range (4):
  259. # motionProxy.angleInterpolation(names,[1.15,-1.13,1.17,-1.18,1.6,1.6,0.13,-0.13,-1.45,-0.28],times, True)
  260. # motionProxy.angleInterpolation(names,[0.045,-0.045,-0.06,-0.04537,1.6,1.6,0.13,-0.13,-1.45,0.21],times, True)
  261. #
  262. #
  263. # ##DAB
  264. # BPM = analyseSon()
  265. # x=BPM/100
  266. #
  267. # names = ['RElbowRoll' ,'RShoulderRoll','RShoulderPitch','RElbowYaw','LShoulderPitch','LShoulderRoll','LElbowYaw','HeadPitch','HeadYaw','LHipPitch','RHipPitch','LKneePitch','RKneePitch','LAnklePitch','RAnklePitch']
  268. # times = [[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x]]
  269. #
  270. # for i in range (2):
  271. # motionProxy.angleInterpolation(names,[0.035,-0.28,0.91,-0.4,1.2,0,-0.17,-0.21,0,0,0,0,0,0,0],times, True)
  272. # motionProxy.angleInterpolation(names,[1.38,0.28,0.4,0.47,1.11,1.3,2.08,0.51,-0.4,-0.994,-0.994,1.24,1.24,-0.49,-0.49],times, True)
  273. # motionProxy.angleInterpolation(names,[0.035,-0.28,0.91,-0.4,1.2,0,-0.17,-0.21,0,0,0,0,0,0,0],times, True)
  274. #
  275. # ##COUCOU
  276. #
  277. # BPM = analyseSon()
  278. # x=BPM/100
  279. #
  280. # names = ['RElbowRoll' ,'RShoulderRoll','LShoulderRoll','LElbowRoll','RShoulderPitch','LShoulderPitch','RElbowYaw', 'LElbowYaw',]
  281. # times = [[3*x],[3*x],[3*x],[3*x],[3*x],[3*x],[3*x],[3*x]]
  282. #
  283. # for i in range (2):
  284. # motionProxy.angleInterpolation(names,[0.98,-0.07,1.1,-0.05,-1.46,-1.6,0,0],times, True)
  285. # motionProxy.angleInterpolation(names,[0.034,-1.06,-0.07,-1,-1.6,-1.6,0,0],times, True)
  286. #
  287. #
  288. # ##GENOU
  289. #
  290. # BPM = analyseSon()
  291. # x=BPM/100
  292. #
  293. # names = ['RElbowRoll' ,'RShoulderRoll','RShoulderPitch','RElbowYaw','LElbowRoll','LShoulderRoll','LShoulderPitch','LElbowYaw','RAnklePitch','LAnklePitch', 'LKneePitch', 'RKneePitch','LHipPitch','RHipPitch']
  294. # times = [[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x]]
  295. #
  296. # for i in range (4):
  297. # motionProxy.angleInterpolation(names,[1.45,0.23,0,0,-1.33,-0.07,0.87,-0.2,0.09,0.09,-0.09,-0.09,0.13,0.13],times, True)
  298. # motionProxy.angleInterpolation(names,[1.45,0.23,0,0,-1.33,-0.07,0.87,-0.2,-0.63,-0.63,1.3,1.3,-0.43,-0.43],times, True)
  299. # motionProxy.angleInterpolation(names,[1.45,0.23,0,0,-1.33,-0.07,0.87,-0.2,0.09,0.09,-0.09,-0.09,0.13,0.13],times, True)
  300. #
  301. # ##petits mouvements bras
  302. #
  303. # BPM = analyseSon()
  304. # x=BPM/100
  305. #
  306. # names = ['RElbowRoll' ,'LElbowRoll', 'RShoulderRoll','LShoulderRoll','RShoulderPitch','LShoulderPitch','HeadYaw']
  307. # times = [[x],[x],[x],[x],[x],[x],[x]]
  308. #
  309. # for i in range (8):
  310. # motionProxy.angleInterpolation(names,[0.65,-0.65,0.14,-0.14,0.3,0.71,-0.46],times, True)
  311. # motionProxy.angleInterpolation(names,[0.65,-0.65,0.14,-0.14,0.71,0.3,0.46],times, True)
  312. #
  313. # ##BRAS EN L'AIR
  314. # BPM = analyseSon()
  315. # x=BPM/100
  316. #
  317. # names = ['RElbowRoll' ,'LElbowRoll', 'RShoulderRoll','LShoulderRoll','RShoulderPitch','LShoulderPitch','HeadPitch']
  318. # times = [[3*x],[3*x],[3*x],[3*x],[3*x],[3*x],[3*x]]
  319. #
  320. # for i in range (4):
  321. # motionProxy.angleInterpolation(names,[0.06,-0.16,0.29,-0.28,0.84,0.84,0.36],times, True)
  322. # motionProxy.angleInterpolation(names,[-0.07,0.04,0.17,-0.14,-1.5,-1.5,-0.44],times, True)
  323. # motionProxy.angleInterpolation(names,[0.06,-0.16,0.29,-0.28,0.84,0.84,0.36],times, True)
  324. #
  325. #
  326. #
  327. # time.sleep(10)
  328. #
  329. #
  330. #
  331. #
  332. #
  333. #
  334. #port = 9559
  335. #if len(sys.argv) < 2:
  336. # print("veuillez passer une ip en cli")
  337. # sys.exit(1)
  338. #
  339. #ip = sys.argv[1]
  340. #
  341. #postureProxy = ALProxy("ALRobotPosture", ip, 9559)
  342. #postureProxy.goToPosture("Stand", 0.5)
  343. #motionProxy = ALProxy ("ALMotion", ip, 9559)
  344. #
  345. #
  346. #x = BPS
  347. #
  348. # ##COUDES EN L'AIR GAUCHE
  349. #
  350. #names = ['RElbowRoll' ,'RShoulderRoll','LShoulderRoll','LElbowRoll','RShoulderPitch','LShoulderPitch','RElbowYaw', 'LElbowYaw', 'HeadYaw', 'HeadPitch']
  351. #times = [[x],[x],[x],[x],[x],[x],[x],[x],[x],[x]]
  352. #
  353. #for i in range (4):
  354. # motionProxy.angleInterpolation(names,[1.15,-1.13,1.17,-1.18,1.6,1.6,0.13,-0.13,1.45,-0.28],times, True)
  355. # motionProxy.angleInterpolation(names,[0.045,-0.045,-0.06,-0.04537,1.6,1.6,0.13,-0.13,1.45,0.21],times, True)
  356. #
  357. #
  358. #
  359. # ##COUDES EN L'AIR DROITE
  360. #
  361. #
  362. #
  363. #names = ['RElbowRoll' ,'RShoulderRoll','LShoulderRoll','LElbowRoll','RShoulderPitch','LShoulderPitch','RElbowYaw', 'LElbowYaw', 'HeadYaw', 'HeadPitch']
  364. #times = [[x],[x],[x],[x],[x],[x],[x],[x],[x],[x]]
  365. #
  366. #for i in range (4):
  367. # motionProxy.angleInterpolation(names,[1.15,-1.13,1.17,-1.18,1.6,1.6,0.13,-0.13,-1.45,-0.28],times, True)
  368. # motionProxy.angleInterpolation(names,[0.045,-0.045,-0.06,-0.04537,1.6,1.6,0.13,-0.13,-1.45,0.21],times, True)
  369. #
  370. #
  371. # ##DAB
  372. #
  373. #names = ['RElbowRoll' ,'RShoulderRoll','RShoulderPitch','RElbowYaw','LShoulderPitch','LShoulderRoll','LElbowYaw','HeadPitch','HeadYaw','LHipPitch','RHipPitch','LKneePitch','RKneePitch','LAnklePitch','RAnklePitch']
  374. #times = [[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x]]
  375. #
  376. #for i in range (2):
  377. # motionProxy.angleInterpolation(names,[0.035,-0.28,0.91,-0.4,1.2,0,-0.17,-0.21,0,0,0,0,0,0,0],times, True)
  378. # motionProxy.angleInterpolation(names,[1.38,0.28,0.4,0.47,1.11,1.3,2.08,0.51,-0.4,-0.994,-0.994,1.24,1.24,-0.49,-0.49],times, True)
  379. # motionProxy.angleInterpolation(names,[0.035,-0.28,0.91,-0.4,1.2,0,-0.17,-0.21,0,0,0,0,0,0,0],times, True)
  380. #
  381. # ##COUCOU
  382. #
  383. #
  384. #names = ['RElbowRoll' ,'RShoulderRoll','LShoulderRoll','LElbowRoll','RShoulderPitch','LShoulderPitch','RElbowYaw', 'LElbowYaw',]
  385. #times = [[3*x],[3*x],[3*x],[3*x],[3*x],[3*x],[3*x],[3*x]]
  386. #
  387. #for i in range (4):
  388. # motionProxy.angleInterpolation(names,[0.98,-0.07,1.1,-0.05,-1.46,-1.6,0,0],times, True)
  389. # motionProxy.angleInterpolation(names,[0.034,-1.06,-0.07,-1,-1.6,-1.6,0,0],times, True)
  390. #
  391. #
  392. # ##GENOU
  393. #
  394. #
  395. #names = ['RElbowRoll' ,'RShoulderRoll','RShoulderPitch','RElbowYaw','LElbowRoll','LShoulderRoll','LShoulderPitch','LElbowYaw','RAnklePitch','LAnklePitch', 'LKneePitch', 'RKneePitch','LHipPitch','RHipPitch']
  396. #times = [[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x]]
  397. #
  398. #for i in range (8):
  399. # motionProxy.angleInterpolation(names,[1.45,0.23,0,0,-1.33,-0.07,0.87,-0.2,0.09,0.09,-0.09,-0.09,0.13,0.13],times, True)
  400. # motionProxy.angleInterpolation(names,[1.45,0.23,0,0,-1.33,-0.07,0.87,-0.2,-0.63,-0.63,1.3,1.3,-0.43,-0.43],times, True)
  401. # motionProxy.angleInterpolation(names,[1.45,0.23,0,0,-1.33,-0.07,0.87,-0.2,0.09,0.09,-0.09,-0.09,0.13,0.13],times, True)
  402. #
  403. # ##petits mouvements bras
  404. #
  405. #names = ['RElbowRoll' ,'LElbowRoll', 'RShoulderRoll','LShoulderRoll','RShoulderPitch','LShoulderPitch','HeadYaw']
  406. #times = [[x],[x],[x],[x],[x],[x],[x]]
  407. #
  408. #for i in range (8):
  409. # motionProxy.angleInterpolation(names,[0.65,-0.65,0.14,-0.14,0.3,0.71,-0.46],times, True)
  410. # motionProxy.angleInterpolation(names,[0.65,-0.65,0.14,-0.14,0.71,0.3,0.46],times, True)
  411. #
  412. # ##BRAS EN L'AIR
  413. #
  414. #
  415. #names = ['RElbowRoll' ,'LElbowRoll', 'RShoulderRoll','LShoulderRoll','RShoulderPitch','LShoulderPitch','HeadPitch']
  416. #times = [[3*x],[3*x],[3*x],[3*x],[3*x],[3*x],[3*x]]
  417. #
  418. #for i in range (4):
  419. # motionProxy.angleInterpolation(names,[0.06,-0.16,0.29,-0.28,0.84,0.84,0.36],times, True)
  420. # motionProxy.angleInterpolation(names,[-0.07,0.04,0.17,-0.14,-1.5,-1.5,-0.44],times, True)
  421. # motionProxy.angleInterpolation(names,[0.06,-0.16,0.29,-0.28,0.84,0.84,0.36],times, True)
  422. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement