def run(self): # Setup environment lgsvl_sim = self.simConnection.connect() control = lgsvl.NPCControl() ego_control = lgsvl.VehicleControl() # Placing the school_bus school_bus_state = spawn_state(lgsvl_sim) school_bus_state = CarControl.place_car_on_the_point( state=school_bus_state, sim=lgsvl_sim, point=self.npc_source) school_bus = load_npc(lgsvl_sim, "SchoolBus", school_bus_state) # Placing the ego on the starting point ego_state = spawn_state(lgsvl_sim) ego_state = CarControl.place_car_from_the_point(dimension="horizontal", distance=-6, state=ego_state) ego_state = CarControl.drive_ego_car(ego_state, [("vertical", self.ego_speed)]) ego = load_ego(lgsvl_sim, "Lincoln2017MKZ (Apollo 5.0)", ego_state) # Callback collision function ego.on_collision(self.on_collision) school_bus.on_collision(self.on_collision) # Set waypoints for School Bus waypoints = [] for point in [self.npc_source, self.npc_target]: waypoints.append( lgsvl.DriveWaypoint(point, self.npc_speed, school_bus.state.transform.rotation)) try: # Start the scenario # The School Bus is parked on the street control.headlights = 2 control.e_stop = True school_bus.apply_control(control) # Let the ego running for 2 seconds self.simConnection.execute(timeout=2) # The school bus turns on signal to prepare for the turn control.headlights = 0 # turn off headlight control.turn_signal_left = True school_bus.apply_control(control) self.simConnection.execute(timeout=2) # Brake the ego CarControl.brake_ego(ego=ego, control=ego_control, brake_value=self.ego_brake, sticky=True) # The school bus starts to turn right school_bus.follow(waypoints) self.simConnection.execute(timeout=10) except Exception: print("Failed!")
def test_EGO_exit_park_with_incoming_NPC(self): NPC_START = lgsvl.geometry.Vector(120, -0.0120140314102173, -2) NPC_TARGET = lgsvl.geometry.Vector(60, -0.0121138095855713, -2) NPC_SPEED = 4 VEHICLE_SET = [ { "name": "Sedan", "load_vehicle": load_npc, "distance": 0, "type": "Sedan" }, { "name": "Ego", "load_vehicle": load_ego, "distance": 10, "type": "Lincoln2017MKZ (Apollo 5.0)" }, { "name": "SUV", "load_vehicle": load_npc, "distance": 5, "type": "SUV" }, { "name": "Jeep", "load_vehicle": load_npc, "distance": 20, "type": "Jeep" }, ] # Setup environment sim_connection = SimConnection() lgsvl_sim = sim_connection.connect() scenario = Scenario(sim_connection) # Setup vehicles position sedan, ego, suv, jeep = scenario.generate_vehicles( lgsvl_sim, VEHICLE_SET) # Setup a new NPC NPC_state = spawn_state(lgsvl_sim) NPC_state = CarControl.place_car_on_the_point(sim=lgsvl_sim, point=NPC_START, state=NPC_state) NPC_state = CarControl.rotate_car_by_degree(state=NPC_state, degree=-90) NPC = load_npc(lgsvl_sim, "Sedan", NPC_state) NPC.on_collision(scenario.on_collision) waypointsCommand = [ lgsvl.DriveWaypoint(NPC_START, NPC_SPEED, NPC_state.transform.rotation), lgsvl.DriveWaypoint(NPC_TARGET, NPC_SPEED, NPC_state.transform.rotation) ] # Delay the scenario for 2s sim_connection.execute(timeout=2) try: NPC.follow(waypointsCommand) scenario.drive_ego(sim_connection, ego) except Exception: sim_connection.sim.close() self.fail("Failed!") # Passed! sim_connection.sim.close() self.assertTrue(True, True)