Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from naoqi import ALProxy
- import scipy.io.wavfile as wave
- from numpy import NaN, Inf, arange, isscalar, asarray, array, size
- import time
- import sys
- import os
- import pysftp
- import numpy
- #record = ALProxy("ALAudioRecorder", "169.254.28.144", 9559)
- #record = None
- def soundRecord(robot_IP, robot_PORT=9559, temp=5):
- global record
- record = ALProxy("ALAudioRecorder", "169.254.28.144", 9559)
- record_path = '/home/nao/danseavec.wav'
- record.stopMicrophonesRecording()
- record.startMicrophonesRecording(record_path, 'wav', 16000, (1,0,0,0))
- time.sleep(temp)
- record.stopMicrophonesRecording()
- def peakdet(v, delta, x = None):
- maxtab = []
- mintab = []
- if x is None:
- x = arange(len(v))
- v = asarray(v)
- if len(v) != len(x):
- sys.exit('Input vectors v and x must have same length')
- if not isscalar(delta):
- sys.exit('Input argument delta must be a scalar')
- if delta <= 0:
- sys.exit('Input argument delta must be positive')
- mn, mx = Inf, -Inf
- mnpos, mxpos = NaN, NaN
- lookformax = True
- for i in arange(len(v)):
- this = v[i]
- if this > mx:
- mx = this
- mxpos = x[i]
- if this < mn:
- mn = this
- mnpos = x[i]
- if lookformax:
- if this < mx-delta:
- maxtab.append((mxpos, mx))
- mn = this
- mnpos = x[i]
- lookformax = False
- else:
- if this > mn+delta:
- mintab.append((mnpos, mn))
- mx = this
- mxpos = x[i]
- lookformax = True
- return array(maxtab)
- def moveUp(T, N, givenPos):
- 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']
- nbPoses = len(givenPos)
- nbMoteur = len(names)
- temps = list()
- tableTemps = list()
- for i in range (N):
- temps.append((i+1)*T)
- for i in range(nbMoteur):
- tableTemps.append(temps)
- allPos = list()
- j=0
- for i in range(N):
- if j == nbPoses:
- j = 0
- allPos.append(givenPos[j])
- j = j+1
- allPos = zip(*allPos)
- motionProxy.angleInterpolationBezier(names, tableTemps, allPos)
- pass
- def debout():
- f = open("/home/nao/deboutDegre.txt", "r")
- lignes = f.readlines()
- pos = list()
- for L in lignes[1:]:
- L = L.split(',')
- for i in range(len(L)):
- L[i] = float(L[i])*(pi/180)
- pos.append(L)
- f.close()
- moveUp(p,1,pos)
- pass
- def analyseSon(ipp, port, temp=5):
- soundRecord(ipp, port, temp)
- curdir = os.getcwd()
- dir = curdir + '/audio/danseavec.wav'
- with pysftp.Connection('169.254.28.144', username = 'nao', password = 'stark') as sftp :
- sftp.get('/home/nao/danseavec.wav', dir)
- rate,data = wave.read('/home/eleve/Bureau/audio/danseavec.wav')
- #print rate
- #print data
- if len(data) != size(data) :
- data=data[:,0]
- Debut = 0
- duree = 5
- N = duree*rate
- zzrot = data[ Debut : N + Debut]
- fvi = numpy.fft.fft(zzrot, n=2*N)
- acf = numpy.real( numpy.fft.ifft( fvi * numpy.conjugate(fvi) )[:N] )
- acf = acf/N
- acfcarre=acf*acf
- moy = 2000
- rate1 = rate / moy
- ajf = []
- count = 0
- ajfa = 0
- while size(ajf) != size (acfcarre) / moy :
- for it in range (moy) :
- ajfa = acfcarre[it+count*moy] + ajfa
- ajf = ajf + [ajfa]
- ajfa = 0
- count = count + 1
- ajf=ajf/ajf[0] * 100
- axex = numpy.arange(size(ajf))/rate1
- Npic=len(peakdet(ajf, 0.1, axex))
- TPP = Npic / duree
- return TPP
- while True :
- ipp = "169.254.28.144"
- port = 9559
- temp = 5
- TPP = analyseSon(ipp, port, temp)
- print TPP
- if len(sys.argv) < 2:
- print("veuillez passer une ip en cli")
- sys.exit(1)
- ip = sys.argv[1]
- postureProxy = ALProxy("ALRobotPosture", ipp, port)
- postureProxy.goToPosture("Stand", 0.5)
- motionProxy = ALProxy ("ALMotion", ipp, port)
- TPP= analyseSon(ipp, port)
- motionProxy=ALProxy("ALMotion")
- self.framemanager = ALProxy("ALFrameManager")
- #0 0
- #-1 1
- #1 -1
- #1 -1
- #1 1
- #f = open("C:\Users\comte\Documents\ISEP\Cours\NaoDance\NaoDanceMouvement\balanceTete.txt", "r")
- f = open("/home/nao/poseStable1degre.txt", "r")
- lignes = f.readlines()
- pos = list()
- for L in lignes[1:]:
- L = L.split(',')
- for i in range(len(L)):
- L[i] = float(L[i])*(pi/180)
- pos.append(L)
- f.close()
- moveUp(TPP,4,pos)
- debout()
- TPP= analyseSon(ipp, port)
- f = open("/home/nao/poseStable2degre.txt", "r")
- lignes = f.readlines()
- pos = list()
- for L in lignes[1:]:
- L = L.split(',')
- for i in range(len(L)):
- L[i] = float(L[i])*(pi/180)
- pos.append(L)
- f.close()
- moveUp(TPP,4,pos)
- debout()
- TPP= analyseSon(ipp, port)
- f = open("/home/nao/hanches.txt", "r")
- lignes = f.readlines()
- pos = list()
- for L in lignes[1:]:
- L = L.split(',')
- for i in range(len(L)):
- L[i] = float(L[i])#*(pi/180)
- pos.append(L)
- f.close()
- moveUp(TPP,4,pos)
- debout()
- TPP= analyseSon(ipp, port)
- f = open("/home/nao/discodegre.txt", "r")
- lignes = f.readlines()
- pos = list()
- for L in lignes[1:]:
- L = L.split(',')
- for i in range(len(L)):
- L[i] = float(L[i])#*(pi/180)
- pos.append(L)
- f.close()
- moveUp(TPP,4,pos)
- debout()
- # ##COUDES EN L'AIR GAUCHE
- #
- # names = ['RElbowRoll' ,'RShoulderRoll','LShoulderRoll','LElbowRoll','RShoulderPitch','LShoulderPitch','RElbowYaw', 'LElbowYaw', 'HeadYaw', 'HeadPitch']
- # times = [[x],[x],[x],[x],[x],[x],[x],[x],[x],[x]]
- #
- # for i in range (4):
- # 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)
- # 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)
- #
- #
- #
- # ##COUDES EN L'AIR DROITE
- #
- #
- # names = ['RElbowRoll' ,'RShoulderRoll','LShoulderRoll','LElbowRoll','RShoulderPitch','LShoulderPitch','RElbowYaw', 'LElbowYaw', 'HeadYaw', 'HeadPitch']
- # times = [[x],[x],[x],[x],[x],[x],[x],[x],[x],[x]]
- #
- # for i in range (4):
- # 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)
- # 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)
- #
- #
- # ##DAB
- # BPM = analyseSon()
- # x=BPM/100
- #
- # names = ['RElbowRoll' ,'RShoulderRoll','RShoulderPitch','RElbowYaw','LShoulderPitch','LShoulderRoll','LElbowYaw','HeadPitch','HeadYaw','LHipPitch','RHipPitch','LKneePitch','RKneePitch','LAnklePitch','RAnklePitch']
- # 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]]
- #
- # for i in range (2):
- # 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)
- # 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)
- # 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)
- #
- # ##COUCOU
- #
- # BPM = analyseSon()
- # x=BPM/100
- #
- # names = ['RElbowRoll' ,'RShoulderRoll','LShoulderRoll','LElbowRoll','RShoulderPitch','LShoulderPitch','RElbowYaw', 'LElbowYaw',]
- # times = [[3*x],[3*x],[3*x],[3*x],[3*x],[3*x],[3*x],[3*x]]
- #
- # for i in range (2):
- # motionProxy.angleInterpolation(names,[0.98,-0.07,1.1,-0.05,-1.46,-1.6,0,0],times, True)
- # motionProxy.angleInterpolation(names,[0.034,-1.06,-0.07,-1,-1.6,-1.6,0,0],times, True)
- #
- #
- # ##GENOU
- #
- # BPM = analyseSon()
- # x=BPM/100
- #
- # names = ['RElbowRoll' ,'RShoulderRoll','RShoulderPitch','RElbowYaw','LElbowRoll','LShoulderRoll','LShoulderPitch','LElbowYaw','RAnklePitch','LAnklePitch', 'LKneePitch', 'RKneePitch','LHipPitch','RHipPitch']
- # 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]]
- #
- # for i in range (4):
- # 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)
- # 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)
- # 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)
- #
- # ##petits mouvements bras
- #
- # BPM = analyseSon()
- # x=BPM/100
- #
- # names = ['RElbowRoll' ,'LElbowRoll', 'RShoulderRoll','LShoulderRoll','RShoulderPitch','LShoulderPitch','HeadYaw']
- # times = [[x],[x],[x],[x],[x],[x],[x]]
- #
- # for i in range (8):
- # motionProxy.angleInterpolation(names,[0.65,-0.65,0.14,-0.14,0.3,0.71,-0.46],times, True)
- # motionProxy.angleInterpolation(names,[0.65,-0.65,0.14,-0.14,0.71,0.3,0.46],times, True)
- #
- # ##BRAS EN L'AIR
- # BPM = analyseSon()
- # x=BPM/100
- #
- # names = ['RElbowRoll' ,'LElbowRoll', 'RShoulderRoll','LShoulderRoll','RShoulderPitch','LShoulderPitch','HeadPitch']
- # times = [[3*x],[3*x],[3*x],[3*x],[3*x],[3*x],[3*x]]
- #
- # for i in range (4):
- # motionProxy.angleInterpolation(names,[0.06,-0.16,0.29,-0.28,0.84,0.84,0.36],times, True)
- # motionProxy.angleInterpolation(names,[-0.07,0.04,0.17,-0.14,-1.5,-1.5,-0.44],times, True)
- # motionProxy.angleInterpolation(names,[0.06,-0.16,0.29,-0.28,0.84,0.84,0.36],times, True)
- #
- #
- #
- # time.sleep(10)
- #
- #
- #
- #
- #
- #
- #port = 9559
- #if len(sys.argv) < 2:
- # print("veuillez passer une ip en cli")
- # sys.exit(1)
- #
- #ip = sys.argv[1]
- #
- #postureProxy = ALProxy("ALRobotPosture", ip, 9559)
- #postureProxy.goToPosture("Stand", 0.5)
- #motionProxy = ALProxy ("ALMotion", ip, 9559)
- #
- #
- #x = BPS
- #
- # ##COUDES EN L'AIR GAUCHE
- #
- #names = ['RElbowRoll' ,'RShoulderRoll','LShoulderRoll','LElbowRoll','RShoulderPitch','LShoulderPitch','RElbowYaw', 'LElbowYaw', 'HeadYaw', 'HeadPitch']
- #times = [[x],[x],[x],[x],[x],[x],[x],[x],[x],[x]]
- #
- #for i in range (4):
- # 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)
- # 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)
- #
- #
- #
- # ##COUDES EN L'AIR DROITE
- #
- #
- #
- #names = ['RElbowRoll' ,'RShoulderRoll','LShoulderRoll','LElbowRoll','RShoulderPitch','LShoulderPitch','RElbowYaw', 'LElbowYaw', 'HeadYaw', 'HeadPitch']
- #times = [[x],[x],[x],[x],[x],[x],[x],[x],[x],[x]]
- #
- #for i in range (4):
- # 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)
- # 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)
- #
- #
- # ##DAB
- #
- #names = ['RElbowRoll' ,'RShoulderRoll','RShoulderPitch','RElbowYaw','LShoulderPitch','LShoulderRoll','LElbowYaw','HeadPitch','HeadYaw','LHipPitch','RHipPitch','LKneePitch','RKneePitch','LAnklePitch','RAnklePitch']
- #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]]
- #
- #for i in range (2):
- # 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)
- # 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)
- # 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)
- #
- # ##COUCOU
- #
- #
- #names = ['RElbowRoll' ,'RShoulderRoll','LShoulderRoll','LElbowRoll','RShoulderPitch','LShoulderPitch','RElbowYaw', 'LElbowYaw',]
- #times = [[3*x],[3*x],[3*x],[3*x],[3*x],[3*x],[3*x],[3*x]]
- #
- #for i in range (4):
- # motionProxy.angleInterpolation(names,[0.98,-0.07,1.1,-0.05,-1.46,-1.6,0,0],times, True)
- # motionProxy.angleInterpolation(names,[0.034,-1.06,-0.07,-1,-1.6,-1.6,0,0],times, True)
- #
- #
- # ##GENOU
- #
- #
- #names = ['RElbowRoll' ,'RShoulderRoll','RShoulderPitch','RElbowYaw','LElbowRoll','LShoulderRoll','LShoulderPitch','LElbowYaw','RAnklePitch','LAnklePitch', 'LKneePitch', 'RKneePitch','LHipPitch','RHipPitch']
- #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]]
- #
- #for i in range (8):
- # 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)
- # 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)
- # 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)
- #
- # ##petits mouvements bras
- #
- #names = ['RElbowRoll' ,'LElbowRoll', 'RShoulderRoll','LShoulderRoll','RShoulderPitch','LShoulderPitch','HeadYaw']
- #times = [[x],[x],[x],[x],[x],[x],[x]]
- #
- #for i in range (8):
- # motionProxy.angleInterpolation(names,[0.65,-0.65,0.14,-0.14,0.3,0.71,-0.46],times, True)
- # motionProxy.angleInterpolation(names,[0.65,-0.65,0.14,-0.14,0.71,0.3,0.46],times, True)
- #
- # ##BRAS EN L'AIR
- #
- #
- #names = ['RElbowRoll' ,'LElbowRoll', 'RShoulderRoll','LShoulderRoll','RShoulderPitch','LShoulderPitch','HeadPitch']
- #times = [[3*x],[3*x],[3*x],[3*x],[3*x],[3*x],[3*x]]
- #
- #for i in range (4):
- # motionProxy.angleInterpolation(names,[0.06,-0.16,0.29,-0.28,0.84,0.84,0.36],times, True)
- # motionProxy.angleInterpolation(names,[-0.07,0.04,0.17,-0.14,-1.5,-1.5,-0.44],times, True)
- # motionProxy.angleInterpolation(names,[0.06,-0.16,0.29,-0.28,0.84,0.84,0.36],times, True)
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement