Skip to content

Commit eda7c36

Browse files
added tracking based on encoder
1 parent ed6c8cd commit eda7c36

File tree

12 files changed

+43
-13
lines changed

12 files changed

+43
-13
lines changed

cv_pick_place/cv_pick_place_main.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ def main_pick_place_conveyor_w_point_cloud(server_in):
438438
ret, depth_frame, rgb_frame, colorized_depth = dc.get_frame()
439439

440440
rgb_frame = rgb_frame[:,240:1680]
441+
# 1080x1440x3
441442
height, width, depth = rgb_frame.shape
442-
443443
try:
444444
rgb_frame = apriltag.detect_tags(rgb_frame)
445445
if frame_count == 1:
@@ -464,15 +464,17 @@ def main_pick_place_conveyor_w_point_cloud(server_in):
464464
heatmap = colorized_depth
465465
heatmap = heatmap[90:400,97:507,:]
466466
heatmap = cv2.resize(heatmap, (width,height))
467+
encoder_vel = robot_server_dict['encoder_vel']
468+
encoder_pos = robot_server_dict['encoder_pos']
467469

468470
img_detect, detected = pack_detect.deep_pack_obj_detector(
469471
rgb_frame,
470-
depth_frame,
472+
depth_frame,
473+
encoder_pos,
471474
bnd_box = bbox)
472475
objects, deregistered_packets = pt.update(detected, depth_frame)
473476
print(objects, rob_stopped, stop_active, prog_done)
474477
is_detect = len(detected) != 0
475-
encoder_vel = robot_server_dict['encoder_vel']
476478
is_conv_mov = encoder_vel < - 100.0
477479

478480
if is_detect:
@@ -485,10 +487,11 @@ def main_pick_place_conveyor_w_point_cloud(server_in):
485487
track_result, packet = rc.pack_obj_tracking_update(objects,
486488
img_detect,
487489
homography,
488-
is_detect,
489-
x_fixed = x_fixed,
490-
track_frame = track_frame,
491-
frames_lim = frames_lim)
490+
is_detect,
491+
x_fixed,
492+
track_frame,
493+
frames_lim,
494+
encoder_pos)
492495
if track_result is not None:
493496
dist_to_pack = track_result[2]
494497
delay = dist_to_pack/(abs(encoder_vel)/10)
Binary file not shown.

cv_pick_place/packet_detection/packet_detector.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def deep_detector_v2(self, color_frame, depth_frame, bnd_box = True, segment = F
323323
else:
324324
return img_np_detect, detected
325325

326-
def deep_pack_obj_detector(self, color_frame, depth_frame, bnd_box = True, segment = False):
326+
def deep_pack_obj_detector(self, color_frame, depth_frame, encoder_pos, bnd_box = True, segment = False):
327327
"""
328328
Main packet detector function.
329329
@@ -393,7 +393,8 @@ def deep_pack_obj_detector(self, color_frame, depth_frame, bnd_box = True, segme
393393
pack_type = detections['detection_classes'][i],
394394
centroid = centroid,
395395
angle = angle,
396-
width = w, height= h)
396+
width = w, height = h,
397+
encoder_position = encoder_pos)
397398
if centroid[0] - w/2 > guard and centroid[0] + w/2 < (width - guard ):
398399
detected.append(packet)
399400
img_np_detect, box_mask = self.compute_mask(img_np_detect,box_mask, box_array)
Binary file not shown.

cv_pick_place/packet_object/packet.py

+27-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Class containing relevant packet data for convenience
44
class Packet:
5-
def __init__(self, box = np.empty(()), pack_type = None,centroid=(0, 0), angle=0, width=0, height=0):
5+
def __init__(self, box = np.empty(()), pack_type = None,centroid=(0, 0), angle=0, width=0, height=0, encoder_position=0):
66
# Tuple of 2 numbers describing center of the packet
77
self.centroid = centroid
88

@@ -21,6 +21,31 @@ def __init__(self, box = np.empty(()), pack_type = None,centroid=(0, 0), angle=0
2121
# Number of frames the packet has disappeared for
2222
self.disappeared = 0
2323

24+
self.time_of_disappearance = None
25+
2426
self.box = box
2527

26-
self.pack_type = pack_type
28+
self.pack_type = pack_type
29+
30+
# Encoder data
31+
self.starting_encoder_position = encoder_position
32+
33+
# Used for offsetting centroid position calculated using encoder
34+
self.first_centroid_position = centroid
35+
36+
37+
self.marked_for_picking = False
38+
def getCentroidFromEncoder(self, encoder_position):
39+
# k = 0.8299 # 640 x 480
40+
# k = 1.2365 # 1280 x 720
41+
k = 1.8672 # 1440 x 1080
42+
# k = 1.2365 # 1080 x 720
43+
return (int(k * (encoder_position - self.starting_encoder_position) + self.first_centroid_position[0]), self.centroid[1])
44+
45+
# Get centroid in world coordinates
46+
def getCentroidInWorldFrame(self, homography):
47+
centroid_robot_frame = np.matmul(homography, np.array([self.centroid[0], self.centroid[1], 1]))
48+
49+
packet_x = centroid_robot_frame[0] * 10
50+
packet_y = centroid_robot_frame[1] * 10
51+
return packet_x, packet_y
Binary file not shown.

cv_pick_place/packet_reconstruction/point_cloud_viz.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def show_point_cloud(self):
4848
vis.create_window()
4949
vis.add_geometry(source)
5050
# vis.add_geometry(target)
51-
icp_iteration = 500
51+
icp_iteration = 250
5252

5353
for i in range(icp_iteration):
5454
# source.transform(Rot_z)
Binary file not shown.
Binary file not shown.

cv_pick_place/robot_communication/robot_control.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def packet_tracking_update(self, objects, img, homog, enable, x_fixed,
451451
mean_y = 0
452452
return x_fixed, world_y, dist_to_pack
453453
def pack_obj_tracking_update(self, objects, img, homog, enable, x_fixed,
454-
track_frame, frames_lim, track_list = []):
454+
track_frame, frames_lim, encoder_pos, track_list = []):
455455
"""
456456
Computes distance to packet and updated x, mean y packet positions of tracked moving packets.
457457
@@ -479,6 +479,7 @@ def pack_obj_tracking_update(self, objects, img, homog, enable, x_fixed,
479479
cv2.putText(img, text, (centroid[0] , centroid[1] - 40),
480480
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 0), 2)
481481
cv2.circle(img, (centroid[0], centroid[1]), 4, (255, 255, 0), -1)
482+
cv2.circle(img, packet.getCentroidFromEncoder(encoder_pos), 4, (0, 0, 255), -1)
482483
if homog is not None:
483484
new_centroid = np.append(centroid,1)
484485
world_centroid = homog.dot(new_centroid)
-4.87 KB
Loading
1.11 KB
Loading

0 commit comments

Comments
 (0)