示例#1
0
    def generate_step(self, state, action):
        """
        Generates a full StepResult, including the next state, an observation, and the reward
        *
        * For convenience, the action taken is also included in the result, as well as a flag for
        * whether or not the resulting next state is terminal.
        :param state: [ OccupancyGrid with only {0, 1}?, Pose of the robot]
        :param action: [ Velocity vector ] s.t. Pose + Velocity = Next pose
        :return: StepResult
        """
        # Separate the occupancygrid into known and unknown area with a mask
        occgrid = state.map
        unknown = occgrid == -1
        image = occgrid.copy()
        image[unknown] = occgrid.max() / 2
        image = np.uint8(image * 255 / image.max())

        next_map_image = self._predict_image_from_unknown(image, unknown)
        unknown_area = ((next_map_image < 200) | (next_map_image > 50))
        next_map_image[unknown_area] = -1

        nest_state = State()
        next_state.map = next_map_image

        # Predict the next action
        velocity = action
        next_state.pose = state.pose + velocity

        return StepResult(next_state=next_state, action=action)
示例#2
0
    def generate_step(self, state, action):
        if action is None:
            print('Tried to generate a step with a null action')
            return None
        elif type(action) is int:
            action = NetworkAction(action)

        result = StepResult()
        result.next_state, is_legal = self.make_next_state(state, action)
        if self.fresh and result.action is not ActionType.SCAN:
            self.fresh = False
            action = NetworkAction(ActionType.SCAN)
        result.action = action.copy()
        if result.action.bin_number is ActionType.SCAN:
            self.last_action_scan = True
        else:
            self.last_action_scan = False
        result.observation = self.make_observation(action, result.next_state)
        result.reward = self.make_reward(state, action, result.next_state, is_legal)
        result.is_terminal = self.is_terminal(result.next_state)
        #print('action')
        #print(result.action.to_string())
        #print('observation')
        #print(result.observation.to_string())
        #print('next state node')
        #print(result.next_state.current_node.to_string())
        #sys.exit(0)
        return result, is_legal
示例#3
0
    def generate_step(self, state, action):
        if action is None:
            print("Tried to generate a step with a null action")
            return None
        elif type(action) is int:
            action = RockAction(action)

        result = StepResult()
        result.next_state, is_legal = self.make_next_state(state, action)
        result.action = action.copy()
        result.observation = self.make_observation(action, result.next_state)
        result.reward = self.make_reward(state, action, result.next_state,
                                         is_legal)
        result.is_terminal = self.is_terminal(result.next_state)

        return result, is_legal
示例#4
0
    def generate_step(self, state, action):
        # type: (object, object) -> object
        if type(action) is int:
            action = RobotAction(action)
        elif action is None:
            logging.error("Tried to generate a step with a null action")
            return None

        result = StepResult()
        result.next_state, is_legal = self.make_next_state(state, action)
        result.action = action
        result.observation = self.make_observation(action, result.next_state)
        result.reward = self.make_reward(state, action, result.next_state,
                                         is_legal)
        result.is_terminal = self.is_terminal(result.next_state)

        return result, is_legal