def _get_objects_in_tree(root_object=None, object_type=ObjectType.ALL, exclude_base=True, first_generation_only=False) -> List['Object']: if root_object is None: root_object = sim.sim_handle_scene elif isinstance(root_object, Object): root_object = root_object.get_handle() elif not isinstance(root_object, int): raise ValueError('root_object must be None, int or Object') options = 0 if exclude_base: options |= 1 if first_generation_only: options |= 2 handles = sim.simGetObjectsInTree(root_object, object_type.value, options) objects = [] for handle in handles: try: objects.append(Object.get_object(handle)) except KeyError: # e.g., CAMERA and LIGHT are not officially supported name = Object.get_object_name(handle) type = Object.get_object_type(name) warnings.warn("Object ({}, '{}') has {}, " 'which is not supported'.format( handle, name, type)) return objects
def get_object(name_or_handle: str) -> 'Object': """Gets object retrieved by name. :return: The object. """ name = Object.get_object_name(name_or_handle) object_type = Object.get_object_type(name) cls = object_type_to_class[object_type] return cls(name)
def _get_waypoints(self, validating=False) -> List[Waypoint]: waypoint_name = 'waypoint%d' waypoints = [] additional_waypoint_inits = [] i = 0 while True: name = waypoint_name % i if not Object.exists(name): # There are no more waypoints... break ob_type = Object.get_object_type(name) way = None if ob_type == ObjectType.DUMMY: waypoint = Dummy(name) start_func = None end_func = None if i in self._waypoint_abilities_start: start_func = self._waypoint_abilities_start[i] if i in self._waypoint_abilities_end: end_func = self._waypoint_abilities_end[i] way = Point(waypoint, self.robot, start_of_path_func=start_func, end_of_path_func=end_func) elif ob_type == ObjectType.PATH: cartestian_path = CartesianPath(name) way = PredefinedPath(cartestian_path, self.robot) else: raise WaypointError( '%s is an unsupported waypoint type %s' % (name, ob_type), self) if name in self._waypoint_additional_inits and not validating: additional_waypoint_inits.append( (self._waypoint_additional_inits[name], way)) waypoints.append(way) i += 1 # Check if all of the waypoints are feasible feasible, way_i = self._feasible(waypoints) if not feasible: raise WaypointError( "Infeasible episode. Can't reach waypoint %d." % way_i, self) for func, way in additional_waypoint_inits: func(way) return waypoints
def test_get_object_type(self): self.assertEqual(Object.get_object_type('dynamic_cube'), ObjectType.SHAPE) self.assertEqual(Object.get_object_type('dummy'), ObjectType.DUMMY)
def test_get_object_type(self): self.assertEqual(Object.get_object_type('DefaultCamera'), ObjectType.CAMERA)