示例#1
0
 def new_action(self):
     '''Creates new action.'''
     if self.n_actions() > 0:
         self.get_current_action().reset_viz()
     time_str = datetime.datetime.now().strftime('%c')
     name = 'Untitled action {}'.format(time_str)
     action_id = self._db.insert_new(name)
     self.current_action_id = action_id
     action = ProgrammedAction(self._world, self.current_action_id,
                               self._selected_step_cb)
     action.name = name
     self.actions.update({self.current_action_id: action})
     self._session_actions.append(action_id)
     self._update_experiment_state()
示例#2
0
    def _load_session_state(self, object_list):
        '''Loads the experiment state from disk.

        Args:
            object_list ([Object]): List of Object (as defined by
                Object.msg), the current reference frames.
        '''
        # Load data from YAML file into Python dictionary.
        with open(self._data_dir + SAVE_FILENAME, 'r') as state_file:
            exp_state = yaml.load(state_file)

        # Create all actions.
        n_actions = exp_state[YAML_KEY_NACTIONS]
        for i in range(n_actions):
            act_idx = i + 1
            self.actions[act_idx] = ProgrammedAction(act_idx,
                                                     self._selected_step_cb)
            # Load each action's data from a ROS bag.
            self.actions[act_idx].load(self._data_dir)

        # Select the correct starting action.
        self.current_action_index = exp_state[YAML_KEY_CURIDX]

        # NOTE(mbforbes): The object_list is not saved to
        # self._object_list here because this method is only called from
        # the constructor, where the object_list is already saved.
        self.actions[self.current_action_index].initialize_viz(object_list)
示例#3
0
    def load_action(self, db_id):
        '''Loads an action from the database.
        This effectively creates an action in the current session.

        Args:
            db_id: string, the ID of the action to load from the database.

        Returns:
            True on success, False otherwise.
        '''
        if self.n_actions() > 0:
            self.get_current_action().reset_viz()

        self.current_action_id = db_id
        if db_id not in self.actions:
            msg = self._db.find(db_id)
            if msg is None:
                return False
            self.actions.update({
                self.current_action_id:
                ProgrammedAction.from_msg(msg, self._world,
                                          self.current_action_id,
                                          self._selected_step_cb)
            })
            self._session_actions.append(db_id)
        self._update_experiment_state()
        return True
示例#4
0
 def new_action(self):
     '''Creates new action.'''
     if self.n_actions() > 0:
         self.get_current_action().reset_viz()
     self.current_action_index = self.n_actions() + 1
     self.actions.update({
         self.current_action_index:
         ProgrammedAction(self.current_action_index, self._selected_step_cb)
     })
     self._update_experiment_state()