def random_place(body, surface, fixed=(), region=None, max_attempt=10): for _ in range(max_attempt): if region is None: pose = sample_placement(body, surface, percent=0.6) else: pose = sample_placement_region(body, surface, region=region, percent=0.3) set_pose(body, pose) if (pose is None) or any(pairwise_collision(body, b) for b in fixed): continue return pose return False
def add_object(self, task_object, init_pose=None, randomly_place_on=None): assert(task_object.type in self.all_types) assert('/' not in task_object.type) assert(isinstance(task_object.type, str)) assert(isinstance(task_object.uid, int)) assert(task_object.uid not in self._odb_id) tname = task_object.type if tname not in self._odb_type: self._odb_type[tname] = [] # rename the object task_object.name = '%s/%i' % (tname, len(self._odb_type[tname])) self._odb_type[tname].append(task_object) self._odb_id[task_object.uid] = task_object # place the object if init_pose is not None: assert (randomly_place_on is None) set_pose(task_object.uid, init_pose) elif randomly_place_on is not None: self.random_place(task_object.uid, randomly_place_on)
def place(self, body, surface, pose): body_id = self[body].uid surface_id = self[surface].uid z = stable_z(body_id, surface_id) pose[0][-1] = z set_pose(body_id, pose)