-
Notifications
You must be signed in to change notification settings - Fork 3
/
jointAnkleForceTask.py
84 lines (61 loc) · 3.2 KB
/
jointAnkleForceTask.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
'''
Neuromuscular simulator in Python.
Copyright (C) 2017 Renato Naville Watanabe
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Contact: renato.watanabe@ufabc.edu.br
'''
import math
import numpy as np
class jointAnkleForceTask(object):
def __init__(self, conf, pools):
self.conf = conf
self.muscles = []
for i in xrange(0,len(pools)):
if pools[i].pool == 'SOL' or pools[i].pool == 'MG' or pools[i].pool == 'LG' or pools[i].pool == 'TA':
self.muscles.append(pools[i])
##
self.ankleAngle_rad = np.zeros((int(np.rint(conf.simDuration_ms/conf.timeStep_ms)), 1), dtype = float)
self.ankleTorque_Nm = np.zeros((int(np.rint(conf.simDuration_ms/conf.timeStep_ms)), 1), dtype = float)
print 'Ankle joint for Force Task built'
def atualizeAnkle(self, t, ankleAngle):
'''
Update the ankle joint.
- Inputs:
+ **t**: current instant, in ms.
+ **ankleAngle**: ankle angle, in rad.
'''
self.atualizeAngle(t, ankleAngle)
for muscle in self.muscles:
muscle.Muscle.atualizeMusculoTendonLength(ankleAngle)
muscle.Muscle.atualizeMomentArm(ankleAngle)
def atualizeAngle(self, t, ankleAngle):
'''
'''
self.ankleAngle_rad[int(np.rint(t / self.conf.timeStep_ms))] = ankleAngle
def computeTorque(self, t):
'''
'''
torque = 0
for muscle in self.muscles:
torque += muscle.Muscle.force[int(np.rint(t / self.conf.timeStep_ms))] * muscle.Muscle.momentArm_m[int(np.rint(t / self.conf.timeStep_ms))]
velocity = (self.ankleAngle_rad[int(np.rint(t / self.conf.timeStep_ms))] -
self.ankleAngle_rad[int(np.rint(t / self.conf.timeStep_ms)) - 1]) / self.conf.timeStep_ms
acceleration = (self.ankleAngle_rad[int(np.rint(t / self.conf.timeStep_ms))] -
2*self.ankleAngle_rad[int(np.rint(t / self.conf.timeStep_ms)) - 1]+
self.ankleAngle_rad[int(np.rint(t / self.conf.timeStep_ms)) - 2]) / (self.conf.timeStep_ms**2)
torque -= 0*1100*velocity + 0*320*self.ankleAngle_rad[int(np.rint(t / self.conf.timeStep_ms))] + 0*acceleration
self.ankleTorque_Nm[int(np.rint(t / self.conf.timeStep_ms))] = torque
def reset(self, t):
'''
'''
self.ankleAngle_rad = np.zeros((int(np.rint(conf.simDuration_ms/conf.timeStep_ms)), 1), dtype = float)
self.ankleTorque_Nm = np.zeros((int(np.rint(conf.simDuration_ms/conf.timeStep_ms)), 1), dtype = float)