forked from s2mLab/ControlOdrive
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcomputation.py
51 lines (36 loc) · 1013 Bytes
/
computation.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
import json
import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import curve_fit
a = []
b = []
h = "h"
for bike in ["10", "8", "6", "4", "3", "2", "1"]:
with open(f"./calibration_files/resisting_current_load_h{h}_b{bike}.json", "r") as f:
data = json.load(f)
a.append(data["a"])
b.append(data["b"])
def find(pig, prop, cst):
return prop / pig + cst
pig = np.asarray([11, 15, 19, 25, 28, 32, 36])
popt = curve_fit(find, pig, a)
plt.plot(pig, a)
plt.plot(pig, find(pig, *popt[0]))
print(popt[0])
plt.show()
a = []
b = []
bike = "10"
for h in ["h", "5", "4", "3", "2", "1", "l"]:
with open(f"./calibration_files/resisting_current_load_h{h}_b{bike}.json", "r") as f:
data = json.load(f)
a.append(data["a"])
b.append(data["b"])
def find(ht, prop, cst):
return prop * ht + cst
ht = np.asarray([6, 5, 4, 3, 2, 1, 0])
popt = curve_fit(find, ht, a)
print(popt[0])
plt.plot(ht, a)
plt.plot(ht, find(ht, *popt[0]))
plt.show()