File size: 2,212 Bytes
1ec9b78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
from perception_utils import detect

objects = ['green block', 'yellow line']
# Query: ee.
ee = detect('ee')[0]
ret_val = ee

objects = ['drawer', 'blue block', 'yellow block']
# Query: topmost handle.
handles = detect('drawer handle')
# topmost so sort by z, take the last one
handles = sorted(handles, key=lambda x: x.position[2])
top_handle = handles[-1]
ret_val = top_handle

objects = ['yellow block', 'pink block', 'brown line', 'pink block']
# Query: second to the left block.
blocks = detect('block')
# second to the left so sort by y, take the second one
blocks = sorted(blocks, key=lambda x: x.position[1])
second_left_block = blocks[1]
ret_val = second_left_block

objects = ['blue line', 'pink line', 'green block']
# Query: table.
table = detect('table')[0]
ret_val = table

objects = ['green line', 'drawer', 'yellow block']
# Query: second to the bottom handle.
handles = detect('drawer handle')
# second to the bottom so sort by z, take the second one
handles = sorted(handles, key=lambda x: x.position[2])
second_bottom_handle = handles[1]
ret_val = second_bottom_handle

objects = ['brown line', 'brown block']
# Query: brown line.
brown_line = detect('brown line')[0]
ret_val = brown_line

objects = ['green block', 'brown block', 'yellow line']
# Query: block.
block = detect('green block')[0]
ret_val = block

objects = ['pink block', 'pink line', 'blue block']
# Query: block closest to the pink line.
blocks = detect('block')
pink_line = detect('pink line')[0]
closest_block = min(blocks, key=lambda x: np.linalg.norm(x.position - pink_line.position))
ret_val = closest_block

objects = ['blue block', 'blue line', 'green block', 'pink block', 'brown block']
# Query: the block that is on top of the blue block.
blocks = detect('block')
blue_block = detect('blue block')[0]
# find the block that is on top of the blue block
for block in blocks:
    if block.position[2] > blue_block.position[2]:
        ret_val = block
        break

objects = ['drawer']
# Query: top drawer handle.
handles = detect('drawer handle')
# top drawer handle so sort by z, take the last one
handles = sorted(handles, key=lambda x: x.position[2])
top_handle = handles[-1]
ret_val = top_handle