Skip to content

Commit

Permalink
musculoskeletal
Browse files Browse the repository at this point in the history
  • Loading branch information
demotu committed Mar 20, 2015
1 parent 40a8f33 commit 299287f
Show file tree
Hide file tree
Showing 5 changed files with 2,714 additions and 1,142 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Modeling and simulation of human movement
-----------------------------------------
- [Muscle modeling](http://nbviewer.ipython.org/github/demotu/BMC/blob/master/notebooks/MuscleModeling.ipynb)
- [Muscle simulation](http://nbviewer.ipython.org/github/demotu/BMC/blob/master/notebooks/MuscleSimulation.ipynb)
- [Musculoskeletal modeling and simulation](http://nbviewer.ipython.org/github/demotu/BMC/blob/master/notebooks/MusculoskeletaModelingSimulation.ipynb)

Stabilography
-------------
Expand Down
107 changes: 107 additions & 0 deletions data/vas_int_r.mot
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
UNKNOWN
version=1
nRows=100
nColumns=3
inDegrees=no
endheader
time knee_angle_r vas_int_r
0.00000000 -119.99999986 0.02467318
1.00000000 -118.68686855 0.02498702
2.00000000 -117.37373723 0.02531730
3.00000000 -116.06060592 0.02566117
4.00000000 -114.74747460 0.02601704
5.00000000 -113.43434329 0.02638334
6.00000000 -112.12121198 0.02675857
7.00000000 -110.80808066 0.02714124
8.00000000 -109.49494935 0.02752992
9.00000000 -108.18181803 0.02792318
10.00000000 -106.86868672 0.02831963
11.00000000 -105.55555540 0.02871792
12.00000000 -104.24242409 0.02911673
13.00000000 -102.92929277 0.02951475
14.00000000 -101.61616146 0.02991069
15.00000000 -100.30303015 0.03030330
16.00000000 -98.98989883 0.03069144
17.00000000 -97.67676752 0.03107407
18.00000000 -96.36363620 0.03144991
19.00000000 -95.05050489 0.03181767
20.00000000 -93.73737357 0.03217606
21.00000000 -92.42424226 0.03252380
22.00000000 -91.11111094 0.03285959
23.00000000 -89.79797963 0.03318213
24.00000000 -88.48484831 0.03348993
25.00000000 -87.17171700 0.03378156
26.00000000 -85.85858569 0.03405566
27.00000000 -84.54545437 0.03431083
28.00000000 -83.23232306 0.03454537
29.00000000 -81.91919174 0.03475078
30.00000000 -80.60606043 0.03436133
31.00000000 -79.29292911 0.03503595
32.00000000 -77.97979780 0.03568605
33.00000000 -76.66666648 0.03631325
34.00000000 -75.35353517 0.03691874
35.00000000 -74.04040385 0.03750376
36.00000000 -72.72727254 0.03806961
37.00000000 -71.41414123 0.03861761
38.00000000 -70.10100991 0.03914917
39.00000000 -68.78787860 0.03966562
40.00000000 -67.47474728 0.04016831
41.00000000 -66.16161597 0.04065876
42.00000000 -64.84848465 0.04113847
43.00000000 -63.53535334 0.04160901
44.00000000 -62.22222202 0.04207194
45.00000000 -60.90909071 0.04252888
46.00000000 -59.59595939 0.04298115
47.00000000 -58.28282808 0.04342578
48.00000000 -56.96969677 0.04386112
49.00000000 -55.65656545 0.04428673
50.00000000 -54.34343414 0.04470217
51.00000000 -53.03030282 0.04510706
52.00000000 -51.71717151 0.04550104
53.00000000 -50.40404019 0.04588375
54.00000000 -49.09090888 0.04625489
55.00000000 -47.77777756 0.04661418
56.00000000 -46.46464625 0.04696136
57.00000000 -45.15151493 0.04729621
58.00000000 -43.83838362 0.04761851
59.00000000 -42.52525231 0.04792808
60.00000000 -41.21212099 0.04822478
61.00000000 -39.89898968 0.04850853
62.00000000 -38.58585836 0.04879002
63.00000000 -37.27272705 0.04907708
64.00000000 -35.95959573 0.04936940
65.00000000 -34.64646442 0.04966653
66.00000000 -33.33333310 0.04996798
67.00000000 -32.02020179 0.05027312
68.00000000 -30.70707048 0.05058125
69.00000000 -29.39393916 0.05087780
70.00000000 -28.08080785 0.05110989
71.00000000 -26.76767653 0.05128466
72.00000000 -25.45454522 0.05141649
73.00000000 -24.14141390 0.05152009
74.00000000 -22.82828259 0.05161049
75.00000000 -21.51515127 0.05170299
76.00000000 -20.20201996 0.05181306
77.00000000 -18.88888864 0.05190026
78.00000000 -17.57575733 0.05188635
79.00000000 -16.26262602 0.05179396
80.00000000 -14.94949470 0.05164796
81.00000000 -13.63636339 0.05147323
82.00000000 -12.32323207 0.05129426
83.00000000 -11.01010076 0.05113467
84.00000000 -9.69696944 0.05102168
85.00000000 -8.38383813 0.05108717
86.00000000 -7.07070681 0.05135911
87.00000000 -5.75757550 0.05180707
88.00000000 -4.44444418 0.05240165
89.00000000 -3.13131287 0.05311443
90.00000000 -1.81818156 0.05391796
91.00000000 -0.50505024 0.05478569
92.00000000 0.80808107 0.05454853
93.00000000 2.12121239 0.05377130
94.00000000 3.43434370 0.05242298
95.00000000 4.74747502 0.05028654
96.00000000 6.06060633 0.04778168
97.00000000 7.37373765 0.04574031
98.00000000 8.68686896 0.04416718
99.00000000 10.00000028 0.04304499
30 changes: 20 additions & 10 deletions functions/muscles.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def calc_data(self, t, lm, lm0, lmt0, ltslack, lmopt, alpha0, fm0):
fce_t = fse/np.cos(alpha) - fpe
vm = self.velo_fm(fm=fce_t, a=a, fl=fl, lmopt=lmopt)
fm = self.force_vm(vm=vm, fl=fl, lmopt=lmopt, a=a) + fpe
data = [t, lmt, lm, lt, vm, fm*fm0, fse*fm0, a*fl*fm0, fpe*fm0]
data = [t, lmt, lm, lt, vm, fm*fm0, fse*fm0, a*fl*fm0, fpe*fm0, alpha]

return data

Expand All @@ -368,7 +368,8 @@ def muscle_plot(self, a=1, axs=None):
lm0 = self.S['lm0']
lmt0 = self.S['lmt0']
lt0 = self.S['lt0']
if np.isnan(lt0): lt0 = lmt0 - lm0*np.cos(alpha0)
if np.isnan(lt0):
lt0 = lmt0 - lm0*np.cos(alpha0)

lm = np.linspace(0, 2, 101)
lt = np.linspace(0, 1, 101)*0.05 + 1
Expand Down Expand Up @@ -449,10 +450,12 @@ def muscle_plot(self, a=1, axs=None):
plt.tight_layout(w_pad=.1)
plt.show()


def lm_plot(self, x, axs):
return axs


def lm_plot(self, x, axs=None):
"""Plot results of actdyn_ode45 function.
data = [t, lmt, lm, lt, vm, fm*fm0, fse*fm0, fl*fm0, fpe*fm0]
data = [t, lmt, lm, lt, vm, fm*fm0, fse*fm0, fl*fm0, fpe*fm0, alpha]
"""

try:
Expand All @@ -465,7 +468,11 @@ def lm_plot(self, x, axs):
_, axs = plt.subplots(nrows=3, ncols=2, sharex=True, figsize=(10, 6))

axs[0, 0].plot(x[:, 0], x[:, 1], 'b', label='LMT')
axs[0, 0].plot(x[:, 0], x[:, 2] + x[:, 3], 'g--', label='LM+LT')
lmt = x[:, 2]*np.cos(x[:, 9]) + x[:, 3]
if np.sum(x[:, 9]) > 0:
axs[0, 0].plot(x[:, 0], lmt, 'g--', label=r'$LM \cos \alpha + LT$')
else:
axs[0, 0].plot(x[:, 0], lmt, 'g--', label=r'LM+LT')
ylim = self.margins(x[:, 1], margin=.1)
axs[0, 0].set_ylim(ylim)
axs[0, 0].legend(framealpha=.5, loc='best')
Expand Down Expand Up @@ -497,10 +504,9 @@ def lm_plot(self, x, axs):
axs[2, 1].set_xlabel('Time (s)')
axs[2, 1].legend(framealpha=.5, loc='best')

axs = axs.flatten()
ylabel = ['$L_{MT}\,(m)$', '$L_{T}\,(m)$', '$L_{M}\,(m)$',
'$V_{CE}\,(m/s)$', '$Force\,(N)$', '$Force\,(N)$']
for i, axi in enumerate(axs):
for i, axi in enumerate(axs.flat):
axi.set_ylabel(ylabel[i], fontsize=14)
axi.yaxis.set_major_locator(plt.MaxNLocator(4))
axi.yaxis.set_label_coords(-.2, 0.5)
Expand All @@ -510,6 +516,8 @@ def lm_plot(self, x, axs):
plt.tight_layout()
plt.show()

return axs


def penn_ang(self, lmt, lm, lt=None, lm0=None, alpha0=None):
"""Pennation angle.
Expand Down Expand Up @@ -689,7 +697,7 @@ def activation(self, t=None):
return a


def actvation_plot(self, data, axs):
def actvation_plot(self, data, axs=None):
"""Plot results of actdyn_ode45 function."""

try:
Expand All @@ -708,7 +716,9 @@ def actvation_plot(self, data, axs):
axs.legend()
plt.title('Activation dynamics')
plt.tight_layout()
plt.show()
plt.show()

return axs


def margins(self, x, margin=0.01, minmargin=True):
Expand Down
Binary file modified images/knee.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 299287f

Please sign in to comment.