コード例 #1
0
def main():
    sim_host_ip = "127.0.0.1"  # of your local machine running sim
    sim_host_port = 8181
    sim_map = "CubeTown"
    ego_car_model = "Jaguar2015XE (Autoware)"  #  Lexus2016RXHybrid (Autoware)
    ros_bridge_ip = "192.168.1.127"  # of the ros machine that runs the websocket_server
    ros_bridge_port = 9090

    time_limit = 0  # 0 means unlimited time otherwise sim will produce this much data in virtual seconds
    time_scale = 1  # 1 means normal speed, 1.5 means 1.5x speed

    ego_pos = Vector(-22, 0, 59.9)
    ego_roll = 0
    ego_pitch = 0
    ego_yaw = 250
    ego_rot = Vector(ego_pitch, ego_yaw, ego_roll)
    ego_tf = Transform(ego_pos, ego_rot)
    ego_v = Vector(0, 0, 0)
    ego_ang_v = Vector(0, 0, 0)
    ego_state = ObjectState(ego_tf, ego_v, ego_ang_v)

    no_of_npc = 0
    spawn_idx = 0
    spawn_pos = Vector(-32.6, 0, 45)
    spawn_tf = Transform(spawn_pos)

    sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", sim_host_ip),
                          sim_host_port)

    initScene(sim, sim_map, ego_car_model, ego_state, ros_bridge_ip,
              ros_bridge_port, spawn_idx)
    # addNpcRandomAtlanes(sim, no_of_npc, spawn_idx, ego_tf)

    spawns = sim.get_spawn()
    state = lgsvl.AgentState()

    forward = lgsvl.utils.transform_to_forward(spawns[0])
    right = lgsvl.utils.transform_to_right(spawns[0])

    # 10 meters ahead, on left lane
    state.transform.position = spawns[0].position + 45.0 * forward + 2 * right
    state.transform.rotation = spawns[0].rotation

    addNpcAtFixedPoints(sim, state, 0.0, False)

    # state.transform.position = spawns[0].position + 45.0 * forward - 7 * right
    # state.transform.rotation = spawns[0].rotation + Vector(0, 180, 0)

    # addNpcAtFixedPoints(sim, state, 0.0, False)

    # start the sim
    input("Press Enter to run simulation")
    sim.run(time_limit, time_scale)
コード例 #2
0
 def set_state_relative_obj(self, state: ObjectState, forward: float,
                            right: float, yaw: float) -> ObjectState:
     forward_dir_obj = lgsvl.utils.transform_to_forward(state)
     right_dir_obj = lgsvl.utils.transform_to_right(state)
     state.transform.position += \
         forward * forward_dir_obj + right * right_dir_obj
     state.transform.rotation += Vector(0, yaw, 0)
     return state
コード例 #3
0
    def test_EGO_respond_SCHOOLBUS_with_crash(self):
        sim_connection = SimConnection(scene="CubeTown")
        scenario = SchoolBus(
            sim_connection=sim_connection,
            ego_target=Vector(3.03013730049133, -0.00637590885162354,
                              -16.5673313140869),
            ego_speed=7,
            ego_brake=0,
            npc_speed=6,
            npc_source=Vector(-3.84999561309814, -0.00320455431938171,
                              10.877103805542),
            npc_target=Vector(3.03013730049133, -0.00320455431938171,
                              -5.877103805542),
        )
        try:
            scenario.run()
        except Exception:
            sim_connection.sim.close()
            self.fail("Failed!")

        # Passed!
        sim_connection.sim.close()
        self.assertTrue(True, True)
コード例 #4
0
    def test_finding_ego_speed_to_avoid_encroaching_schoolbus_speed_6(self):
        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,
            }

        school_bus_wps = [
            Vector(-3.31942486763, -0.0809718370437622, 24.2049713134766),
            Vector(-3.84999561309814, -0.00320455431938171, 14.877103805542),
            Vector(3.84999561309814, -0.00320455431938171, -20.877103805542)
        ]
        npc_speed = 6
        ego_speed = 6
        encroaching = Encroaching(
            npc_speed=npc_speed,
            ego_speed=ego_speed,
            sim_connection=SimConnection(scene="CubeTown"),
            step=1,
            setup_vehicles=setup_cars,
            npc_waypoints=school_bus_wps)
        encroaching.run()

        self.assertEqual(8.0, encroaching.ego_speed)
コード例 #5
0
ファイル: 01-Shalun.py プロジェクト: a-i-lab/lgsvl_scenario
def main():
    sim_host_ip = "127.0.0.1"  # of your local machine running sim
    sim_host_port = 8181
    sim_map = "Shalun"
    ego_car_model = "Lexus2016RXHybrid (Autoware)"  #  Jaguar2015XE (Autoware)
    ros_bridge_ip = "192.168.1.100"  # of the ros machine that runs the websocket_server
    ros_bridge_port = 9090

    time_limit = 0  # 0 means unlimited time otherwise sim will produce this much data in virtual seconds
    time_scale = 0.5  # 1 means normal speed, 1.5 means 1.5x speed

    ego_pos = Vector(-32.6, 0, 45)
    ego_roll = 0
    ego_pitch = 0
    ego_yaw = 160
    ego_rot = Vector(ego_pitch, ego_yaw, ego_roll)
    ego_tf = Transform(ego_pos, ego_rot)
    ego_v = Vector(0, 0, 0)
    ego_ang_v = Vector(0, 0, 0)
    ego_state = ObjectState(ego_tf, ego_v, ego_ang_v)

    no_of_npc = 0
    spawn_idx = 0
    spawn_pos = Vector(-32.6, 0, 45)
    spawn_tf = Transform(spawn_pos)

    sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", sim_host_ip),
                          sim_host_port)

    initScene(sim, sim_map, ego_car_model, ego_state, ros_bridge_ip,
              ros_bridge_port, spawn_idx)
    addNpcRandomAtlanes(sim, no_of_npc, spawn_idx, spawn_tf)

    pedestrian_pos = Vector(-35, 0, 30)
    pedestrian_state = ObjectState(Transform(pedestrian_pos))
    waypoints = [
        lgsvl.WalkWaypoint(lgsvl.Vector(-16, 0, 34), 5, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(-14, 0, 12), 5, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(-30, 0, 12), 5, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(-30, 0, 30), 5, 0),
    ]
    createPedestrian(sim, pedestrian_state, waypoints)

    input("Press Enter to run simulation")
    sim.run(time_limit, time_scale)
コード例 #6
0
    def test_EGO_encroach_schoolbus_speed_6_with_apollo(self):
        LGSVL__APOLLO_HOST = config("LGSVL__APOLLO_HOST")
        LGSVL__APOLLO_PORT = int(config("LGSVL__APOLLO_PORT"))
        LGSVL__DREAMVIEW_HOST = config("LGSVL__DREAMVIEW_HOST")
        MODULES = [
            'Recorder', 'Localization', 'Perception', 'Transform', 'Routing',
            'Prediction', 'Planning', 'Traffic Light', 'Control'
        ]
        TARGET = Vector(3.03013730049133, -0.00637590885162354,
                        -16.5673313140869)
        COLLISIONS = []
        SEDAN_WPS = [
            Vector(-3.31942486763, -0.0809718370437622, 24.2049713134766),
            Vector(-3.84999561309814, -0.00320455431938171, 14.877103805542),
            Vector(3.84999561309814, -0.00320455431938171, -20.877103805542)
        ]
        NPC_SPEED = 6

        sim_connection = SimConnection(scene="CubeTown")
        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", 6)])
        ego = load_ego(lgsvl_sim, "Lincoln2017MKZ (Apollo 5.0)", ego_state)

        def on_collision(agent1, agent2, contact):
            COLLISIONS.append([agent1, agent2, contact])
            sim_connection.sim.close()
            print("Exception: {} collided with {}".format(agent1, agent2))

        ego.on_collision(on_collision)
        school_bus.on_collision(on_collision)

        try:
            ego.connect_bridge(LGSVL__APOLLO_HOST, LGSVL__APOLLO_PORT)
            dv = lgsvl.dreamview.Connection(lgsvl_sim, ego,
                                            LGSVL__DREAMVIEW_HOST)
            dv.set_hd_map("CubeTown")
            dv.set_vehicle("Lincoln2017MKZ (Apollo 5.0)")
            dv.setup_apollo(TARGET.x, TARGET.z, MODULES)
            # Start the scenario
            school_bus.follow_closest_lane(follow=True, max_speed=10)
            waypoints = []
            for point in SEDAN_WPS:
                waypoints.append(
                    lgsvl.DriveWaypoint(point, NPC_SPEED,
                                        school_bus.state.transform.rotation))

            school_bus.follow(waypoints)
            sim_connection.execute(timeout=15)
        except Exception:
            sim_connection.sim.close()
            self.fail("Failed!")

        sim_connection.sim.close()
        self.assertTrue(True, True)
コード例 #7
0
 def set_state_absolute(self, state: ObjectState, x: float, y: float,
                        z: float, yaw: float) -> ObjectState:
     state.transform.position = Vector(x, z, y)
     state.transform.rotation = Vector(0, yaw, 0)
     return state
コード例 #8
0
 def set_state_relative_map(self, state: ObjectState, forward: float,
                            right: float, yaw: float) -> ObjectState:
     state.transform.position += \
         forward * self.forward_dir_map + right * self.right_dir_map
     state.transform.rotation += Vector(0, yaw, 0)
     return state
コード例 #9
0
    def test_EGO_exit_with_apollo(self):
        LGSVL__APOLLO_HOST = config("LGSVL__APOLLO_HOST")
        LGSVL__APOLLO_PORT = int(config("LGSVL__APOLLO_PORT"))
        LGSVL__DREAMVIEW_HOST = config("LGSVL__DREAMVIEW_HOST")
        MODULES = [
            'Recorder', 'Localization', 'Perception', 'Transform', 'Routing',
            'Prediction', 'Planning', 'Traffic Light', 'Control'
        ]
        EGO_TARGET = Vector(114.219772338867, -0.003660649061203,
                            -1.39988207817078)
        COLLISIONS = []

        # Setup environment
        sim_connection = SimConnection()
        lgsvl_sim = sim_connection.connect()

        NPC_state = spawn_state(lgsvl_sim)
        NPC = load_npc(lgsvl_sim, "Sedan", NPC_state)

        sedan2_state = spawn_state(lgsvl_sim)
        sedan2_state = CarControl.place_car_from_the_point(
            dimension="vertical", distance=10, state=sedan2_state)
        sedan2 = load_npc(lgsvl_sim, "Sedan", sedan2_state)
        sedan3_state = spawn_state(lgsvl_sim)
        sedan3_state = CarControl.place_car_from_the_point(
            dimension="vertical", distance=15, state=sedan3_state)
        sedan3 = load_npc(lgsvl_sim, "Sedan", sedan3_state)

        # Placing the ego on the starting point
        ego_state = spawn_state(lgsvl_sim)
        ego_state = CarControl.place_car_from_the_point(dimension="vertical",
                                                        distance=5,
                                                        state=ego_state)
        ego = load_ego(lgsvl_sim, "Lincoln2017MKZ (Apollo 5.0)", ego_state)

        sim_connection.execute(timeout=5, debug=True, vehicles=[ego])

        def on_collision(agent1, agent2, contact):
            COLLISIONS.append([agent1, agent2, contact])
            sim_connection.sim.close()
            # print("Exception: {} collided with {}".format(agent1, agent2))
            raise Exception()

        ego.on_collision(on_collision)
        NPC.on_collision(on_collision)
        sedan2.on_collision(on_collision)
        sedan3.on_collision(on_collision)

        try:
            ego.connect_bridge(LGSVL__APOLLO_HOST, LGSVL__APOLLO_PORT)
            dv = lgsvl.dreamview.Connection(lgsvl_sim, ego,
                                            LGSVL__DREAMVIEW_HOST)
            dv.set_hd_map("CubeTown")
            dv.set_vehicle("Lincoln2017MKZ (Apollo 5.0)")
            dv.setup_apollo(EGO_TARGET.x, EGO_TARGET.z, MODULES)
            # Start the scenario
            sim_connection.execute(timeout=15)
        except Exception:
            sim_connection.sim.close()
            self.fail("Failed!")

        sim_connection.sim.close()
        self.assertTrue(True, True)
コード例 #10
0
def main():
    sim_host_ip = "127.0.0.1"  # of your local machine running sim
    sim_host_port = 8181
    sim_map = "Shalun"
    ego_car_model = "Jaguar2015XE (Autoware)"  #  Lexus2016RXHybrid (Autoware)
    ros_bridge_ip = "192.168.2.18"  # of the ros machine that runs the websocket_server
    ros_bridge_port = 9090

    time_limit = 0  # 0 means unlimited time otherwise sim will produce this much data in virtual seconds
    time_scale = 1  # 1 means normal speed, 1.5 means 1.5x speed

    ego_pos = Vector(-22, 0, 59.9)
    ego_roll = 0
    ego_pitch = 0
    ego_yaw = 250
    ego_rot = Vector(ego_pitch, ego_yaw, ego_roll)
    ego_tf = Transform(ego_pos, ego_rot)
    ego_v = Vector(0, 0, 0)
    ego_ang_v = Vector(0, 0, 0)
    ego_state = ObjectState(ego_tf, ego_v, ego_ang_v)

    no_of_npc = 5
    spawn_idx = 0
    spawn_pos = Vector(-32.6, 0, 45)
    spawn_tf = Transform(spawn_pos)

    sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", sim_host_ip),
                          sim_host_port)

    initScene(sim, sim_map, ego_car_model, ego_state, ros_bridge_ip,
              ros_bridge_port, spawn_idx)
    addNpcRandomAtlanes(sim, no_of_npc, spawn_idx, ego_tf)

    pedestrian_idle = 0

    pedestrian_pos = Vector(-31, 0, 31)
    pedestrian_state = ObjectState(Transform(pedestrian_pos))
    waypoints = [
        lgsvl.WalkWaypoint(lgsvl.Vector(-18, 0, 29), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(-12, 0, 12), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(-18, 0, 29), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(-31, 0, 2), pedestrian_idle, 0),
    ]
    createPedestrian(sim, pedestrian_state, waypoints)

    pedestrian_pos = Vector(-18, 0, 29)
    pedestrian_state = ObjectState(Transform(pedestrian_pos))
    waypoints = [
        lgsvl.WalkWaypoint(lgsvl.Vector(-35, 0, 30), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(-18, 0, 29), pedestrian_idle, 0),
    ]
    createPedestrian(sim, pedestrian_state, waypoints)

    pedestrian_pos = Vector(-13, 0, 12)
    pedestrian_state = ObjectState(Transform(pedestrian_pos))
    waypoints = [
        lgsvl.WalkWaypoint(lgsvl.Vector(-18, 0, 29), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(-35, 0, 30), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(-18, 0, 29), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(-12, 0, 12), pedestrian_idle, 0),
    ]
    createPedestrian(sim, pedestrian_state, waypoints)

    ### OTHER SIDE

    pedestrian_pos = Vector(11, 0, -18.5)
    pedestrian_state = ObjectState(Transform(pedestrian_pos))
    waypoints = [
        lgsvl.WalkWaypoint(lgsvl.Vector(28, 0, -14), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(11, 0, -15), pedestrian_idle, 0),
    ]
    createPedestrian(sim, pedestrian_state, waypoints)

    pedestrian_pos = Vector(28, 0, -11.5)
    pedestrian_state = ObjectState(Transform(pedestrian_pos))
    waypoints = [
        lgsvl.WalkWaypoint(lgsvl.Vector(11, 0, -19), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(28, 0, -12), pedestrian_idle, 0),
    ]
    createPedestrian(sim, pedestrian_state, waypoints)

    pedestrian_pos = Vector(30, 0, -13)
    pedestrian_state = ObjectState(Transform(pedestrian_pos))
    waypoints = [
        lgsvl.WalkWaypoint(lgsvl.Vector(25, 0, -1), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(30, 0, -13), pedestrian_idle, 0),
    ]
    createPedestrian(sim, pedestrian_state, waypoints)

    pedestrian_pos = Vector(25, 0, -1)
    pedestrian_state = ObjectState(Transform(pedestrian_pos))
    waypoints = [
        lgsvl.WalkWaypoint(lgsvl.Vector(30, 0, -13), pedestrian_idle, 0),
        lgsvl.WalkWaypoint(lgsvl.Vector(25, 0, -1), pedestrian_idle, 0),
    ]
    createPedestrian(sim, pedestrian_state, waypoints)

    # PEDESTIRAN NEAR THE VEHICLE TO TEST AVOIDANCE
    # pedestrian_pos = Vector(-32, 0, 57.5)
    # pedestrian_state = ObjectState(Transform(pedestrian_pos))
    # waypoints = [
    #     lgsvl.WalkWaypoint(lgsvl.Vector(-32, 0, 57.5), 1e10, 0),
    # ]
    # createPedestrian(sim, pedestrian_state, waypoints)

    input("Press Enter to run simulation")
    sim.run(time_limit, time_scale)
コード例 #11
0
def main():
    sim_host_ip = "127.0.0.1"  # of your local machine running sim
    sim_host_port = 8181
    sim_map = "CubeTown"
    ego_car_model = "Jaguar2015XE (Autoware)"  #  Lexus2016RXHybrid (Autoware)
    ros_bridge_ip = "192.168.1.78"  # of the ros machine that runs the websocket_server
    ros_bridge_port = 9090

    time_limit = 0  # 0 means unlimited time otherwise sim will produce this much data in virtual seconds
    time_scale = 1  # 1 means normal speed, 1.5 means 1.5x speed

    sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", sim_host_ip),
                          sim_host_port)

    ego_pos = Vector(-22, 0, 59.9)
    ego_roll = 0
    ego_pitch = 0
    ego_yaw = 250
    ego_rot = Vector(ego_pitch, ego_yaw, ego_roll)
    ego_tf = Transform(ego_pos, ego_rot)
    ego_v = Vector(0, 0, 0)
    ego_ang_v = Vector(0, 0, 0)
    ego_state = ObjectState(ego_tf, ego_v, ego_ang_v)

    no_of_npc = 0
    spawn_idx = 0
    spawn_pos = Vector(-32.6, 0, 45)
    spawn_tf = Transform(spawn_pos)

    initScene(sim, sim_map, ego_car_model, ego_state, ros_bridge_ip,
              ros_bridge_port, spawn_idx)
    # addNpcRandomAtlanes(sim, no_of_npc, spawn_idx, ego_tf)

    spawns = sim.get_spawn()
    state = lgsvl.AgentState()

    forward = lgsvl.utils.transform_to_forward(spawns[0])
    right = lgsvl.utils.transform_to_right(spawns[0])

    state.transform.position = spawns[0].position + 88 * forward + 55 * right
    state.transform.rotation = spawns[0].rotation - Vector(0, 90, 0)
    npcSpeed = 10

    waypoints = [
        DriveWaypoint(state.transform.position, npcSpeed,
                      state.transform.rotation, 0, False, 0),
        DriveWaypoint(state.transform.position, npcSpeed,
                      state.transform.rotation, 20, False, 0)
    ]

    pos = state.transform.position
    increment = 100
    start = 55
    end = -25

    for i in range(increment):
        pos += (end - start) / increment * right
        waypoints.append(
            DriveWaypoint(pos, npcSpeed, state.transform.rotation, 0, False,
                          0))

    addNpcAFollowWaypoints(sim, state, waypoints, True)

    state.transform.position = spawns[0].position + 94 * forward + -70 * right
    state.transform.rotation = spawns[0].rotation + Vector(0, 90, 0)
    npcSpeed = 10

    waypoints = [
        DriveWaypoint(state.transform.position, npcSpeed,
                      state.transform.rotation, 0, False, 0),
        DriveWaypoint(state.transform.position, npcSpeed,
                      state.transform.rotation, 20, False, 0)
    ]

    pos = state.transform.position
    increment = 100
    start = -70
    end = 50

    for i in range(increment):
        pos += (end - start) / increment * right
        waypoints.append(
            DriveWaypoint(pos, npcSpeed, state.transform.rotation, 0, False,
                          0))

    addNpcAFollowWaypoints(sim, state, waypoints, True)

    # start the sim
    input("Press Enter to run simulation")
    sim.run(time_limit, time_scale)
コード例 #12
0
with open('parameters.json') as json_file:
    scenario_parameters = json.load(json_file)

# Intersections
ego_intersection_transform = Transform.from_json(scenario_config["ego_intersection"]['transform'])
agent_1_intersection_transform = Transform.from_json(scenario_config["agent_1_intersection"]['transform'])
agent_2_intersection_transform = Transform.from_json(scenario_config["agent_2_intersection"]['transform'])

# Waypoints
with open('waypoints.json') as json_file:
    scenario_waypoints = json.load(json_file)

# Agent 1 Way Points
agent_1_waypoints = []
for waypoint in scenario_waypoints['agent_1']:
    agent_1_waypoints.append(lgsvl.agent.DriveWaypoint(Vector.from_json(waypoint['position']),
                                                       waypoint['speed'],
                                                       Vector.from_json(waypoint['angle']),
                                                       waypoint['idle'],
                                                       waypoint['deactivate'],
                                                       waypoint['trigger_distance'],
                                                       waypoint['timestamp']))

# Agent 2 Way Points
agent_2_waypoints = []
for waypoint in scenario_waypoints['agent_2']:
    agent_2_waypoints.append(lgsvl.agent.DriveWaypoint(Vector.from_json(waypoint['position']),
                                                       waypoint['speed'],
                                                       Vector.from_json(waypoint['angle']),
                                                       waypoint['idle'],
                                                       waypoint['deactivate'],
コード例 #13
0
    def test_EGO_encroach_NPC_speed_20_with_apollo(self):
        LGSVL__APOLLO_HOST = config("LGSVL__APOLLO_HOST")
        LGSVL__APOLLO_PORT = int(config("LGSVL__APOLLO_PORT"))
        LGSVL__DREAMVIEW_HOST = config("LGSVL__DREAMVIEW_HOST")
        MODULES = [
            'Recorder', 'Localization', 'Perception', 'Transform', 'Routing',
            'Prediction', 'Planning', 'Traffic Light', 'Control'
        ]
        TARGET = Vector(4.85003185272217, -0.0120296478271484,
                        22.7699680328369)
        COLLISIONS = []
        SEDAN_WPS = [
            Vector(-3.15000438690186, 0, 37.7700042724609),
            Vector(4.85003137588501, -0.0120288729667664, 22.7699680328369)
        ]
        NPC_SPEED = 10

        sim_connection = SimConnection(scene="CubeTown")
        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", 3)])
        ego = load_ego(lgsvl_sim, "Lincoln2017MKZ (Apollo 5.0)", ego_state)

        def on_collision(agent1, agent2, contact):
            COLLISIONS.append([agent1, agent2, contact])
            sim_connection.sim.close()
            print("Exception: {} collided with {}".format(agent1, agent2))

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

        try:
            ego.connect_bridge(LGSVL__APOLLO_HOST, LGSVL__APOLLO_PORT)
            dv = lgsvl.dreamview.Connection(lgsvl_sim, ego,
                                            LGSVL__DREAMVIEW_HOST)
            dv.set_hd_map("CubeTown")
            dv.set_vehicle("Lincoln2017MKZ (Apollo 5.0)")
            dv.setup_apollo(TARGET.x, TARGET.z, MODULES)
            # Start the scenario
            waypoints = []
            for point in SEDAN_WPS:
                waypoints.append(
                    lgsvl.DriveWaypoint(point, NPC_SPEED,
                                        sedan.state.transform.rotation))

            sedan.follow(waypoints)
            sim_connection.execute(timeout=15)
        except Exception:
            sim_connection.sim.close()
            self.fail("Failed!")

        sim_connection.sim.close()
        self.assertTrue(True, True)
コード例 #14
0
    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,
    }


sedan_wps = [
    Vector(-3.15000438690186, 0, 37.7700042724609),
    Vector(4.85003137588501, -0.0120288729667664, 22.7699680328369)
]


class TestCase04(unittest.TestCase):
    @unittest.expectedFailure
    def test_ego_crash_encroaching_npc(self):
        sim_connection = SimConnection(scene="CubeTown")
        encroaching = Encroaching(npc_speed=20,
                                  ego_speed=1,
                                  sim_connection=sim_connection,
                                  step=1,
                                  setup_vehicles=setup_cars,
                                  npc_waypoints=sedan_wps)