-
Notifications
You must be signed in to change notification settings - Fork 0
/
degen_3.py
93 lines (75 loc) · 2.77 KB
/
degen_3.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
from calibration.util import *
from calibration.solver import *
import os
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
# change working directory to the directory this file is in (for saving data)
os.chdir(os.path.dirname(os.path.abspath(__file__)))
NUM_OBS = 32
MEASURE_NOISE = 0.5
RADII = [0.1, 0.4, 0.7, 1, 1.3, 1.6, 1.9]
NUM_SAMPLES = 100
GEN_DATA = False
if(GEN_DATA):
results = {
"radius": [],
"p_error": [],
"u_error": [],
"a_error": []
}
# use a fixed plane and true p, u soln for simplicity
a = np.array([0, 0, 1])
d = 500
start_p = np.array([0, 0, 0])
start_u = np.array([0, 0, -1])
for radius in RADII:
print("radius", radius)
errors = []
for _ in range(NUM_SAMPLES):
bbox = [
[-400, 400],
[-400, 400],
[-400, 400]
]
tfs = generate_motions(start_p, start_u, a, d, np.array([0, 0, -500]), bbox, radius=radius, n=NUM_OBS)
ps = [from_hom(tf @ to_hom(np.array(start_p))) for tf in tfs]
us = [from_hom(tf @ np.append(start_u, [0])) for tf in tfs]
measurements = [gen_observation(p, u, a, d)[0] for p, u in zip(ps, us)]
for m, u, p in zip(measurements, us, ps):
# check that the point projected out from p and u is on plane
x = (np.array(u) * m) + np.array(p)
res = np.dot(np.array(a), x) + d
assert(np.abs(res) < 0.01)
# add noise to measurements
measurements = [m + np.random.normal(0, MEASURE_NOISE) for m in measurements]
soln, _ = slsqp(
tfs,
measurements,
a,
d,
start_p,
start_u,
[[-10000, 10000]]*3,
[-10000, 10000]
)
p_error = np.linalg.norm(np.array(start_p) - np.array(soln[0]))
u_error = np.degrees(angle_between(start_u, soln[1]))
a_error = np.degrees(angle_between(a, soln[2]))
print(a_error)
results["radius"].append(radius)
results["p_error"].append(p_error)
results["u_error"].append(u_error)
results["a_error"].append(a_error)
results = pd.DataFrame(results)
results.to_csv("data/simulated/degen_3.csv")
else:
results = pd.read_csv("data/simulated/degen_3.csv")
plt.figure(figsize=(6,4))
ax = sns.boxplot(x="radius", y="a_error", data=results, color="lightgray")
ax.set_xlabel("Radius of observed point spread on plane (mm)", fontsize=14)
ax.set_ylabel("Error in solved a vector (degrees)", fontsize=14)
plt.tight_layout()
plt.savefig("figures/degen_3.png", dpi=200)
plt.show()