Пример #1
0
    def copy_action(self, action_id):
        '''Make a copy of action

        Args:
            action_id (int)
        '''
        self._clear_world_objects_srv()

        new_id = self.n_actions()

        map_fun = '''function(doc) {
                     emit(doc.id, doc);
                  }'''

        results = self._db.query(map_fun)

        # Load data from db into Action objects.
        for result in results:
            if int(result.value['id']) == action_id:
                action = Action(self._robot, self._tf_listener,
                                self._im_server, self._selected_primitive_cb,
                                self._action_change_cb)
                result.value['id'] = new_id
                action.build_from_json(result.value)
                name = action.get_name()
                action.set_name("Copy of " + name)
                self._actions[new_id] = action
                self._action_ids.append(new_id)

        self._current_action_id = new_id
        self._update_session_state()
Пример #2
0
    def new_action(self, name=None):
        '''Creates new action.'''
        self._clear_world_objects_srv()
        if self.n_actions() > 0:
            if not self._current_action_id is None:
                self.get_current_action().reset_viz()
            self._current_action_id = self.n_actions()
        else:
            self._current_action_id = 0

        # action_id = self._db.insert_new(name)
        action = Action(self._robot, self._tf_listener, self._im_server,
                        self._selected_primitive_cb, self._action_change_cb,
                        self._current_action_id,
                        self._grasp_suggestion_service,
                        self._grasp_feedback_topic, self._external_ee_link)
        if not name is None:
            action.set_name(name)
        else:
            time_str = datetime.datetime.now().strftime('%c')
            action.set_name("Untitled action {}".format(time_str))

        self._actions.update({self._current_action_id: action})
        self._actions_disabled.append(False)
        self._action_ids.append(self._current_action_id)
        self._marker_visibility = [True] * self.n_primitives()
        self._update_session_state()
Пример #3
0
    def _load_session_state(self):
        '''Loads the experiment state from couchdb database or json file.'''
        # It retrieves actions from db sorted by their integer ids.

        map_fun = '''function(doc) {
                     emit(doc.id, doc);
                  }'''

        results = self._db.query(map_fun)

        # Load data from db into Action objects.
        for result in results:
            action = Action(self._robot, self._tf_listener, self._im_server,
                            self._selected_primitive_cb,
                            self._action_change_cb)
            action.build_from_json(result.value)
            self._actions[int(result.value['id'])] = action
            self._action_ids.append(int(result.value['id']))
            self._update_db_with_action(action)

        if self._from_file:
            time_str = datetime.datetime.now().strftime('%c')
            for key in self._actions:
                action = self._actions[key]
                self._update_db_with_action(action, time_str + '.json')

            del self._couch['fetch_pbd']
            self._db = self._couch.create('fetch_pbd')
            self._actions = {}
            self._action_ids = []
            with open(self._from_file) as json_file:
                self._json = json.load(json_file)

            keys = self._json.keys()
            keys.sort()
            for key in keys:
                action = Action(self._robot, self._tf_listener,
                                self._im_server, self._selected_primitive_cb,
                                self._action_change_cb)
                action.build_from_json(self._json[key])
                self._actions[int(self._json[key]['id'])] = action
                self._action_ids.append(int(self._json[key]['id']))
                self._update_db_with_action(action)
Пример #4
0
    def _load_session_state(self):
        '''Loads the experiment state from couchdb database or json file.'''
        # It retrieves actions from db sorted by their integer ids.

        map_fun = '''function(doc) {
                     emit(doc.id, doc);
                  }'''

        results = self._db.query(map_fun)

        # Load data from db into Action objects.
        for result in results:
            action = Action(
                self._robot,
                self._tf_listener,
                self._im_server,
                self._selected_primitive_cb,
                self._action_change_cb,
                grasp_suggestion_service=self._grasp_suggestion_service,
                grasp_feedback_topic=self._grasp_feedback_topic,
                external_ee_link=self._external_ee_link)
            success = action.build_from_json(result.value)
            self._actions_disabled.append(not success)
            self._actions[int(result.value['id'])] = action
            self._action_ids.append(int(result.value['id']))
            self._update_db_with_action(action)

        if self._from_file:
            time_str = datetime.datetime.now().strftime('%c')
            for key in self._actions:
                action = self._actions[key]
                self._update_db_with_action(action, time_str + '.json')

            del self._couch['fetch_pbd']
            self._db = self._couch.create('fetch_pbd')
            self._actions = {}
            self._action_ids = []
            with open(self._from_file) as json_file:
                self._json = json.load(json_file)

            keys = self._json.keys()
            keys.sort()
            self._actions_disabled = []
            for key in keys:
                action = Action(
                    self._robot,
                    self._tf_listener,
                    self._im_server,
                    self._selected_primitive_cb,
                    self._action_change_cb,
                    grasp_suggestion_service=self._grasp_suggestion_service,
                    grasp_feedback_topic=self._grasp_feedback_topic,
                    external_ee_link=self._external_ee_link)
                success = action.build_from_json(self._json[key])
                self._actions_disabled.append(not success)
                self._actions[int(self._json[key]['id'])] = action
                self._action_ids.append(int(self._json[key]['id']))
                self._update_db_with_action(action)

        if True in self._actions_disabled:
            self._status_publisher.publish(
                String("Some actions have been " +
                       "disabled because they require grasp suggestion."))