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 setup_cars(sim_connection: SimConnection, ego_speed: float, npc_speed: float): lgsvl_sim = sim_connection.connect() # Placing the school_bus school_bus_state = spawn_state(lgsvl_sim) 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", ego_speed)]) ego = load_ego(lgsvl_sim, "Lincoln2017MKZ (Apollo 5.0)", ego_state) return { "school_bus": school_bus, "ego": ego, }
def init_configuration(lgsvl_sim: lgsvl.Simulator, initial_state: lgsvl.AgentState, npc_speed: float): # Init ego state ego_state = copy.deepcopy(initial_state) # Place Ego Car - 5 meter ahead from the initial point ego_state = CarControl.place_car_from_the_point(dimension="vertical", distance=5, state=ego_state) # Place Ego Car - 3.5m meter on the left ego_state = CarControl.place_car_from_the_point(dimension="horizontal", distance=-3.5, state=ego_state) # Drive ego car with speed 5m/s ego_state = CarControl.drive_ego_car(state=ego_state, directions=[("vertical", 5)]) # Add ego to simulator ego = load_ego(lgsvl_sim, "Lincoln2017MKZ (Apollo 5.0)", ego_state) # Init sedan state sedan_state = copy.deepcopy(initial_state) # Place Sedan - 5 meter ahead from the initial point sedan_state = CarControl.place_car_from_the_point(dimension="vertical", distance=5, state=sedan_state) # Add Sedan to simulator sedan = load_npc(lgsvl_sim, "Sedan", sedan_state) # Drive sedan follow its lane with given speed in m/s sedan.follow_closest_lane(True, npc_speed) # Init suv state suv_state = copy.deepcopy(initial_state) # Place SUV - 15 meter ahead from the initial point suv_state = CarControl.place_car_from_the_point(dimension="vertical", distance=20, state=suv_state) # Add suv to simulator suv = load_npc(lgsvl_sim, "SUV", suv_state) # Drive suv follow its lane with given speed in m/s suv.follow_closest_lane(True, npc_speed) return { "sedan": sedan, "suv": suv, "ego": ego, }
def test_EGO_following_NPC_without_crash(self): simConnection = SimConnection() sim = simConnection.connect() # Placing the suv - 10m ahead from the starting point state = spawn_state(sim) truck_state = CarControl.place_car_from_the_point(dimension="vertical", distance=10, state=state) truck = load_npc(sim, "BoxTruck", truck_state) # Driving the truck - speed 5m/s from the starting point truck.follow_closest_lane(True, 5) # Driving the ego - speed 1m/s from the starting point state = spawn_state(sim) ego_state = CarControl.drive_ego_car(state=state, directions=[("vertical", 4.5)]) ego = load_ego(sim, "Lincoln2017MKZ (Apollo 5.0)", ego_state) # Run the simulator for 10 seconds with debug mode simConnection.execute(timeout=10) self.assertEqual(True, True) simConnection.sim.close()
def setup_cars(sim_connection: SimConnection, ego_speed: float): lgsvl_sim = sim_connection.connect() # Placing the sedan sedan_state = spawn_state(lgsvl_sim) sedan_state = CarControl.place_car_from_the_point(dimension="vertical", distance=15, state=sedan_state) sedan_state = CarControl.place_car_from_the_point(dimension="horizontal", distance=-8, state=sedan_state) sedan_state = CarControl.rotate_car_by_degree(state=sedan_state, degree=-45) sedan = load_npc(lgsvl_sim, "Sedan", sedan_state) # Placing the ego on the starting point ego_state = spawn_state(lgsvl_sim) ego_state = CarControl.drive_ego_car(ego_state, [("vertical", ego_speed)]) ego = load_ego(lgsvl_sim, "Lincoln2017MKZ (Apollo 5.0)", ego_state) return { "sedan": sedan, "ego": ego, }
def setup_cars(simc: SimConnection, npc_speed: float): lgsvl_sim = simc.connect() sedan_state = spawn_state(lgsvl_sim) sedan_state = CarControl.place_car_from_the_point(dimension="vertical", distance=0, state=sedan_state) sedan = load_npc(lgsvl_sim, "Sedan", sedan_state) sedan.follow_closest_lane(True, npc_speed) suv_state = spawn_state(lgsvl_sim) suv_state = CarControl.place_car_from_the_point(dimension="vertical", distance=17, state=suv_state) suv = load_npc(lgsvl_sim, "Sedan", suv_state) suv.follow_closest_lane(True, npc_speed) ego_state = spawn_state(lgsvl_sim) ego_state = CarControl.place_car_from_the_point(dimension="horizontal", distance=-3.5, state=ego_state) ego_state = CarControl.place_car_from_the_point(dimension="vertical", distance=5, state=ego_state) ego_state = CarControl.drive_ego_car(state=ego_state, directions=[("vertical", 5)]) ego = load_ego(lgsvl_sim, "Lincoln2017MKZ (Apollo 5.0)", ego_state) return { "sedan": sedan, "suv": suv, "ego": ego, }