示例#1
0
    def test_not_sticky_control(
            self):  # Check that the a non sticky control is removed
        with SimConnection(60) as sim:
            state = spawnState(sim)
            ego = sim.add_agent(
                lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5,
                lgsvl.AgentType.EGO, state)
            control = lgsvl.VehicleControl()
            control.throttle = 1
            ego.apply_control(control, True)
            sim.run(3)
            stickySpeed = ego.state.speed

            sim.reset()
            ego = sim.add_agent(
                lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5,
                lgsvl.AgentType.EGO, state)
            control = lgsvl.VehicleControl()
            control.throttle = 1
            ego.apply_control(control, True)
            sim.run(1)
            ego.apply_control(control, False)
            sim.run(2)
            finalSpeed = ego.state.speed
            self.assertGreater(stickySpeed, finalSpeed)
示例#2
0
    def test_ego_handbrake(
        self
    ):  # Check that the handbrake can be enable on an EGO vehicle, and the car stops sooner than without brakes
        with SimConnection(60) as sim:
            state = spawnState(sim)
            ego = sim.add_agent(
                lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5,
                lgsvl.AgentType.EGO, state)
            control = lgsvl.VehicleControl()
            control.throttle = 1
            ego.apply_control(control, True)
            sim.run(1)
            control = lgsvl.VehicleControl()
            ego.apply_control(control, True)
            sim.run(3)
            noBrakeDistance = (ego.state.position - state.position).magnitude()

            sim.reset()
            ego = sim.add_agent(
                lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5,
                lgsvl.AgentType.EGO, state)
            control = lgsvl.VehicleControl()
            control.throttle = 1
            ego.apply_control(control, True)
            sim.run(1)
            control = lgsvl.VehicleControl()
            control.handbrake = True
            ego.apply_control(control, True)
            sim.run(3)
            brakeDistance = (ego.state.position - state.position).magnitude()
            self.assertLess(brakeDistance, noBrakeDistance)
    def test_ego_braking(
        self
    ):  # Check that a brake command can be given to an EGO vehicle, and the car stops sooner than without brakes
        with SimConnection(60) as sim:
            state = spawnState(sim)
            ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)",
                                lgsvl.AgentType.EGO, state)
            control = lgsvl.VehicleControl()
            control.throttle = 1
            ego.apply_control(control, True)
            sim.run(1)
            control = lgsvl.VehicleControl()
            ego.apply_control(control, True)
            sim.run(3)
            noBrakeDistance = (ego.state.position - state.position).magnitude()

            sim.reset()
            ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)",
                                lgsvl.AgentType.EGO, state)
            control = lgsvl.VehicleControl()
            control.throttle = 1
            ego.apply_control(control, True)
            sim.run(1)
            control = lgsvl.VehicleControl()
            control.braking = 1
            ego.apply_control(control, True)
            sim.run(3)
            brakeDistance = (ego.state.position - state.position).magnitude()
            self.assertLess(brakeDistance, noBrakeDistance)
示例#4
0
    def test_ego_handbrake(
        self
    ):  # Check that the handbrake can be enable on an EGO vehicle, and the car stops sooner than without brakes
        with SimConnection() as sim:
            state = spawnState(sim)
            ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, state)
            control = lgsvl.VehicleControl()
            control.throttle = 1
            ego.apply_control(control, True)
            sim.run(1)
            control = lgsvl.VehicleControl()
            ego.apply_control(control, True)
            sim.run(3)
            noBrakePosition = ego.state.position.x

            sim.reset()
            ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, state)
            control = lgsvl.VehicleControl()
            control.throttle = 1
            ego.apply_control(control, True)
            sim.run(1)
            control = lgsvl.VehicleControl()
            control.handbrake = True
            ego.apply_control(control, True)
            sim.run(3)
            self.assertGreater(ego.state.position.x, noBrakePosition)
示例#5
0
    def test_wipers(self):
        try:
            with SimConnection() as sim:
                ego = sim.add_agent(
                    lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5,
                    lgsvl.AgentType.EGO, spawnState(sim))
                control = lgsvl.VehicleControl()
                control.windshield_wipers = 1
                ego.apply_control(control, True)
                sim.run(1)
                input("Press Enter if wipers are on low")

                control = lgsvl.VehicleControl()
                control.windshield_wipers = 2
                ego.apply_control(control, True)
                sim.run(1)
                input("Press Enter if wipers are on medium")

                control = lgsvl.VehicleControl()
                control.windshield_wipers = 3
                ego.apply_control(control, True)
                sim.run(1)
                input("Press Enter if wipers are on high")
        except TestTimeout:
            self.fail("Wipers were not on")
示例#6
0
 def test_not_sticky_control(
         self):  # Check that the a non sticky control is removed
     with SimConnection() as sim:
         ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO,
                             spawnState(sim))
         control = lgsvl.VehicleControl()
         control.throttle = 0.5
         ego.apply_control(control, True)
         sim.run(1)
         initialSpeed = ego.state.speed
         control = lgsvl.VehicleControl()
         control.throttle = 0.5
         ego.apply_control(control, False)
         sim.run(1)
         finalSpeed = ego.state.speed
         self.assertGreater(initialSpeed, finalSpeed)
示例#7
0
	def applyTo(self, obj, sim):
		lgsvlObject = obj.lgsvlObject
		state = lgsvlObject.state
		pos = state.transform.position
		rot = state.transform.rotation
		velocity = state.velocity
		th, x, y, v = rot.y/180.0*np.pi, pos.x, pos.z, (velocity.x**2 + velocity.z**2)**0.5
		#print('state:', th, x, y, v)
		PREDICTIVE_LENGTH = 3
		MIN_SPEED = 1
		WHEEL_BASE = 3
		v = max(MIN_SPEED, v)

		x = x + PREDICTIVE_LENGTH * np.cos(-th+np.pi/2)
		y = y + PREDICTIVE_LENGTH * np.sin(-th+np.pi/2)
		#print('car front:', x, y)
		dists = np.linalg.norm(self.waypoints - np.array([x, y]), axis=1)
		dist_pos = np.argpartition(dists,1)
		index = dist_pos[0]
		if index > self.curr_index and index < len(self.waypoints)-1:
			self.curr_index = index
		p1, p2, p3 = self.waypoints[self.curr_index-1], self.waypoints[self.curr_index], self.waypoints[self.curr_index+1]

		p1_a = np.linalg.norm(p1 - np.array([x, y]))
		p3_a = np.linalg.norm(p3 - np.array([x, y]))
		p1_p2= np.linalg.norm(p1 - p2)
		p3_p2= np.linalg.norm(p3 - p2)

		if p1_a - p1_p2 > p3_a - p3_p2:
			p1 = p2
			p2 = p3

		#print('points:',p1, p2)
		x1, y1, x2, y2 = p1[0], p1[1], p2[0], p2[1]
		th_n = -math.atan2(y2-y1,x2-x1)+np.pi/2
		d_th = (th - th_n + 3*np.pi) % (2*np.pi) - np.pi
		d_x = (x2-x1)*y - (y2-y1)*x + y2*x1 - y1*x2
		d_x /= np.linalg.norm(np.array([x1, y1]) - np.array([x2, y2]))
		#print('d_th, d_x:',d_th, d_x)


		K = TrackWaypoints.LQR(v, WHEEL_BASE, np.array([[1, 0], [0, 3]]), np.array([[10]]))
		u = -K * np.matrix([[-d_x], [d_th]])
		u = np.double(u)
		u_steering = min(max(u, -1), 1)

		K = 1
		u = -K*(v - self.cruising_speed)
		u_thrust = min(max(u, -1), 1)

		#print('u:', u_thrust, u_steering)

		cntrl = lgsvl.VehicleControl()
		cntrl.steering = u_steering
		if u_thrust > 0:
			cntrl.throttle = u_thrust
		elif u_thrust < 0.1:
			cntrl.braking = -u_thrust
		lgsvlObject.apply_control(cntrl, True)
    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!")
示例#9
0
    def test_headlights(self):
        try:
            with SimConnection() as sim:
                ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)",
                                    lgsvl.AgentType.EGO, spawnState(sim))
                control = lgsvl.VehicleControl()
                control.headlights = 1
                ego.apply_control(control, True)
                sim.run(1)
                input("Press Enter if headlights are on")

                control = lgsvl.VehicleControl()
                control.headlights = 2
                ego.apply_control(control, True)
                sim.run(1)
                input("Press Enter if high beams are on")
        except TestTimeout:
            self.fail("Headlights were not on")
示例#10
0
    def test_blinkers(self):
        try:
            with SimConnection() as sim:
                ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)",
                                    lgsvl.AgentType.EGO, spawnState(sim))
                control = lgsvl.VehicleControl()
                control.turn_signal_left = True
                ego.apply_control(control, True)
                sim.run(3)
                input("Press Enter if left turn signal is on")

                control = lgsvl.VehicleControl()
                control.turn_signal_right = True
                ego.apply_control(control, True)
                sim.run(3)
                input("Press Enter if right turn signal is on")
        except TestTimeout:
            self.fail("Turn signals were not on")
示例#11
0
    def test_vary_throttle(
            self
    ):  # Check that different throttle values accelerate differently
        with SimConnection() as sim:
            ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO,
                                spawnState(sim))
            control = lgsvl.VehicleControl()
            control.throttle = 0.5
            ego.apply_control(control, True)
            sim.run(1)
            initialSpeed = ego.state.speed

            sim.reset()
            ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO,
                                spawnState(sim))
            control = lgsvl.VehicleControl()
            control.throttle = 0.1
            ego.apply_control(control, True)
            sim.run(1)
            self.assertLess(ego.state.speed, initialSpeed)
示例#12
0
 def test_wiper_large_value(self):
     try:
         with SimConnection() as sim:
             ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO,
                                 spawnState(sim))
             control = lgsvl.VehicleControl()
             control.windshield_wipers = 4
             ego.apply_control(control, True)
             sim.run(1)
             input("Press Enter if wipers are off")
     except TestTimeout:
         self.fail("Wipers were on")
示例#13
0
 def test_headlights_str(self):
     try:
         with SimConnection() as sim:
             ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO,
                                 spawnState(sim))
             control = lgsvl.VehicleControl()
             control.headlights = "123"
             ego.apply_control(control, True)
             sim.run(1)
             input("Press Enter if headlights are off")
     except TestTimeout:
         self.fail("Headlights were on")
示例#14
0
 def test_wiper_str(self):
     try:
         with SimConnection() as sim:
             ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)",
                                 lgsvl.AgentType.EGO, spawnState(sim))
             control = lgsvl.VehicleControl()
             control.windshield_wipers = "on"
             ego.apply_control(control, True)
             sim.run(1)
             input("Press Enter if wipers are off")
     except TestTimeout:
         self.fail("Wipers were on")
 def drive_ego(sim_connection: SimConnection, ego: lgsvl.agent.EgoVehicle):
     control = lgsvl.VehicleControl()
     control.steering = -0.4
     control.throttle = 0.2
     ego.apply_control(control, True)
     sim_connection.execute(timeout=3)
     control.steering = 0.13
     ego.apply_control(control, True)
     sim_connection.execute(timeout=3)
     control.steering = 0
     ego.apply_control(control, True)
     sim_connection.execute(timeout=5)
示例#16
0
 def test_headlights_large_value(self):
     try:
         with SimConnection() as sim:
             ego = sim.add_agent(
                 lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5,
                 lgsvl.AgentType.EGO, spawnState(sim))
             control = lgsvl.VehicleControl()
             control.headlights = 123
             ego.apply_control(control, True)
             sim.run(1)
             input("Press Enter if headlights are off")
     except TestTimeout:
         self.fail("Headlights were on")
示例#17
0
    def test_vary_steering(
            self
    ):  # Check that different steering values turn the car differently
        with SimConnection() as sim:
            ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO,
                                spawnState(sim))
            control = lgsvl.VehicleControl()
            control.throttle = 0.5
            control.steering = -0.8
            ego.apply_control(control, True)
            sim.run(1)
            initialAngle = ego.state.rotation.y

            sim.reset()
            ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO,
                                spawnState(sim))
            control = lgsvl.VehicleControl()
            control.throttle = 0.5
            control.steering = -0.3
            ego.apply_control(control, True)
            sim.run(1)
            self.assertGreater(ego.state.rotation.y, initialAngle)
示例#18
0
 def test_ego_reverse(
     self
 ):  # Check that the gear can be changed in an EGO vehicle, and the car moves in reverse
     with SimConnection() as sim:
         ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO,
                             spawnState(sim))
         control = lgsvl.VehicleControl()
         control.throttle = 0.5
         control.reverse = True
         ego.apply_control(control, True)
         sim.run(2)
         self.assertGreater(ego.state.position.x,
                            sim.get_spawn()[0].position.x)
示例#19
0
 def test_ego_throttle(
     self
 ):  # Check that a throttle command can be given to an EGO vehicle, and the car accelerates
     with SimConnection() as sim:
         ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO,
                             spawnState(sim))
         control = lgsvl.VehicleControl()
         control.throttle = 0.5
         ego.apply_control(control, True)
         initialSpeed = ego.state.speed
         sim.run(2)
         finalSpeed = ego.state.speed
         self.assertGreater(finalSpeed, initialSpeed)
示例#20
0
 def test_ego_steering(
     self
 ):  # Check that a steering command can be given to an EGO vehicle, and the car turns
     with SimConnection() as sim:
         ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO,
                             spawnState(sim))
         control = lgsvl.VehicleControl()
         control.throttle = 0.3
         control.steering = -1.0
         ego.apply_control(control, True)
         initialRotation = ego.state.rotation
         sim.run(1)
         finalRotation = ego.state.rotation
         self.assertNotAlmostEqual(initialRotation.y, finalRotation.y)
示例#21
0
 def reset(self):
     obs = super(LG_Sim_Env, self).reset()
     if self.sim is not None:
         self.sim.reset()
     else:
         self.sim = lgsvl.Simulator(address="127.0.0.1", port=8181)
         self.control = lgsvl.VehicleControl()
         print("self.sim.current_scene ", self.sim.current_scene)
         if self.sim.current_scene == self.config["map"]:
             self.sim.reset()
         else:
             self.sim.load(self.config["map"])
     self._populate_scene()
     return obs
 def test_ego_reverse(
     self
 ):  # Check that the gear can be changed in an EGO vehicle, and the car moves in reverse
     with SimConnection() as sim:
         state = spawnState(sim)
         ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)",
                             lgsvl.AgentType.EGO, state)
         control = lgsvl.VehicleControl()
         control.throttle = 0.5
         control.reverse = True
         ego.apply_control(control, True)
         sim.run(2)
         forward = lgsvl.utils.transform_to_forward(state.transform)
         target = state.position - 3.5 * forward
         diff = ego.state.position - target
         self.assertLess((diff).magnitude(), 1)
    def evaluate(self):
        # Setup vehicles
        vehicles = self.setup_vehicles(self.simConnection, self.npc_speed)
        self.sedan = vehicles["sedan"]
        self.suv = vehicles["suv"]
        self.ego = vehicles["ego"]

        # Run the simulator for 5 seconds
        self.simConnection.execute(timeout=5)

        self.sedan.on_collision(self.on_collision)
        self.suv.on_collision(self.on_collision)
        self.ego.on_collision(self.on_collision)

        # Drive ego to make lane change
        self.simConnection.execute(timeout=5)
        control = lgsvl.VehicleControl()
        control.steering = 0.037
        self.ego.apply_control(control, True)
        self.simConnection.execute(timeout=5)
        control.steering = -0.041
        self.ego.apply_control(control, True)
        self.simConnection.execute(timeout=5)
        control.steering = 0
        self.ego.apply_control(control, True)
        self.simConnection.execute(timeout=7)
        control.braking = 1
        self.ego.apply_control(control, True)
        self.simConnection.execute(timeout=3)

        if (self.suv.state.position.x < self.ego.state.position.x < self.sedan.state.position.x) is False:
            print("Exception: An ego car not between Sedan and SUV!")
            raise Exception()

        if abs(self.sedan.state.position.z - self.ego.state.position.z) > 1.5:
            print("Exception: Sedan and Ego not on same lane!")
            raise Exception()

        if abs(self.suv.state.position.z - self.ego.state.position.z) > 1.5:
            print("Exception: SUV and Ego not on same lane!")
            raise Exception()

        print(f'Congratulation! Final NPCs speed is: {self.npc_speed}')
        # Close the simulator
        self.simConnection.sim.close()
示例#24
0
def drive_ego_no_apollo(simConnection: SimConnection, npc_speed: float):
    lgsvl_sim = simConnection.connect()
    initial_state = spawn_state(lgsvl_sim)  # Mutable object

    configuration = init_configuration(lgsvl_sim,
                                       initial_state,
                                       npc_speed=npc_speed)
    sedan = configuration["sedan"]
    ego = configuration["ego"]
    suv = configuration["suv"]

    # Run the simulator for 5 seconds with debug mode
    # simConnection.execute(timeout=5, vehicles=[ego, sedan, suv], debug=True)
    # Run the simulator for 5 seconds
    simConnection.execute(timeout=5)

    # Record collision if happen
    collisions = []

    def on_collision(agent1, agent2, contact):
        collisions.append([agent1, agent2, contact])
        # print("{} collided with {}".format(agent1, agent2))

    sedan.on_collision(on_collision)
    suv.on_collision(on_collision)
    ego.on_collision(on_collision)

    # Drive ego to make lane change
    simConnection.execute(timeout=5)
    control = lgsvl.VehicleControl()
    control.steering = 0.037
    ego.apply_control(control, True)
    simConnection.execute(timeout=5)
    control.steering = -0.041
    ego.apply_control(control, True)
    simConnection.execute(timeout=5)
    control.steering = 0
    ego.apply_control(control, True)
    simConnection.execute(timeout=7)
    control.braking = 1
    ego.apply_control(control, True)
    simConnection.execute(timeout=3)

    return {"sedan": sedan, "suv": suv, "ego": ego, "collisions": collisions}
示例#25
0
def drive_ego_with_apollo(simConnection: SimConnection):
    lgsvl_sim = simConnection.connect()
    initial_state = spawn_state(lgsvl_sim)  # Mutable object
    configuration = init_configuration(lgsvl_sim, initial_state, npc_speed=3.9)
    sedan = configuration["sedan"]
    ego = configuration["ego"]
    suv = configuration["suv"]

    # Run the simulator for 5 seconds with debug mode
    simConnection.execute(timeout=5)

    # Record collision if happen
    collisions = []

    def on_collision(agent1, agent2, contact):
        collisions.append([agent1, agent2, contact])
        print("{} collided with {}".format(agent1, agent2))

    sedan.on_collision(on_collision)
    suv.on_collision(on_collision)
    ego.on_collision(on_collision)

    # Drive ego to make lane change
    simConnection.execute(timeout=5)
    control = lgsvl.VehicleControl()
    control.steering = 0.037
    ego.apply_control(control, True)
    simConnection.execute(timeout=5)

    # Start to drive the ego by Apollo
    try:
        dv_connection = connect_to_dreamview(ego, TARGET_POINT,
                                             LGSVL__APOLLO_HOST,
                                             LGSVL__APOLLO_PORT,
                                             LGSVL__DREAMVIEW_PORT)
        dv_connection.set_hd_map(config.test_place.map_name)
        dv_connection.enable_module(ApolloModule.Control.value)

        dv_connection.setup_apollo(TARGET_POINT.x, TARGET_POINT.z, [])
    except Exception:
        simConnection.sim.close()

    return {"sedan": sedan, "suv": suv, "ego": ego, "collisions": collisions}
示例#26
0
    def start(self):
        _TOTAL_TIME_ = self.parameters.get("execution_time")
        _EXECUTION_TIME_STEP_ = 0.1
        self.log.debug(f"Total simulation time is set to {_TOTAL_TIME_} seconds")
        self.log.debug(f"Execution time-step is set to {_EXECUTION_TIME_STEP_} seconds")
        
        controls = lgsvl.VehicleControl()
        self.log.debug("Created vehicle controls")
        if self.no_control:
            controls.throttle = 1.0
            self.log.debug(f"The simulation without and automatic control sets throttle to {controls.throttle}")
        
        self.log.debug("Starting the simulation loop...")
        curTime = 0
        self.start_time = time.time()
        self.sim.run(0.01)
        while True:
            new_controls = None
            self.log.debug("Loading sensors from the server")
            sensors = self._get_sensors()
            self.log.debug("Loaded sensors from the server")
            if not self.no_control:
                new_controls = self._checkControlProcess(sensors)
            
            if new_controls:
                controls = self._updateControls(controls, new_controls)
                self.log.debug("Updating controls on the server")
                self.vehicle.apply_control(controls, True)

            frame = self._sensor_visualization(sensors, controls, curTime)
            self._save_frame(frame)
            self._visualize_frame(frame)

            self.log.debug(f"Running the simulation for {_EXECUTION_TIME_STEP_} seconds")
            self.sim.run(_EXECUTION_TIME_STEP_)
            curTime += _EXECUTION_TIME_STEP_
            self.log.info(f"Current execution time: {curTime}")
            if curTime >= _TOTAL_TIME_:
                self.log.info("Current execution time reached the limit. Quitting the simulation.")
                self.log.info(f"The simulation took {time.time() - self.start_time} seconds")
                break
示例#27
0
  def __init__(self, config=CONFIG):

    self.env = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), config["port"])
    if self.env.current_scene == config["scene"]:
      self.env.reset()
    else:
      self.env.load(config["scene"])

    self.spawns = self.env.get_spawn()
    self.vehicles = dict()
    self._occupied = list()
    self.seed()
    self.control = lgsvl.VehicleControl()

    self.action_space = config["action_space"]
    self.observation_space = config["observation_space"]

    self.width = self.observation_space.shape[1]
    self.height = self.observation_space.shape[0]

    self.reward = 0
    self.done = False
示例#28
0
    def initApolloFor(self, obj, lgsvlObj):
        """Initialize Apollo for an ego vehicle.

        Uses LG's interface which injects packets into Dreamview.
        """
        if self.usingApollo:
            raise RuntimeError('can only use one Apollo vehicle')
        self.usingApollo = True

        def on_collision(agent1, agent2, contact):
            if agent1 is not None and agent1.name == lgsvlObj.name:
                self.data[obj]['collision'] = True
            if agent2 is not None and agent2.name == lgsvlObj.name:
                self.data[obj]['collision'] = True
            if self.data[obj]['collision']:
                self.collisionOccurred = True

        # Initialize Data
        self.data[obj]['collision'] = False
        lgsvlObj.on_collision(on_collision)

        # connect bridge from LGSVL to Apollo
        lgsvlObj.connect_bridge(obj.bridgeHost, obj.bridgePort)

        # set up connection and map/vehicle configuration
        import dreamview
        dv = dreamview.Connection(self.client, lgsvlObj)
        obj.dreamview = dv
        waitToStabilize = False
        hdMap = self.scene.params['apolloHDMap']
        if dv.getCurrentMap() != hdMap:
            dv.setHDMap(hdMap)
            waitToStabilize = True
        if dv.getCurrentVehicle() != obj.apolloVehicle:
            dv.setVehicle(obj.apolloVehicle)
            waitToStabilize = True
        
        verbosePrint('Initializing Apollo...')

        # stop the car to cancel buffered speed from previous simulations
        cntrl = lgsvl.VehicleControl()
        cntrl.throttle = 0.0
        lgsvlObj.apply_control(cntrl, True)
        # start modules
        dv.disableModule('Control')
        ready = dv.getModuleStatus()
        for module in obj.apolloModules:
            if not ready[module]:
                dv.enableModule(module)
                verbosePrint(f'Module {module} is not ready...')
                waitToStabilize = True
        while True:
            ready = dv.getModuleStatus()
            if all(ready[module] for module in obj.apolloModules):
                break

        # wait for Apollo to stabilize, if needed
        if waitToStabilize:
            verbosePrint('Waiting for Apollo to stabilize...')
            self.client.run(25)
        dv.enableModule('Control')
        self.client.run(15)
        verbosePrint('Initialized Apollo.')
示例#29
0
 def setEvThrottle(self, throttle):
     ego = self.ego
     c = lgsvl.VehicleControl()
     c.throttle = throttle
     ego.apply_control(c, True)
#
# This software contains code licensed as described in LICENSE.
#

import os
import lgsvl

sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181)
if sim.current_scene == "SanFrancisco":
    sim.reset()
else:
    sim.load("SanFrancisco")

spawns = sim.get_spawn()

state = lgsvl.AgentState()
state.transform = spawns[0]
a = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, state)

print("Current time = ", sim.current_time)
print("Current frame = ", sim.current_frame)

input("press enter to start driving")

c = lgsvl.VehicleControl()
c.throttle = 0.3
c.steering = -1.0
a.apply_control(c, True)

sim.run()