nbv_sim/active_grasp/baselines.py

37 lines
1.0 KiB
Python
Raw Normal View History

2021-07-07 17:46:11 +02:00
import numpy as np
2021-08-25 21:32:47 +02:00
from .policy import SingleViewPolicy, MultiViewPolicy
2021-08-25 18:29:10 +02:00
from vgn.utils import look_at
2021-07-07 17:46:11 +02:00
2021-08-25 18:29:10 +02:00
class InitialView(SingleViewPolicy):
2021-09-03 22:39:17 +02:00
def update(self, img, pose):
self.x_d = pose
2021-09-04 17:17:29 +02:00
cmd = super().update(img, pose)
return cmd
2021-07-07 17:46:11 +02:00
2021-08-25 21:32:47 +02:00
class TopView(SingleViewPolicy):
2021-07-07 17:46:11 +02:00
def activate(self, bbox):
super().activate(bbox)
2021-09-10 23:29:15 +02:00
eye = np.r_[self.center[:2], self.bbox.max[2] + self.min_z_dist]
2021-07-07 17:46:11 +02:00
up = np.r_[1.0, 0.0, 0.0]
2021-09-03 22:39:17 +02:00
self.x_d = look_at(eye, self.center, up)
2021-07-07 17:46:11 +02:00
2021-07-08 09:36:51 +02:00
2021-08-25 21:32:47 +02:00
class TopTrajectory(MultiViewPolicy):
2021-07-08 09:36:51 +02:00
def activate(self, bbox):
super().activate(bbox)
2021-09-10 23:29:15 +02:00
eye = np.r_[self.center[:2], self.bbox.max[2] + self.min_z_dist]
2021-07-08 09:36:51 +02:00
up = np.r_[1.0, 0.0, 0.0]
2021-09-03 22:39:17 +02:00
self.x_d = look_at(eye, self.center, up)
2021-08-25 21:32:47 +02:00
2021-09-03 22:39:17 +02:00
def update(self, img, x):
self.integrate(img, x)
linear, angular = self.compute_error(self.x_d, x)
2021-09-04 15:50:29 +02:00
if np.linalg.norm(linear) < 0.02:
2021-08-25 21:32:47 +02:00
self.done = True
2021-09-04 15:50:29 +02:00
return np.zeros(6)
2021-08-25 21:32:47 +02:00
else:
2021-09-03 22:39:17 +02:00
return self.compute_velocity_cmd(linear, angular)