Page 2 of 2

Re: Plotting muscle tendon legth against gait cycle - Python

Posted: Thu Feb 15, 2018 5:52 am
by manunez
Tom:
Thanks for your help! I solved the issue, it hadn't anything to do with coordinates orders: storage values where in degrees. :roll: . I modified the state looping for the unordered state nevertheless. Thank you very much for your assistance!

Code: Select all

from math import radians

def computeLen(mot,mod):
    
    storage = opensim.Storage(mot)
    
    model = opensim.Model(mod)
    model.setUseVisualizer(False)
    state = model.initSystem()
    
    semiten_l = model.getMuscles().get('semiten_l')
    
    lengths_array = []

    if storage.isInDegrees():
        r = radians
    else:
        r = lambda x: x

    for t in range(storage.getSize()):
        for i in range(model.getNumCoordinates()):
            n = model.getCoordinateSet().get(i).getName()
            j = storage.getStateIndex(n)
            v = storage.getStateVector(t).getData().get(j)
            model.updCoordinateSet().get(i).setValue(state,r(v))
            
        # Here should go model.realizePosition(state), which I lack.
        model.computeStateVariableDerivatives(state)
        lengths_array.append(semiten_l.getLength(state))
    return lengths_array

Re: Plotting muscle tendon legth against gait cycle - Python

Posted: Thu Feb 15, 2018 6:24 am
by tkuchida
Great, glad you got it working. Thanks for posting your final code; someone may find it helpful in the future.