-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_some_other_test.py
79 lines (64 loc) · 2.4 KB
/
run_some_other_test.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
import pickle
import trimesh
import meshcat
import lcm
from contact_particle_filter.contact_particle_filter_core import (
ContactParticleFilter)
from contact_particle_filter.lcmt_contact_particle_filter import lcmt_contact_position
from drake import lcmt_iiwa_status
from pydrake.multibody.tree import JacobianWrtVariable
from contact_particle_filter.contact_visualizer import *
#%%
test_result_file_name = "../cpf_mc_test Tue Apr 28 04:59:42 2020"
test_result = pickle.load(open(test_result_file_name, "rb"))
test_idx = 6
q0 = test_result["joint_angles"][test_idx]
link_idx = test_result["true_contact_link"][test_idx]
p_LC_L_true = test_result["true_contact_point_p_LC_L"][test_idx]
f_W_true = test_result["true_contact_force_f_W"][test_idx]
tau_external = test_result["tau_ext"][test_idx]
cpf = ContactParticleFilter()
cpf.UpdateLinkPoses(q0)
X_WL7 = cpf.pose_bundle[link_idx]
X_WB7 = X_WL7.multiply(cpf.X_LB_list[link_idx])
point_true_world = X_WB7.multiply(p_LC_L_true)
vis = meshcat.Visualizer(zmq_url="tcp://127.0.0.1:6000")
DrawRobot(vis, cpf.pose_bundle, cpf.X_LB_list)
DrawArrow(vis, "arrow_true",
origin=point_true_world,
direction=-f_W_true,
color=0x0000ff, length=0.2)
#%%
cpf.Reset()
while True:
cpf.RunContactParticleFilter(q0, tau_external)
result = cpf.CalcBelief()
if result[0] > 0:
break
print(np.mean(cpf.particles, axis=0))
print(np.var(cpf.particles, axis=0))
num_contacts, closest_points, f_Ws, link_idx, normal, triangle_id = result
f_W_detected = f_Ws[0]
DrawPointCloud(vis,
name="link6_points",
points=cpf.particles,
color=[1, 0, 0],
X_WB=cpf.pose_bundle[link_idx[0]].multiply(
cpf.X_LB_list[link_idx[0]]).matrix())
DrawArrow(vis, "arrow_belief",
origin=cpf.pose_bundle[link_idx[0]].multiply(closest_points[0]),
direction=-f_W_detected,
color=0xff0000, length=0.2)
#%% compare detected and true contact forces.
f_W_true_norm = np.linalg.norm(f_W_true)
f_W_detected_norm = np.linalg.norm(f_W_detected)
u_W_true = f_W_true / f_W_true_norm
u_W_detected = f_W_detected / f_W_detected_norm
print("frue force norm: ", f_W_true_norm)
print("detected force norm: ", f_W_detected_norm)
print("inner product: ", u_W_true.dot(u_W_detected))
#%%
import cProfile
cProfile.runctx(
"cpf.RunContactParticleFilter(q0, tau_external)",
globals(), locals(), filename="stats")