-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInitial Sim.py
79 lines (65 loc) · 1.8 KB
/
Initial Sim.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
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 26 12:31:41 2024
@author: malac
"""
import matplotlib.pyplot as plt
import numpy as np
#simulation params
global dt
dt = 0.001 #delta t for approx
time = np.arange(0,10,dt)
#parameters, physical
Mm = 2 #kg, mass of motor
Mp = 60 #kg, mass of human
B = 0.01 #Ns/m, probably small
g = 9.81 #m/s^2
uf = 0.1 #probably small
l = 1 #meter
#derived params (constant)
Fsupp = Mp*g
#inputs
Fapp = np.sin(time) #walking force input
Fm = np.zeros_like(time) #motor response force (controller will determine eventually)
#outputs, with initial conditions!
vm = [0]
theta = [0]
vp = [0]
#derived params (nonconstant)
def Ff(Fsupp, uf):
return(Fsupp * uf)
#GOVERNING EQUATIONS
#1: Mm * vm' = -B*vm + 0*Fsupp + Fm - (Fsupp + Mm*g)*uf
#want to get vm' from known inputs. returns vm one dt in the future
def step_vm(vm, Mm, B, theta, Fsupp, Fm, g, uf):
if (Fsupp + Mm*g)*uf > (-B*vm) + (theta*Fsupp) + Fm:
d_vm = 0
else:
d_vm = (-B*vm) + (theta*Fsupp) + Fm - (Fsupp + Mm*g)*uf
d_vm /= Mm
return (vm + d_vm*dt)
#2: Mp * vp' = -0*Fsupp + Fapp
#returns vp one dt in the future
def step_vp(vp, Mp, theta, Fsupp, Fapp):
d_vp = -theta*Fsupp + Fapp
d_vp /= Mp
return (vp + d_vp*dt)
#3: l*0'= vp - vm
#returns theta one dt in the future
def step_theta(theta, vp, vm, l):
d_theta = (vp-vm)/l
return(theta*d_theta*dt)
#SIMULATE LOOP
for i, t in enumerate(time):
if not i == len(time) - 1:
vm.append(step_vm(vm[i], Mm, B, theta[i], Fsupp, Fm[i], g, uf))
vp.append(step_vp(vp[i], Mp, theta[i], Fsupp, Fapp[i]))
theta.append(step_theta(theta[i],vp[i],vm[i],l))
plt.figure()
plt.plot(time, vm, label='vm')
plt.plot(time, vp, label = 'vp')
plt.legend()
plt.show()
plt.figure()
plt.plot(time, theta, label = 'theta')
plt.show()