|
7 | 7 | from geometry_msgs.msg import Quaternion, Pose, Point |
8 | 8 | from grasp_detection.msg import Grasp |
9 | 9 | from src.grasp_detection.utils import select_grasp_by_preference |
10 | | -from src.env.utils import calculate_place_position, is_collision, adjust_z |
11 | 10 |
|
12 | 11 | class Env: |
13 | 12 | """Wrapper for the environment grounding capabilities. |
@@ -128,6 +127,12 @@ def parse_question(self, question, **kwargs): |
128 | 127 | raise NotImplementedError("parse_question() not implemented") |
129 | 128 |
|
130 | 129 | ################ parse pose tools ############################## |
| 130 | + def parse_place_pose(self, object_name, receptacle_name:str=None, **kwargs)->Pose: |
| 131 | + """ |
| 132 | + Parse place pose for the object. |
| 133 | + """ |
| 134 | + raise NotImplementedError("parse_place_pose() not implemented") |
| 135 | + |
131 | 136 | def parse_adaptive_shape_grasp_pose(self, object_name, **kwargs)->Pose: |
132 | 137 | """ |
133 | 138 | Parse grasp pose for the object. Use ground truth grounding and grasp detection model. |
@@ -172,64 +177,6 @@ def parse_adaptive_shape_grasp_pose(self, object_name, **kwargs)->Pose: |
172 | 177 |
|
173 | 178 | return best_grasp_pose |
174 | 179 |
|
175 | | - def parse_place_pose(self, object_name, receptacle_name:str=None, **kwargs)->Pose: |
176 | | - """ |
177 | | - Parse place pose for the object. Use ground truth grounding and heuristic place position calculation. |
178 | | - Args: |
179 | | - object_name: str, name of the object |
180 | | - receptacle_name: Optional(str), name of the receptacle |
181 | | - position: Optional(np.array), position of the place pose |
182 | | - description: Optional(str), description of the pose, "canonical pose" or "current pose" |
183 | | - """ |
184 | | - # get parameters from kwargs |
185 | | - position = kwargs.get('position', None) |
186 | | - if isinstance(position, Point): |
187 | | - position = np.array([position.x, position.y, position.z]) |
188 | | - if isinstance(position, list): |
189 | | - position = np.array(position) |
190 | | - description: str= kwargs.get('description', "current pose") |
191 | | - assert description in ["canonical pose", "current pose"] # only support canonical pose and current pose for now |
192 | | - |
193 | | - # get the bounding box of the object and all other objectss |
194 | | - object_bbox = self.get_3d_bbox(object_name) |
195 | | - object_names = self.get_obj_name_list() |
196 | | - obstacle_bbox_list = [ |
197 | | - self.get_3d_bbox(obstacle_name) for obstacle_name in object_names |
198 | | - if obstacle_name not in [object_name] |
199 | | - ] |
200 | | - |
201 | | - pose = Pose() |
202 | | - |
203 | | - # If receptacle_name is given, get the receptacle position and bounding box |
204 | | - if receptacle_name is not None: |
205 | | - receptacle_bbox = self.get_3d_bbox(receptacle_name) |
206 | | - # FIXME: for drawer, just hard code the receptacle position x to [max_x-0.2, max_x] |
207 | | - if "drawer" in receptacle_name.lower(): |
208 | | - receptacle_bbox[0] = receptacle_bbox[3] - 0.2 |
209 | | - |
210 | | - # If position is given, use it directly, otherwise use grounding model to get the receptacle position |
211 | | - if position is None: |
212 | | - assert receptacle_name is not None, "parse_place_pose: position must be given if receptacle_name is not given" |
213 | | - position = calculate_place_position( |
214 | | - object_bbox, receptacle_bbox, obstacle_bbox_list, max_tries=100) |
215 | | - else: |
216 | | - # position already given, check if the position is valid, if not, adjust it until no collision found |
217 | | - collision_mask = np.array([is_collision(object_bbox, obstacle_bbox) for obstacle_bbox in obstacle_bbox_list]) |
218 | | - # adjust the z position if there is collision |
219 | | - if np.any(collision_mask): |
220 | | - collided_bbox_list = np.array(obstacle_bbox_list)[collision_mask] |
221 | | - position[2] = adjust_z(object_bbox, collided_bbox_list, extra_elevation=0.1) |
222 | | - |
223 | | - pose.position = Point(*position) |
224 | | - if description == "canonical pose": |
225 | | - # use canonical orientation |
226 | | - pose.orientation = Quaternion(-1.0,0.0,0.0,0.0) |
227 | | - else: |
228 | | - # remain current orientation |
229 | | - pose.orientation = self.get_gripper_pose().orientation |
230 | | - |
231 | | - return pose |
232 | | - |
233 | 180 | def parse_central_lift_grasp_pose(self, object_name, description="top")->Pose: |
234 | 181 | """ |
235 | 182 | Parse central lift grasp pose for the object. Use ground truth grounding and heuristic place position calculation. |
|
0 commit comments