def run(agent_class, agent_config_file_path: Path, carla_config_file_path: Path) -> Tuple[float, int, bool]: """ Run the agent along the track and produce a score based on certain metrics Args: agent_class: the participant's agent agent_config_file_path: agent configuration path carla_config_file_path: carla configuration path Returns: float between 0 - 1 representing scores """ agent_config = AgentConfig.parse_file(agent_config_file_path) carla_config = CarlaConfig.parse_file(carla_config_file_path) carla_runner = CarlaRunner(carla_settings=carla_config, agent_settings=agent_config, npc_agent_class=PurePursuitAgent, competition_mode=True, max_collision=3) try: my_vehicle = carla_runner.set_carla_world() agent = agent_class(vehicle=my_vehicle, agent_settings=agent_config) carla_runner.start_game_loop(agent=agent, use_manual_control=True) return compute_score(carla_runner) except Exception as e: print(f"something bad happened during initialization: {e}") carla_runner.on_finish() logging.error(f"{e}. Might be a good idea to restart Server") return 0, 0, False
def run(agent_class, agent_config_file_path: Path, carla_config_file_path: Path, num_laps: int = 10) -> Tuple[float, int, int]: """ Run the agent along the track and produce a score based on certain metrics Args: num_laps: int number of laps that the agent should run agent_class: the participant's agent agent_config_file_path: agent configuration path carla_config_file_path: carla configuration path Returns: float between 0 - 1 representing scores """ agent_config: AgentConfig = AgentConfig.parse_file(agent_config_file_path) carla_config = CarlaConfig.parse_file(carla_config_file_path) # hard code agent config such that it reflect competition requirements agent_config.num_laps = num_laps carla_runner = CarlaRunner(carla_settings=carla_config, agent_settings=agent_config, npc_agent_class=PurePursuitAgent, competition_mode=True, lap_count=num_laps) try: my_vehicle = carla_runner.set_carla_world() agent = agent_class(vehicle=my_vehicle, agent_settings=agent_config) carla_runner.start_game_loop(agent=agent, use_manual_control=False) return compute_score(carla_runner) except Exception as e: print(f"something bad happened during initialization: {e}") carla_runner.on_finish() logging.error(f"{e}. Might be a good idea to restart Server") return 0, 0, False
def main(): agent_config = AgentConfig.parse_file( Path("./ROAR_Sim/configurations/agent_configuration.json")) carla_config = CarlaConfig.parse_file( Path("./ROAR_Sim/configurations/configuration.json")) carla_runner = CarlaRunner(carla_settings=carla_config, agent_settings=agent_config, npc_agent_class=PurePursuitAgent) ''' Data collection code. Currently unnecessary # make csv file to store some data in # we have current position x, y, z, current velocity x, y, z, next waypoint position x, y, z, # next waypoint direction relative to the current position of the car x, y, z, steering, and throttle csvNotes = "{}\n{}\n".format("we have current car position x, y, z, current car velocity x, y, z, next waypoint position x, y, z,", "next waypoint direction relative to the current position of the car x, y, z, steering, and throttle") csvHeader = "px, py, pz, vx, vy, vz, wpx, wpy, wpz, wvx, wvy, wvz, steering, throttle\n" with open("tmp/pid_data.csv", "w") as f: f.write(csvNotes) f.write(csvHeader) ''' try: my_vehicle = carla_runner.set_carla_world() # agent = PIDAgent(vehicle=my_vehicle, agent_settings=agent_config) agent = LQRAgent(vehicle=my_vehicle, agent_settings=agent_config) carla_runner.start_game_loop(agent=agent, use_manual_control=False) except Exception as e: logging.error(f"Something bad happened during initialization: {e}") carla_runner.on_finish() logging.error(f"{e}. Might be a good idea to restart Server")
def main(): agent_config = AgentConfig.parse_file(Path("../ROAR/configurations/carla_configuration.json")) carla_config = CarlaConfig.parse_file(Path("../ROAR_Sim/configurations/carla_configuration.json")) carla_runner = CarlaRunner(carla_settings=carla_config, agent_settings=agent_config, npc_agent_class=PurePursuitAgent) try: my_vehicle = carla_runner.set_carla_world() agent = PointCloudMapRecordingAgent(vehicle=my_vehicle, agent_settings=agent_config) carla_runner.start_game_loop(agent=agent, use_manual_control=False) except Exception as e: print("Ending abnormally: ", e) carla_runner.on_finish() logging.error(f"Hint: Might be a good idea to restart Server. ")
def main(): agent_config = AgentConfig.parse_file( Path("./ROAR_Sim/configurations/agent_configuration.json")) carla_config = CarlaConfig.parse_file( Path("./ROAR_Sim/configurations/configuration.json")) carla_runner = CarlaRunner(carla_settings=carla_config, agent_settings=agent_config, npc_agent_class=PurePursuitAgent) try: my_vehicle = carla_runner.set_carla_world() agent = PIDAgent(vehicle=my_vehicle, agent_settings=agent_config) carla_runner.start_game_loop(agent=agent, use_manual_control=False) except Exception as e: logging.error(f"Something bad happened during initialization: {e}") carla_runner.on_finish() logging.error(f"{e}. Might be a good idea to restart Server")
def main(): """Starts game loop""" agent_config = AgentConfig.parse_file( Path("./ROAR_Sim/configurations/agent_configuration.json")) carla_config = CarlaConfig.parse_file( Path("./ROAR_Sim/configurations/configuration.json")) carla_runner = CarlaRunner(carla_settings=carla_config, agent_settings=agent_config, npc_agent_class=PurePursuitAgent) try: my_vehicle = carla_runner.set_carla_world() #agent = PIDAgent(vehicle=my_vehicle, agent_settings=agent_config) #agent = OccupancyMapAgent(vehicle=my_vehicle, agent_settings=agent_config) #agent = PurePursuitAgent(vehicle=my_vehicle, agent_settings=agent_config) #agent = JAM1Agent_old(vehicle=my_vehicle, agent_settings=agent_config) # *** roll controller agent = PIDRollAgent( vehicle=my_vehicle, agent_settings=agent_config) # *** roll controller #agent = JAM1Agent(vehicle=my_vehicle, agent_settings=agent_config) #agent = JAM2Agent(vehicle=my_vehicle, agent_settings=agent_config) #agent = JAM3Agent_old(vehicle=my_vehicle, agent_settings=agent_config) # *** bstanley #agent = JAM3Agent(vehicle=my_vehicle, agent_settings=agent_config) # *** use to record new waypoints *** # waypointrecord = agent.bstanley_controller.blat_stanley_controller.waypointrecord # np.save("James_waypoints", np.array(waypointrecord)) #agent = RecordingAgent(vehicle=my_vehicle, agent_settings=agent_config) #carla_runner.start_game_loop(agent=agent, use_manual_control=True)#*******True for manual control, False auto carla_runner.start_game_loop( agent=agent, use_manual_control=False ) # *******True for manual control, False auto except Exception as e: logging.error(f"Something bad happened during initialization: {e}") carla_runner.on_finish() logging.error(f"{e}. Might be a good idea to restart Server")
def main(): """Starts game loop""" carla_config = CarlaConfig.parse_file(Path("./ROAR_Sim/configurations/configuration.json")) agent_config = AgentConfig.parse_file(Path("./ROAR_Sim/configurations/agent_configuration.json")) """ Pit Stop: Use different kinds of 'set' functions at PitStop to tune/fix your own car! """ pitstop = PitStop(carla_config, agent_config) pitstop.set_carla_version(version = "0.9.9") pitstop.set_carla_sync_mode(False) pitstop.set_autopilot_mode(True) pitstop.set_car_color(CarlaCarColor(r = 255,g = 200,b = 00,a = 255)) pitstop.set_num_laps(num=1) pitstop.set_output_data_folder_path("./data/output") pitstop.set_output_data_file_name(time.strftime("%Y%m%d-%H%M%S-") + "map-waypoints") pitstop.set_max_speed(speed = 200) pitstop.set_target_speed(speed = 30) print(agent_config.target_speed, " target speed") pitstop.set_steering_boundary(boundary = (-1.0, 1.0)) pitstop.set_throttle_boundary(boundary = (0, 0.5)) pitstop.set_waypoints_look_ahead_values(values={ "60": 5, "80": 10, "120": 20, "180": 50}) pid_value = { "longitudinal_controller": { "40": { "Kp": 0.8, "Kd": 0.2, "Ki": 0 }, "60": { "Kp": 0.5, "Kd": 0.2, "Ki": 0 }, "150": { "Kp": 0.2, "Kd": 0.1, "Ki": 0.1 } }, "latitudinal_controller": { "60": { "Kp": 0.8, "Kd": 0.1, "Ki": 0.1 }, "100": { "Kp": 0.6, "Kd": 0.2, "Ki": 0.1 }, "150": { "Kp": 0.5, "Kd": 0.2, "Ki": 0.1 } } } pitstop.set_pid_values(pid_value) """Passing configurations to Carla and Agent""" carla_runner = CarlaRunner(carla_settings=carla_config, # ROAR Academy: fine agent_settings=agent_config, # ROAR Academy: fine npc_agent_class=PurePursuitAgent) try: my_vehicle = carla_runner.set_carla_world() agent = PIDAgent(vehicle=my_vehicle, agent_settings=agent_config) # agent = WaypointGeneratigAgent(vehicle=my_vehicle, agent_settings=agent_config) carla_runner.start_game_loop(agent=agent, use_manual_control=False) # for PIDAgent # carla_runner.start_game_loop(agent=agent, use_manual_control=True) # for WaypointGeneratingAgent except Exception as e: logging.error(f"Something bad happened during initialization: {e}") carla_runner.on_finish() logging.error(f"{e}. Might be a good idea to restart Server")