예제 #1
0
    def test_getBipedGaitStates():
        bvhFilePath = '../samples/wd2_WalkSameSame00.bvh'
        motion = yf.readBvhFile(bvhFilePath, .01)
        
        hRef = .1; vRef = .3
        lc = yma.getElementContactStates(motion, motion[0].skeleton.getElementIndex('LeftFoot'), hRef, vRef)
        rc = yma.getElementContactStates(motion, motion[0].skeleton.getElementIndex('RightFoot'), hRef, vRef)

        rawStateList = getBipedGaitStates(lc, rc)
        cookedStateList = getBipedGaitStates(lc, rc, 10, 1.)
        
        intervals, types = yma.states2intervals(cookedStateList)
        for i in range(len(intervals)):
            print(intervals[i], GaitState.text[types[i]])

        print()
        print([yma.intIntervalUp(int) for int in intervals])
        print(getWalkingSteps(lc, rc, True))
        print(getBipedGaitIntervals(lc, rc, 10, 1.))
        
        plot = ymp.SmartPlot()
        plot.setXdata('frame', range(len(motion)))
        plot.addYdata('rawState', rawStateList)
        plot.addYdata('cookedState', cookedStateList)
        plot.showModeless()
        
        viewer = ysv.SimpleViewer()
        viewer.record(False)
        viewer.doc.addRenderer('motion', yr.JointMotionRenderer(motion, (0,0,255), yr.LINK_LINE))
        viewer.doc.addObject('motion', motion)
        viewer.startTimer(1/30.)
        viewer.show()
        Fl.run()
예제 #2
0
def getBipedGaitStates2(lFootContactStates, rFootContactStates, jumpThreshold = 0, jumpBias = .5, stopThreshold = 0, stopBias = .5):
    gaitStates = [None]*len(lFootContactStates)
    
    for i in range(len(lFootContactStates)):
        if lFootContactStates[i] and not rFootContactStates[i]:
            gaitStates[i] = GaitState.RSWING
        elif not lFootContactStates[i] and rFootContactStates[i]:
            gaitStates[i] = GaitState.LSWING
        elif lFootContactStates[i] and rFootContactStates[i]:
            gaitStates[i] = GaitState.STOP
        elif not lFootContactStates[i] and not rFootContactStates[i]:
            gaitStates[i] = GaitState.JUMP
            
    # check thresholds
#    intervals, types = getBipedGaitIntervalsTypes(gaitStates)
#    stopIntervals = getSpecifiedTypeIntervals(GaitState.STOP, intervals, types)
#    jumpIntervals = getSpecifiedTypeIntervals(GaitState.JUMP, intervals, types)

    intervals, types = yma.states2intervals(gaitStates)
    intervals = [yma.intIntervalInner(interval) for interval in intervals]
    stopIntervals = yma.getIntervalsWithState(GaitState.STOP, intervals, types)
    jumpIntervals = yma.getIntervalsWithState(GaitState.JUMP, intervals, types)
    
    total = [stopIntervals, jumpIntervals]
    thresholds = [stopThreshold, jumpThreshold]
    biases = [stopBias, jumpBias]

    for b in range(len(total)):
        intervals = total[b]
        threshold = thresholds[b]
        bias = biases[b]
        
        for interval in intervals:
#            if interval[0] == 0 or interval[1] == len(gaitStates)-1:
#                continue
#            prevState = gaitStates[interval[0]-1] 
#            nextState = gaitStates[interval[1]+1] 

            # temp - to be fixed
            if interval[0] == 0:
                prevState = gaitStates[interval[1]+1]
                nextState = gaitStates[interval[1]+1]
            elif interval[1] == len(gaitStates)-1:
                prevState = gaitStates[interval[0]-1]
                nextState = gaitStates[interval[0]-1]
            else:
                prevState = gaitStates[interval[0]-1] 
                nextState = gaitStates[interval[1]+1]
                
            if interval[1] - interval[0] < threshold:
                mid = (interval[1] + interval[0])*bias
                for i in range(interval[0], interval[1]+1):
                    if i < mid:
                        gaitStates[i] = prevState
                    else:
                        gaitStates[i] = nextState
                          
    return gaitStates
예제 #3
0
    def test_blend():
        bvhFilePath = '../samples/wd2_WalkSameSame00.bvh'
        motion0 = yf.readBvhFile(bvhFilePath, .01)
        #        bvhFilePath = '../samples/wd2_WalkSukiko00.bvh'
        bvhFilePath = '../samples/wd2_WalkForwardVFast00.bvh'
        motion1 = yf.readBvhFile(bvhFilePath, .01)

        hRef = .1
        vRef = .3
        RHEEL = motion0[0].skeleton.getElementIndex('RightFoot')

        rc0 = yma.getElementContactStates(motion0, RHEEL, hRef, vRef)
        rc1 = yma.getElementContactStates(motion1, RHEEL, hRef, vRef)
        intervals0 = yma.states2intervals(rc0)[0]
        intervals1 = yma.states2intervals(rc1)[0]

        blendedMotion = blend(motion0, yma.intIntervalInner(intervals0[3]),
                              motion1, yma.intIntervalInner(intervals1[3]))

        viewer = ysv.SimpleViewer()
        viewer.record(False)
        viewer.doc.addRenderer(
            'motion0',
            yr.JointMotionRenderer(motion0, (0, 0, 255), yr.LINK_LINE))
        viewer.doc.addObject('motion0', motion0)
        viewer.doc.addRenderer(
            'motion1',
            yr.JointMotionRenderer(motion1, (0, 0, 255), yr.LINK_LINE))
        viewer.doc.addObject('motion1', motion1)
        viewer.doc.addRenderer(
            'blendedMotion',
            yr.JointMotionRenderer(blendedMotion, (0, 255, 0), yr.LINK_LINE))
        viewer.doc.addObject('blendedMotion', blendedMotion)

        viewer.startTimer(1 / 30.)
        viewer.show()

        Fl.run()
예제 #4
0
def getWalkingCycle(jointMotion, one_contactStates, endZoneSize = 10):
    intervals, types = yma.states2intervals(one_contactStates)
    half1stIndex = (len(intervals)-1)/2 - 1
    half2ndIndex = half1stIndex + 1
#    print half1stIndex, half2ndIndex, intervals[half1stIndex], intervals[half2ndIndex]
    
#    startFrame = intervals[half1stIndex][0]
#    endFrame = intervals[half2ndIndex][-1]
    startFrame = int(math.ceil(intervals[half1stIndex][0]))
    endFrame = int(math.floor(intervals[half2ndIndex][-1]))
    
    minDistance = sys.maxint
    minFrame = 0
    for i in range(endFrame-endZoneSize, endFrame+endZoneSize):
        d = yma.distanceByRelPos(jointMotion[startFrame], jointMotion[i])
#        print i, d
        if d < minDistance:
#            print 'min', i, d
            minDistance = d
            minFrame = i
    endFrame = minFrame
                        
    return [startFrame, endFrame]
예제 #5
0
def getBipedGaitIntervals2(lFootContactStates, rFootContactStates, jumpThreshold = 0, jumpBias = .5, stopThreshold = 0, stopBias = .5):
    states = getBipedGaitStates2(lFootContactStates, rFootContactStates, jumpThreshold, jumpBias, stopThreshold, stopBias)
    intervals, states = yma.states2intervals(states)
    return [yma.intIntervalUp(interval) for interval in intervals], states