Reuse box lines computation

This commit is contained in:
Michel Breyer 2021-10-08 17:19:36 +02:00
parent fcc5045671
commit fcee4a9517
3 changed files with 8 additions and 23 deletions

View File

@ -63,6 +63,7 @@ class Policy:
self.T_task_base = self.T_base_task.inv() self.T_task_base = self.T_base_task.inv()
tf.broadcast(self.T_base_task, self.base_frame, self.task_frame) tf.broadcast(self.T_base_task, self.base_frame, self.task_frame)
rospy.sleep(1.0) # Wait for tf tree to be updated rospy.sleep(1.0) # Wait for tf tree to be updated
self.vis.workspace(self.task_frame, 0.3)
def update(self, img, x, q): def update(self, img, x, q):
raise NotImplementedError raise NotImplementedError

View File

@ -3,10 +3,11 @@ import numpy as np
from robot_helpers.ros.rviz import * from robot_helpers.ros.rviz import *
from robot_helpers.spatial import Transform from robot_helpers.spatial import Transform
import vgn.rviz import vgn.rviz
from vgn.utils import box_lines
cm = lambda s: tuple([float(1 - s), float(s), float(0)]) cm = lambda s: tuple([float(1 - s), float(s), float(0)])
red = np.r_[1.0, 0.0, 0.0] red = [1.0, 0.0, 0.0]
blue = np.r_[0, 0.6, 1.0] blue = [0, 0.6, 1.0]
class Visualizer(vgn.rviz.Visualizer): class Visualizer(vgn.rviz.Visualizer):
@ -14,22 +15,7 @@ class Visualizer(vgn.rviz.Visualizer):
pose = Transform.identity() pose = Transform.identity()
scale = [0.004, 0.0, 0.0] scale = [0.004, 0.0, 0.0]
color = red color = red
corners = bbox.corners lines = box_lines(bbox.min, bbox.max)
edges = [
(0, 1),
(1, 3),
(3, 2),
(2, 0),
(4, 5),
(5, 7),
(7, 6),
(6, 4),
(0, 4),
(1, 5),
(3, 7),
(2, 6),
]
lines = [(corners[s], corners[e]) for s, e in edges]
marker = create_line_list_marker(frame, pose, scale, color, lines, "bbox") marker = create_line_list_marker(frame, pose, scale, color, lines, "bbox")
self.draw([marker]) self.draw([marker])
@ -88,7 +74,7 @@ class Visualizer(vgn.rviz.Visualizer):
markers = [] markers = []
for i, (view, value) in enumerate(zip(views, values)): for i, (view, value) in enumerate(zip(views, values)):
color = cm((value - vmin) / (vmax - vmin)) color = cm((value - vmin) / (vmax - vmin))
marker = create_cam_view_marker( marker = create_view_marker(
frame, frame,
view, view,
scale, scale,
@ -103,9 +89,7 @@ class Visualizer(vgn.rviz.Visualizer):
self.draw(markers) self.draw(markers)
def create_cam_view_marker( def create_view_marker(frame, pose, scale, color, intrinsic, near, far, ns="", id=0):
frame, pose, scale, color, intrinsic, near, far, ns="", id=0
):
marker = create_marker(Marker.LINE_LIST, frame, pose, scale, color, ns, id) marker = create_marker(Marker.LINE_LIST, frame, pose, scale, color, ns, id)
x_n = near * intrinsic.width / (2.0 * intrinsic.fx) x_n = near * intrinsic.width / (2.0 * intrinsic.fx)
y_n = near * intrinsic.height / (2.0 * intrinsic.fy) y_n = near * intrinsic.height / (2.0 * intrinsic.fy)

View File

@ -170,7 +170,7 @@ class CustomScene(Scene):
def load_config(self): def load_config(self):
with self.config_path.open("r") as f: with self.config_path.open("r") as f:
self.scene = yaml.load(f) self.scene = yaml.load(f, Loader=yaml.FullLoader)
self.center = np.asarray(self.scene["center"]) self.center = np.asarray(self.scene["center"])
self.length = 0.3 self.length = 0.3
self.origin = self.center - np.r_[0.5 * self.length, 0.5 * self.length, 0.0] self.origin = self.center - np.r_[0.5 * self.length, 0.5 * self.length, 0.0]