Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.78 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Tue Jun 13 14:39:54 2017
  4.  
  5. @author: eleve
  6. """
  7.  
  8. from naoqi import ALProxy
  9. import time
  10.  
  11. record = ALProxy("ALAudioRecorder", "169.254.28.144", 9559)
  12. record = None
  13.  
  14. def soundRecord(robot_IP, robot_PORT=9559):
  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(5)
  21. record.stopMicrophonesRecording()
  22.  
  23. import sys
  24. from numpy import NaN, Inf, arange, isscalar, asarray, array, size
  25.  
  26. def peakdet(v, delta, x = None):
  27.  
  28. maxtab = []
  29. mintab = []
  30.  
  31. if x is None:
  32. x = arange(len(v))
  33.  
  34. v = asarray(v)
  35.  
  36. if len(v) != len(x):
  37. sys.exit('Input vectors v and x must have same length')
  38.  
  39. if not isscalar(delta):
  40. sys.exit('Input argument delta must be a scalar')
  41.  
  42. if delta <= 0:
  43. sys.exit('Input argument delta must be positive')
  44.  
  45. mn, mx = Inf, -Inf
  46. mnpos, mxpos = NaN, NaN
  47.  
  48. lookformax = True
  49.  
  50. for i in arange(len(v)):
  51. this = v[i]
  52. if this > mx:
  53. mx = this
  54. mxpos = x[i]
  55. if this < mn:
  56. mn = this
  57. mnpos = x[i]
  58.  
  59. if lookformax:
  60. if this < mx-delta:
  61. maxtab.append((mxpos, mx))
  62. mn = this
  63. mnpos = x[i]
  64. lookformax = False
  65.  
  66. else:
  67. if this > mn+delta:
  68. mintab.append((mnpos, mn))
  69. mx = this
  70. mxpos = x[i]
  71. lookformax = True
  72.  
  73. return array(maxtab)
  74.  
  75.  
  76. def analyseSon():
  77. soundRecord("169.254.28.144", 9559)
  78. import os
  79. import pysftp
  80.  
  81. curdir = os.getcwd()
  82. dir = curdir + '/audio/danseavec.wav'
  83. with pysftp.Connection('169.254.28.144', username = 'nao', password = 'stark') as sftp :
  84. sftp.get('/home/nao/danseavec.wav', dir)
  85.  
  86. from numpy import size
  87. import scipy.io.wavfile as wave
  88. rate,data = wave.read('/home/eleve/Bureau/audio/danseavec.wav')
  89. #print rate
  90. #print data
  91. if len(data) != size(data) :
  92. data=data[:,0]
  93.  
  94. import numpy
  95. Debut = 10
  96. duree = 5
  97. N = duree*rate
  98. f = data[ Debut : N + Debut]
  99.  
  100. axex = numpy.arange(size(f))/rate
  101.  
  102. fvi = numpy.fft.fft(f, n=2*N)
  103. acf = numpy.real( numpy.fft.ifft( fvi * numpy.conjugate(fvi) )[:N] )
  104. acf = acf/N
  105.  
  106.  
  107. acfcarre=acf*acf
  108.  
  109.  
  110. moy = 2000
  111.  
  112. rate1 = rate / moy
  113. ajf = []
  114. count = 0
  115. ajfa = 0
  116. while size(ajf) != size (acfcarre) / moy :
  117. for it in range (moy) :
  118. ajfa = acfcarre[it+count*moy] + ajfa
  119. ajf = ajf + [ajfa]
  120.  
  121. ajfa = 0
  122. count = count + 1
  123.  
  124.  
  125. ajf=ajf/ajf[0] * 100
  126. axex = numpy.arange(size(ajf))/rate1
  127. Npic=len(peakdet(ajf, 0.1, axex))
  128. BPM = Npic * 60 / duree
  129. return BPM
  130.  
  131.  
  132.  
  133. while True :
  134. from naoqi import ALProxy
  135. import sys
  136.  
  137.  
  138. port = 9559
  139. if len(sys.argv) < 2:
  140. print("veuillez passer une ip en cli")
  141. sys.exit(1)
  142.  
  143. ip = sys.argv[1]
  144. postureProxy = ALProxy("ALRobotPosture", ip, 9559)
  145. postureProxy.goToPosture("Stand", 0.5)
  146. motionProxy = ALProxy ("ALMotion", ip, 9559)
  147.  
  148.  
  149. def BPMs():
  150.  
  151. BPM= analyseSon()
  152. if 60<=BPM<=70:
  153. a = 1.5
  154. elif 70<=BPM<=80:
  155. a = 1.3
  156. elif 80<=BPM<=90:
  157. a = 1.1
  158. elif 90<=BPM<=100:
  159. a = 0.9
  160. elif 100<=BPM<=110:
  161. a = 0.7
  162. elif 110<=BPM<=120:
  163. a = 0.5
  164. elif 120<=BPM<=140:
  165. a = 0.4
  166. print BPM
  167. return a
  168.  
  169. x = BPMs()
  170.  
  171. ##COUDES EN L'AIR GAUCHE
  172. names = ['RElbowRoll' ,'RShoulderRoll','LShoulderRoll','LElbowRoll','RShoulderPitch','LShoulderPitch','RElbowYaw','LElbowYaw', 'HeadYaw', 'HeadPitch']
  173. times = [[x],[x],[x],[x],[x],[x],[x],[x],[x],[x]]
  174.  
  175. for i in range (4):
  176. 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)
  177. 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)
  178.  
  179.  
  180.  
  181. ##COUDES EN L'AIR DROITE
  182.  
  183.  
  184. names = ['RElbowRoll' ,'RShoulderRoll','LShoulderRoll','LElbowRoll','RShoulderPitch','LShoulderPitch','RElbowYaw', 'LElbowYaw', 'HeadYaw', 'HeadPitch']
  185. times = [[x],[x],[x],[x],[x],[x],[x],[x],[x],[x]]
  186.  
  187. for i in range (4):
  188. 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)
  189. 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)
  190.  
  191.  
  192. ##DAB
  193. x = BPMs()
  194. names = ['RElbowRoll' ,'RShoulderRoll','RShoulderPitch','RElbowYaw','LShoulderPitch','LShoulderRoll','LElbowYaw','HeadPitch','HeadYaw','LHipPitch','RHipPitch','LKneePitch','RKneePitch','LAnklePitch','RAnklePitch']
  195. 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]]
  196.  
  197. for i in range (2):
  198. 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)
  199. 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)
  200. 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)
  201.  
  202. ##COUCOU
  203.  
  204. x = BPMs()
  205. names = ['RElbowRoll' ,'RShoulderRoll','LShoulderRoll','LElbowRoll','RShoulderPitch','LShoulderPitch','RElbowYaw', 'LElbowYaw',]
  206. times = [[x],[x],[x],[x],[x],[x],[x],[x]]
  207.  
  208. for i in range (8):
  209. motionProxy.angleInterpolation(names,[0.98,-0.07,1.1,-0.05,-1.46,-1.6,0,0],times, True)
  210. motionProxy.angleInterpolation(names,[0.034,-1.06,-0.07,-1,-1.6,-1.6,0,0],times, True)
  211.  
  212.  
  213. ##GENOU
  214. x = BPMs()
  215. names = ['RElbowRoll' ,'RShoulderRoll','RShoulderPitch','RElbowYaw','LElbowRoll','LShoulderRoll','LShoulderPitch','LElbowYaw','RAnklePitch','LAnklePitch', 'LKneePitch', 'RKneePitch','LHipPitch','RHipPitch']
  216. times = [[x],[x],[x],[x],[x],[x],[x],[x],[x],[x],[x],[x],[x],[x]]
  217.  
  218. for i in range (4):
  219. 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)
  220. 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)
  221. 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)
  222.  
  223. ##petits mouvements bras
  224.  
  225. x = BPMs()
  226.  
  227. names = ['RElbowRoll' ,'LElbowRoll', 'RShoulderRoll','LShoulderRoll','RShoulderPitch','LShoulderPitch','HeadYaw']
  228. times = [[x],[x],[x],[x],[x],[x],[x]]
  229.  
  230. for i in range (8):
  231. motionProxy.angleInterpolation(names,[0.65,-0.65,0.14,-0.14,0.3,0.71,-0.46],times, True)
  232. motionProxy.angleInterpolation(names,[0.65,-0.65,0.14,-0.14,0.71,0.3,0.46],times, True)
  233.  
  234. ##BRAS EN L'AIR
  235. x = BPMs()
  236.  
  237. names = ['RElbowRoll' ,'LElbowRoll', 'RShoulderRoll','LShoulderRoll','RShoulderPitch','LShoulderPitch','HeadPitch']
  238. times = [[2*x],[2*x],[2*x],[2*x],[2*x],[2*x],[2*x]]
  239.  
  240. for i in range (4):
  241. motionProxy.angleInterpolation(names,[0.06,-0.16,0.29,-0.28,0.84,0.84,0.36],times, True)
  242. motionProxy.angleInterpolation(names,[-0.07,0.04,0.17,-0.14,-1.5,-1.5,-0.44],times, True)
  243. motionProxy.angleInterpolation(names,[0.06,-0.16,0.29,-0.28,0.84,0.84,0.36],times, True)
  244.  
  245.  
  246.  
  247. time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement