コード例 #1
0
    def drive(self, carstate: State) -> Command:

        print('Drive')
        input = carstate.to_input_array()

        if np.isnan(input).any():
            if not self.stopped:
                self.saveResults()

            print(input)
            print('NaN INPUTS!!! STOP WORKING')
            return Command()

        self.stopped = np.isnan(input).any()

        self.print_log(carstate)

        self.update(carstate)

        try:
            output = self.net.activate(input)
            command = Command()

            if self.unstuck and self.isStuck(carstate):
                print('Ops! I got STUCK!!!')
                self.reverse(carstate, command)

            else:

                if self.unstuck and carstate.gear <= 0:
                    carstate.gear = 1

                for i in range(len(output)):
                    if np.isnan(output[i]):
                        output[i] = 0.0

                print('Out = ' + str(output))

                self.accelerate(output[0], output[1], 0, carstate, command)

                if len(output) == 3:
                    # use this if the steering is just one output
                    self.steer(output[2], 0, carstate, command)
                else:
                    # use this command if there are 2 steering outputs
                    self.steer(output[2], output[3], carstate, command)
        except:
            print('Error!')
            self.saveResults()
            raise

        if self.data_logger:
            self.data_logger.log(carstate, command)

        return command
コード例 #2
0
    def drive(self, carstate: State) -> Command:
        """
        Produces driving command in response to newly received car state.

        This is a dummy driving routine, very dumb and not really considering a
        lot of inputs. But it will get the car (if not disturbed by other
        drivers) successfully driven along the race track.
        """
        print('Drive')
        input = carstate.to_input_array()

        self.distance = carstate.distance_raced
        if self.curr_time > carstate.current_lap_time:
            self.time += carstate.last_lap_time

        self.curr_time = carstate.current_lap_time

        try:
            output = self.model.step(input)

            for i in range(len(output)):
                output[i] = max(0, output[i])

            print('Out = ' + str(output))

            command = Command()

            self.accelerate(output[0], output[1], carstate, command)
            self.steer(output[2], output[3], carstate, command)

            # self.steer(carstate, 0.0, command)
            #
            # v_x = min(output[0], 300)
            #
            # self.accelerate(carstate, v_x, command)

        except OverflowError as err:
            print('--------- OVERFLOW! ---------')
            self.saveResults()
            raise err

        if self.data_logger:
            self.data_logger.log(carstate, command)

        return command