Esempio n. 1
0
    def __init__(self,
                 task_name,
                 state_type_list=['left_shoulder_rgb'],
                 dataset_root='',
                 observation_mode='state',
                 headless=True):
        obs_config = ObservationConfig()
        obs_config.set_all(True)
        action_mode = ActionMode(ArmActionMode.ABS_JOINT_VELOCITY)
        self._observation_mode = observation_mode
        self.env = Environment(
            action_mode, dataset_root, obs_config=obs_config, headless=headless)
        # Dont need to call launch as task.get_task can launch env.
        self.env.launch()
        self.task = self.env.get_task(task_name)
        _, obs = self.task.reset()
        self.action_space = spaces.Box(
            low=-1.0, high=1.0, shape=(self.env.action_size,), dtype=np.float32)
#         self.logger = logger.create_logger(__class__.__name__)
#         self.logger.propagate = 0
        if len(state_type_list) > 0:
            self.observation_space = []
            # for state_type in state_type_list:
            #     state = getattr(obs, state_type)
            self.observation_space = spaces.Box(
                low=-np.inf, high=np.inf, shape=obs.get_low_dim_data().shape)      
        else:
            raise ValueError('No State Type!')

        self.state_type_list = state_type_list
Esempio n. 2
0
    def __init__(self, task_name, state_type='left_shoulder_rgb'):
        obs_config = ObservationConfig()
        obs_config.set_all(True)
        action_mode = ActionMode(ArmActionMode.ABS_JOINT_VELOCITY)
        self.env = Environment(action_mode,
                               obs_config=obs_config,
                               headless=False)
        self.env.launch()
        try:
            self.task = self.env.get_task(
                getattr(sys.modules[__name__], task_name))
        except:
            raise NotImplementedError

        _, obs = self.task.reset()
        state = getattr(obs, state_type)
        self.state_type = state_type
        self.spec = Spec(task_name)

        self.action_space = spaces.Box(low=-1.0,
                                       high=1.0,
                                       shape=(action_mode.action_size, ),
                                       dtype=np.float32)
        self.observation_space = spaces.Box(low=-np.inf,
                                            high=np.inf,
                                            shape=state.shape)
Esempio n. 3
0
 def test_run_task_validator(self):
     for task_file in TASKS:
         test_name = task_file.split('.py')[0]
         with self.subTest(task=test_name):
             if test_name in FLAKY_TASKS:
                 self.skipTest('Flaky task.')
             sim = PyRep()
             ttt_file = os.path.join(
                 DIR_PATH, '..', '..', 'rlbench', TTT_FILE)
             sim.launch(ttt_file, headless=True)
             sim.step_ui()
             sim.set_simulation_timestep(50.0)
             sim.step_ui()
             sim.start()
             robot = Robot(Panda(), PandaGripper())
             obs = ObservationConfig()
             obs.set_all(False)
             scene = Scene(sim, robot, obs)
             sim.start()
             task_class = task_file_to_task_class(task_file)
             active_task = task_class(sim, robot)
             try:
                 task_smoke(active_task, scene, variation=-1,
                            max_variations=2, success=0.25)
             except Exception as e:
                 sim.stop()
                 sim.shutdown()
                 raise e
             sim.stop()
             sim.shutdown()
Esempio n. 4
0
    def initialize(self, headless=False):
        DATASET = ''
        obs_config = ObservationConfig()
        obs_config.set_all(True)
        obs_config.left_shoulder_camera.rgb = True
        obs_config.right_shoulder_camera.rgb = True
        action_mode = ActionMode(ArmActionMode.ABS_EE_POSE_PLAN)
        self.env = Environment(action_mode,
                               DATASET,
                               obs_config,
                               headless=headless)
        self.sensor = NoisyObjectPoseSensor(self.env)
        self.env.launch()
        self.task = self.env.get_task(EmptyContainer)
        self.task.reset()
        self.home = self.get_objects(False)['large_container'].get_pose()
        self.home[2] += 0.3
        # demos = task.get_demos(3, live_demos=live_demos)

        self.objs = self.get_objects()
        self.movable_objects = ['Shape', 'Shape1', 'Shape3']
        self.target_bins = ['small_container0']
        self.start_bins = ['large_container']
        self.max_retry = 5
        self.env._robot.gripper.set_joint_forces([50, 50])
Esempio n. 5
0
    def __init__(self, task_name, state_type_list=None, headless=False):
        if state_type_list is None:
            state_type_list = ['left_shoulder_rgb']
        obs_config = ObservationConfig()
        obs_config.set_all(True)
        action_mode = ActionMode(ArmActionMode.ABS_JOINT_VELOCITY)
        self.env = Environment(action_mode,
                               obs_config=obs_config,
                               headless=headless)
        self.env.launch()
        try:
            self.task = self.env.get_task(ReachTarget)
        except:
            raise NotImplementedError

        _, obs = self.task.reset()

        if len(state_type_list) > 0:
            self.observation_space = []
            for state_type in state_type_list:
                state = getattr(obs, state_type)
                if isinstance(state, (int, float)):
                    shape = (1, )
                else:
                    shape = state.shape
                self.observation_space.append(
                    spaces.Box(low=-np.inf, high=np.inf, shape=shape))
        else:
            raise ValueError('No State Type!')
        self.action_space = spaces.Box(low=-1.0,
                                       high=1.0,
                                       shape=(action_mode.action_size, ),
                                       dtype=np.float32)

        self.state_type_list = state_type_list
Esempio n. 6
0
    def __init__(self, task_name: str, state_type: list = 'state', ):
        # render_mode=None):
        """
        create RL Bench environment
        :param task_name: task names can be found in rlbench.tasks
        :param state_type: state or vision or a sub list of state_types list like ['left_shoulder_rgb']
        """
        if state_type == 'state' or state_type == 'vision' or isinstance(state_type, list):
            self._state_type = state_type
        else:
            raise ValueError('State type value error, your value is {}'.format(state_type))
        # self._render_mode = render_mode
        self._render_mode = None
        obs_config = ObservationConfig()
        obs_config.set_all(True)
        action_mode = ActionMode(ArmActionMode.ABS_JOINT_VELOCITY)
        self.env = Environment(
            action_mode, obs_config=obs_config, headless=True)
        self.env.launch()
        try:
            self.task = self.env.get_task(getattr(sys.modules[__name__], task_name))
        except:
            raise NotImplementedError

        _, obs = self.task.reset()
        self.spec = Spec(task_name)

        if self._state_type == 'state':
            self.observation_space = spaces.Box(
                low=-np.inf, high=np.inf, shape=obs.get_low_dim_data().shape)
        elif self._state_type == 'vision':
            space_dict = OrderedDict()
            space_dict["state"] = spaces.Box(
                low=-np.inf, high=np.inf, shape=obs.get_low_dim_data().shape)
            for i in ["left_shoulder_rgb", "right_shoulder_rgb", "wrist_rgb", "front_rgb"]:
                space_dict[i] = spaces.Box(
                    low=0, high=1, shape=getattr(obs, i).shape)
            self.observation_space = spaces.Dict(space_dict)
        else:
            space_dict = OrderedDict()
            for name in self._state_type:
                if name.split('_')[-1] in ('rgb', 'depth', 'mask'):
                    space_dict[name] = spaces.Box(
                        low=0, high=1, shape=getattr(obs, name).shape)
                else:
                    space_dict[name] = spaces.Box(
                        low=-np.inf, high=np.inf,
                        shape=getattr(obs, name).shape)
                self.observation_space = spaces.Dict(space_dict)
        self.action_space = spaces.Box(low=-1.0, high=1.0, shape=(self.env.action_size,), dtype=np.float32)
def simulation(q):
    # See rlbench/action_modes.py for other action modes
    withLearning = False
    action_mode = ActionMode(ArmActionMode.ABS_EE_POSE_PLAN)
    action_mode_v = ActionMode(ArmActionMode.ABS_JOINT_VELOCITY)
    if withLearning:
        env = Environment(action_mode_v, '', ObservationConfig(), False)
    else:
        env = Environment(action_mode, '', ObservationConfig(), False)
    task = env.get_task(EmptyContainer)
    obj_pose_sensor = NoisyObjectPoseSensor(env)
    descriptions, obs = task.reset()
    allPoses = obj_pose_sensor.get_poses()
    agent = RandomAgent(allPoses["large_container"],
                        allPoses["small_container0"], env)
    print(descriptions)
    obj_poses = obj_pose_sensor.get_poses()
    training_steps = 10000
    episode_length = 100
    i = 0
    rewardFunc = Reward(env, ['Shape0', 'Shape2', 'Shape4'],
                        "small_container0")
    while i < training_steps:
        # Getting noisy object poses
        obj_poses = obj_pose_sensor.get_poses()
        mask = env._scene._cam_wrist_mask.capture_rgb()
        data = (obs.wrist_depth, obs.wrist_rgb, mask)
        if withLearning:
            if i > 0 and i % episode_length == 0:
                print(i, 'Reset Episode')
                agent.updateV()
                i += 1
                continue
            oldState, action = agent.act(obs)
            obs, _, terminate = task.step(action)
            reward = rewardFunc.evaluate(obs)
            print(reward)
            nextState = np.zeros(8)
            nextState[:7] = obs.joint_positions
            nextState[7] = obs.gripper_open > 0.5
            agent.updateQ(oldState, action, nextState, reward)
            i += 1
        else:
            q.put(data)
            nextState = agent.resetAct(obs, obj_poses)
            obs, reward, terminate = task.step(nextState)
        # if terminate:
        #     break
    env.shutdown()
 def __init__(self,\
             action_mode=DEFAULT_ACTION_MODE,\
             task=DEFAULT_TASK,\
             dataset_root='',\
             headless=True):
     obs_config = ObservationConfig()
     obs_config.set_all(True)
     action_mode = action_mode
     self.env = Environment(
         action_mode,dataset_root,obs_config=obs_config, headless=headless)
     # Dont need to call launch as task.get_task can launch env. 
     self.task = self.env.get_task(task)
     _, obs = self.task.reset()
     self.action_space =  spaces.Box(low=-1.0, high=1.0, shape=(self.env.action_size,), dtype=np.float32)
     self.logger = logger.create_logger(__class__.__name__)
     self.logger.propagate = 0
Esempio n. 9
0
    def __init__(self,
                 pyrep: PyRep,
                 robot: Robot,
                 obs_config: ObservationConfig = ObservationConfig(),
                 randomize_every: RandomizeEvery = RandomizeEvery.EPISODE,
                 frequency: int = 1,
                 visual_randomization_config=None,
                 dynamics_randomization_config=None):
        super().__init__(pyrep, robot, obs_config)
        self._randomize_every = randomize_every
        self._frequency = frequency
        self._visual_rand_config = visual_randomization_config
        self._dynamics_rand_config = dynamics_randomization_config
        self._previous_index = -1
        self._count = 0

        if self._dynamics_rand_config is not None:
            raise NotImplementedError('Dynamics randomization coming soon! '
                                      'Only visual randomization available.')

        self._scene_objects = [Shape(name) for name in SCENE_OBJECTS]
        self._scene_objects += self._robot.arm.get_visuals()
        self._scene_objects += self._robot.gripper.get_visuals()
        if self._visual_rand_config is not None:
            # Make the floor plane renderable (to cover old floor)
            self._scene_objects[0].set_renderable(True)
Esempio n. 10
0
    def __init__(self,
                 pyrep: PyRep,
                 robot: Robot,
                 obs_config=ObservationConfig()):
        self._pyrep = pyrep
        self._robot = robot
        self._obs_config = obs_config
        self._active_task = None
        self._inital_task_state = None
        self._start_arm_joint_pos = robot.arm.get_joint_positions()
        self._starting_gripper_joint_pos = robot.gripper.get_joint_positions()
        self._workspace = Shape('workspace')
        self._workspace_boundary = SpawnBoundary([self._workspace])
        self._cam_over_shoulder_left = VisionSensor('cam_over_shoulder_left')
        self._cam_over_shoulder_right = VisionSensor('cam_over_shoulder_right')
        self._cam_wrist = VisionSensor('cam_wrist')
        self._cam_over_shoulder_left_mask = VisionSensor(
            'cam_over_shoulder_left_mask')
        self._cam_over_shoulder_right_mask = VisionSensor(
            'cam_over_shoulder_right_mask')
        self._cam_wrist_mask = VisionSensor('cam_wrist_mask')
        self._has_init_task = self._has_init_episode = False
        self._variation_index = 0

        self._initial_robot_state = (robot.arm.get_configuration_tree(),
                                     robot.gripper.get_configuration_tree())

        # Set camera properties from observation config
        self._set_camera_properties()
Esempio n. 11
0
    def __init__(self,
                 task_class,
                 observation_mode='state',
                 render_mode: Union[None, str] = None):
        self._observation_mode = observation_mode
        self._render_mode = render_mode
        obs_config = ObservationConfig()
        if observation_mode == 'state':
            obs_config.set_all_high_dim(False)
            obs_config.set_all_low_dim(True)
        elif observation_mode == 'vision':
            obs_config.set_all(True)
        else:
            raise ValueError('Unrecognised observation_mode: %s.' %
                             observation_mode)
        action_mode = ActionMode(ArmActionMode.ABS_JOINT_VELOCITY)
        self.env = Environment(action_mode,
                               obs_config=obs_config,
                               headless=True)
        self.env.launch()
        self.task = self.env.get_task(task_class)

        _, obs = self.task.reset()

        self.action_space = spaces.Box(low=-1.0,
                                       high=1.0,
                                       shape=(self.env.action_size, ))

        if observation_mode == 'state':
            self.observation_space = spaces.Box(
                low=-np.inf, high=np.inf, shape=obs.get_low_dim_data().shape)
        elif observation_mode == 'vision':
            self.observation_space = spaces.Dict({
                "state":
                spaces.Box(low=-np.inf,
                           high=np.inf,
                           shape=obs.get_low_dim_data().shape),
                "left_shoulder_rgb":
                spaces.Box(low=0, high=1, shape=obs.left_shoulder_rgb.shape),
                "right_shoulder_rgb":
                spaces.Box(low=0, high=1, shape=obs.right_shoulder_rgb.shape),
                "wrist_rgb":
                spaces.Box(low=0, high=1, shape=obs.wrist_rgb.shape),
                "front_rgb":
                spaces.Box(low=0, high=1, shape=obs.front_rgb.shape),
            })

        if render_mode is not None:
            # Add the camera to the scene
            cam_placeholder = Dummy('cam_cinematic_placeholder')
            self._gym_cam = VisionSensor.create([640, 360])
            self._gym_cam.set_pose(cam_placeholder.get_pose())
            if render_mode == 'human':
                self._gym_cam.set_render_mode(RenderMode.OPENGL3_WINDOWED)
            else:
                self._gym_cam.set_render_mode(RenderMode.OPENGL3)
Esempio n. 12
0
    def __init__(self, h):

        #64x64 camera outputs
        cam = CameraConfig(image_size=(64, 64))
        obs_config = ObservationConfig(left_shoulder_camera=cam,
                                       right_shoulder_camera=cam,
                                       wrist_camera=cam,
                                       front_camera=cam)
        obs_config.set_all(True)

        # delta EE control with motion planning
        action_mode = ActionMode(ArmActionMode.DELTA_EE_POSE_PLAN_WORLD_FRAME)

        #Inits
        self.env = Environment(action_mode, obs_config=obs_config, headless=h)
        self.env.launch()
        self.task = self.env.get_task(ReachTarget)
Esempio n. 13
0
 def __init__(self, action_mode, static_positions=True):
     # Initialize environment with Action mode and observations
     # Resize the write camera to fit the GQCNN
     wrist_camera = CameraConfig(image_size=(1032, 772))
     self.env = Environment(action_mode, '', ObservationConfig(wrist_camera=wrist_camera), False, static_positions=static_positions)
     self.env.launch()
     # Load specified task into the environment
     self.task = self.env.get_task(EmptyContainer)
Esempio n. 14
0
    def __init__(self,
                 task_name: str,
                 observation_mode: str = "state",
                 action_mode: str = "delta joint position",
                 robot_name: str = "panda"):
        super(FakeRLBenchEnv, self).__init__(task_name)
        if task_name not in all_class_names(tasks):
            raise KeyError(f"Error: unknown task name {task_name}")
        if observation_mode not in FakeRLBenchEnv.OBSERVATION_MODE:
            raise KeyError(
                f"Error: unknown observation mode {observation_mode}, available: {FakeRLBenchEnv.OBSERVATION_MODE}"
            )
        if action_mode not in FakeRLBenchEnv.ACTION_MODE:
            raise KeyError(
                f"Error: unknown action mode {action_mode}, available: {FakeRLBenchEnv.ACTION_MODE.keys()}"
            )
        if robot_name not in FakeRLBenchEnv.ROBOT_NAME:
            raise KeyError(
                f"Error: unknown robot name {robot_name}, available: {FakeRLBenchEnv.ROBOT_NAME}"
            )

        # TODO: modify the task/robot/arm/gripper to support early instantiation before v-rep launched
        self._observation_mode = observation_mode
        self._action_mode = action_mode
        self._task_name = task_name
        self._robot_name = robot_name

        self._observation_config = ObservationConfig()
        if self._observation_mode == "state":
            self._observation_config.set_all_low_dim(True)
            self._observation_config.set_all_high_dim(False)
        elif self._observation_mode == "vision":
            self._observation_config.set_all_low_dim(False)
            self._observation_config.set_all_high_dim(True)
        elif self._observation_mode == "all":
            self._observation_config.set_all(True)

        self._action_config = ActionMode(
            FakeRLBenchEnv.ACTION_MODE[self._action_mode])

        self.env = None
        self.task = None

        self._update_info_dict()
Esempio n. 15
0
def main(argv):

    obs_config = ObservationConfig(record_gripper_closing=True)
    obs_config.set_all(False)

    vrc = rand_every = None
    frequency = 0
    if FLAGS.domain_randomization:
        vrc = VisualRandomizationConfig(FLAGS.textures_path)
        rand_every = RandomizeEvery.TRANSITION
        frequency = 10

    env = Environment(ActionMode(), obs_config=obs_config,
                      randomize_every=rand_every, frequency=frequency,
                      visual_randomization_config=vrc, headless=FLAGS.headless)
    env.launch()

    # Add the camera to the scene
    cam_placeholder = Dummy('cam_cinematic_placeholder')
    cam = VisionSensor.create(FLAGS.camera_resolution)
    cam.set_pose(cam_placeholder.get_pose())
    cam.set_parent(cam_placeholder)

    cam_motion = CircleCameraMotion(cam, Dummy('cam_cinematic_base'), 0.005)
    tr = TaskRecorder(env, cam_motion, fps=30)

    if len(FLAGS.tasks) > 0:
        task_names = FLAGS.tasks
    else:
        task_names = [t.split('.py')[0] for t in os.listdir(TASKS_PATH)
                      if t != '__init__.py' and t.endswith('.py')]
    task_classes = [task_file_to_task_class(
        task_file) for task_file in task_names]

    for i, (name, cls) in enumerate(zip(task_names, task_classes)):
        good = tr.record_task(cls)
        if FLAGS.individual and good:
            tr.save(os.path.join(FLAGS.save_dir, '%s.avi' % name))

    if not FLAGS.individual:
        tr.save(os.path.join(FLAGS.save_dir, 'recorded_tasks.avi'))
    env.shutdown()
Esempio n. 16
0
def act(graph,model,sess):
    obs_config = ObservationConfig()
    # obs_config.set_all(True)

    # 这几个参数用来关闭摄像头
    obs_config.right_shoulder_camera.set_all(False)
    obs_config.wrist_camera.set_all(False)
    obs_config.left_shoulder_camera.set_all(False)

    action_mode = ActionMode(ArmActionMode.ABS_JOINT_VELOCITY)
    env = Environment(
        action_mode, obs_config=obs_config, headless=False)
    env.launch()

    task = env.get_task(ReachTarget)

    training_steps = 150
    episode_length = 60
    obs = None
    gripper = [1.0] # 爪子保持打开

    for i in range(training_steps):
        # 初始化一次任务,包括初始Obs数据
        if i % episode_length == 0:
            print('Reset Episode')
            descriptions, obs = task.reset()
            print(descriptions)
        
        # 网络的输入
        vision = obs.front_rgb
        vision = vision[np.newaxis,:]
        state = obs.joint_positions
        state = state[np.newaxis,:]
        action = None
        feed_dict = {
            model.vision:vision,
            model.state:state,
            model.action:action
        }
        run_ops = [model.predict_out]

        with graph.as_default():
            res = sess.run(run_ops,feed_dict=feed_dict)

        # print(res[0][0].shape)
        # print(gripper.shape)
        # input('check shape')
        action = np.concatenate([res[0][0],gripper],axis=-1)
        obs, reward, terminate = task.step(action)
        if reward == 1:
            print("successful try!")

    print('Done')
    env.shutdown()
Esempio n. 17
0
def simulation():
    # See rlbench/action_modes.py for other action modes
    action_mode = ActionMode(ArmActionMode.ABS_EE_POSE_PLAN)
    action_mode_v = ActionMode(ArmActionMode.ABS_JOINT_VELOCITY)
    env = Environment(action_mode_v, '', ObservationConfig(), False)
    task = env.get_task(EmptyContainer)
    obj_pose_sensor = NoisyObjectPoseSensor(env)
    descriptions, obs = task.reset()
    allPoses = obj_pose_sensor.get_poses()
    all_object_poses = [
        allPoses["Shape0"], allPoses["Shape1"], allPoses["Shape4"]
    ]
    all_object_poses.sort(
        key=lambda x: np.linalg.norm(x[:3] - allPoses["large_container"][:3]))
    agent = RandomAgent(allPoses["large_container"],
                        allPoses["small_container0"], env)
    print(descriptions)
    obj_poses = obj_pose_sensor.get_poses()
    training_steps = 10000
    episode_length = 1
    i = 0
    while i < training_steps:
        # Getting noisy object poses
        obj_poses = obj_pose_sensor.get_poses()
        mask = env._scene._cam_wrist_mask.capture_rgb()
        depth = (obs.wrist_depth, obs.wrist_rgb, mask)
        if agent.isResetting:
            #if agent._graspState == 1:
            #q.put(depth)
            nextState = agent.resetAct(obs, obj_poses)
            obs, reward, terminate = task.step(nextState)
            if not agent.isResetting:
                task._action_mode = action_mode_v
                env._action_mode = action_mode_v
                env._set_arm_control_action()
        else:
            if i > 0 and i % episode_length == 0:
                print(i, 'Reset Episode')
                agent.isResetting = True
                task._action_mode = action_mode
                env._action_mode = action_mode
                env._set_arm_control_action()
                agent.updateV()
                continue
            oldState, action = agent.act(obs)
            obs, reward, terminate = task.step(action)
            print(reward)
            nextState = np.zeros(8)
            nextState[:7] = obs.joint_positions
            nextState[7] = obs.gripper_open > 0.5
            agent.updateQ(oldState, action, nextState, reward)
            i += 1
    env.shutdown()
Esempio n. 18
0
 def test_get_all_camera_observations(self):
     obs_config = ObservationConfig()
     obs_config.left_shoulder_camera.rgb = True
     obs_config.right_shoulder_camera.rgb = True
     obs_config.front_camera.rgb = True
     obs_config.wrist_camera.rgb = True
     task = self.get_task(ReachTarget, ArmActionMode.ABS_JOINT_VELOCITY,
                          obs_config)
     desc, obs = task.reset()
     self.assertIsNotNone(obs.left_shoulder_rgb)
     self.assertIsNotNone(obs.right_shoulder_rgb)
     self.assertIsNotNone(obs.front_rgb)
     self.assertIsNotNone(obs.wrist_rgb)
Esempio n. 19
0
 def test_sensor_noise_robot(self):
     obs_config = ObservationConfig(
         joint_velocities_noise=GaussianNoise(0.01),
         joint_forces=False,
         task_low_dim_state=False)
     scene = Scene(self.pyrep, self.robot, obs_config)
     scene.load(ReachTarget(self.pyrep, self.robot))
     obs1 = scene.get_observation()
     obs2 = scene.get_observation()
     self.assertTrue(
         np.array_equal(obs1.joint_positions, obs2.joint_positions))
     self.assertFalse(
         np.array_equal(obs1.joint_velocities, obs2.joint_velocities))
Esempio n. 20
0
 def test_sensor_noise_images(self):
     cam_config = CameraConfig(rgb_noise=GaussianNoise(0.05, (.0, 1.)))
     obs_config = ObservationConfig(left_shoulder_camera=cam_config,
                                    joint_forces=False,
                                    task_low_dim_state=False)
     scene = Scene(self.pyrep, self.robot, obs_config)
     scene.load(ReachTarget(self.pyrep, self.robot))
     obs1 = scene.get_observation()
     obs2 = scene.get_observation()
     self.assertTrue(
         np.array_equal(obs1.right_shoulder_rgb, obs2.right_shoulder_rgb))
     self.assertFalse(
         np.array_equal(obs1.left_shoulder_rgb, obs2.left_shoulder_rgb))
     self.assertTrue(obs1.left_shoulder_rgb.max() <= 1.0)
     self.assertTrue(obs1.left_shoulder_rgb.min() >= 0.0)
Esempio n. 21
0
    def __init__(self, action_mode: ActionMode, dataset_root: str= '',
                 obs_config=ObservationConfig(), headless=False,
                 static_positions: bool = False):

        self._dataset_root = dataset_root
        self._action_mode = action_mode
        self._obs_config = obs_config
        self._headless = headless
        self._static_positions = static_positions
        self._check_dataset_structure()

        self._pyrep = None
        self._robot = None
        self._scene = None
        self._prev_task = None
Esempio n. 22
0
 def get_task(self, task_class, arm_action_mode):
     obs_config = ObservationConfig()
     obs_config.set_all(False)
     obs_config.set_all_low_dim(True)
     obs_config.right_shoulder_camera.rgb = True
     action_mode = ActionMode(arm_action_mode)
     self.env = Environment(
         action_mode, ASSET_DIR, obs_config, headless=True)
     self.env.launch()
     return self.env.get_task(task_class)
Esempio n. 23
0
    def __init__(
            self,
            action_mode: ActionMode,
            dataset_root: str = '',
            obs_config=ObservationConfig(),
            headless=False,
            static_positions: bool = False,
            robot_configuration='panda',
            randomize_every: RandomizeEvery = None,
            frequency: int = 1,
            visual_randomization_config: VisualRandomizationConfig = None,
            dynamics_randomization_config: DynamicsRandomizationConfig = None,
            attach_grasped_objects: bool = True):
        if 'suction' in robot_configuration:
            assert obs_config.gripper_touch_forces == False,\
                "Please disable gripper touch force observation for suction manipulator"
            assert obs_config.gripper_joint_positions == False,\
                "Please disable joint position observation for suction manipulator"

        self._dataset_root = dataset_root
        self._action_mode = action_mode
        self._obs_config = obs_config
        self._headless = headless
        self._static_positions = static_positions
        self._robot_configuration = robot_configuration

        self._randomize_every = randomize_every
        self._frequency = frequency
        self._visual_randomization_config = visual_randomization_config
        self._dynamics_randomization_config = dynamics_randomization_config
        self._attach_grasped_objects = attach_grasped_objects

        if robot_configuration not in SUPPORTED_ROBOTS.keys():
            raise ValueError('robot_configuration must be one of %s' %
                             str(SUPPORTED_ROBOTS.keys()))

        if (randomize_every is not None and visual_randomization_config is None
                and dynamics_randomization_config is None):
            raise ValueError(
                'If domain randomization is enabled, must supply either '
                'visual_randomization_config or dynamics_randomization_config')

        self._check_dataset_structure()

        self._pyrep = None
        self._robot = None
        self._scene = None
        self._prev_task = None
 def __init__(self,
              action_mode: ActionMode,
              dataset_root='',
              obs_config=ObservationConfig(),
              headless=False,
              static_positions: bool = False,
              randomize_every: RandomizeEvery = RandomizeEvery.EPISODE,
              frequency: int = 1,
              visual_randomization_config=None,
              dynamics_randomization_config=None):
     super().__init__(action_mode, dataset_root, obs_config, headless,
                      static_positions)
     self._randomize_every = randomize_every
     self._frequency = frequency
     self._visual_rand_config = visual_randomization_config
     self._dynamics_rand_config = dynamics_randomization_config
Esempio n. 25
0
    def __init__(self,
                 task_class,
                 state_dim,
                 n_features,
                 n_cluster,
                 n_latent,
                 parameters=None,
                 headless=False,
                 cov_reg=1E-8,
                 n_samples=50,
                 dense_reward=False,
                 imitation_noise=0.03):

        obs_config = ObservationConfig()
        obs_config.set_all_low_dim(True)
        obs_config.set_all_high_dim(False)
        self._obs_config = obs_config

        self._state_dim = state_dim
        self._headless = headless

        action_mode = ActionMode(ArmActionMode.ABS_JOINT_POSITION)
        self._task_class = task_class
        self._action_mode = action_mode
        self.env = Environment(action_mode, "", obs_config, headless=headless)
        self.env.launch()

        self.task = self.env.get_task(task_class)
        if parameters is None:
            self.parameters = np.load(
                "parameters/%s_%d.npy" %
                (self.task.get_name(), n_features))[:n_samples]
        # parameters = np.concatenate([parameters for _ in range(20)])
        self.imitation_noise = imitation_noise
        self.parameters[:, :3] += imitation_noise * np.random.normal(
            size=self.parameters[:, :3].shape)
        self.mppca = MPPCA(n_cluster,
                           n_latent,
                           n_iterations=30,
                           cov_reg=cov_reg,
                           n_init=500)
        self.mppca.fit(self.parameters)

        self.rlmppca = None
        self.dense_reward = dense_reward

        print(np.exp(self.mppca.log_pi))

        group = Group("rlbench", ["d%d" % i for i in range(7)] + ["gripper"])
        self.space = ClassicSpace(group, n_features=n_features)

        print("mpcca learned")
Esempio n. 26
0
    def __init__(self, task_class, observation_mode='state'):
        self._observation_mode = observation_mode
        obs_config = ObservationConfig()
        if observation_mode == 'state':
            obs_config.set_all_high_dim(False)
            obs_config.set_all_low_dim(True)
        elif observation_mode == 'vision':
            obs_config.set_all(True)
        else:
            raise ValueError('Unrecognised observation_mode: %s.' %
                             observation_mode)
        action_mode = ActionMode(ArmActionMode.ABS_JOINT_VELOCITY)
        self.env = Environment(action_mode,
                               obs_config=obs_config,
                               headless=True)
        self.env.launch()
        self.task = self.env.get_task(task_class)

        _, obs = self.task.reset()

        self.action_space = spaces.Box(low=-1.0,
                                       high=1.0,
                                       shape=(action_mode.action_size, ))

        if observation_mode == 'state':
            self.observation_space = spaces.Box(
                low=-np.inf, high=np.inf, shape=obs.get_low_dim_data().shape)
        elif observation_mode == 'vision':
            self.observation_space = spaces.Dict({
                "state":
                spaces.Box(low=-np.inf,
                           high=np.inf,
                           shape=obs.get_low_dim_data().shape),
                "left_shoulder_rgb":
                spaces.Box(low=0, high=1, shape=obs.left_shoulder_rgb.shape),
                "right_shoulder_rgb":
                spaces.Box(low=0, high=1, shape=obs.right_shoulder_rgb.shape),
                "wrist_rgb":
                spaces.Box(low=0, high=1, shape=obs.wrist_rgb.shape),
            })

        self._gym_cam = None
 def get_task(self, randomize_every, frequency, visual_config=None,
              dynamics_config=None):
     cam_config = CameraConfig(render_mode=RenderMode.OPENGL)
     obs_config = ObservationConfig(right_shoulder_camera=cam_config)
     obs_config.set_all(False)
     obs_config.set_all_low_dim(True)
     obs_config.right_shoulder_camera.rgb = True
     mode = ActionMode(ArmActionMode.ABS_JOINT_VELOCITY)
     self.env = DomainRandomizationEnvironment(
         mode, ASSET_DIR, obs_config, True, True,
         randomize_every, frequency, visual_config, dynamics_config)
     self.env.launch()
     return self.env.get_task(OpenMicrowave)
Esempio n. 28
0
    def __init__(self,
                 pyrep: PyRep,
                 robot: Robot,
                 obs_config=ObservationConfig()):
        self._pyrep = pyrep
        self._robot = robot
        self._obs_config = obs_config
        self._active_task = None
        self._inital_task_state = None
        self._start_arm_joint_pos = robot.arm.get_joint_positions()
        if robot.is_grip():
            self._starting_gripper_joint_pos = robot.gripper.get_joint_positions(
            )
        else:
            self._starting_gripper_joint_pos = None
        self._workspace = Shape('workspace')
        self._workspace_boundary = SpawnBoundary([self._workspace])
        self._cam_over_shoulder_left = VisionSensor('cam_over_shoulder_left')
        self._cam_over_shoulder_right = VisionSensor('cam_over_shoulder_right')
        self._cam_wrist = VisionSensor('cam_wrist')
        self._cam_front = VisionSensor('cam_front')
        self._cam_over_shoulder_left_mask = VisionSensor(
            'cam_over_shoulder_left_mask')
        self._cam_over_shoulder_right_mask = VisionSensor(
            'cam_over_shoulder_right_mask')
        self._cam_wrist_mask = VisionSensor('cam_wrist_mask')
        self._cam_front_mask = VisionSensor('cam_front_mask')
        self._has_init_task = self._has_init_episode = False
        self._variation_index = 0

        self._initial_robot_state = (robot.arm.get_configuration_tree(),
                                     robot.gripper.get_configuration_tree())

        # Set camera properties from observation config
        self._set_camera_properties()

        x, y, z = self._workspace.get_position()
        minx, maxx, miny, maxy, _, _ = self._workspace.get_bounding_box()
        self._workspace_minx = x - np.fabs(minx)
        self._workspace_maxx = x + maxx
        self._workspace_miny = y - np.fabs(miny)
        self._workspace_maxy = y + maxy
        self._workspace_minz = z
        self._workspace_maxz = z + 1.0  # 1M above workspace
Esempio n. 29
0
 def test_get_stored_demos_images_without_init_sim(self):
     obs_config = ObservationConfig()
     obs_config.set_all(False)
     obs_config.set_all_low_dim(True)
     obs_config.right_shoulder_camera.rgb = True
     action_mode = ActionMode()
     self.env = environment.Environment(
         action_mode, ASSET_DIR, obs_config, headless=True)
     demos = self.env.get_demos('reach_target', 2)
     self.assertEqual(len(demos), 2)
     self.assertGreater(len(demos[0]), 0)
     self.assertIsInstance(demos[0][0].right_shoulder_rgb, np.ndarray)
     self.assertIsNone(demos[0][0].left_shoulder_rgb)
Esempio n. 30
0
    def __init__(self, task_name: str, obs_config: ObservationConfig = ObservationConfig(task_low_dim_state=True),
                 action_mode: ActionMode = ActionMode(),
                 arm_name: str = "Panda", gripper_name: str = "Panda_gripper"):
        super(EnvironmentImpl, self).__init__(task_name)

        self._arm_name = arm_name
        self._gripper_name = gripper_name
        self._action_mode = action_mode
        self._obs_config = obs_config
        # TODO: modify the task/robot/arm/gripper to support early instantiation before v-rep launched
        self._task = None
        self._pyrep = None
        self._robot = None
        self._scene = None

        self._variation_number = 0
        self._reset_called = False
        self._prev_ee_velocity = None
        self._update_info_dict()