def drive(self, carstate: State) -> Command: """ Description Args: carstate: All parameters packed in a State object Returns: command: The next move packed in a Command object """ self.iter += 1 self.back_up_driver.update_status(carstate) # trackers self.update_trackers(carstate) if PRINT_STATE: # and (self.iter % PRINT_CYCLE_INTERVAL) == 0: self.print_trackers(carstate, r=True) # crash and collision detection for swarm if ENABLE_SWARM: if self.back_up_driver.needs_help or self.back_up_driver.is_off_road: self.crashed_in_last_frame = True if not self.crashed_in_last_frame: debug(self.iter, "SWARM: crashed") for dist in carstate.opponents: if dist == 0: self.contact_in_last_frame = True # crisis handling if ENABLE_CRISIS_DRIVER: if self.back_up_driver.is_in_control: return self.back_up_driver.drive(carstate) elif self.back_up_driver.needs_help: self.back_up_driver.pass_control(carstate) return self.back_up_driver.drive(carstate) # since the data and python's values differ we need to adjust them try: carstate.angle = radians(carstate.angle) carstate.speed_x = carstate.speed_x * 3.6 command = self.make_next_command(carstate) except Exception as e: err(self.iter, str(e)) command = self.back_up_driver.driver.drive(carstate) return command
def drive(self, carstate: State) -> Command: self.update_trackers(carstate) if self.in_a_bad_place(carstate): command = self.back_up_driver.drive(carstate) if self.bad_counter >= 600 and is_stuck(carstate): # we try reversing command.gear = -command.gear if command.gear < 0: command.steering = -command.steering command.gear = -1 self.bad_counter = 200 else: # since the data and python's values differ we need to adjust them carstate.angle = math.radians(carstate.angle) carstate.speed_x = carstate.speed_x*3.6 command = self.make_next_command(carstate) # based on target, implement speed/steering manually print("Executing command: gear={}, acc={}, break={}, steering={}".format(command.gear, command.accelerator, command.brake, command.steering)) return command