1+ from itertools import chain
2+
13# ROS
24import rospy
35import smach
68from ed .entity import Entity
79
810from 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
1012from robot_smach_states .world_model import SegmentObjects
1113from robot_smach_states .designator_iterator import IterateDesignator
1214from 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
105128if __name__ == "__main__" :
0 commit comments