-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmuscleModels.py
203 lines (164 loc) · 8.39 KB
/
muscleModels.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
'''
This script contains classes that implement muscle models.
'''
# %% Import packages.
import numpy as np
# %% DeGrooteFregly2016MuscleModel
# This class implements the muscle model desrcribed in De Groote et al. (2016).
# https://link.springer.com/article/10.1007%2Fs10439-016-1591-9
class DeGrooteFregly2016MuscleModel:
def __init__(self, mtParameters, activation, mtLength, mtVelocity,
normTendonForce, normTendonForceDT, tendonCompliance,
specificTension):
self.mtParameters = mtParameters
self.maximalIsometricForce = mtParameters[0]
self.optimalFiberLength = mtParameters[1]
self.tendonSlackLength = mtParameters[2]
self.optimalPennationAngle = mtParameters[3]
self.maximalFiberVelocity = mtParameters[4]
self.activation = activation
self.mtLength = mtLength
self.mtVelocity = mtVelocity
self.normTendonForce = normTendonForce
self.normTendonForceDT = normTendonForceDT
self.tendonCompliance = tendonCompliance
self.specificTension = specificTension
self.paramFLa = np.array([0.814483478343008, 1.05503342897057,
0.162384573599574, 0.0633034484654646,
0.433004984392647, 0.716775413397760,
-0.0299471169706956, 0.200356847296188])
self.paramFLp = np.array([-0.995172050006169, 53.5981500331442])
self.paramFV = np.array([-0.318323436899127, -8.14915604347525,
-0.374121508647863, 0.885644059915004])
def getMuscleVolume(self):
self.muscleVolume = np.multiply(self.maximalIsometricForce,
self.optimalFiberLength)
return self.muscleVolume
def getMuscleMass(self):
muscleMass = np.divide(np.multiply(self.muscleVolume, 1059.7),
np.multiply(self.specificTension, 1e6))
return muscleMass
def getTendonForce(self):
tendonForce = np.multiply(self.normTendonForce,
self.maximalIsometricForce)
return tendonForce
def getTendonShift(self):
genericTendonCompliance = 35
genericTendonShift = 0
referenceNormTendonLength = 1
referenceNormTendonForce = (0.2 * np.exp(
genericTendonCompliance * (referenceNormTendonLength - 0.995))
- 0.25 + genericTendonShift)
adjustedNormTendonForce = (0.2 * np.exp(
self.tendonCompliance * (referenceNormTendonLength - 0.995))
- 0.25 + genericTendonShift)
self.tendonShift = referenceNormTendonForce - adjustedNormTendonForce
adjustedNormTendonForce_afterShift = (0.2 * np.exp(
self.tendonCompliance * (referenceNormTendonLength - 0.995))
- 0.25 + self.tendonShift)
assert np.alltrue(
np.abs(referenceNormTendonForce -
adjustedNormTendonForce_afterShift)
< 1e-12), "Error when shifting tendon curve"
return self.tendonShift
def getTendonLength(self):
# Tendon force-length relationship.
self.getTendonShift()
self.normTendonLength = np.divide(
np.log(5*(self.normTendonForce + 0.25 - self.tendonShift)),
self.tendonCompliance) + 0.995
self.tendonLength = np.multiply(self.tendonSlackLength,
self.normTendonLength)
return self.tendonLength, self.normTendonLength
def getFiberLength(self):
# Hill-type muscle model: geometric relationships.
self.getTendonLength()
w = np.multiply(self.optimalFiberLength,
np.sin(self.optimalPennationAngle))
self.fiberLength = np.sqrt(
(self.mtLength - self.tendonLength)**2 + w**2)
self.normFiberLength = np.divide(self.fiberLength,
self.optimalFiberLength)
return self.fiberLength, self.normFiberLength
def getFiberVelocity(self):
# Hill-type muscle model: geometric relationships.
self.getFiberLength()
tendonVelocity = np.divide(np.multiply(self.tendonSlackLength,
self.normTendonForceDT),
0.2 * self.tendonCompliance * np.exp(self.tendonCompliance *
(self.normTendonLength -
0.995)))
self.cosPennationAngle = np.divide((self.mtLength - self.tendonLength),
self.fiberLength)
self.fiberVelocity = np.multiply((self.mtVelocity - tendonVelocity),
self.cosPennationAngle)
self.normFiberVelocity = np.divide(self.fiberVelocity,
self.maximalFiberVelocity)
return self.fiberVelocity, self.normFiberVelocity
def getActiveFiberLengthForce(self):
self.getFiberLength()
# Active muscle force-length relationship.
b11 = self.paramFLa[0]
b21 = self.paramFLa[1]
b31 = self.paramFLa[2]
b41 = self.paramFLa[3]
b12 = self.paramFLa[4]
b22 = self.paramFLa[5]
b32 = self.paramFLa[6]
b42 = self.paramFLa[7]
b13 = 0.1
b23 = 1
b33 = 0.5 * np.sqrt(0.5)
b43 = 0
num3 = self.normFiberLength - b23
den3 = b33 + b43 * self.normFiberLength
FMtilde3 = b13 * np.exp(-0.5 * (np.divide(num3**2, den3**2)))
num1 = self.normFiberLength - b21
den1 = b31 + b41 * self.normFiberLength
FMtilde1 = b11 * np.exp(-0.5 * (np.divide(num1**2, den1**2)))
num2 = self.normFiberLength - b22
den2 = b32 + b42 * self.normFiberLength
FMtilde2 = b12 * np.exp(-0.5 * (np.divide(num2**2, den2**2)))
self.normActiveFiberLengthForce = FMtilde1 + FMtilde2 + FMtilde3
return self.normActiveFiberLengthForce
def getActiveFiberVelocityForce(self):
self.getFiberVelocity()
# Active muscle force-velocity relationship.
e1 = self.paramFV[0]
e2 = self.paramFV[1]
e3 = self.paramFV[2]
e4 = self.paramFV[3]
self.normActiveFiberVelocityForce = e1 * np.log(
(e2 * self.normFiberVelocity + e3)
+ np.sqrt((e2 * self.normFiberVelocity + e3)**2 + 1)) + e4
def getActiveFiberForce(self):
d = 0.01
self.getActiveFiberLengthForce()
self.getActiveFiberVelocityForce()
self.normActiveFiberForce = ((self.activation *
self.normActiveFiberLengthForce *
self.normActiveFiberVelocityForce) +
d * self.normFiberVelocity)
activeFiberForce = (self.normActiveFiberForce *
self.maximalIsometricForce)
return activeFiberForce, self.normActiveFiberForce
def getPassiveFiberForce(self):
paramFLp = self.paramFLp
self.getFiberLength()
# Passive muscle force-length relationship.
e0 = 0.6
kpe = 4
t5 = np.exp(kpe * (self.normFiberLength - 1) / e0)
self.normPassiveFiberForce = np.divide(((t5 - 1) - paramFLp[0]),
paramFLp[1])
passiveFiberForce = (self.normPassiveFiberForce *
self.maximalIsometricForce)
return passiveFiberForce, self.normPassiveFiberForce
def deriveHillEquilibrium(self):
self.getActiveFiberForce()
self.getPassiveFiberForce()
hillEquilibrium = ((np.multiply(self.normActiveFiberForce +
self.normPassiveFiberForce,
self.cosPennationAngle)) -
self.normTendonForce)
return hillEquilibrium