def init(self, info=None):
        ''' check configs '''
        assert self.configs
        n_substeps = self.configs['n_substeps']
        initial_qpos = self.configs['initial_qpos']
        control_method = self.configs['control_method']
        control_hand_position = self.configs['control_hand_position']
        control_camera_position = self.configs['control_camera_position']
        ''' get model_path '''
        if info is not None:
            self.type = info['type']
        model_path = MODEL_PATHS[self.type]
        ''' get model path '''
        full_path, prefix_path = set_model_path(model_path)
        ''' generate info '''
        if info is None:
            info = self._get_info(full_path)
        ''' add current model_path to info '''
        info['model_path'] = model_path
        ''' get model xml '''
        model_xml = self._get_model_xml(full_path, info)
        ''' set info '''
        self.info = info
        ''' init environment '''
        with tempfile.NamedTemporaryFile(suffix=".xml",
                                         dir=os.path.join(
                                             prefix_path, 'basic')) as fp:
            # write temporary xml file
            fp.write(model_xml)
            fp.flush()

            # set up modified model path
            modified_model_path = fp.name

            # init environment
            cameractrl_env.CameraCtrlEnv.__init__(
                self,
                modified_model_path,
                n_substeps=n_substeps,
                initial_qpos=initial_qpos,
                control_method=control_method,
                control_hand_position=control_hand_position,
                control_camera_position=control_camera_position)

        utils.EzPickle.__init__(self)
Exemple #2
0
    def init(self, info=None):
        ''' check configs '''
        assert self.configs
        n_substeps = self.configs['n_substeps']
        initial_qpos = self.configs['initial_qpos']
        control_method = self.configs['control_method']
        control_hand_position = self.configs['control_hand_position']
        #control_camera_position=self.configs['control_camera_position']
        max_num_objs = self.configs['max_num_objs']
        sample_position = self.configs['sample_position']
        ''' get template_path '''
        template_path = TEMPLATE_PATH
        full_path, prefix_path = set_model_path(template_path)
        ''' set (scene) info '''
        if info is None:
            info = {}
            obj_elts = []
            obj_infos = []
            ''' number of objects '''
            num_objs = np.random.randint(max_num_objs) + 1
            info['num_objs'] = num_objs
            ''' generate objs infos '''
            for i in range(num_objs):
                # select object type
                obj_type = np.random.choice(OBJ_TYPES, 1)[0]

                # parse model path
                _full_path, _ = set_model_path(MODEL_PATHS[obj_type])

                # get model info
                obj_info = self._get_obj_info(_full_path, obj_type, i,
                                              sample_position)
                obj_infos += [obj_info]

                # get obj xml
                obj_elt = self._gen_obj_elt(_full_path, obj_info)
                obj_elts += [obj_elt]

            # add to info
            info['obj_infos'] = obj_infos
            info['obj_elts'] = obj_elts
            ''' generate wall + floor info '''
            room_info = self._get_room_info()
            _full_path, _ = set_model_path(ROOM_PATH)
            room_elt = self._gen_room_elt(_full_path, room_info)
            info['room_info'] = room_info
            info['room_elt'] = room_elt

            #''' generate camera info '''
            #_full_path, _ = set_model_path(CAMERA_PATH)
            #camera_info = self._get_camera_info()
            #info['camera_info']  = camera_info
        ''' get model xml using obj_elts '''
        model_xml = self._gen_scene_xml(full_path, info['obj_elts'],
                                        info['room_elt'])
        ''' set info '''
        self.info = info
        ''' init environment '''
        with tempfile.NamedTemporaryFile(suffix=".xml",
                                         dir=os.path.join(
                                             prefix_path, 'rooms')) as fp:
            # write temporary xml file
            fp.write(model_xml)
            fp.flush()

            # set up modified model path
            modified_model_path = fp.name

            # init environment
            rooms_hand_env.RoomsEnv.__init__(
                self,
                modified_model_path,
                n_substeps=n_substeps,
                initial_qpos=initial_qpos,
                control_method=control_method,
                control_hand_position=control_hand_position,
                #control_camera_position=control_camera_position,
            )

        utils.EzPickle.__init__(self)
Exemple #3
0
    def init(self, info=None):
        ''' check configs '''
        assert self.configs
        n_substeps=self.configs['n_substeps']
        initial_qpos=self.configs['initial_qpos']
        control_method=self.configs['control_method']
        control_hand_position=self.configs['control_hand_position']
        control_camera_position=self.configs['control_camera_position']
        #max_num_objs=self.configs['max_num_objs']
        rand_pos=self.configs['rand_pos']
        obj_type=self.configs['obj_type']

        ''' get template_path '''
        template_path = TEMPLATE_PATH
        full_path, prefix_path = set_model_path(template_path)

        ''' set (scene) info '''
        if info is None:
            info = {}
            obj_elt = []
            obj_info = []

            ''' generate obj info '''
            # select model
            MODEL_PATH = MODEL_PATHS[obj_type]

            # parse model path
            _full_path, _ = set_model_path(MODEL_PATH)

            # get obj info and xml
            obj_info, obj_elt = self._get_obj_info_elt(_full_path, obj_type, rand_pos)

            #''' temporary '''
            #obj_infos
            #scale = 0.03
            #geom = elt.Element('geom')
            #geom.set('size', '{:.5f}'.format(scale))
            #body = elt.Element('body')
            #body.set('pos', '{:.5f} {:.5f} {:.5f}'.format(0., 0., 0.2))
            #body.append(geom)
            #obj_elts += [body]

            # add to info
            info['obj_info'] = obj_info
            info['obj_elt']  = obj_elt

            #''' generate wall + floor info '''
            #table_info = self._get_table_info()
            #_full_path, _ = set_model_path(TABLE_PATH)
            #table_elt = self._gen_table_elt(_full_path, table_info)
            #info['table_info']  = table_info
            #info['table_elt']   = table_elt
            info['table_elt']   = None

        ''' get model xml using obj_elt '''
        model_xml = self._gen_scene_xml(full_path, info['obj_elt'], info['table_elt'])

        ''' set info '''
        self.info = info

        ''' init environment '''
        with tempfile.NamedTemporaryFile(suffix=".xml", dir=os.path.join(prefix_path, 'toy')) as fp:
            # write temporary xml file
            fp.write(model_xml)
            fp.flush()

            # set up modified model path
            modified_model_path=fp.name

            # init environment
            toy_hand_camera_env.ToyEnv.__init__(
                self,
                modified_model_path,
                n_substeps=n_substeps,
                initial_qpos=initial_qpos,
                control_method=control_method,
                control_hand_position=control_hand_position,
                control_camera_position=control_camera_position)

        utils.EzPickle.__init__(self)
Exemple #4
0
    def init(self, info=None):
        ''' check configs '''
        assert self.configs
        n_substeps = self.configs['n_substeps']
        initial_qpos = self.configs['initial_qpos']
        control_method = self.configs['control_method']
        control_hand_position = self.configs['control_hand_position']
        #control_camera_position=self.configs['control_camera_position']
        max_num_objs = self.configs['max_num_objs']
        rand_pos = self.configs['rand_pos']
        num_parts = self.configs['num_parts']
        do_random_branch = self.configs['do_random_branch']
        ''' get template_path '''
        template_path = TEMPLATE_PATH
        full_path, prefix_path = set_model_path(template_path)
        ''' set (scene) info '''
        if info is None:
            info = {}
            obj_elts = []
            obj_infos = []
            ''' number of objects '''
            num_objs = np.random.randint(max_num_objs) + 1
            info['num_objs'] = num_objs
            ''' generate objs infos '''
            for i in range(num_objs):
                # parse model path
                _full_path, _ = set_model_path(MODEL_PATH)

                # get obj info and xml
                obj_info, obj_elt = self._get_obj_info_elt(
                    _full_path,
                    i,
                    num_parts,
                    rand_pos,
                    do_random_branch=do_random_branch)
                obj_infos += [obj_info]
                obj_elts += [obj_elt]
            ''' set camera '''
            if num_objs == 1:
                self.viewer_lookat = [
                    obj_info['cm'][0], obj_info['cm'][1], obj_info['cm'][2]
                ]

            #''' temporary '''
            #obj_infos
            #scale = 0.03
            #geom = elt.Element('geom')
            #geom.set('size', '{:.5f}'.format(scale))
            #body = elt.Element('body')
            #body.set('pos', '{:.5f} {:.5f} {:.5f}'.format(0., 0., 0.2))
            #body.append(geom)
            #obj_elts += [body]

            # add to info
            info['obj_infos'] = obj_infos
            info['obj_elts'] = obj_elts

            #''' generate wall + floor info '''
            #table_info = self._get_table_info()
            #_full_path, _ = set_model_path(TABLE_PATH)
            #table_elt = self._gen_table_elt(_full_path, table_info)
            #info['table_info']  = table_info
            #info['table_elt']   = table_elt
            info['table_elt'] = None
        ''' get model xml using obj_elts '''
        model_xml = self._gen_scene_xml(full_path, info['obj_elts'],
                                        info['table_elt'])
        ''' set info '''
        self.info = info
        ''' init environment '''
        with tempfile.NamedTemporaryFile(suffix=".xml",
                                         dir=os.path.join(
                                             prefix_path,
                                             'shepard_metzler')) as fp:
            # write temporary xml file
            fp.write(model_xml)
            fp.flush()

            # set up modified model path
            modified_model_path = fp.name

            # init environment
            shepard_metzler_hand_env.ShepardMetzlerEnv.__init__(
                self,
                modified_model_path,
                n_substeps=n_substeps,
                initial_qpos=initial_qpos,
                control_method=control_method,
                control_hand_position=control_hand_position,
                #control_camera_position=control_camera_position,
            )

        utils.EzPickle.__init__(self)