def calibrateData(procCmd):
    
#    calData = datAc.pipeAcquisition(procCmd,4,measNr=150)
    calData = datAc.collectForTime(procCmd,5)
    
    # convert to Tesla
#    print "type calData", type(calData)
#    print "type calData[0]",type(calData[0])
    nInd = calData[0]*1e-7
    nMid = calData[1]*1e-7
    nRin = calData[2]*1e-7
    nPin = calData[3]*1e-7
    # reassign the tuple...
    calData = None
    calData = (nInd, nMid, nRin, nPin)
    
        
    # calculating the B-field
    fingerList = [h.phalInd]
    jointList = [h.jointInd]
    sensList = [h.sInd,h.sMid,h.sRin,h.sPin]

    t = np.arange(0,1/2.*np.pi,0.01)
    angles = np.zeros((len(t),3))
    cnt = 0
    for i in t:
        angles[cnt] = np.array([i, 0., 0.])                                
        cnt += 1
    

#    calcB_dip = np.zeros((len(t),3*len(sensList)))
    calcB_cyl = np.zeros((len(t),3*len(sensList)))
    cnt = 0
    for i in angles:
#        calcB_dip[cnt] = modD.cy.angToBm_cy(i,fingerList,sensList,jointList)
        calcB_cyl[cnt] = modC.cy.angToB_cyl(i,fingerList,sensList,jointList)
        cnt += 1

    # fitting to dipole model
    (scaleInd,offInd) = datAc.getScaleOff(calcB_cyl[:,0:3] , calData[0])
    (scaleMid,offMid) = datAc.getScaleOff(calcB_cyl[:,3:6] , calData[1])
    (scaleRin,offRin) = datAc.getScaleOff(calcB_cyl[:,6:9] , calData[2])
    (scalePin,offPin) = datAc.getScaleOff(calcB_cyl[:,9:12], calData[3])
    
    scaleArr = np.array([scaleInd, scaleMid, scaleRin, scalePin])
    offArr = np.array([offInd, offMid, offRin, offPin])
    
    cInd = calData[0]*scaleInd+offInd
    cMid = calData[1]*scaleMid+offMid
    cRin = calData[2]*scaleRin+offRin
    cPin = calData[3]*scalePin+offPin
    
    plo.plotter2d((cInd,cMid,cRin,cPin),("calIndex","calMid","calRin","calPin"))
    plt.figure()
    plo.plotter2d((calcB_cyl[:,0:3],calcB_cyl[:,3:6],calcB_cyl[:,6:9],calcB_cyl[:,9:]),
                  ("simIndex","simMid","simRin","simPin"))

    return (scaleArr, offArr)
示例#2
0
def calibrateData(procCmd):
    print "cali"


    fingerList = [h.phalInd,h.phalMid,h.phalRin,h.phalPin]
    jointList = [h.jointInd_car,h.jointMid_car,h.jointRin_car,h.jointPin_car]
    sensList = [h.sInd_car,h.sMid_car,h.sRin_car,h.sPin_car]


#    calData = datAc.pipeAcquisition(procCmd,4,measNr=150)
    calData = datAc.collectForTime(procCmd,20)

    t = np.arange(0,1/2.*np.pi,0.01)
    angles = np.zeros((len(t),2*len(sensList)))
    cnt = 0
    for i in t:
        angles[cnt] = np.array([i, 0.,
                                i, 0.,
                                i, 0.,
                                i, 0.])
        cnt += 1

    # calculating the B-field
    fingerList = [h.phalInd,h.phalMid,h.phalRin,h.phalPin]
    jointList = [h.jointInd_car,h.jointMid_car,h.jointRin_car,h.jointPin_car]
    sensList = [h.sInd_car,h.sMid_car,h.sRin_car,h.sPin_car]

    calcB_dip = np.zeros((len(t),3*len(sensList)))
    calcB_cyl = np.zeros((len(t),3*len(sensList)))
    cnt = 0
    for i in angles:
        calcB_dip[cnt] = modD.cy.angToBm_cy(i,fingerList,sensList,jointList)
        calcB_cyl[cnt] = modC.cy.angToB_cyl(i,fingerList,sensList,jointList)
        cnt += 1

    # fitting to dipole model
    (scaleInd,offInd) = datAc.getScaleOff(calcB_dip[:,0:3] , calData[0])
    (scaleMid,offMid) = datAc.getScaleOff(calcB_dip[:,3:6] , calData[1])
    (scaleRin,offRin) = datAc.getScaleOff(calcB_dip[:,6:9] , calData[2])
    (scalePin,offPin) = datAc.getScaleOff(calcB_dip[:,9:12], calData[3])

    # fitting to cylindrical model
    # (scaleInd,offInd) = datAc.getScaleOff(calcB_cyl[:,0:3] , calData[0])
    # (scaleMid,offMid) = datAc.getScaleOff(calcB_cyl[:,3:6] , calData[1])
    # (scaleRin,offRin) = datAc.getScaleOff(calcB_cyl[:,6:9] , calData[2])
    # (scalePin,offPin) = datAc.getScaleOff(calcB_cyl[:,9:12], calData[3])

    scaleArr = np.array([scaleInd, scaleMid, scaleRin, scalePin])
    offArr = np.array([offInd, offMid, offRin, offPin])

    return (scaleArr, offArr)
import dataAcquisitionMulti as datAc
import plotting as plo
import modelCyl as modC
import modelDip as modD
import handDim as h
import numpy as np

bleCmd = "gatttool -t random -b E7:00:30:16:CD:18 --char-write-req --handle=0x000f --value=0300 --listen"



#calData = datAc.pipeAcquisition(bleCmd,4,measNr=100)

calData = datAc.collectForTime(bleCmd, 30)



#calData = datAc.textAcquisition("160202_hand2")
meas = np.array([calData[0][:,0],calData[0][:,1],calData[0][:,2],
                 calData[1][:,0],calData[1][:,1],calData[1][:,2],
                 calData[2][:,0],calData[2][:,1],calData[2][:,2],
                 calData[3][:,0],calData[3][:,1],calData[3][:,2],]).T

# calculating the B-field
fingerList = [h.phalInd,h.phalMid,h.phalRin,h.phalPin]
jointList = [h.jointInd_car,h.jointMid_car,h.jointRin_car,h.jointPin_car]
sensList = [h.sInd_car,h.sMid_car,h.sRin_car,h.sPin_car]

t = np.arange(0,1/2.*np.pi,0.01)
angles = np.zeros((len(t),2*len(sensList)))
cnt = 0