Skip to content

Commit 8ec3ee2

Browse files
IasonTheodorouMatthijsBurgh
authored andcommitted
enable similarity entity identification between shelf and table objects
1 parent 77c9681 commit 8ec3ee2

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

challenge_storing_groceries/src/challenge_storing_groceries/inspect_shelves.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from itertools import chain
2+
13
# ROS
24
import rospy
35
import smach
@@ -6,7 +8,7 @@
68
from ed.entity import Entity
79

810
from robot_smach_states.navigation import NavigateToSymbolic, NavigateToObserve
9-
from robot_smach_states.util.designators import Designator, VariableDesignator, check_type
11+
from robot_smach_states.util.designators import Designator, VariableDesignator, check_resolve_type, check_type
1012
from robot_smach_states.world_model import SegmentObjects
1113
from robot_smach_states.designator_iterator import IterateDesignator
1214
from robot_smach_states.rise import RiseForInspect
@@ -57,7 +59,7 @@ def __init__(self, robot, entityDes, objectIDsDes=None, roomDes=None, searchArea
5759

5860
check_type(entityDes, Entity)
5961

60-
if not objectIDsDes:
62+
if objectIDsDes is None:
6163
objectIDsDes = VariableDesignator([], resolve_type=[ClassificationResult])
6264

6365
if searchAreas:
@@ -71,6 +73,8 @@ def __init__(self, robot, entityDes, objectIDsDes=None, roomDes=None, searchArea
7173
rospy.loginfo("searchAreas: {}".format(searchAreas.resolve()))
7274
searchArea = VariableDesignator(resolve_type=str)
7375

76+
found_object_ids = VariableDesignator([], resolve_type=[ClassificationResult])
77+
7478
with self:
7579
if navigation_area:
7680
smach.StateMachine.add('NAVIGATE_TO_INSPECT', NavigateToSymbolic(robot, {entityDes: navigation_area},
@@ -96,10 +100,29 @@ def __init__(self, robot, entityDes, objectIDsDes=None, roomDes=None, searchArea
96100
'failed': 'SEGMENT'})
97101

98102
smach.StateMachine.add('SEGMENT',
99-
SegmentObjects(robot, objectIDsDes.writeable, entityDes, searchArea,
103+
SegmentObjects(robot, found_object_ids.writeable, entityDes, searchArea,
100104
unknown_threshold=unknown_threshold,
101105
filter_threshold=filter_threshold),
102-
transitions={'done': 'ITERATE_AREA'})
106+
transitions={'done': 'APPEND_OBJECT_IDS'})
107+
108+
@smach.cb_interface(outcomes=["done"])
109+
def append_object_ids(_, stored_objects, segmented_objects):
110+
"""
111+
@param stored_objects: is the new list of objects we have seen,
112+
@param segmented_objects: the list of the segmented objects which will be appended in the stored_objects
113+
"""
114+
check_resolve_type(stored_objects, [ClassificationResult])
115+
check_resolve_type(segmented_objects, [ClassificationResult])
116+
objects_dict = {}
117+
for item in chain(stored_objects.resolve(), segmented_objects.resolve()):
118+
objects_dict[item.uuid] = item
119+
all_objects = list(objects_dict.values())
120+
stored_objects.write(all_objects)
121+
return "done"
122+
123+
smach.StateMachine.add("APPEND_OBJECT_IDS",
124+
smach.CBState(append_object_ids, cb_args=[objectIDsDes.writeable, found_object_ids]),
125+
transitions={"done": "ITERATE_AREA"})
103126

104127

105128
if __name__ == "__main__":

0 commit comments

Comments
 (0)