コード例 #1
0
ファイル: test_objects.py プロジェクト: ydawei/PyRep
 def test_remove(self):
     self.dynamic_cube.remove()
     self.simple_model.remove()
     self.assertFalse(self.dynamic_cube.still_exists())
     self.assertFalse(self.simple_model.still_exists())
     self.assertFalse(Object.exists('dynamic_cube'))
     self.assertFalse(Object.exists('simple_model'))
コード例 #2
0
 def load(self) -> Object:
     if Object.exists(self.get_name()):
         return Dummy(self.get_name())
     ttm_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             '../task_ttms/%s.ttm' % self.name)
     if not os.path.isfile(ttm_file):
         raise FileNotFoundError(
             'The following is not a valid task .ttm file: %s' % ttm_file)
     self._base_object = self.pyrep.import_model(ttm_file)
     return self._base_object
コード例 #3
0
    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
コード例 #4
0
    def init_task(self) -> None:
        self.target_block = Shape('pick_and_lift_target')
        self.target = Shape("success_visual")
        self.target.set_renderable(False)
        self.register_graspable_objects([self.target_block])
        self.boundary = SpawnBoundary([Shape('pick_and_lift_boundary')])
        self.success_detector = ProximitySensor('pick_and_lift_success')
        self.front_camera_exists = Object.exists('cam_front')
        if self.front_camera_exists:
            self.front_camera = VisionSensor('cam_front')
            self.init_front_camera_position = self.front_camera.get_position()
            self.init_front_camera_orientation = self.front_camera.get_orientation(
            )
            self.panda_base = Shape("Panda_link0_visual")

        cond_set = ConditionSet([
            GraspedCondition(self.robot.gripper, self.target_block),
            DetectedCondition(self.target_block, self.success_detector)
        ])
        self.register_success_conditions([cond_set])
コード例 #5
0
    def init_task(self) -> None:
        self.target = Shape('target')
        self.distractor0 = Shape('distractor0')
        self.distractor1 = Shape('distractor1')

        self.target.set_renderable(True)
        self.distractor0.set_renderable(False)
        self.distractor1.set_renderable(False)
        self.front_camera_exists = Object.exists('cam_front')
        if self.front_camera_exists:
            self.front_camera = VisionSensor('cam_front')
        #curr_pos = self.front_camera.get_position()
        # new_pos = curr_pos + np.array([-1.25, 1.6 , -0.35])
        # self.front_camera.set_position(new_pos)
        # curr_ori = self.front_camera.get_orientation()
        # new_ori = np.array([1.6, 0, 0])
        # self.front_camera.set_orientation(new_ori)

        # front pos
        #new_pos = curr_pos + np.array([0.0, 0.0 , -0.2])
        #self.front_camera.set_position(new_pos)
        #curr_ori = self.front_camera.get_orientation()
        #new_ori = curr_ori + np.array([0, -0.25, 0])
        #self.front_camera.set_orientation(new_ori)
        self.step_in_episode = 0

        self.obstacle = Shape.create(type=PrimitiveShape.SPHERE,
                                     size=[0.3, 0.3, 0.3],
                                     renderable=True,
                                     respondable=True,
                                     static=True,
                                     position=[0.1, 0.1, 1.4],
                                     color=[0, 0, 0])

        self.boundaries = Shape('boundary')
        success_sensor = ProximitySensor('success')
        self.register_success_conditions(
            [DetectedCondition(self.robot.arm.get_tip(), success_sensor)])
コード例 #6
0
ファイル: test_objects.py プロジェクト: ydawei/PyRep
 def test_object_exists(self):
     yes = Object.exists('dynamic_cube')
     no = Object.exists('dynamic_cubeee')
     self.assertTrue(yes)
     self.assertFalse(no)