Plotting muscle tendon legth against gait cycle - Python

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Marcos Alfredo Núñez
Posts: 22
Joined: Thu Sep 01, 2016 1:41 pm

Re: Plotting muscle tendon legth against gait cycle - Python

Post by Marcos Alfredo Núñez » Thu Feb 15, 2018 5:52 am

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

User avatar
Thomas Uchida
Posts: 1760
Joined: Wed May 16, 2012 11:40 am

Re: Plotting muscle tendon legth against gait cycle - Python

Post by Thomas Uchida » Thu Feb 15, 2018 6:24 am

Great, glad you got it working. Thanks for posting your final code; someone may find it helpful in the future.

POST REPLY