From 6fbbdf18a8a41e8a9038956f3961df56a0c56a52 Mon Sep 17 00:00:00 2001 From: "eric.boise" Date: Wed, 11 Mar 2020 16:54:19 -0700 Subject: [PATCH 001/115] add color option to agent --- lgsvl/simulator.py | 7 ++++--- quickstart/10-npc-follow-the-lane.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index 2c32f15..0323dbf 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -105,10 +105,11 @@ def _process(self, cmd, args): break j = self.remote.command("simulator/continue") - @accepts(str, AgentType, AgentState) - def add_agent(self, name, agent_type, state = None): + @accepts(str, AgentType, AgentState, Vector) + def add_agent(self, name, agent_type, state = None, color = None): if state is None: state = AgentState() - args = {"name": name, "type": agent_type.value, "state": state.to_json()} + if color is None: color = Vector(-1, -1, -1) + args = {"name": name, "type": agent_type.value, "state": state.to_json(), "color": color.to_json()} uid = self.remote.command("simulator/add_agent", args) agent = Agent.create(self, uid, agent_type) agent.name = name diff --git a/quickstart/10-npc-follow-the-lane.py b/quickstart/10-npc-follow-the-lane.py index 85cdbf9..23db6b6 100755 --- a/quickstart/10-npc-follow-the-lane.py +++ b/quickstart/10-npc-follow-the-lane.py @@ -37,7 +37,7 @@ state.transform.position = spawns[0].position + 4.0 * right + 10.0 * forward state.transform.rotation = spawns[0].rotation -npc2 = sim.add_agent("SUV", lgsvl.AgentType.NPC, state) +npc2 = sim.add_agent("SUV", lgsvl.AgentType.NPC, state, lgsvl.Vector(1,1,0)) # If the passed bool is False, then the NPC will not moved # The float passed is the maximum speed the NPC will drive From 3374a80ad1f853b194222dbfcb6b67344a947c0e Mon Sep 17 00:00:00 2001 From: "shalin.mehta" Date: Tue, 17 Mar 2020 14:56:18 -0700 Subject: [PATCH 002/115] Add sim.run to quickstart script --- quickstart/22-connecting-bridge.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/quickstart/22-connecting-bridge.py b/quickstart/22-connecting-bridge.py index 0afe53d..d13afc3 100755 --- a/quickstart/22-connecting-bridge.py +++ b/quickstart/22-connecting-bridge.py @@ -34,3 +34,5 @@ time.sleep(1) print("Bridge connected:", a.bridge_connected) + +sim.run() From 58b3c0cec0f1972e867649ba07140df985e32397 Mon Sep 17 00:00:00 2001 From: "eric.boise" Date: Fri, 10 Apr 2020 14:07:50 -0700 Subject: [PATCH 003/115] enable random npc and pedestrians --- lgsvl/simulator.py | 5 +++++ quickstart/29-add-random-agents.py | 35 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 quickstart/29-add-random-agents.py diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index 0323dbf..d2b9f58 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -123,6 +123,11 @@ def remove_agent(self, agent): if agent in self.callbacks: del self.callbacks[agent] + @accepts(AgentType) + def add_random_agents(self, agent_type): + args = {"type": agent_type.value} + self.remote.command("simulator/add_random_agents", args) + def get_agents(self): return list(self.agents.values()) diff --git a/quickstart/29-add-random-agents.py b/quickstart/29-add-random-agents.py new file mode 100755 index 0000000..f0e0562 --- /dev/null +++ b/quickstart/29-add-random-agents.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2020 LG Electronics, Inc. +# +# 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 == "BorregasAve": + sim.reset() +else: + sim.load("BorregasAve") + +spawns = sim.get_spawn() +forward = lgsvl.utils.transform_to_forward(spawns[0]) +right = lgsvl.utils.transform_to_right(spawns[0]) + +sx = spawns[0].position.x +sz = spawns[0].position.z + +state = lgsvl.AgentState() +state.transform.position = spawns[0].position + 40 * forward +state.transform.rotation = spawns[0].rotation + +a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) + +sim.add_random_agents(lgsvl.AgentType.NPC) +sim.add_random_agents(lgsvl.AgentType.PEDESTRIAN) + +input("Press Enter to start") + +sim.run() From 1069645019512d5b2129e2a94680f649aae6f0df Mon Sep 17 00:00:00 2001 From: "eric.boise" Date: Tue, 5 May 2020 00:38:13 -0700 Subject: [PATCH 004/115] NPC work --- lgsvl/agent.py | 5 +- lgsvl/simulator.py | 10 ++- quickstart/98-npc-behaviour.py | 107 +++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 2 deletions(-) create mode 100755 quickstart/98-npc-behaviour.py diff --git a/lgsvl/agent.py b/lgsvl/agent.py index e60bb78..bbfb1ff 100644 --- a/lgsvl/agent.py +++ b/lgsvl/agent.py @@ -216,6 +216,9 @@ def follow(self, waypoints, loop = False): def follow_closest_lane(self, follow, max_speed, isLaneChange=True): self.remote.command("vehicle/follow_closest_lane", {"uid": self.uid, "follow": follow, "max_speed": max_speed, "isLaneChange": isLaneChange}) + def set_behaviour(self, behaviour): + self.remote.command("vehicle/behaviour", {"uid": self.uid, "behaviour": behaviour}) + @accepts(bool) def change_lane(self, isLeftChange): self.remote.command("vehicle/change_lane", {"uid": self.uid, "isLeftChange": isLeftChange}) @@ -296,4 +299,4 @@ def follow(self, waypoints, loop = False): def on_waypoint_reached(self, fn): self.remote.command("agent/on_waypoint_reached", {"uid": self.uid}) self.simulator._add_callback(self, "waypoint_reached", fn) - \ No newline at end of file + diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index d2b9f58..d83f87b 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -53,6 +53,14 @@ def current_frame(self): def current_time(self): return self.remote.command("simulator/current_time") + @property + def available_agents(self): + return self.remote.command("simulator/available_agents") + + @property + def available_npc_behaviours(self): + return self.remote.command("simulator/npc/available_behaviours") + def reset(self): self.remote.command("simulator/reset") self.agents.clear() @@ -273,4 +281,4 @@ def get_controllable(self, position, control_type = None): "position": position.to_json(), "type": control_type, }) - return Controllable(self.remote, j) \ No newline at end of file + return Controllable(self.remote, j) diff --git a/quickstart/98-npc-behaviour.py b/quickstart/98-npc-behaviour.py new file mode 100755 index 0000000..d7983c0 --- /dev/null +++ b/quickstart/98-npc-behaviour.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2020 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +import os +import lgsvl +import math +import random +import time + +sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +drunkDriverAvailable = False +trailerAvailable = 0 +map = "CubeTown" + +print("Current Scene = {}".format(sim.current_scene)) +# Loads the named map in the connected simulator. The available maps can be set up in web interface +if sim.current_scene == map: + sim.reset() +else: + print("Loading Scene = {}".format(map)) + sim.load(map) + +agents = sim.available_agents +print("agents:") +for i in range(len(agents)): + agent = agents[i] + if agent["name"]=="TrailerTruckTest": trailerAvailable |= 1 + if agent["name"]=="MackAnthemStandupSleeperCab2018": trailerAvailable |= 2 + print("#{:>2}: {} {:40} ({:9}) {}".format(i, ("✔️" if agent["loaded"] else "❌"), agent["name"], agent["NPCType"], agent["AssetGuid"])) + +behaviours = sim.available_npc_behaviours + + +print("behaviours:") +for i in range(len(behaviours)): + if behaviours[i]["name"]=="NPCDrunkDriverBehaviour": drunkDriverAvailable = True + if behaviours[i]["name"]=="NPCTrailerBehaviour": trailerAvailable |= 4 + print("#{:>2}: {}".format(i, behaviours[i]["name"])) + +spawns = sim.get_spawn() + +state = lgsvl.AgentState() +state.transform = spawns[0] +a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) + +mindist = 10.0 +maxdist = 40.0 + +random.seed(0) +trailerAvailable = (trailerAvailable==(1|2|4)) + +print("Trailer support: {} Drunk Driver support: {}".format("✔️" if trailerAvailable else "❌", "✔️" if drunkDriverAvailable else "❌")) + +while True: + if trailerAvailable: + inp = input("Enter index of Agent to spawn, t to spawn truck and trailer, r to run:") + else: + inp = input("Enter index of Agent to spawn, r to run:") + + angle = random.uniform(0.0, 2*math.pi) + dist = random.uniform(mindist, maxdist) + spawn = random.choice(spawns); + sx = spawn.position.x + sy = spawn.position.y + sz = spawn.position.z + point = lgsvl.Vector(sx + dist * math.cos(angle), sy, sz + dist * math.sin(angle)) + state = lgsvl.AgentState() + state.transform = sim.map_point_on_lane(point) + + if (inp == "r"): + print("running.") + sim.run() + + if (inp == "t" and trailerAvailable): + truck = sim.add_agent("MackAnthemStandupSleeperCab2018", lgsvl.AgentType.NPC, state) + truck.follow_closest_lane(True, 5.6) + trailer = sim.add_agent("TrailerTruckTest", lgsvl.AgentType.NPC, state) + trailer.set_behaviour("NPCTrailerBehaviour") + sim.remote.command("agent/trailer/attach", {"trailer_uid": trailer.uid, "truck_uid": truck.uid}) + + else: + try: + agentIndex = int(inp) + if (agentIndex > len(agents)): + print("index out of range") + continue + + agent = agents[agentIndex]["name"] + print("Selected {}".format(agent)) + npc = sim.add_agent(agent, lgsvl.AgentType.NPC, state) + + if drunkDriverAvailable: + inp = input("make drunk driver? yN") + if (inp == "y" or inp == "Y"): + npc.set_behaviour("NPCDrunkDriverBehaviour") + npc.remote.command("agent/drunk/config", { "uid": npc.uid, "correctionMinTime":0.0, "correctionMaxTime":0.6, "steerDriftMin": 0.00, "steerDriftMax":0.09}) + + npc.follow_closest_lane(True, 5.6) + print("spawned agent {}, uid {}".format(agent, npc.uid)) + + except ValueError: + print("expected a number") + From 183ccdcb1d66fb827c074aaadacc012ec33da306 Mon Sep 17 00:00:00 2001 From: Guodong Rong Date: Fri, 22 May 2020 10:56:11 -0700 Subject: [PATCH 005/115] Add set_speed for Pedestrian. --- lgsvl/agent.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lgsvl/agent.py b/lgsvl/agent.py index bbfb1ff..6b6fe41 100644 --- a/lgsvl/agent.py +++ b/lgsvl/agent.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -295,6 +295,10 @@ def follow(self, waypoints, loop = False): "loop": loop, }) + @accepts(float) + def set_speed(self, speed): + self.remote.command("pedestrian/set_speed", {"uid": self.uid, "speed": speed}) + @accepts(Callable) def on_waypoint_reached(self, fn): self.remote.command("agent/on_waypoint_reached", {"uid": self.uid}) From 5304ad133f54ea848f08e4de57c82897fbccae95 Mon Sep 17 00:00:00 2001 From: "karol.byczkowski" Date: Thu, 2 Jul 2020 14:31:54 -0700 Subject: [PATCH 006/115] [FEATURE] AUTO-4016 Added triggers system to the Python API. --- lgsvl/__init__.py | 2 +- lgsvl/agent.py | 51 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/lgsvl/__init__.py b/lgsvl/__init__.py index 7e12606..c88223c 100644 --- a/lgsvl/__init__.py +++ b/lgsvl/__init__.py @@ -7,6 +7,6 @@ from .geometry import Vector, BoundingBox, Transform from .simulator import Simulator, RaycastHit, WeatherState from .sensor import Sensor, CameraSensor, LidarSensor, ImuSensor -from .agent import AgentType, AgentState, VehicleControl, Vehicle, EgoVehicle, NpcVehicle, Pedestrian, DriveWaypoint, WalkWaypoint, NPCControl +from .agent import AgentType, AgentState, VehicleControl, Vehicle, EgoVehicle, NpcVehicle, Pedestrian, DriveWaypoint, WalkWaypoint, WaypointTrigger, TriggerEffector, NPCControl from .controllable import Controllable from .utils import ObjectState \ No newline at end of file diff --git a/lgsvl/agent.py b/lgsvl/agent.py index 6b6fe41..dfefb11 100644 --- a/lgsvl/agent.py +++ b/lgsvl/agent.py @@ -11,9 +11,10 @@ from enum import Enum from collections.abc import Iterable, Callable import math +import json class DriveWaypoint: - def __init__(self, position, speed, angle = Vector(0,0,0), idle = 0, deactivate = False, trigger_distance = 0, timestamp = -1): + def __init__(self, position, speed, angle = Vector(0,0,0), idle = 0, deactivate = False, trigger_distance = 0, timestamp = -1, trigger = None): self.position = position self.speed = speed self.angle = angle @@ -21,12 +22,47 @@ def __init__(self, position, speed, angle = Vector(0,0,0), idle = 0, deactivate self.deactivate = deactivate self.trigger_distance = trigger_distance self.timestamp = timestamp + self.trigger = trigger class WalkWaypoint: - def __init__(self, position, idle, trigger_distance = 0): + def __init__(self, position, idle, trigger_distance = 0, trigger = None): self.position = position self.idle = idle self.trigger_distance = trigger_distance + self.trigger = trigger + +class WaypointTrigger: + def __init__(self, effectors): + self.effectors = effectors + + @staticmethod + def from_json(j): + return WaypointTrigger( + json.loads(j["effectors"]) + ) + + def to_json(self): + effectors_json = [] + for effector in self.effectors: + effectors_json.append(effector.to_json()) + return { + "effectors": effectors_json + } + +class TriggerEffector: + def __init__(self, type_name, value): + self.type_name = type_name + self.value = value + + @staticmethod + def from_json(j): + return TriggerEffector(j["type_name"], j["value"]) + + def to_json(self): + return { + "type_name": self.type_name, + "value": self.value + } class AgentType(Enum): EGO = 1 @@ -196,6 +232,14 @@ def follow(self, waypoints, loop = False): trigger_distance : float how close an EGO must approach for the NPC to continue + trigger : Class (list of Effectors) + trigger data with effectors applied on this waypoint + effectors : Class (type, value) + typeName : string + effector type name + value : float + value of the effector (for example time duration) + loop : bool whether the NPC should loop through the waypoints after reaching the final one ''' @@ -208,7 +252,8 @@ def follow(self, waypoints, loop = False): "idle": wp.idle, "deactivate": wp.deactivate, "trigger_distance": wp.trigger_distance, - "timestamp": wp.timestamp + "timestamp": wp.timestamp, + "trigger": (None if wp.trigger is None else wp.trigger.to_json()) } for wp in waypoints], "loop": loop, }) From 53ce333e1e3c6c3fb5d2c3ab98e2075ea9511ec8 Mon Sep 17 00:00:00 2001 From: Shalin Mehta Date: Wed, 1 Jul 2020 13:39:48 -0700 Subject: [PATCH 007/115] Change test to use simulation time vs system time --- tests/test_peds.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_peds.py b/tests/test_peds.py index 06fa731..69b11e4 100644 --- a/tests/test_peds.py +++ b/tests/test_peds.py @@ -102,10 +102,10 @@ def on_waypoint(agent, index): zoe.on_waypoint_reached(on_waypoint) zoe.follow(waypoints) - t0 = time.time() + t0 = sim.current_time sim.run() # reach the first waypoint sim.run() # reach the second waypoint - t1 = time.time() + t1 = sim.current_time noIdleTime = t1-t0 zoe.state = state @@ -115,10 +115,10 @@ def on_waypoint(agent, index): hit = sim.raycast(state.position - 5 * right, lgsvl.Vector(0, -1, 0), layer_mask) waypoints.append(lgsvl.WalkWaypoint(hit.point, 0)) zoe.follow(waypoints) - t2 = time.time() + t2 = sim.current_time sim.run() # reach the first waypoint sim.run() # reach the second waypoint - t3 = time.time() + t3 = sim.current_time idleTime = t3-t2 self.assertAlmostEqual(idleTime-noIdleTime, 2.0, delta=0.5) From cc8dfc24407cbfa930ad6e312c2f3e369856c5c7 Mon Sep 17 00:00:00 2001 From: "guodong.rong" Date: Tue, 14 Jul 2020 21:23:16 -0700 Subject: [PATCH 008/115] AUTO-3962 Add speed in WalkWaypoints. --- lgsvl/agent.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lgsvl/agent.py b/lgsvl/agent.py index dfefb11..cde7a8a 100644 --- a/lgsvl/agent.py +++ b/lgsvl/agent.py @@ -25,8 +25,9 @@ def __init__(self, position, speed, angle = Vector(0,0,0), idle = 0, deactivate self.trigger = trigger class WalkWaypoint: - def __init__(self, position, idle, trigger_distance = 0, trigger = None): + def __init__(self, position, idle, trigger_distance = 0, speed = 1, trigger = None): self.position = position + self.speed = speed self.idle = idle self.trigger_distance = trigger_distance self.trigger = trigger @@ -320,7 +321,7 @@ def follow(self, waypoints, loop = False): Parameters ---------- waypoints : list of WalkWaypoints - WalkWaypoint : Class (position, idle, trigger_distance) + WalkWaypoint : Class (position, idle, trigger_distance, speed) position : lgsvl.Vector() Unity coordinates of waypoint @@ -331,12 +332,20 @@ def follow(self, waypoints, loop = False): trigger_distance : float how close an EGO must approach for the pedestrian to continue + speed : float + how fast the pedestrian should drive to the waypoint (default value 1) + loop : bool whether the pedestrian should loop through the waypoints after reaching the final one ''' self.remote.command("pedestrian/follow_waypoints", { "uid": self.uid, - "waypoints": [{"position": wp.position.to_json(), "idle": wp.idle, "trigger_distance": wp.trigger_distance} for wp in waypoints], + "waypoints": [{ + "position": wp.position.to_json(), + "idle": wp.idle, + "trigger_distance": wp.trigger_distance, + "speed": wp.speed + } for wp in waypoints], "loop": loop, }) From 9d69f04f35c0a3c568d916ea8e1471ceb1896441 Mon Sep 17 00:00:00 2001 From: "karol.byczkowski" Date: Wed, 15 Jul 2020 13:42:11 -0700 Subject: [PATCH 009/115] AUTO-4092: Added"agents_traversed_waypoints" callback and updated quickstarts. --- lgsvl/agent.py | 12 +-- lgsvl/simulator.py | 43 ++++++---- quickstart/30-time-to-collision-trigger.py | 96 ++++++++++++++++++++++ quickstart/31-wait-for-distance-trigger.py | 96 ++++++++++++++++++++++ 4 files changed, 225 insertions(+), 22 deletions(-) create mode 100755 quickstart/30-time-to-collision-trigger.py create mode 100644 quickstart/31-wait-for-distance-trigger.py diff --git a/lgsvl/agent.py b/lgsvl/agent.py index cde7a8a..c5f7cd5 100644 --- a/lgsvl/agent.py +++ b/lgsvl/agent.py @@ -51,18 +51,18 @@ def to_json(self): } class TriggerEffector: - def __init__(self, type_name, value): + def __init__(self, type_name, parameters): self.type_name = type_name - self.value = value + self.parameters = parameters @staticmethod def from_json(j): - return TriggerEffector(j["type_name"], j["value"]) + return TriggerEffector(j["type_name"], j["parameters"]) def to_json(self): return { "type_name": self.type_name, - "value": self.value + "parameters": self.parameters } class AgentType(Enum): @@ -238,8 +238,8 @@ def follow(self, waypoints, loop = False): effectors : Class (type, value) typeName : string effector type name - value : float - value of the effector (for example time duration) + parameters : dictionary + parameters of the effector (for example "value", "max_distance", "radius") loop : bool whether the NPC should loop through the waypoints after reaching the final one diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index d83f87b..a1db875 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -61,6 +61,9 @@ def available_agents(self): def available_npc_behaviours(self): return self.remote.command("simulator/npc/available_behaviours") + def agents_traversed_waypoints(self, fn): + self._add_callback(None, "agents_traversed_waypoints", fn) + def reset(self): self.remote.command("simulator/reset") self.agents.clear() @@ -83,24 +86,32 @@ def _add_callback(self, agent, name, fn): def _process_events(self, events): self.stopped = False for ev in events: - agent = self.agents[ev["agent"]] - if agent in self.callbacks: - callbacks = self.callbacks[agent] + if "agent" in ev: + agent = self.agents[ev["agent"]] + if agent in self.callbacks: + callbacks = self.callbacks[agent] + event_type = ev["type"] + if event_type in callbacks: + for fn in callbacks[event_type]: + if event_type == "collision": + fn(agent, self.agents.get(ev["other"]), Vector.from_json(ev["contact"]) if ev["contact"] is not None else None) + elif event_type == "waypoint_reached": + fn(agent, ev["index"]) + elif event_type == "stop_line": + fn(agent) + elif event_type == "lane_change": + fn(agent) + elif event_type == "custom": + fn(agent, ev["kind"], ev["context"]) + if self.stopped: + return + elif None in self.callbacks: + callbacks = self.callbacks[None] event_type = ev["type"] if event_type in callbacks: - for fn in callbacks[event_type]: - if event_type == "collision": - fn(agent, self.agents.get(ev["other"]), Vector.from_json(ev["contact"]) if ev["contact"] is not None else None) - elif event_type == "waypoint_reached": - fn(agent, ev["index"]) - elif event_type == "stop_line": - fn(agent) - elif event_type == "lane_change": - fn(agent) - elif event_type == "custom": - fn(agent, ev["kind"], ev["context"]) - if self.stopped: - return + for fn in callbacks[event_type]: + if event_type == "agents_traversed_waypoints": + fn() def _process(self, cmd, args): j = self.remote.command(cmd, args) diff --git a/quickstart/30-time-to-collision-trigger.py b/quickstart/30-time-to-collision-trigger.py new file mode 100755 index 0000000..fa8ccab --- /dev/null +++ b/quickstart/30-time-to-collision-trigger.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +import os +import lgsvl +import math + +sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +if sim.current_scene == "BorregasAve": + sim.reset() +else: + sim.load("BorregasAve") + +spawns = sim.get_spawn() +layer_mask = 0 +layer_mask |= 1 << 0 # 0 is the layer for the road (default) + +# EGO + +state = lgsvl.AgentState() +forward = lgsvl.utils.transform_to_forward(spawns[0]) +right = lgsvl.utils.transform_to_right(spawns[0]) +spawn_state = spawns[0] +hit = sim.raycast(spawn_state.position+forward*40, lgsvl.Vector(0,-1,0), layer_mask) +spawn_state.position = hit.point +state.transform = spawn_state +state.velocity = forward*2 +a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) + +# NPC +state = lgsvl.AgentState() +npc_position = lgsvl.Vector(-4,-1,-48) +hit = sim.raycast(npc_position, lgsvl.Vector(0,-1,0), layer_mask) +npc_rotation = lgsvl.Vector(0,16, 0) +state.transform.position = hit.point +state.transform.rotation = npc_rotation +npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, state) + +vehicles = { + a: "EGO", + npc: "Sedan", +} + +# Executed upon receiving collision callback -- NPC is expected to drive through colliding objects +def on_collision(agent1, agent2, contact): + name1 = vehicles[agent1] + name2 = vehicles[agent2] if agent2 is not None else "OBSTACLE" + print("{} collided with {}".format(name1, name2)) + +a.on_collision(on_collision) +npc.on_collision(on_collision) + +# This block creates the list of waypoints that the NPC will follow +# Each waypoint is an position vector paired with the speed that the NPC will drive to it +waypoints = [] +x_max = 2 +z_delta = 12 + +for i in range(2): + speed = 8 + # Waypoint angles are input as Euler angles (roll, pitch, yaw) + angle = npc_rotation + # Raycast the points onto the ground because BorregasAve is not flat + npc_position.x += 6 + npc_position.z += 21 + hit = sim.raycast(npc_position, lgsvl.Vector(0,-1,0), layer_mask) + + trigger = None + if i == 1: + parameters = {"value": 4.0} + effector = lgsvl.TriggerEffector("TimeToCollision", {}) + trigger = lgsvl.WaypointTrigger([effector]) + wp = lgsvl.DriveWaypoint(position=hit.point, speed=speed, angle=angle, idle=0, trigger_distance=0, trigger = trigger) + waypoints.append(wp) + +def on_waypoint(agent, index): + print("waypoint {} reached".format(index)) +def agents_traversed_waypoints(): + print("All agents traversed their waypoints.") + sim.stop() + +# The above function needs to be added to the list of callbacks for the NPC +npc.on_waypoint_reached(on_waypoint) +sim.agents_traversed_waypoints(agents_traversed_waypoints) + +# The NPC needs to be given the list of waypoints. +# A bool can be passed as the 2nd argument that controls whether or not the NPC loops over the waypoints (default false) +npc.follow(waypoints) + +input("Press Enter to run") + +sim.run() diff --git a/quickstart/31-wait-for-distance-trigger.py b/quickstart/31-wait-for-distance-trigger.py new file mode 100644 index 0000000..1baaf5a --- /dev/null +++ b/quickstart/31-wait-for-distance-trigger.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +import os +import lgsvl +import math + +sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +if sim.current_scene == "BorregasAve": + sim.reset() +else: + sim.load("BorregasAve") + +spawns = sim.get_spawn() +layer_mask = 0 +layer_mask |= 1 << 0 # 0 is the layer for the road (default) + +# EGO + +state = lgsvl.AgentState() +forward = lgsvl.utils.transform_to_forward(spawns[0]) +right = lgsvl.utils.transform_to_right(spawns[0]) +spawn_state = spawns[0] +hit = sim.raycast(spawn_state.position+forward*40, lgsvl.Vector(0,-1,0), layer_mask) +spawn_state.position = hit.point +state.transform = spawn_state +state.velocity = forward*2 +a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) + +# NPC +state = lgsvl.AgentState() +npc_position = lgsvl.Vector(-4,-1,-48) +hit = sim.raycast(npc_position, lgsvl.Vector(0,-1,0), layer_mask) +npc_rotation = lgsvl.Vector(0,16, 0) +state.transform.position = hit.point +state.transform.rotation = npc_rotation +npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, state) + +vehicles = { + a: "EGO", + npc: "Sedan", +} + +# Executed upon receiving collision callback -- NPC is expected to drive through colliding objects +def on_collision(agent1, agent2, contact): + name1 = vehicles[agent1] + name2 = vehicles[agent2] if agent2 is not None else "OBSTACLE" + print("{} collided with {}".format(name1, name2)) + +a.on_collision(on_collision) +npc.on_collision(on_collision) + +# This block creates the list of waypoints that the NPC will follow +# Each waypoint is an position vector paired with the speed that the NPC will drive to it +waypoints = [] +x_max = 2 +z_delta = 12 + +for i in range(2): + speed = 8# if i % 2 == 0 else 12 + # Waypoint angles are input as Euler angles (roll, pitch, yaw) + angle = npc_rotation + # Raycast the points onto the ground because BorregasAve is not flat + npc_position.x += 6 + npc_position.z += 21 + hit = sim.raycast(npc_position, lgsvl.Vector(0,-1,0), layer_mask) + + trigger = None + if i == 1: + parameters = {"value": 4.0} + effector = lgsvl.TriggerEffector("WaitForDistance", parameters) + trigger = lgsvl.WaypointTrigger([effector]) + wp = lgsvl.DriveWaypoint(position=hit.point, speed=speed, angle=angle, idle=0, trigger_distance=0, trigger = trigger) + waypoints.append(wp) + +def on_waypoint(agent, index): + print("waypoint {} reached".format(index)) +def agents_traversed_waypoints(): + print("All agents traversed their waypoints.") + sim.stop() + +# The above function needs to be added to the list of callbacks for the NPC +npc.on_waypoint_reached(on_waypoint) +sim.agents_traversed_waypoints(agents_traversed_waypoints) + +# The NPC needs to be given the list of waypoints. +# A bool can be passed as the 2nd argument that controls whether or not the NPC loops over the waypoints (default false) +npc.follow(waypoints) + +input("Press Enter to run") + +sim.run() From 02471829e7d739ab93ff2c0d7a7e0a505072ed60 Mon Sep 17 00:00:00 2001 From: eric_boise Date: Thu, 23 Jul 2020 14:30:36 -0700 Subject: [PATCH 010/115] change light bc of rotation of map --- quickstart/27-control-traffic-lights.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickstart/27-control-traffic-lights.py b/quickstart/27-control-traffic-lights.py index 298e6d1..8773760 100755 --- a/quickstart/27-control-traffic-lights.py +++ b/quickstart/27-control-traffic-lights.py @@ -33,7 +33,7 @@ for c in controllables: print(c) -signal = sim.get_controllable(lgsvl.Vector(19, 5, 21), "signal") +signal = sim.get_controllable(lgsvl.Vector(15.5, 4.7, -23.9), "signal") print("\n# Signal of interest:") print(signal) From 4bb5b69b1bc4694fc5e0aa43259b7764403bf1fd Mon Sep 17 00:00:00 2001 From: eric_boise Date: Thu, 23 Jul 2020 16:33:17 -0700 Subject: [PATCH 011/115] fix ped waypoint radius --- quickstart/16-pedestrian-follow-waypoints.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickstart/16-pedestrian-follow-waypoints.py b/quickstart/16-pedestrian-follow-waypoints.py index 4712413..220f8c8 100755 --- a/quickstart/16-pedestrian-follow-waypoints.py +++ b/quickstart/16-pedestrian-follow-waypoints.py @@ -26,7 +26,7 @@ a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) # This will create waypoints in a circle for the pedestrian to follow -radius = 5 +radius = 4 count = 8 wp = [] for i in range(count): From 4f1853ce15318c49f6a32a12c998717ba083cc60 Mon Sep 17 00:00:00 2001 From: Hadi Tabatabaee Date: Wed, 29 Jul 2020 16:51:43 -0700 Subject: [PATCH 012/115] Make quickstart-31 executable --- quickstart/31-wait-for-distance-trigger.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 quickstart/31-wait-for-distance-trigger.py diff --git a/quickstart/31-wait-for-distance-trigger.py b/quickstart/31-wait-for-distance-trigger.py old mode 100644 new mode 100755 From fe6465163521ec8e904eca164e3a557fd883f549 Mon Sep 17 00:00:00 2001 From: Karol Byczkowski Date: Thu, 30 Jul 2020 17:26:25 +0200 Subject: [PATCH 013/115] Updated 31 quickstart with new parameter name in the Simulator --- quickstart/31-wait-for-distance-trigger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickstart/31-wait-for-distance-trigger.py b/quickstart/31-wait-for-distance-trigger.py index 1baaf5a..4b81d42 100755 --- a/quickstart/31-wait-for-distance-trigger.py +++ b/quickstart/31-wait-for-distance-trigger.py @@ -71,7 +71,7 @@ def on_collision(agent1, agent2, contact): trigger = None if i == 1: - parameters = {"value": 4.0} + parameters = {"max_distance": 4.0} effector = lgsvl.TriggerEffector("WaitForDistance", parameters) trigger = lgsvl.WaypointTrigger([effector]) wp = lgsvl.DriveWaypoint(position=hit.point, speed=speed, angle=angle, idle=0, trigger_distance=0, trigger = trigger) From 43116673101f9ce68817e790d46a227d4c035f5c Mon Sep 17 00:00:00 2001 From: eric_boise Date: Fri, 7 Aug 2020 13:12:15 -0700 Subject: [PATCH 014/115] add recorder and analysis sensor --- lgsvl/sensor.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lgsvl/sensor.py b/lgsvl/sensor.py index 0ac1031..247af02 100644 --- a/lgsvl/sensor.py +++ b/lgsvl/sensor.py @@ -51,6 +51,10 @@ def create(remote, j): return RadarSensor(remote, j) if j["type"] == "canbus": return CanBusSensor(remote, j) + if j["type"] == "recorder": + return VideoRecordingSensor(remote, j) + if j["type"] == "analysis": + return AnalysisSensor(remote, j) raise ValueError("Sensor type '{}' not supported".format(j["type"])) @@ -126,4 +130,23 @@ def __init__(self, remote, j): class CanBusSensor(Sensor): def __init__(self, remote, j): super().__init__(remote, j["uid"], j["name"]) - self.frequency = j["frequency"] \ No newline at end of file + self.frequency = j["frequency"] + + +class VideoRecordingSensor(Sensor): + def __init__(self, remote, j): + super().__init__(remote, j["uid"], j["name"]) + self.width = j["width"] + self.height = j["height"] + self.framerate = j["framerate"] + + +class AnalysisSensor(Sensor): + def __init__(self, remote, j): + super().__init__(remote, j["uid"], j["name"]) + self.suddenbrakemax = j["suddenbrakemax"] + self.suddensteermax = j["suddensteermax"] + self.stucktravelthreshold = j["stucktravelthreshold"] + self.stucktimethreshold = j["stucktimethreshold"] + self.minfps = j["minfps"] + self.minfpstime = j["minfpstime"] From 6231dad4dec523cb227d9f0d5a6c627468cc722e Mon Sep 17 00:00:00 2001 From: Karol Byczkowski Date: Tue, 11 Aug 2020 14:01:01 -0700 Subject: [PATCH 015/115] Updated 31-wait-for-distance-trigger according to Simulator changes. --- quickstart/31-wait-for-distance-trigger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickstart/31-wait-for-distance-trigger.py b/quickstart/31-wait-for-distance-trigger.py index 4b81d42..af34675 100755 --- a/quickstart/31-wait-for-distance-trigger.py +++ b/quickstart/31-wait-for-distance-trigger.py @@ -70,7 +70,7 @@ def on_collision(agent1, agent2, contact): hit = sim.raycast(npc_position, lgsvl.Vector(0,-1,0), layer_mask) trigger = None - if i == 1: + if i == 0: parameters = {"max_distance": 4.0} effector = lgsvl.TriggerEffector("WaitForDistance", parameters) trigger = lgsvl.WaypointTrigger([effector]) From c65b08eb39c02aa236dfa7e39700a61ad8a4bd07 Mon Sep 17 00:00:00 2001 From: Karol Byczkowski Date: Wed, 19 Aug 2020 16:17:51 +0200 Subject: [PATCH 016/115] Added new trigger quickstart script. New script 32-pedestrian-time-to-collision plays a scenario where pedestrian forces a collision with ego vehicle. Fixed 30-time-to-collision-trigger. --- quickstart/30-time-to-collision-trigger.py | 7 +- quickstart/31-wait-for-distance-trigger.py | 4 +- quickstart/32-pedestrian-time-to-collision.py | 92 +++++++++++++++++++ 3 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 quickstart/32-pedestrian-time-to-collision.py diff --git a/quickstart/30-time-to-collision-trigger.py b/quickstart/30-time-to-collision-trigger.py index fa8ccab..89cfea0 100755 --- a/quickstart/30-time-to-collision-trigger.py +++ b/quickstart/30-time-to-collision-trigger.py @@ -1,13 +1,12 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # import os import lgsvl -import math sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": @@ -20,7 +19,6 @@ layer_mask |= 1 << 0 # 0 is the layer for the road (default) # EGO - state = lgsvl.AgentState() forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) @@ -70,8 +68,7 @@ def on_collision(agent1, agent2, contact): hit = sim.raycast(npc_position, lgsvl.Vector(0,-1,0), layer_mask) trigger = None - if i == 1: - parameters = {"value": 4.0} + if i == 0: effector = lgsvl.TriggerEffector("TimeToCollision", {}) trigger = lgsvl.WaypointTrigger([effector]) wp = lgsvl.DriveWaypoint(position=hit.point, speed=speed, angle=angle, idle=0, trigger_distance=0, trigger = trigger) diff --git a/quickstart/31-wait-for-distance-trigger.py b/quickstart/31-wait-for-distance-trigger.py index af34675..8181a18 100755 --- a/quickstart/31-wait-for-distance-trigger.py +++ b/quickstart/31-wait-for-distance-trigger.py @@ -1,13 +1,12 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # import os import lgsvl -import math sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": @@ -20,7 +19,6 @@ layer_mask |= 1 << 0 # 0 is the layer for the road (default) # EGO - state = lgsvl.AgentState() forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) diff --git a/quickstart/32-pedestrian-time-to-collision.py b/quickstart/32-pedestrian-time-to-collision.py new file mode 100644 index 0000000..1aa98d5 --- /dev/null +++ b/quickstart/32-pedestrian-time-to-collision.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019 LG Electronics, Inc. +# +# 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 == "BorregasAve": + sim.reset() +else: + sim.load("BorregasAve") + +spawns = sim.get_spawn() +layer_mask = 0 +layer_mask |= 1 << 0 # 0 is the layer for the road (default) + +# EGO +state = lgsvl.AgentState() +ego_position = lgsvl.Vector(342.0, 0.0, -87.7) +hit = sim.raycast(ego_position, lgsvl.Vector(0, -1, 0), layer_mask) +state.transform.position = hit.point +state.transform.rotation = lgsvl.Vector(0.0, 15.0, 0.0) +forward = lgsvl.Vector(0.2, 0.0, 0.8) +state.velocity = forward*15 +a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) + +# Pedestrian +state = lgsvl.AgentState() +pedestrian_position = lgsvl.Vector(350.0, 0.0, -12) +hit = sim.raycast(pedestrian_position, lgsvl.Vector(0, -1, 0), layer_mask) +pedestrian_rotation = lgsvl.Vector(0.0, 105.0, 0.0) +state.transform.position = hit.point +state.transform.rotation = pedestrian_rotation +pedestrian = sim.add_agent("Bob", lgsvl.AgentType.PEDESTRIAN, state) + +agents = { + a: "EGO", + pedestrian: "Bob" +} + + +# Executed upon receiving collision callback -- pedestrian is expected to walk into colliding objects +def on_collision(agent1, agent2, contact): + name1 = agents[agent1] + name2 = agents[agent2] if agent2 is not None else "OBSTACLE" + print("{} collided with {}".format(name1, name2)) + + +a.on_collision(on_collision) +pedestrian.on_collision(on_collision) + +# This block creates the list of waypoints that the pedestrian will follow +# Each waypoint is an position vector paired with the speed that the pedestrian will walk to +waypoints = [] + +trigger = None +speed = 3 +hit = sim.raycast(pedestrian_position+lgsvl.Vector(7.4, 0.0, -2.2), lgsvl.Vector(0, -1, 0), layer_mask) +effector = lgsvl.TriggerEffector("TimeToCollision", {}) +trigger = lgsvl.WaypointTrigger([effector]) +wp = lgsvl.WalkWaypoint(position=hit.point, speed=speed, idle=0, trigger_distance=0, trigger=trigger) +waypoints.append(wp) + +hit = sim.raycast(pedestrian_position+lgsvl.Vector(12.4, 0.0, -3.4), lgsvl.Vector(0, -1, 0), layer_mask) +wp = lgsvl.WalkWaypoint(position=hit.point, speed=speed, idle=0, trigger_distance=0, trigger=None) +waypoints.append(wp) + + +def on_waypoint(agent, index): + print("waypoint {} reached".format(index)) + + +def agents_traversed_waypoints(): + print("All agents traversed their waypoints.") + sim.stop() + + +# The above function needs to be added to the list of callbacks for the pedestrian +pedestrian.on_waypoint_reached(on_waypoint) +sim.agents_traversed_waypoints(agents_traversed_waypoints) + +# The pedestrian needs to be given the list of waypoints. A bool can be passed as the 2nd argument that controls +# whether or not the pedestrian loops over the waypoints (default false) +pedestrian.follow(waypoints, False) + +input("Press Enter to run") + +sim.run() From b8b4e6f1f9a726f3a802eb4cef87328b20e9a9dd Mon Sep 17 00:00:00 2001 From: Karol Byczkowski Date: Tue, 25 Aug 2020 20:35:24 +0200 Subject: [PATCH 017/115] Triggers support for the pedestrian agents. --- lgsvl/agent.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lgsvl/agent.py b/lgsvl/agent.py index c5f7cd5..8c81d8a 100644 --- a/lgsvl/agent.py +++ b/lgsvl/agent.py @@ -344,7 +344,8 @@ def follow(self, waypoints, loop = False): "position": wp.position.to_json(), "idle": wp.idle, "trigger_distance": wp.trigger_distance, - "speed": wp.speed + "speed": wp.speed, + "trigger": (None if wp.trigger is None else wp.trigger.to_json()) } for wp in waypoints], "loop": loop, }) From 3868b9384735984937df910ea00b4724522ce4f7 Mon Sep 17 00:00:00 2001 From: "hadi.tabatabaee" Date: Sat, 29 Aug 2020 15:27:42 -0700 Subject: [PATCH 018/115] AUTO-4382: Cleanup quickstart scripts --- quickstart/03-raycast.py | 2 +- quickstart/04-ego-drive-straight.py | 7 ++-- quickstart/05-ego-drive-in-circle.py | 6 ++-- quickstart/06-save-camera-image.py | 6 ++-- quickstart/07-save-lidar-point-cloud.py | 6 ++-- quickstart/08-create-npc.py | 5 ++- quickstart/09-reset-scene.py | 6 ++-- quickstart/10-npc-follow-the-lane.py | 4 +-- quickstart/11-collision-callbacks.py | 8 +---- quickstart/12-create-npc-on-lane.py | 4 +-- quickstart/13-npc-follow-waypoints.py | 34 ++++++++----------- quickstart/14-create-pedestrians.py | 7 ++-- quickstart/15-pedestrian-walk-randomly.py | 8 ++--- quickstart/16-pedestrian-follow-waypoints.py | 7 ++-- quickstart/17-many-pedestrians-walking.py | 9 ++--- quickstart/18-weather-effects.py | 6 ++-- quickstart/19-time-of-day.py | 5 ++- quickstart/20-enable-sensors.py | 8 ++--- quickstart/21-map-coordinates.py | 4 +-- quickstart/22-connecting-bridge.py | 3 +- quickstart/23-npc-callbacks.py | 12 +++---- .../24-ego-drive-straight-non-realtime.py | 4 +-- quickstart/25-waypoint-flying-npc.py | 14 +++----- quickstart/26-npc-trigger-waypoints.py | 17 ++++------ quickstart/28-control-traffic-cone.py | 4 +-- quickstart/29-add-random-agents.py | 5 +-- quickstart/30-time-to-collision-trigger.py | 17 +++++----- quickstart/31-wait-for-distance-trigger.py | 13 ++++--- quickstart/98-npc-behaviour.py | 1 - 29 files changed, 92 insertions(+), 140 deletions(-) diff --git a/quickstart/03-raycast.py b/quickstart/03-raycast.py index d745693..c0065fd 100755 --- a/quickstart/03-raycast.py +++ b/quickstart/03-raycast.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # diff --git a/quickstart/04-ego-drive-straight.py b/quickstart/04-ego-drive-straight.py index 61d91d1..fffb250 100755 --- a/quickstart/04-ego-drive-straight.py +++ b/quickstart/04-ego-drive-straight.py @@ -1,13 +1,12 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # import os import lgsvl -import math sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": @@ -24,10 +23,10 @@ # Agents can be spawned with a velocity. Default is to spawn with 0 velocity state.velocity = 20 * forward -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) # The bounding box of an agent are 2 points (min and max) such that the box formed from those 2 points completely encases the agent -print("Vehicle bounding box =", a.bounding_box) +print("Vehicle bounding box =", ego.bounding_box) print("Current time = ", sim.current_time) print("Current frame = ", sim.current_frame) diff --git a/quickstart/05-ego-drive-in-circle.py b/quickstart/05-ego-drive-in-circle.py index 8264bcb..652b0ba 100755 --- a/quickstart/05-ego-drive-in-circle.py +++ b/quickstart/05-ego-drive-in-circle.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -20,7 +20,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) state.transform.position += 5 * forward# 5m forwards -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) print("Current time = ", sim.current_time) print("Current frame = ", sim.current_frame) @@ -33,6 +33,6 @@ c.throttle = 0.3 c.steering = -1.0 # a True in apply_control means the control will be continuously applied ("sticky"). False means the control will be applied for 1 frame -a.apply_control(c, True) +ego.apply_control(c, True) sim.run() diff --git a/quickstart/06-save-camera-image.py b/quickstart/06-save-camera-image.py index cd3a912..4e4559d 100755 --- a/quickstart/06-save-camera-image.py +++ b/quickstart/06-save-camera-image.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -18,10 +18,10 @@ state = lgsvl.AgentState() state.transform = spawns[0] -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) # get_sensors returns a list of sensors on the EGO vehicle -sensors = a.get_sensors() +sensors = ego.get_sensors() for s in sensors: if s.name == "Main Camera": # Camera and LIDAR sensors can save data to the specified file path diff --git a/quickstart/07-save-lidar-point-cloud.py b/quickstart/07-save-lidar-point-cloud.py index 23038ef..f5980ca 100755 --- a/quickstart/07-save-lidar-point-cloud.py +++ b/quickstart/07-save-lidar-point-cloud.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -18,9 +18,9 @@ state = lgsvl.AgentState() state.transform = spawns[0] -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) -sensors = a.get_sensors() +sensors = ego.get_sensors() for s in sensors: if s.name == "Lidar": s.save("lidar.pcd") diff --git a/quickstart/08-create-npc.py b/quickstart/08-create-npc.py index 4d68c1e..b935b1f 100755 --- a/quickstart/08-create-npc.py +++ b/quickstart/08-create-npc.py @@ -1,13 +1,12 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # import os import lgsvl -import random sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": @@ -19,7 +18,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) diff --git a/quickstart/09-reset-scene.py b/quickstart/09-reset-scene.py index c03dc02..ad43933 100755 --- a/quickstart/09-reset-scene.py +++ b/quickstart/09-reset-scene.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -8,8 +8,6 @@ import os import lgsvl import random -import time -import math random.seed(0) @@ -23,7 +21,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) diff --git a/quickstart/10-npc-follow-the-lane.py b/quickstart/10-npc-follow-the-lane.py index 23db6b6..a790c71 100755 --- a/quickstart/10-npc-follow-the-lane.py +++ b/quickstart/10-npc-follow-the-lane.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -18,7 +18,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) state = lgsvl.AgentState() diff --git a/quickstart/11-collision-callbacks.py b/quickstart/11-collision-callbacks.py index 5a06626..40032ea 100755 --- a/quickstart/11-collision-callbacks.py +++ b/quickstart/11-collision-callbacks.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -16,12 +16,7 @@ spawns = sim.get_spawn() -sx = spawns[0].position.x -sz = spawns[0].position.z -ry = spawns[0].rotation.y - # ego vehicle - state = lgsvl.AgentState() state.transform = spawns[0] ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) @@ -30,7 +25,6 @@ right = lgsvl.utils.transform_to_right(spawns[0]) # school bus, 20m ahead, perpendicular to road, stopped - state = lgsvl.AgentState() state.transform.position = spawns[0].position + 20.0 * forward state.transform.rotation.y = spawns[0].rotation.y + 90.0 diff --git a/quickstart/12-create-npc-on-lane.py b/quickstart/12-create-npc-on-lane.py index 5c001a6..8d6863e 100755 --- a/quickstart/12-create-npc-on-lane.py +++ b/quickstart/12-create-npc-on-lane.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -20,7 +20,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) sx = spawns[0].position.x sy = spawns[0].position.y diff --git a/quickstart/13-npc-follow-waypoints.py b/quickstart/13-npc-follow-waypoints.py index 4f87979..d6dd701 100755 --- a/quickstart/13-npc-follow-waypoints.py +++ b/quickstart/13-npc-follow-waypoints.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -19,27 +19,23 @@ spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) -# EGO +# Creating state object to define state for Ego and NPC state = lgsvl.AgentState() state.transform = spawns[0] -state2 = copy.deepcopy(state) -state2.transform.position += 50 * forward -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state2) -# NPC, 10 meters ahead +# Ego +ego_state = copy.deepcopy(state) +ego_state.transform.position += 50 * forward +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, ego_state) -sx = spawns[0].position.x -sy = spawns[0].position.y -sz = spawns[0].position.z + 10.0 - -state = lgsvl.AgentState() -state.transform.position = spawns[0].position + 10 * forward -state.transform.rotation = spawns[0].rotation -npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, state) +# NPC +npc_state = copy.deepcopy(state) +npc_state.transform.position += 10 * forward +npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, npc_state) vehicles = { - a: "EGO", + ego: "EGO", npc: "Sedan", } @@ -49,7 +45,7 @@ def on_collision(agent1, agent2, contact): name2 = vehicles[agent2] if agent2 is not None else "OBSTACLE" print("{} collided with {}".format(name1, name2)) -a.on_collision(on_collision) +ego.on_collision(on_collision) npc.on_collision(on_collision) # This block creates the list of waypoints that the NPC will follow @@ -68,7 +64,7 @@ def on_collision(agent1, agent2, contact): # Waypoint angles are input as Euler angles (roll, pitch, yaw) angle = spawns[0].rotation # Raycast the points onto the ground because BorregasAve is not flat - hit = sim.raycast(spawns[0].position + pz * forward, lgsvl.Vector(0,-1,0), layer_mask) + hit = sim.raycast(spawns[0].position + pz * forward, lgsvl.Vector(0,-1,0), layer_mask) # NPC will wait for 1 second at each waypoint wp = lgsvl.DriveWaypoint(hit.point, speed, angle, 1) @@ -81,10 +77,10 @@ def on_waypoint(agent, index): # The above function needs to be added to the list of callbacks for the NPC npc.on_waypoint_reached(on_waypoint) -# The NPC needs to be given the list of waypoints. +# The NPC needs to be given the list of waypoints. # A bool can be passed as the 2nd argument that controls whether or not the NPC loops over the waypoints (default false) npc.follow(waypoints) -input("Press Enter to run") +input("Press Enter to run\n") sim.run() diff --git a/quickstart/14-create-pedestrians.py b/quickstart/14-create-pedestrians.py index 978c180..992eb37 100755 --- a/quickstart/14-create-pedestrians.py +++ b/quickstart/14-create-pedestrians.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -22,10 +22,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) - -sx = state.transform.position.x -sz = state.transform.position.z +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) input("Press Enter to start creating pedestrians") diff --git a/quickstart/15-pedestrian-walk-randomly.py b/quickstart/15-pedestrian-walk-randomly.py index 9b4e72b..19d9ce6 100755 --- a/quickstart/15-pedestrian-walk-randomly.py +++ b/quickstart/15-pedestrian-walk-randomly.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -8,7 +8,6 @@ import os import lgsvl import random -import time sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": @@ -20,14 +19,11 @@ forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) -sx = spawns[0].position.x -sz = spawns[0].position.z - state = lgsvl.AgentState() state.transform.position = spawns[0].position + 40 * forward state.transform.rotation = spawns[0].rotation -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) state = lgsvl.AgentState() # Spawn the pedestrian in front of car diff --git a/quickstart/16-pedestrian-follow-waypoints.py b/quickstart/16-pedestrian-follow-waypoints.py index 220f8c8..9367042 100755 --- a/quickstart/16-pedestrian-follow-waypoints.py +++ b/quickstart/16-pedestrian-follow-waypoints.py @@ -1,13 +1,12 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # import os import lgsvl -import random import time import math @@ -23,7 +22,7 @@ state = lgsvl.AgentState() state.transform = spawns[1] -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) # This will create waypoints in a circle for the pedestrian to follow radius = 4 @@ -34,7 +33,7 @@ z = radius * math.sin(i * 2 * math.pi / count) # idle is how much time the pedestrian will wait once it reaches the waypoint idle = 1 if i < count//2 else 0 - wp.append(lgsvl.WalkWaypoint(spawns[1].position + (8 + x) * right + z * forward, idle)) + wp.append(lgsvl.WalkWaypoint(spawns[1].position + x * right + (z + 8) * forward, idle)) state = lgsvl.AgentState() state.transform = spawns[1] diff --git a/quickstart/17-many-pedestrians-walking.py b/quickstart/17-many-pedestrians-walking.py index e924324..2c06bbb 100755 --- a/quickstart/17-many-pedestrians-walking.py +++ b/quickstart/17-many-pedestrians-walking.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -8,7 +8,6 @@ import os import lgsvl import random -import time sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": @@ -22,11 +21,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) - -sx = state.transform.position.x -sy = state.transform.position.y -sz = state.transform.position.z +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) names = ["Bob", "EntrepreneurFemale", "Howard", "Johny", "Pamela", "Presley", "Robin", "Stephen", "Zoe"] diff --git a/quickstart/18-weather-effects.py b/quickstart/18-weather-effects.py index 0b031eb..86c3ae0 100755 --- a/quickstart/18-weather-effects.py +++ b/quickstart/18-weather-effects.py @@ -1,14 +1,12 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # import os import lgsvl -import random -import time sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": @@ -20,7 +18,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) print(sim.weather) diff --git a/quickstart/19-time-of-day.py b/quickstart/19-time-of-day.py index a0597db..90f412f 100755 --- a/quickstart/19-time-of-day.py +++ b/quickstart/19-time-of-day.py @@ -1,13 +1,12 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # import os import lgsvl -import random import time sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) @@ -20,7 +19,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) print("Current time:", sim.time_of_day) diff --git a/quickstart/20-enable-sensors.py b/quickstart/20-enable-sensors.py index 6b9ae9c..31fb638 100755 --- a/quickstart/20-enable-sensors.py +++ b/quickstart/20-enable-sensors.py @@ -1,14 +1,12 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # import os import lgsvl -import random -import time sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": @@ -20,9 +18,9 @@ state = lgsvl.AgentState() state.transform = spawns[1] -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) -sensors = a.get_sensors() +sensors = ego.get_sensors() # Sensors have an enabled/disabled state that can be set # By default all sensors are enabled diff --git a/quickstart/21-map-coordinates.py b/quickstart/21-map-coordinates.py index e9a3cfe..e81afee 100755 --- a/quickstart/21-map-coordinates.py +++ b/quickstart/21-map-coordinates.py @@ -1,14 +1,12 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # import os import lgsvl -import random -import time sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": diff --git a/quickstart/22-connecting-bridge.py b/quickstart/22-connecting-bridge.py index d13afc3..bf1d085 100755 --- a/quickstart/22-connecting-bridge.py +++ b/quickstart/22-connecting-bridge.py @@ -1,13 +1,12 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # import os import lgsvl -import random import time sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) diff --git a/quickstart/23-npc-callbacks.py b/quickstart/23-npc-callbacks.py index 92ce5d3..b316f37 100755 --- a/quickstart/23-npc-callbacks.py +++ b/quickstart/23-npc-callbacks.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -22,7 +22,7 @@ state = lgsvl.AgentState() state.transform = sim.map_point_on_lane(spawns[0].position + 200 * forward) -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) mindist = 10.0 maxdist = 40.0 @@ -46,9 +46,9 @@ def on_lane_change(agent): state = lgsvl.AgentState() state.transform = sim.map_point_on_lane(point) - n = sim.add_agent(name, lgsvl.AgentType.NPC, state) - n.follow_closest_lane(True, 10) - n.on_lane_change(on_lane_change) - n.on_stop_line(on_stop_line) + npc = sim.add_agent(name, lgsvl.AgentType.NPC, state) + npc.follow_closest_lane(True, 10) + npc.on_lane_change(on_lane_change) + npc.on_stop_line(on_stop_line) sim.run() diff --git a/quickstart/24-ego-drive-straight-non-realtime.py b/quickstart/24-ego-drive-straight-non-realtime.py index 272fe39..b262bcd 100755 --- a/quickstart/24-ego-drive-straight-non-realtime.py +++ b/quickstart/24-ego-drive-straight-non-realtime.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -22,7 +22,7 @@ forward = lgsvl.utils.transform_to_forward(spawns[0]) # Agents can be spawned with a velocity. Default is to spawn with 0 velocity state.velocity = 20 * forward -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) print("Real time elapsed =", 0) print("Simulation time =", sim.current_time) diff --git a/quickstart/25-waypoint-flying-npc.py b/quickstart/25-waypoint-flying-npc.py index 8005e6d..5d61bb8 100755 --- a/quickstart/25-waypoint-flying-npc.py +++ b/quickstart/25-waypoint-flying-npc.py @@ -1,13 +1,12 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # import os import lgsvl -import math sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": @@ -18,15 +17,14 @@ spawns = sim.get_spawn() # EGO - state = lgsvl.AgentState() forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) up = lgsvl.utils.transform_to_up(spawns[0]) state.transform = spawns[0] -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) -# NPC, 10 meters ahead +# NPC state = lgsvl.AgentState() state.transform.position = spawns[0].position + 10 * forward state.transform.rotation = spawns[0].rotation @@ -36,8 +34,6 @@ # This block creates the list of waypoints that the NPC will follow # Each waypoint consists of a position vector, speed, and an angular orientation vector waypoints = [] -x_max = 2 -y_max = 2 z_delta = 12 layer_mask = 0 @@ -54,7 +50,7 @@ angle = lgsvl.Vector(i, 0, 3*i) # Raycast the points onto the ground because BorregasAve is not flat - hit = sim.raycast(spawns[0].position + px * right + pz * forward, lgsvl.Vector(0,-1,0), layer_mask) + hit = sim.raycast(spawns[0].position + px * right + pz * forward, lgsvl.Vector(0,-1,0), layer_mask) wp = lgsvl.DriveWaypoint(spawns[0].position + px * right + py * up + pz * forward, speed, angle, 0, 0) waypoints.append(wp) @@ -66,7 +62,7 @@ def on_waypoint(agent, index): # The above function needs to be added to the list of callbacks for the NPC npc.on_waypoint_reached(on_waypoint) -# The NPC needs to be given the list of waypoints. +# The NPC needs to be given the list of waypoints. # A bool can be passed as the 2nd argument that controls whether or not the NPC loops over the waypoints (default false) npc.follow(waypoints) diff --git a/quickstart/26-npc-trigger-waypoints.py b/quickstart/26-npc-trigger-waypoints.py index 410fd72..f3f291f 100755 --- a/quickstart/26-npc-trigger-waypoints.py +++ b/quickstart/26-npc-trigger-waypoints.py @@ -1,13 +1,12 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # import os import lgsvl -import math sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": @@ -18,21 +17,20 @@ spawns = sim.get_spawn() # EGO - state = lgsvl.AgentState() forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) state.transform = spawns[0] -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) -# NPC, 10 meters ahead +# NPC state = lgsvl.AgentState() state.transform.position = spawns[0].position + 10 * forward state.transform.rotation = spawns[0].rotation npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, state) vehicles = { - a: "EGO", + ego: "EGO", npc: "Sedan", } @@ -42,13 +40,12 @@ def on_collision(agent1, agent2, contact): name2 = vehicles[agent2] if agent2 is not None else "OBSTACLE" print("{} collided with {}".format(name1, name2)) -a.on_collision(on_collision) +ego.on_collision(on_collision) npc.on_collision(on_collision) # This block creates the list of waypoints that the NPC will follow # Each waypoint is an position vector paired with the speed that the NPC will drive to it waypoints = [] -x_max = 2 z_delta = 12 layer_mask = 0 @@ -61,7 +58,7 @@ def on_collision(agent1, agent2, contact): # Waypoint angles are input as Euler angles (roll, pitch, yaw) angle = spawns[0].rotation # Raycast the points onto the ground because BorregasAve is not flat - hit = sim.raycast(spawns[0].position + px * right + pz * forward, lgsvl.Vector(0,-1,0), layer_mask) + hit = sim.raycast(spawns[0].position + px * right + pz * forward, lgsvl.Vector(0,-1,0), layer_mask) # Trigger is set to 10 meters for every other waypoint (0 means no trigger) tr = 0 @@ -77,7 +74,7 @@ def on_waypoint(agent, index): # The above function needs to be added to the list of callbacks for the NPC npc.on_waypoint_reached(on_waypoint) -# The NPC needs to be given the list of waypoints. +# The NPC needs to be given the list of waypoints. # A bool can be passed as the 2nd argument that controls whether or not the NPC loops over the waypoints (default false) npc.follow(waypoints) diff --git a/quickstart/28-control-traffic-cone.py b/quickstart/28-control-traffic-cone.py index 485873d..c2e1ac2 100755 --- a/quickstart/28-control-traffic-cone.py +++ b/quickstart/28-control-traffic-cone.py @@ -40,10 +40,10 @@ # Set velocity and angular_velocity state.velocity = 10 * up state.angular_velocity = 6.5 * right - + # add controllable o = sim.controllable_add("TrafficCone", state) - + print("\nAdded {} Traffic Cones".format(i + 1)) diff --git a/quickstart/29-add-random-agents.py b/quickstart/29-add-random-agents.py index f0e0562..4c66cb5 100755 --- a/quickstart/29-add-random-agents.py +++ b/quickstart/29-add-random-agents.py @@ -18,14 +18,11 @@ forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) -sx = spawns[0].position.x -sz = spawns[0].position.z - state = lgsvl.AgentState() state.transform.position = spawns[0].position + 40 * forward state.transform.rotation = spawns[0].rotation -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) sim.add_random_agents(lgsvl.AgentType.NPC) sim.add_random_agents(lgsvl.AgentType.PEDESTRIAN) diff --git a/quickstart/30-time-to-collision-trigger.py b/quickstart/30-time-to-collision-trigger.py index 89cfea0..3cea290 100755 --- a/quickstart/30-time-to-collision-trigger.py +++ b/quickstart/30-time-to-collision-trigger.py @@ -23,11 +23,11 @@ forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) spawn_state = spawns[0] -hit = sim.raycast(spawn_state.position+forward*40, lgsvl.Vector(0,-1,0), layer_mask) +hit = sim.raycast(spawn_state.position+forward*40, lgsvl.Vector(0,-1,0), layer_mask) spawn_state.position = hit.point state.transform = spawn_state state.velocity = forward*2 -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() @@ -39,7 +39,7 @@ npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, state) vehicles = { - a: "EGO", + ego: "EGO", npc: "Sedan", } @@ -49,14 +49,12 @@ def on_collision(agent1, agent2, contact): name2 = vehicles[agent2] if agent2 is not None else "OBSTACLE" print("{} collided with {}".format(name1, name2)) -a.on_collision(on_collision) +ego.on_collision(on_collision) npc.on_collision(on_collision) # This block creates the list of waypoints that the NPC will follow # Each waypoint is an position vector paired with the speed that the NPC will drive to it waypoints = [] -x_max = 2 -z_delta = 12 for i in range(2): speed = 8 @@ -65,8 +63,8 @@ def on_collision(agent1, agent2, contact): # Raycast the points onto the ground because BorregasAve is not flat npc_position.x += 6 npc_position.z += 21 - hit = sim.raycast(npc_position, lgsvl.Vector(0,-1,0), layer_mask) - + hit = sim.raycast(npc_position, lgsvl.Vector(0,-1,0), layer_mask) + trigger = None if i == 0: effector = lgsvl.TriggerEffector("TimeToCollision", {}) @@ -76,6 +74,7 @@ def on_collision(agent1, agent2, contact): def on_waypoint(agent, index): print("waypoint {} reached".format(index)) + def agents_traversed_waypoints(): print("All agents traversed their waypoints.") sim.stop() @@ -84,7 +83,7 @@ def agents_traversed_waypoints(): npc.on_waypoint_reached(on_waypoint) sim.agents_traversed_waypoints(agents_traversed_waypoints) -# The NPC needs to be given the list of waypoints. +# The NPC needs to be given the list of waypoints. # A bool can be passed as the 2nd argument that controls whether or not the NPC loops over the waypoints (default false) npc.follow(waypoints) diff --git a/quickstart/31-wait-for-distance-trigger.py b/quickstart/31-wait-for-distance-trigger.py index 8181a18..3d86d3a 100755 --- a/quickstart/31-wait-for-distance-trigger.py +++ b/quickstart/31-wait-for-distance-trigger.py @@ -23,11 +23,11 @@ forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) spawn_state = spawns[0] -hit = sim.raycast(spawn_state.position+forward*40, lgsvl.Vector(0,-1,0), layer_mask) +hit = sim.raycast(spawn_state.position+forward*40, lgsvl.Vector(0,-1,0), layer_mask) spawn_state.position = hit.point state.transform = spawn_state state.velocity = forward*2 -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() @@ -39,7 +39,7 @@ npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, state) vehicles = { - a: "EGO", + ego: "EGO", npc: "Sedan", } @@ -49,14 +49,12 @@ def on_collision(agent1, agent2, contact): name2 = vehicles[agent2] if agent2 is not None else "OBSTACLE" print("{} collided with {}".format(name1, name2)) -a.on_collision(on_collision) +ego.on_collision(on_collision) npc.on_collision(on_collision) # This block creates the list of waypoints that the NPC will follow # Each waypoint is an position vector paired with the speed that the NPC will drive to it waypoints = [] -x_max = 2 -z_delta = 12 for i in range(2): speed = 8# if i % 2 == 0 else 12 @@ -77,6 +75,7 @@ def on_collision(agent1, agent2, contact): def on_waypoint(agent, index): print("waypoint {} reached".format(index)) + def agents_traversed_waypoints(): print("All agents traversed their waypoints.") sim.stop() @@ -85,7 +84,7 @@ def agents_traversed_waypoints(): npc.on_waypoint_reached(on_waypoint) sim.agents_traversed_waypoints(agents_traversed_waypoints) -# The NPC needs to be given the list of waypoints. +# The NPC needs to be given the list of waypoints. # A bool can be passed as the 2nd argument that controls whether or not the NPC loops over the waypoints (default false) npc.follow(waypoints) diff --git a/quickstart/98-npc-behaviour.py b/quickstart/98-npc-behaviour.py index d7983c0..4ba51c1 100755 --- a/quickstart/98-npc-behaviour.py +++ b/quickstart/98-npc-behaviour.py @@ -9,7 +9,6 @@ import lgsvl import math import random -import time sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) drunkDriverAvailable = False From fe6201ec0e6701d109630c9593049950c3c6cc37 Mon Sep 17 00:00:00 2001 From: "taehyung1.kim" Date: Tue, 1 Sep 2020 09:13:24 -0700 Subject: [PATCH 019/115] AUTO-4369: Updated coordinates after rotation --- tests/test_EGO.py | 10 +++++----- tests/test_NPC.py | 36 ++++++++++++++++++------------------ tests/test_peds.py | 4 ++-- tests/test_simulator.py | 10 +++++----- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/test_EGO.py b/tests/test_EGO.py index fbffbfb..392dfe9 100644 --- a/tests/test_EGO.py +++ b/tests/test_EGO.py @@ -34,7 +34,7 @@ def test_different_spawns(self): # Check if EGO is spawned in the spawn position cmEqual(self, agent2.state.rotation, spawns[1].rotation, "Spawn Rotation 1") def test_agent_velocity(self): # Check EGO velocity - with SimConnection() as sim: + with SimConnection(60) as sim: state = spawnState(sim) agent = self.create_EGO(sim) cmEqual(self, agent.state.velocity, state.velocity, "0 Velocity") @@ -47,7 +47,7 @@ def test_agent_velocity(self): # Check EGO velocity cmEqual(self, agent.state.velocity, state.velocity, "50 Velocity") def test_ego_different_directions(self): # Check that the xyz velocities equate to xyz changes in position - with SimConnection(40) as sim: + with SimConnection(60) as sim: state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) up = lgsvl.utils.transform_to_up(state.transform) @@ -87,7 +87,7 @@ def test_speed(self): # check that speed returns a reasonable number def test_rotation_on_highway_ramp(self): # Check that vehicle is rotated when spawned on the highway ramp with SimConnection() as sim: state = spawnState(sim) - state.transform.position = lgsvl.Vector(100.4229, 15.67488, -469.6401) + state.transform.position = lgsvl.Vector(469.6401, 15.67488, 100.4229) ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) self.assertAlmostEqual(ego.state.rotation.z, state.rotation.z) sim.run(0.5) @@ -204,7 +204,7 @@ def test_not_sticky_control(self): # Check that the a non sticky control is remo self.assertGreater(stickySpeed, finalSpeed) def test_vary_throttle(self): # Check that different throttle values accelerate differently - with SimConnection() as sim: + with SimConnection(40) as sim: ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.throttle = 0.5 @@ -221,7 +221,7 @@ def test_vary_throttle(self): # Check that different throttle values accelerate self.assertLess(ego.state.speed, initialSpeed) def test_vary_steering(self): # Check that different steering values turn the car differently - with SimConnection() as sim: + with SimConnection(40) as sim: ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.throttle = 0.5 diff --git a/tests/test_NPC.py b/tests/test_NPC.py index 0d45c67..6a07979 100644 --- a/tests/test_NPC.py +++ b/tests/test_NPC.py @@ -69,7 +69,7 @@ def test_NPC_follow_lane(self): #Check if NPC can follow lane agentState = agent.state self.assertGreater(agentState.speed, 0) # self.assertAlmostEqual(agent.state.speed, 5.6, delta=1) - self.assertLess(agent.state.position.x - sim.get_spawn()[0].position.x, 5.6) + self.assertLess(agent.state.position.x - sim.get_spawn()[0].position.x, 5.6*2) def test_rotate_NPC(self): # Check if NPC can be rotated with SimConnection() as sim: @@ -78,11 +78,11 @@ def test_rotate_NPC(self): # Check if NPC can be rotated state.transform.position = state.position - 5 * right sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) agent = self.create_NPC(sim, "SUV") - self.assertAlmostEqual(agent.state.transform.rotation.y, 194.823394, places=3) + self.assertAlmostEqual(agent.state.transform.rotation.y, 104.823394, places=3) x = agent.state - x.transform.rotation.y = 100 + x.transform.rotation.y = 10 agent.state = x - self.assertAlmostEqual(agent.state.transform.rotation.y, 100, delta=0.1) + self.assertAlmostEqual(agent.state.transform.rotation.y, 10, delta=0.1) def test_blank_agent(self): # Check that an exception is raised if a blank name is given with SimConnection() as sim: @@ -299,10 +299,10 @@ def test_spawn_speed(self): # Checks that a spawned agent keeps the correct spee def test_lane_change_right(self): with SimConnection(40) as sim: state = lgsvl.AgentState() - state.transform = sim.map_point_on_lane(lgsvl.Vector(40.85, -1.57, -4.49)) + state.transform = sim.map_point_on_lane(lgsvl.Vector(4.49, -1.57, 40.85)) npc = sim.add_agent("SUV", lgsvl.AgentType.NPC, state) - state.transform = sim.map_point_on_lane(lgsvl.Vector(42.73, -1.57, -0.63)) + state.transform = sim.map_point_on_lane(lgsvl.Vector(0.63, -1.57, 42.73)) sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(state.transform) target = state.position + 31 * forward @@ -324,12 +324,12 @@ def on_lane_change(agent): def test_lane_change_right_missing_lane(self): with SimConnection(40) as sim: state = lgsvl.AgentState() - state.transform = sim.map_point_on_lane(lgsvl.Vector(42.73, -1.57, -0.63)) + state.transform = sim.map_point_on_lane(lgsvl.Vector(0.63, -1.57, 42.73)) npc = sim.add_agent("Hatchback", lgsvl.AgentType.NPC, state) forward = lgsvl.utils.transform_to_forward(state.transform) target = state.position + 42.75 * forward - state.transform = sim.map_point_on_lane(lgsvl.Vector(40.85, -1.57, -4.49)) + state.transform = sim.map_point_on_lane(lgsvl.Vector(4.49, -1.57, 40.85)) sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) npc.follow_closest_lane(True, 10) @@ -349,10 +349,10 @@ def on_lane_change(agent): def test_lane_change_left(self): with SimConnection(40) as sim: state = lgsvl.AgentState() - state.transform = sim.map_point_on_lane(lgsvl.Vector(40.85, -1.57, -4.49)) + state.transform = sim.map_point_on_lane(lgsvl.Vector(4.49, -1.57, 40.85)) npc = sim.add_agent("SUV", lgsvl.AgentType.NPC, state) - state.transform = sim.map_point_on_lane(lgsvl.Vector(42.02, -1.79, -9.82)) + state.transform = sim.map_point_on_lane(lgsvl.Vector(9.82, -1.79, 42.02)) sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(state.transform) target = state.position + 31 * forward @@ -374,7 +374,7 @@ def on_lane_change(agent): def test_lane_change_left_opposing_traffic(self): with SimConnection(40) as sim: state = lgsvl.AgentState() - state.transform = sim.map_point_on_lane(lgsvl.Vector(-40.292, -3.363, -78.962)) + state.transform = sim.map_point_on_lane(lgsvl.Vector(78.962, -3.363, -40.292)) npc = sim.add_agent("SUV", lgsvl.AgentType.NPC, state) forward = lgsvl.utils.transform_to_forward(state.transform) target = state.position + 42.75 * forward @@ -400,13 +400,13 @@ def on_lane_change(agent): def test_multiple_lane_changes(self): with SimConnection(120) as sim: state = lgsvl.AgentState() - state.transform.position = lgsvl.Vector(239,10,180) - state.transform.rotation = lgsvl.Vector(0,180,0) + state.transform.position = lgsvl.Vector(-180,10,239) + state.transform.rotation = lgsvl.Vector(0,90,0) sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, state) state = lgsvl.AgentState() - state.transform.position = lgsvl.Vector(234.5, 10, 175) - state.transform.rotation = lgsvl.Vector(0.016, 180, 0) + state.transform.position = lgsvl.Vector(-175, 10, 234.5) + state.transform.rotation = lgsvl.Vector(0, 90, 0.016) npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, state) npc.follow_closest_lane(True, 10) @@ -455,9 +455,9 @@ def test_npc_control_exceptions(self): npc.apply_control(control) def test_e_stop(self): - with SimConnection() as sim: + with SimConnection(60) as sim: state = lgsvl.AgentState() - state.transform = sim.map_point_on_lane(lgsvl.Vector(-40.292, -3.363, -78.962)) + state.transform = sim.map_point_on_lane(lgsvl.Vector(78.962, -3.363, -40.292)) sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(state.transform) state.transform.position = state.position + 10 * forward @@ -478,7 +478,7 @@ def test_e_stop(self): def test_waypoint_speed(self): with SimConnection(60) as sim: state = lgsvl.AgentState() - state.transform = sim.map_point_on_lane(lgsvl.Vector(-40.292, -3.363, -78.962)) + state.transform = sim.map_point_on_lane(lgsvl.Vector(78.962, -3.363, -40.292)) sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(state.transform) up = lgsvl.utils.transform_to_up(state.transform) diff --git a/tests/test_peds.py b/tests/test_peds.py index 69b11e4..ed77ce9 100644 --- a/tests/test_peds.py +++ b/tests/test_peds.py @@ -19,13 +19,13 @@ def test_ped_creation(self): # Check if the different types of Peds can be creat state.transform.position = state.position - 4 * forward sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) for name in ["Bob", "EntrepreneurFemale", "Howard", "Johny", \ - "Pamela", "Presley", "Red", "Robin", "Stephen", "Zoe"]: + "Pamela", "Presley", "Robin", "Stephen", "Zoe"]: agent = self.create_ped(sim, name, spawnState(sim)) cmEqual(self, agent.state.position, sim.get_spawn()[0].position, name) self.assertEqual(agent.name, name) def test_ped_random_walk(self): # Check if pedestrians can walk randomly - with SimConnection() as sim: + with SimConnection(40) as sim: state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) state.transform.position = state.position - 4 * forward diff --git a/tests/test_simulator.py b/tests/test_simulator.py index da65a9c..40bd9e5 100644 --- a/tests/test_simulator.py +++ b/tests/test_simulator.py @@ -74,12 +74,12 @@ def test_raycast(self): # Check if raycasting works # Right hit = sim.raycast(p, right, layer_mask) self.assertTrue(hit) - self.assertAlmostEqual(hit.distance, 15.0892992019653) + self.assertAlmostEqual(hit.distance, 15.089282989502, places=3) #Left hit = sim.raycast(p, -right, layer_mask) self.assertTrue(hit) - self.assertAlmostEqual(hit.distance, 19.72922706604) + self.assertAlmostEqual(hit.distance, 19.7292556762695, places=3) #Back hit = sim.raycast(p, -forward, layer_mask) @@ -96,7 +96,7 @@ def test_raycast(self): # Check if raycasting works # Down hit = sim.raycast(p, -up, layer_mask) self.assertTrue(hit) - self.assertAlmostEqual(hit.distance, 1.08376359939575) + self.assertAlmostEqual(hit.distance, 1.0837641954422, places=3) def test_weather(self): # Check that the weather state can be read properly and changed with SimConnection() as sim: @@ -217,7 +217,7 @@ def test_get_gps(self): # Checks that GPS reports the correct values self.assertAlmostEqual(gps.northing, 4141627.34000015) self.assertAlmostEqual(gps.easting, 587060.970000267) self.assertAlmostEqual(gps.altitude, -1.03600001335144) - self.assertAlmostEqual(gps.orientation, -194.823394775391) + self.assertAlmostEqual(gps.orientation, -104.823394775391) def test_from_northing(self): # Check that position vectors are correctly generated given northing and easting with SimConnection() as sim: @@ -236,7 +236,7 @@ def test_from_latlong(self): # Check that position vectors are correctly generat def test_from_alt_orient(self): # Check that position vectors are correctly generated with altitude and orientation with SimConnection() as sim: spawn = sim.get_spawn()[0] - location = sim.map_from_gps(northing=4141627.34000015, easting=587060.970000267, altitude=-1.03600001335144, orientation=-194.823394775391) + location = sim.map_from_gps(northing=4141627.34000015, easting=587060.970000267, altitude=-1.03600001335144, orientation=-104.823371887207) self.assertAlmostEqual(spawn.position.y, location.position.y, places=1) self.assertAlmostEqual(spawn.rotation.y, location.rotation.y, places=1) From 186a2bf7b6c8b3c380209561e78222d481f0f465 Mon Sep 17 00:00:00 2001 From: Hadi Tabatabaee Date: Fri, 4 Sep 2020 13:00:29 -0700 Subject: [PATCH 020/115] Update gitignore to ignore test coverage report --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 69516f1..1abbf76 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ **/__pycache__ *.egg-info +.coverage +htmlcov From e84983cf25cdca81ace2d14050515f55d44ee36d Mon Sep 17 00:00:00 2001 From: "hadi.tabatabaee" Date: Tue, 8 Sep 2020 17:35:58 -0700 Subject: [PATCH 021/115] Cleanup repository --- .flake8 | 11 + LICENSE | 32 +- README.md | 14 +- .../EOV_S_25_20.py | 15 +- .../EOV_S_45_40.py | 15 +- .../EOV_S_65_60.py | 15 +- .../evaluator/utils.py | 7 +- .../Vehicle-Following/VF_S_25_Slow.py | 23 +- .../Vehicle-Following/VF_S_45_Slow.py | 23 +- .../Vehicle-Following/VF_S_65_Slow.py | 23 +- .../Vehicle-Following/evaluator/utils.py | 7 +- examples/kitti_parser.py | 2 +- lgsvl/__init__.py | 17 +- lgsvl/agent.py | 680 ++++++++++-------- lgsvl/controllable.py | 107 +-- lgsvl/geometry.py | 171 ++--- lgsvl/remote.py | 99 +-- lgsvl/sensor.py | 229 +++--- lgsvl/simulator.py | 546 +++++++------- lgsvl/utils.py | 244 ++++--- quickstart/02-loading-scene-show-spawns.py | 8 +- quickstart/03-raycast.py | 20 +- quickstart/04-ego-drive-straight.py | 8 +- quickstart/05-ego-drive-in-circle.py | 6 +- quickstart/06-save-camera-image.py | 14 +- quickstart/07-save-lidar-point-cloud.py | 10 +- quickstart/08-create-npc.py | 14 +- quickstart/09-reset-scene.py | 15 +- quickstart/10-npc-follow-the-lane.py | 6 +- quickstart/11-collision-callbacks.py | 20 +- quickstart/12-create-npc-on-lane.py | 22 +- quickstart/13-npc-follow-waypoints.py | 47 +- quickstart/14-create-pedestrians.py | 38 +- quickstart/15-pedestrian-walk-randomly.py | 5 +- quickstart/16-pedestrian-follow-waypoints.py | 21 +- quickstart/17-many-pedestrians-walking.py | 60 +- quickstart/18-weather-effects.py | 6 +- quickstart/19-time-of-day.py | 5 +- quickstart/20-enable-sensors.py | 12 +- quickstart/21-map-coordinates.py | 13 +- quickstart/22-connecting-bridge.py | 6 +- quickstart/23-npc-callbacks.py | 37 +- .../24-ego-drive-straight-non-realtime.py | 8 +- quickstart/25-waypoint-flying-npc.py | 35 +- quickstart/26-npc-trigger-waypoints.py | 56 +- quickstart/27-control-traffic-lights.py | 8 +- quickstart/28-control-traffic-cone.py | 36 +- quickstart/29-add-random-agents.py | 4 +- quickstart/30-time-to-collision-trigger.py | 74 +- quickstart/31-wait-for-distance-trigger.py | 76 +- quickstart/32-pedestrian-time-to-collision.py | 29 +- quickstart/98-npc-behaviour.py | 72 +- quickstart/99-utils-examples.py | 9 +- tests/__init__.py | 1 + tests/common.py | 93 +-- tests/test_EGO.py | 51 +- tests/test_NPC.py | 62 +- tests/test_collisions.py | 31 +- tests/test_manual_features.py | 6 +- tests/test_peds.py | 15 +- tests/test_sensors.py | 36 +- tests/test_simulator.py | 90 +-- tests/test_utils.py | 61 +- 63 files changed, 1888 insertions(+), 1638 deletions(-) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..845f6ca --- /dev/null +++ b/.flake8 @@ -0,0 +1,11 @@ +[flake8] +max-line-length = 130 +max-complexity = 23 + +ignore = E701, E501, W503 +exclude = + tests/* + examples/* + +per-file-ignores = + lgsvl/__init__.py:F401 diff --git a/LICENSE b/LICENSE index 70a77ed..0c01b02 100644 --- a/LICENSE +++ b/LICENSE @@ -2,14 +2,14 @@ SIMULATOR SOFTWARE LICENSE AGREEMENT DO NOT DOWNLOAD, INSTALL ACCESS, COPY, OR USE ANY PORTION OF THE LICENSED MATERIALS (DEFINED BELOW) UNTIL YOU HAVE READ AND ACCEPTED THE TERMS OF THIS AGREEMENT. BY INSTALLING, COPYING, ACCESSING, OR USING THE LICENSED MATERIALS, YOU ACCEPT AND AGREE TO BE LEGALLY BOUND BY THE TERMS AND CONDITIONS OF THIS AGREEMENT. If You do not agree to be bound by, or the entity for whose benefit You act has not authorized You to accept these terms and conditions, do not install, access, copy, or use the LG Simulator Software and destroy all copies in your possession. -This Software License Agreement (“Agreement”), effective upon your acceptance of this Agreement (“Effective Date”), is between Zenith Electronics, LLC with offices located at 5150 Great America Parkway, Santa Clara, CA 95054 (“LG”) and "You." “You” or “Your” refers to you or your employer or other entity for whose benefit you act, as applicable. +This Software License Agreement (“Agreement”), effective upon your acceptance of this Agreement (“Effective Date”), is between Zenith Electronics, LLC with offices located at 5150 Great America Parkway, Santa Clara, CA 95054 (“LG”) and "You." “You” or “Your” refers to you or your employer or other entity for whose benefit you act, as applicable. -1 PURPOSE; LICENSE GRANT AND RESTRICTIONS. +1 PURPOSE; LICENSE GRANT AND RESTRICTIONS. -1.1 Purpose. This Agreement governs the use of the LG Simulator Software and any accompanying documentation, code, content owned or provided by LG (“LG Content”) and related materials (collectively, the “Licensed Material”) described in more detail in Exhibit A, made available to You by LG. +1.1 Purpose. This Agreement governs the use of the LG Simulator Software and any accompanying documentation, code, content owned or provided by LG (“LG Content”) and related materials (collectively, the “Licensed Material”) described in more detail in Exhibit A, made available to You by LG. -1.2 License Grant. Subject to the terms and conditions of this Agreement, LG grants You a nonexclusive, sublicensable as permitted herein, royalty-free, worldwide, perpetual, irrevocable license for software development and related purposes (the “Purpose”). Any permitted sublicense must be on the same terms and conditions as contained herein. +1.2 License Grant. Subject to the terms and conditions of this Agreement, LG grants You a nonexclusive, sublicensable as permitted herein, royalty-free, worldwide, perpetual, irrevocable license for software development and related purposes (the “Purpose”). Any permitted sublicense must be on the same terms and conditions as contained herein. 1.3 Restrictions. You may not: (a) reverse engineer, decompile, or disassemble the executable or binary builds of Licensed Material, or otherwise attempt to defeat, avoid, by-pass, remove, deactivate or otherwise circumvent any software protection mechanisms in or included with the binary builds of Licensed Material including, without limitation, any such mechanism used to restrict or control the functionality of the binary builds of Licensed Material; (b) use or reproduce the Licensed Material for any reason other than the Purpose; (c) sell or otherwise transfer or make available the Licensed Material, any copies of the Licensed Material, or any information derived from the Licensed Material in any form to any third parties for commercial purposes; or (d) remove or alter any proprietary notices or marks on the Licensed Material. @@ -19,48 +19,48 @@ This Software License Agreement (“Agreement”), effective upon your acceptanc 2 UPDATES. -You acknowledge that LG may update or modify the Licensed Material from time to time and that such updates and modifications may adversely affect the manner in which You access or communicate with the Licensed Material. +You acknowledge that LG may update or modify the Licensed Material from time to time and that such updates and modifications may adversely affect the manner in which You access or communicate with the Licensed Material. -3 TERM; TERMINATION. +3 TERM; TERMINATION. -3.1 Term. This Agreement will be effective as of the Effective Date and will remain effective until terminated as set forth below in Section 3.2. +3.1 Term. This Agreement will be effective as of the Effective Date and will remain effective until terminated as set forth below in Section 3.2. -3.2 Termination. This Agreement will be terminated immediately by LG at any time, by providing written notice to You (such notice may be via email) upon breach of any term or condition of this Agreement. Upon termination, You and any sublicensees will cease access to the Licensed Material, and destroy all copies of the Licensed Material (including all derivatives thereof) You have obtained or created. Sections 4-8 will survive the termination of this Agreement. +3.2 Termination. This Agreement will be terminated immediately by LG at any time, by providing written notice to You (such notice may be via email) upon breach of any term or condition of this Agreement. Upon termination, You and any sublicensees will cease access to the Licensed Material, and destroy all copies of the Licensed Material (including all derivatives thereof) You have obtained or created. Sections 4-8 will survive the termination of this Agreement. -4 OWNERSHIP; FEEDBACK. +4 OWNERSHIP; FEEDBACK. 4.1 Ownership. As between You and LG, LG owns all right, title and interest in and to the Licensed Material (and any LG modifications or enhancements thereof), including but not limited to all intellectual property rights therein. Any rights not expressly granted herein are withheld. As between You and LG, You (or the third party content provider) own all right, title and interest in and to the Simulator Content. Simulator Content includes but is not limited to vehicle models, high definition maps, sensor parameters, and 3D environments. Simulator Content does not include LG Content. -4.2 Feedback. You agree to provide LG with comments concerning the Licensed Material and Your evaluation and use thereof, including bug reports, evaluations, proposed product integrations (and associated metrics and learned knowledge) (“Feedback”). You agree that LG and its designees will be free to copy, modify, create derivative works, publicly display, disclose, distribute, license and sublicense, incorporate and otherwise use the Feedback, including derivative works thereto, for any and all commercial and non-commercial purposes with no obligation of any kind to You. +4.2 Feedback. You agree to provide LG with comments concerning the Licensed Material and Your evaluation and use thereof, including bug reports, evaluations, proposed product integrations (and associated metrics and learned knowledge) (“Feedback”). You agree that LG and its designees will be free to copy, modify, create derivative works, publicly display, disclose, distribute, license and sublicense, incorporate and otherwise use the Feedback, including derivative works thereto, for any and all commercial and non-commercial purposes with no obligation of any kind to You. 4.3 Open Source. You hereby acknowledge that the Licensed Materials may contain Open Source Software. “Open Source Software” means any software or software component, module or package that contains, or is derived in any manner (in whole or in part) from, any software that is distributed as free software, open source software or similar licensing or distribution models. To the extent any such license requires that LG provide You the rights to copy, modify, distribute or otherwise use any Open Source Software that are inconsistent with the limited rights granted to You in this Agreement, then such rights in the applicable Open Source Software license shall take precedence over the rights and restrictions granted in this Agreement, but solely with respect to such Open Source Software. You agree to review any documentation that accompanies the Licensed Materials or is identified in a link provided in the documentation for the Licensed Materials in order to determine which portions of the Licensed Materials are Open Source Software and are licensed under an Open Source Software license. You acknowledge that the Open Source Software license is solely between You and the applicable licensor of the Open Source Software. You shall comply with the terms of all applicable Open Source Software licenses, if any. -5 REPRESENTATIONS AND WARRANTIES; DISCLAIMER. +5 REPRESENTATIONS AND WARRANTIES; DISCLAIMER. 5.1 Representations and Warranties. You represent and warrant that: (a) the performance of Your obligations will not constitute a breach or otherwise violate any other agreement or the rights of any third party arising therefrom; and (b) You will maintain throughout the Term all rights and licenses that are required with respect to use of the Licensed Material, and Your use does and will continue to comply with all applicable foreign, federal, state, and local laws, rules and regulations. -5.2 Disclaimer. THE LICENSED MATERIAL AND ANY OTHER LG PRODUCTS AND SERVICES PROVIDED HEREUNDER ARE PROVIDED “AS IS” AND WITHOUT WARRANTY OF ANY KIND. LG DISCLAIMS ALL WARRANTIES, WHETHER EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, AND ANY WARRANTIES OR CONDITIONS ARISING OUT OF COURSE OF DEALING OR USAGE OF TRADE. LG DOES NOT WARRANT THAT THE LICENSED MATERIAL AND ANY OTHER LG PRODUCTS AND SERVICES PROVIDED HEREUNDER WILL MEET ALL OF YOUR REQUIREMENTS OR EXPECTATIONS, OR THAT USE OF SUCH LICENSED MATERIAL BE ERROR-FREE, UNINTERRUPTED, VIRUS-FREE, OR SECURE. +5.2 Disclaimer. THE LICENSED MATERIAL AND ANY OTHER LG PRODUCTS AND SERVICES PROVIDED HEREUNDER ARE PROVIDED “AS IS” AND WITHOUT WARRANTY OF ANY KIND. LG DISCLAIMS ALL WARRANTIES, WHETHER EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, AND ANY WARRANTIES OR CONDITIONS ARISING OUT OF COURSE OF DEALING OR USAGE OF TRADE. LG DOES NOT WARRANT THAT THE LICENSED MATERIAL AND ANY OTHER LG PRODUCTS AND SERVICES PROVIDED HEREUNDER WILL MEET ALL OF YOUR REQUIREMENTS OR EXPECTATIONS, OR THAT USE OF SUCH LICENSED MATERIAL BE ERROR-FREE, UNINTERRUPTED, VIRUS-FREE, OR SECURE. -6 LIMITATION OF LIABILITY. +6 LIMITATION OF LIABILITY. IN NO EVENT SHALL LG BE LIABLE TO YOU OR YOUR SUBLICENSEES FOR ANY SPECIAL, INCIDENTAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES (INCLUDING LOSS OF USE, DATA, BUSINESS OR PROFITS) ARISING OUT OF OR IN CONNECTION WITH THIS AGREEMENT, WHETHER SUCH LIABILITY ARISES FROM ANY CLAIM BASED UPON CONTRACT, WARRANTY, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, AND WHETHER OR NOT LG HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE. THE FOREGOING LIMITATIONS WILL SURVIVE AND APPLY EVEN IF ANY LIMITED REMEDY SPECIFIED IN THIS AGREEMENT IS FOUND TO HAVE FAILED OF ITS ESSENTIAL PURPOSE. IN ANY CASE, LG’S AGGREGATE LIABILITY UNDER THIS AGREEMENT WILL NOT EXCEED THE FEE, IF ANY, THAT YOU PAID LG FOR USE OF THE LICENSED MATERIAL. -7 INDEMNIFICATION. +7 INDEMNIFICATION. You will indemnify, defend, or at its option settle and hold LG, its subsidiaries, affiliates, officers and employees, harmless from any and all claims, damages, losses, liabilities, actions, judgments, costs and expenses (including reasonable attorneys’ fees) brought by a third party arising out of or in connection with: (a) any intentionally tortious or negligent act or omission by You in connection with Your use of the Licensed Material; (b) Your use of the Licensed Material other than as expressly allowed by this Agreement; (c) any claims that Derivatives or Simulator Content have infringed third party intellectual property rights; or (d) Your breach or alleged breach of any of the terms, restrictions, obligations or representations under this Agreement. -8 MISCELLANEOUS. +8 MISCELLANEOUS. This Agreement constitutes the entire agreement among the parties with respect to the subject matter and supersedes and merges all prior proposals, understandings and contemporaneous communications. Any modification to this Agreement must be in a writing duly authorized by LG or pursuant to Section 2 (Updates). You may not assign any of the rights or obligations granted hereunder, voluntarily or by operation of law (including without limitation in connection with a merger, acquisition, or sale of assets) except with the express written consent of LG, and any attempted assignment in violation of this paragraph is void. This Agreement does not create or imply any partnership, agency or joint venture. This Agreement will be governed by and construed in accordance with the laws of the State of California, without regard to or application of conflicts of law rules or principles. Any controversy arising out of this Agreement shall be heard exclusively in the federal or state courts located in Santa Clara County, CA and You agree to submit to jurisdiction thereof. No waiver by LG of any covenant or right under this Agreement will be effective unless memorialized in a writing duly authorized by LG. If any part of this Agreement is determined to be invalid or unenforceable by a court of competent jurisdiction, that provision will be enforced to the maximum extent permissible and the remaining provisions of this Agreement will remain in full force and effect. - + EXHIBIT A Licensed Material: diff --git a/README.md b/README.md index 5acd0c9..a808229 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Documentation is available on our website: https://www.lgsvlsimulator.com/docs/p # Installing pip3 install --user . - + # install in development mode pip3 install --user -e . @@ -29,10 +29,10 @@ Documentation is available on our website: https://www.lgsvlsimulator.com/docs/p # run all unittests python3 -m unittest discover -v -c - + # run single test module python3 -m unittest -v -c tests/test_XXXX.py - + # run individual test case python3 -m unittest -v tests.test_XXX.TestCaseXXX.test_XXX python3 -m unittest -v tests.test_Simulator.TestSimulator.test_unload_scene @@ -41,17 +41,17 @@ Documentation is available on our website: https://www.lgsvlsimulator.com/docs/p # (one time only) install coverage.py pip3 install --user coverage - + # run all tests with coverage ~/.local/bin/coverage run -m unittest discover - + # generate html report ~/.local/bin/coverage html --omit "~/.local/*","tests/*" - + # output is in htmlcov/index.html # Copyright and License -Copyright (c) 2018-2019 LG Electronics, Inc. +Copyright (c) 2018-2020 LG Electronics, Inc. This software contains code licensed as described in LICENSE. diff --git a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py index f6e8963..34452eb 100755 --- a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py +++ b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -9,18 +9,17 @@ import os import lgsvl -import sys import time import evaluator -MAX_EGO_SPEED = 11.111 # (40 km/h, 25 mph) -MAX_POV_SPEED = 8.889 # (32 km/h, 20 mph) -INITIAL_HEADWAY = 100 # spec says >30m +MAX_EGO_SPEED = 11.111 # (40 km/h, 25 mph) +MAX_POV_SPEED = 8.889 # (32 km/h, 20 mph) +INITIAL_HEADWAY = 100 # spec says >30m SPEED_VARIANCE = 4 TIME_LIMIT = 30 TIME_DELAY = 3 -print("EOV_S_25_20 - ", end = '') +print("EOV_S_25_20 - ", end='') sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "SingleLaneRoad": @@ -46,9 +45,11 @@ POVWaypoints = [] POVWaypoints.append(lgsvl.DriveWaypoint(finalPOVWaypointPosition, MAX_POV_SPEED)) + def on_collision(agent1, agent2, contact): raise evaluator.TestException("Ego collided with {}".format(agent2)) + ego.on_collision(on_collision) POV.on_collision(on_collision) @@ -74,4 +75,4 @@ def on_collision(agent1, agent2, contact): print("FAILED: " + repr(e)) exit() -print("PASSED") \ No newline at end of file +print("PASSED") diff --git a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py index cfd8afb..b8708a0 100755 --- a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py +++ b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -9,18 +9,17 @@ import os import lgsvl -import sys import time import evaluator -MAX_EGO_SPEED = 20 # (72 km/h, 45 mph) -MAX_POV_SPEED = 17.778 # (64 km/h, 40 mph) -INITIAL_HEADWAY = 150 # spec says >68m +MAX_EGO_SPEED = 20 # (72 km/h, 45 mph) +MAX_POV_SPEED = 17.778 # (64 km/h, 40 mph) +INITIAL_HEADWAY = 150 # spec says >68m SPEED_VARIANCE = 4 TIME_LIMIT = 30 TIME_DELAY = 4 -print("EOV_S_45_40 - ", end = '') +print("EOV_S_45_40 - ", end='') sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "SingleLaneRoad": @@ -46,9 +45,11 @@ POVWaypoints = [] POVWaypoints.append(lgsvl.DriveWaypoint(finalPOVWaypointPosition, MAX_POV_SPEED)) + def on_collision(agent1, agent2, contact): raise evaluator.TestException("Ego collided with {}".format(agent2)) + ego.on_collision(on_collision) POV.on_collision(on_collision) @@ -74,4 +75,4 @@ def on_collision(agent1, agent2, contact): print("FAILED: " + repr(e)) exit() -print("PASSED") \ No newline at end of file +print("PASSED") diff --git a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py index faec563..2c64aa9 100755 --- a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py +++ b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -9,18 +9,17 @@ import os import lgsvl -import sys import time import evaluator -MAX_EGO_SPEED = 29.167 # (105 km/h, 65 mph) -MAX_POV_SPEED = 26.667 # (96 km/h, 60 mph) -INITIAL_HEADWAY = 200 # spec says >105m +MAX_EGO_SPEED = 29.167 # (105 km/h, 65 mph) +MAX_POV_SPEED = 26.667 # (96 km/h, 60 mph) +INITIAL_HEADWAY = 200 # spec says >105m SPEED_VARIANCE = 4 TIME_LIMIT = 30 TIME_DELAY = 5 -print("EOV_S_65_60 - ", end = '') +print("EOV_S_65_60 - ", end='') sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "SingleLaneRoad": @@ -46,9 +45,11 @@ POVWaypoints = [] POVWaypoints.append(lgsvl.DriveWaypoint(finalPOVWaypointPosition, MAX_POV_SPEED)) + def on_collision(agent1, agent2, contact): raise evaluator.TestException("Ego collided with {}".format(agent2)) + ego.on_collision(on_collision) POV.on_collision(on_collision) @@ -74,4 +75,4 @@ def on_collision(agent1, agent2, contact): print("FAILED: " + repr(e)) exit() -print("PASSED") \ No newline at end of file +print("PASSED") diff --git a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/evaluator/utils.py b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/evaluator/utils.py index ccc6669..e60df8d 100644 --- a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/evaluator/utils.py +++ b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/evaluator/utils.py @@ -1,17 +1,18 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # -import lgsvl import math + class TestException(Exception): pass + def separation(V1, V2): xdiff = V1.x - V2.x ydiff = V1.y - V2.y zdiff = V1.z - V2.z - return math.sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff) \ No newline at end of file + return math.sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff) diff --git a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_25_Slow.py b/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_25_Slow.py index 61995df..50a5b8b 100755 --- a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_25_Slow.py +++ b/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_25_Slow.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -9,19 +9,18 @@ import os import lgsvl -import sys import time import evaluator -MAX_EGO_SPEED = 11.18 # (40 km/h, 25 mph) -SPEED_VARIANCE = 10 # Simple Physics does not return an accurate value -MAX_POV_SPEED = 8.94 # (32 km/h, 20 mph) -MAX_POV_ROTATION = 5 #deg/s -TIME_LIMIT = 30 # seconds +MAX_EGO_SPEED = 11.18 # (40 km/h, 25 mph) +SPEED_VARIANCE = 10 # Simple Physics does not return an accurate value +MAX_POV_SPEED = 8.94 # (32 km/h, 20 mph) +MAX_POV_ROTATION = 5 # deg/s +TIME_LIMIT = 30 # seconds TIME_DELAY = 3 -MAX_FOLLOWING_DISTANCE = 50 # Apollo 3.5 is very cautious +MAX_FOLLOWING_DISTANCE = 50 # Apollo 3.5 is very cautious -print("VF_S_25_Slow - ", end = '') +print("VF_S_25_Slow - ", end='') sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "SingleLaneRoad": @@ -44,15 +43,17 @@ POVState.transform = sim.map_point_on_lane(lgsvl.Vector(egoX, egoY, egoZ + 30)) POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) + def on_collision(agent1, agent2, contact): raise evaluator.TestException("Ego collided with {}".format(agent2)) + ego.on_collision(on_collision) POV.on_collision(on_collision) try: t0 = time.time() - sim.run(TIME_DELAY) # The EGO should start moving first + sim.run(TIME_DELAY) # The EGO should start moving first POV.follow_closest_lane(True, MAX_POV_SPEED, False) while True: @@ -81,4 +82,4 @@ def on_collision(agent1, agent2, contact): if separation > MAX_FOLLOWING_DISTANCE: print("FAILED: EGO following distance was not maintained, {} > {}".format(separation, MAX_FOLLOWING_DISTANCE)) else: - print("PASSED") \ No newline at end of file + print("PASSED") diff --git a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_45_Slow.py b/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_45_Slow.py index c6f171c..1b5e5fe 100755 --- a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_45_Slow.py +++ b/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_45_Slow.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -9,19 +9,18 @@ import os import lgsvl -import sys import time import evaluator -MAX_EGO_SPEED = 20.12 # (72 km/h, 45 mph) -SPEED_VARIANCE = 10 # Simple Physics does not return an accurate value -MAX_POV_SPEED = 17.88 # (64 km/h, 40 mph) -MAX_POV_ROTATION = 5 #deg/s -TIME_LIMIT = 25 # seconds +MAX_EGO_SPEED = 20.12 # (72 km/h, 45 mph) +SPEED_VARIANCE = 10 # Simple Physics does not return an accurate value +MAX_POV_SPEED = 17.88 # (64 km/h, 40 mph) +MAX_POV_ROTATION = 5 # deg/s +TIME_LIMIT = 25 # seconds TIME_DELAY = 7 -MAX_FOLLOWING_DISTANCE = 100 # Apollo 3.5 is very cautious +MAX_FOLLOWING_DISTANCE = 100 # Apollo 3.5 is very cautious -print("VF_S_45_Slow - ", end = '') +print("VF_S_45_Slow - ", end='') sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "SingleLaneRoad": @@ -43,15 +42,17 @@ POVState.transform = sim.map_point_on_lane(lgsvl.Vector(egoX, egoY, egoZ + 68)) POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) + def on_collision(agent1, agent2, contact): raise evaluator.TestException("Ego collided with {}".format(agent2)) + ego.on_collision(on_collision) POV.on_collision(on_collision) try: t0 = time.time() - sim.run(TIME_DELAY) # The EGO should start moving first + sim.run(TIME_DELAY) # The EGO should start moving first POV.follow_closest_lane(True, MAX_POV_SPEED, False) while True: @@ -80,4 +81,4 @@ def on_collision(agent1, agent2, contact): if separation > MAX_FOLLOWING_DISTANCE: print("FAILED: EGO following distance was not maintained, {} > {}".format(separation, MAX_FOLLOWING_DISTANCE)) else: - print("PASSED") \ No newline at end of file + print("PASSED") diff --git a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_65_Slow.py b/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_65_Slow.py index 5442225..26dfd34 100755 --- a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_65_Slow.py +++ b/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_65_Slow.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -9,19 +9,18 @@ import os import lgsvl -import sys import time import evaluator -MAX_EGO_SPEED = 29.06 # (105 km/h, 65 mph) -SPEED_VARIANCE = 10 # Simple Physics does not return an accurate value -MAX_POV_SPEED = 26.82 # (96 km/h, 60 mph) -MAX_POV_ROTATION = 5 #deg/s -TIME_LIMIT = 45 # seconds +MAX_EGO_SPEED = 29.06 # (105 km/h, 65 mph) +SPEED_VARIANCE = 10 # Simple Physics does not return an accurate value +MAX_POV_SPEED = 26.82 # (96 km/h, 60 mph) +MAX_POV_ROTATION = 5 # deg/s +TIME_LIMIT = 45 # seconds TIME_DELAY = 5 -MAX_FOLLOWING_DISTANCE = 100 # Apollo 3.5 is very cautious +MAX_FOLLOWING_DISTANCE = 100 # Apollo 3.5 is very cautious -print("VF_S_65_Slow - ", end = '') +print("VF_S_65_Slow - ", end='') sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "SingleLaneRoad": @@ -43,15 +42,17 @@ POVState.transform = sim.map_point_on_lane(lgsvl.Vector(egoX - 104.74, egoY, egoZ - 7.34)) POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) + def on_collision(agent1, agent2, contact): raise evaluator.TestException("Ego collided with {}".format(agent2)) + ego.on_collision(on_collision) POV.on_collision(on_collision) try: t0 = time.time() - sim.run(TIME_DELAY) # The EGO should start moving first + sim.run(TIME_DELAY) # The EGO should start moving first POV.follow_closest_lane(True, MAX_POV_SPEED, False) while True: @@ -80,4 +81,4 @@ def on_collision(agent1, agent2, contact): if separation > MAX_FOLLOWING_DISTANCE: print("FAILED: EGO following distance was not maintained, {} > {}".format(separation, MAX_FOLLOWING_DISTANCE)) else: - print("PASSED") \ No newline at end of file + print("PASSED") diff --git a/examples/NHTSA-sample-tests/Vehicle-Following/evaluator/utils.py b/examples/NHTSA-sample-tests/Vehicle-Following/evaluator/utils.py index ccc6669..e60df8d 100644 --- a/examples/NHTSA-sample-tests/Vehicle-Following/evaluator/utils.py +++ b/examples/NHTSA-sample-tests/Vehicle-Following/evaluator/utils.py @@ -1,17 +1,18 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # -import lgsvl import math + class TestException(Exception): pass + def separation(V1, V2): xdiff = V1.x - V2.x ydiff = V1.y - V2.y zdiff = V1.z - V2.z - return math.sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff) \ No newline at end of file + return math.sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff) diff --git a/examples/kitti_parser.py b/examples/kitti_parser.py index fc8eaca..9943981 100755 --- a/examples/kitti_parser.py +++ b/examples/kitti_parser.py @@ -115,7 +115,7 @@ def get_ego_random_transform(self): return transform -# Finds a random point near the EGO on the map. +# Finds a random point near the EGO on the map. # Once that is done, randomly find another nearby point so that the NPCs are spawned on different lanes. def get_npc_random_transform(self): ego_transform = self.ego_state.transform diff --git a/lgsvl/__init__.py b/lgsvl/__init__.py index c88223c..33458e6 100644 --- a/lgsvl/__init__.py +++ b/lgsvl/__init__.py @@ -7,6 +7,19 @@ from .geometry import Vector, BoundingBox, Transform from .simulator import Simulator, RaycastHit, WeatherState from .sensor import Sensor, CameraSensor, LidarSensor, ImuSensor -from .agent import AgentType, AgentState, VehicleControl, Vehicle, EgoVehicle, NpcVehicle, Pedestrian, DriveWaypoint, WalkWaypoint, WaypointTrigger, TriggerEffector, NPCControl +from .agent import ( + AgentType, + AgentState, + VehicleControl, + Vehicle, + EgoVehicle, + NpcVehicle, + Pedestrian, + DriveWaypoint, + WalkWaypoint, + WaypointTrigger, + TriggerEffector, + NPCControl, +) from .controllable import Controllable -from .utils import ObjectState \ No newline at end of file +from .utils import ObjectState diff --git a/lgsvl/agent.py b/lgsvl/agent.py index 8c81d8a..346eeb9 100644 --- a/lgsvl/agent.py +++ b/lgsvl/agent.py @@ -4,358 +4,402 @@ # This software contains code licensed as described in LICENSE. # -from .geometry import Vector, Transform, BoundingBox +from .geometry import Vector, BoundingBox from .sensor import Sensor from .utils import accepts, ObjectState as AgentState from enum import Enum from collections.abc import Iterable, Callable -import math import json + class DriveWaypoint: - def __init__(self, position, speed, angle = Vector(0,0,0), idle = 0, deactivate = False, trigger_distance = 0, timestamp = -1, trigger = None): - self.position = position - self.speed = speed - self.angle = angle - self.idle = idle - self.deactivate = deactivate - self.trigger_distance = trigger_distance - self.timestamp = timestamp - self.trigger = trigger + def __init__( + self, + position, + speed, + angle=Vector(0, 0, 0), + idle=0, + deactivate=False, + trigger_distance=0, + timestamp=-1, + trigger=None, + ): + self.position = position + self.speed = speed + self.angle = angle + self.idle = idle + self.deactivate = deactivate + self.trigger_distance = trigger_distance + self.timestamp = timestamp + self.trigger = trigger + class WalkWaypoint: - def __init__(self, position, idle, trigger_distance = 0, speed = 1, trigger = None): - self.position = position - self.speed = speed - self.idle = idle - self.trigger_distance = trigger_distance - self.trigger = trigger + def __init__(self, position, idle, trigger_distance=0, speed=1, trigger=None): + self.position = position + self.speed = speed + self.idle = idle + self.trigger_distance = trigger_distance + self.trigger = trigger + class WaypointTrigger: - def __init__(self, effectors): - self.effectors = effectors - - @staticmethod - def from_json(j): - return WaypointTrigger( - json.loads(j["effectors"]) - ) - - def to_json(self): - effectors_json = [] - for effector in self.effectors: - effectors_json.append(effector.to_json()) - return { - "effectors": effectors_json - } + def __init__(self, effectors): + self.effectors = effectors + + @staticmethod + def from_json(j): + return WaypointTrigger(json.loads(j["effectors"])) + + def to_json(self): + effectors_json = [] + for effector in self.effectors: + effectors_json.append(effector.to_json()) + return {"effectors": effectors_json} + class TriggerEffector: - def __init__(self, type_name, parameters): - self.type_name = type_name - self.parameters = parameters + def __init__(self, type_name, parameters): + self.type_name = type_name + self.parameters = parameters + + @staticmethod + def from_json(j): + return TriggerEffector(j["type_name"], j["parameters"]) - @staticmethod - def from_json(j): - return TriggerEffector(j["type_name"], j["parameters"]) + def to_json(self): + return {"type_name": self.type_name, "parameters": self.parameters} - def to_json(self): - return { - "type_name": self.type_name, - "parameters": self.parameters - } class AgentType(Enum): - EGO = 1 - NPC = 2 - PEDESTRIAN = 3 + EGO = 1 + NPC = 2 + PEDESTRIAN = 3 class VehicleControl: - def __init__(self): - self.steering = 0.0 # [-1..+1] - self.throttle = 0.0 # [0..1] - self.braking = 0.0 # [0..1] - self.reverse = False - self.handbrake = False - - # optional - self.headlights = None # int, 0=off, 1=low, 2=high beams - self.windshield_wipers = None # int, 0=off, 1-3=on - self.turn_signal_left = None # bool - self.turn_signal_right = None # bool + def __init__(self): + self.steering = 0.0 # [-1..+1] + self.throttle = 0.0 # [0..1] + self.braking = 0.0 # [0..1] + self.reverse = False + self.handbrake = False + + # optional + self.headlights = None # int, 0=off, 1=low, 2=high beams + self.windshield_wipers = None # int, 0=off, 1-3=on + self.turn_signal_left = None # bool + self.turn_signal_right = None # bool + class NPCControl: - def __init__(self): - self.headlights = None # int, 0=off, 1=low, 2=high - self.hazards = None # bool - self.e_stop = None # bool - self.turn_signal_left = None # bool - self.turn_signal_right = None # bool + def __init__(self): + self.headlights = None # int, 0=off, 1=low, 2=high + self.hazards = None # bool + self.e_stop = None # bool + self.turn_signal_left = None # bool + self.turn_signal_right = None # bool + class Agent: - def __init__(self, uid, simulator): - self.uid = uid - self.remote = simulator.remote - self.simulator = simulator - - @property - def state(self): - j = self.remote.command("agent/state/get", {"uid": self.uid}) - return AgentState.from_json(j) - - @state.setter - @accepts(AgentState) - def state(self, state): - self.remote.command("agent/state/set", { - "uid": self.uid, - "state": state.to_json() - }) - - @property - def transform(self): - return self.state.transform - - @property - def bounding_box(self): - j = self.remote.command("agent/bounding_box/get", {"uid": self.uid}) - return BoundingBox.from_json(j) - - def __eq__(self, other): - return self.uid == other.uid - - def __hash__(self): - return hash(self.uid) - - @accepts(Callable) - def on_collision(self, fn): - self.remote.command("agent/on_collision", {"uid": self.uid}) - self.simulator._add_callback(self, "collision", fn) - - @staticmethod - def create(simulator, uid, agent_type): - if agent_type == AgentType.EGO: - return EgoVehicle(uid, simulator) - elif agent_type == AgentType.NPC: - return NpcVehicle(uid, simulator) - elif agent_type == AgentType.PEDESTRIAN: - return Pedestrian(uid, simulator) - else: - raise ValueError("unsupported agent type") + def __init__(self, uid, simulator): + self.uid = uid + self.remote = simulator.remote + self.simulator = simulator + + @property + def state(self): + j = self.remote.command("agent/state/get", {"uid": self.uid}) + return AgentState.from_json(j) + + @state.setter + @accepts(AgentState) + def state(self, state): + self.remote.command( + "agent/state/set", {"uid": self.uid, "state": state.to_json()} + ) + + @property + def transform(self): + return self.state.transform + + @property + def bounding_box(self): + j = self.remote.command("agent/bounding_box/get", {"uid": self.uid}) + return BoundingBox.from_json(j) + + def __eq__(self, other): + return self.uid == other.uid + + def __hash__(self): + return hash(self.uid) + + @accepts(Callable) + def on_collision(self, fn): + self.remote.command("agent/on_collision", {"uid": self.uid}) + self.simulator._add_callback(self, "collision", fn) + + @staticmethod + def create(simulator, uid, agent_type): + if agent_type == AgentType.EGO: + return EgoVehicle(uid, simulator) + elif agent_type == AgentType.NPC: + return NpcVehicle(uid, simulator) + elif agent_type == AgentType.PEDESTRIAN: + return Pedestrian(uid, simulator) + else: + raise ValueError("unsupported agent type") class Vehicle(Agent): - def __init__(self, uid, simulator): - super().__init__(uid, simulator) + def __init__(self, uid, simulator): + super().__init__(uid, simulator) class EgoVehicle(Vehicle): - def __init__(self, uid, simulator): - super().__init__(uid, simulator) - - @property - def bridge_connected(self): - return self.remote.command("vehicle/bridge/connected", {"uid": self.uid}) - - @accepts(str, int) - def connect_bridge(self, address, port): - if port <= 0 or port > 65535: raise ValueError("port value is out of range") - self.remote.command("vehicle/bridge/connect", {"uid": self.uid, "address": address, "port": port}) - - def get_sensors(self): - j = self.remote.command("vehicle/sensors/get", {"uid": self.uid}) - return [Sensor.create(self.remote, sensor) for sensor in j] - - @accepts(bool, float) - def set_fixed_speed(self, isCruise, speed=None): - self.remote.command("vehicle/set_fixed_speed", {"uid": self.uid, "isCruise": isCruise, "speed": speed}) - - @accepts(VehicleControl, bool) - def apply_control(self, control, sticky = False): - args = { - "uid": self.uid, - "sticky": sticky, - "control": { - "steering": control.steering, - "throttle": control.throttle, - "braking": control.braking, - "reverse": control.reverse, - "handbrake": control.handbrake, - } - } - if control.headlights is not None: - args["control"]["headlights"] = control.headlights - if control.windshield_wipers is not None: - args["control"]["windshield_wipers"] = control.windshield_wipers - if control.turn_signal_left is not None: - args["control"]["turn_signal_left"] = control.turn_signal_left - if control.turn_signal_right is not None: - args["control"]["turn_signal_right"] = control.turn_signal_right - self.remote.command("vehicle/apply_control", args) - - def on_custom(self, fn): - self.simulator._add_callback(self, "custom", fn) + def __init__(self, uid, simulator): + super().__init__(uid, simulator) + + @property + def bridge_connected(self): + return self.remote.command("vehicle/bridge/connected", {"uid": self.uid}) + + @accepts(str, int) + def connect_bridge(self, address, port): + if port <= 0 or port > 65535: + raise ValueError("port value is out of range") + self.remote.command( + "vehicle/bridge/connect", + {"uid": self.uid, "address": address, "port": port}, + ) + + def get_sensors(self): + j = self.remote.command("vehicle/sensors/get", {"uid": self.uid}) + return [Sensor.create(self.remote, sensor) for sensor in j] + + @accepts(bool, float) + def set_fixed_speed(self, isCruise, speed=None): + self.remote.command( + "vehicle/set_fixed_speed", + {"uid": self.uid, "isCruise": isCruise, "speed": speed}, + ) + + @accepts(VehicleControl, bool) + def apply_control(self, control, sticky=False): + args = { + "uid": self.uid, + "sticky": sticky, + "control": { + "steering": control.steering, + "throttle": control.throttle, + "braking": control.braking, + "reverse": control.reverse, + "handbrake": control.handbrake, + }, + } + if control.headlights is not None: + args["control"]["headlights"] = control.headlights + if control.windshield_wipers is not None: + args["control"]["windshield_wipers"] = control.windshield_wipers + if control.turn_signal_left is not None: + args["control"]["turn_signal_left"] = control.turn_signal_left + if control.turn_signal_right is not None: + args["control"]["turn_signal_right"] = control.turn_signal_right + self.remote.command("vehicle/apply_control", args) + + def on_custom(self, fn): + self.simulator._add_callback(self, "custom", fn) class NpcVehicle(Vehicle): - def __init__(self, uid, simulator): - super().__init__(uid, simulator) - - @accepts(Iterable, bool) - def follow(self, waypoints, loop = False): - '''Tells the NPC to follow the waypoints - - When an NPC reaches a waypoint, it will: - 1. Wait for an EGO vehicle to approach to within the trigger_distance [meters] (ignored if 0) - 2. Wait the idle time (ignored if 0) - 3. Drive to the next waypoint (if any) - - Parameters - ---------- - waypoints : list of DriveWaypoints - DriveWaypoint : Class (position, speed, angle, idle, trigger_distance) - - position : lgsvl.Vector() - Unity coordinates of waypoint - - speed : float - how fast the NPC should drive to the waypoint - - angle : lgsvl.Vector() - Unity rotation of the NPC at the waypoint - - idle : float - time for the NPC to wait at the waypoint - - deactivate : bool - whether the NPC is to deactivate while waiting at this waypoint - - trigger_distance : float - how close an EGO must approach for the NPC to continue - - trigger : Class (list of Effectors) - trigger data with effectors applied on this waypoint - effectors : Class (type, value) - typeName : string - effector type name - parameters : dictionary - parameters of the effector (for example "value", "max_distance", "radius") - - loop : bool - whether the NPC should loop through the waypoints after reaching the final one - ''' - self.remote.command("vehicle/follow_waypoints", { - "uid": self.uid, - "waypoints": [{ - "position": wp.position.to_json(), - "speed": wp.speed, - "angle": wp.angle.to_json(), - "idle": wp.idle, - "deactivate": wp.deactivate, - "trigger_distance": wp.trigger_distance, - "timestamp": wp.timestamp, - "trigger": (None if wp.trigger is None else wp.trigger.to_json()) - } for wp in waypoints], - "loop": loop, - }) - - def follow_closest_lane(self, follow, max_speed, isLaneChange=True): - self.remote.command("vehicle/follow_closest_lane", {"uid": self.uid, "follow": follow, "max_speed": max_speed, "isLaneChange": isLaneChange}) - - def set_behaviour(self, behaviour): - self.remote.command("vehicle/behaviour", {"uid": self.uid, "behaviour": behaviour}) - - @accepts(bool) - def change_lane(self, isLeftChange): - self.remote.command("vehicle/change_lane", {"uid": self.uid, "isLeftChange": isLeftChange}) - - @accepts(NPCControl) - def apply_control(self, control): - args = { - "uid": self.uid, - "control":{} - } - if control.headlights is not None: - if not control.headlights in [0,1,2]: - raise ValueError("unsupported intensity value") - args["control"]["headlights"] = control.headlights - if control.hazards is not None: - args["control"]["hazards"] = control.hazards - if control.e_stop is not None: - args["control"]["e_stop"] = control.e_stop - if control.turn_signal_left is not None or control.turn_signal_right is not None: - args["control"]["isLeftTurnSignal"] = control.turn_signal_left - args["control"]["isRightTurnSignal"] = control.turn_signal_right - self.remote.command("vehicle/apply_npc_control", args) - - def on_waypoint_reached(self, fn): - self.remote.command("agent/on_waypoint_reached", {"uid": self.uid}) - self.simulator._add_callback(self, "waypoint_reached", fn) - - def on_stop_line(self, fn): - self.remote.command("agent/on_stop_line", {"uid": self.uid}) - self.simulator._add_callback(self, "stop_line", fn) - - def on_lane_change(self, fn): - self.remote.command("agent/on_lane_change", {"uid": self.uid}) - self.simulator._add_callback(self, "lane_change", fn) + def __init__(self, uid, simulator): + super().__init__(uid, simulator) + + @accepts(Iterable, bool) + def follow(self, waypoints, loop=False): + """Tells the NPC to follow the waypoints + + When an NPC reaches a waypoint, it will: + 1. Wait for an EGO vehicle to approach to within the trigger_distance [meters] (ignored if 0) + 2. Wait the idle time (ignored if 0) + 3. Drive to the next waypoint (if any) + + Parameters + ---------- + waypoints : list of DriveWaypoints + DriveWaypoint : Class (position, speed, angle, idle, trigger_distance) + + position : lgsvl.Vector() + Unity coordinates of waypoint + + speed : float + how fast the NPC should drive to the waypoint + + angle : lgsvl.Vector() + Unity rotation of the NPC at the waypoint + + idle : float + time for the NPC to wait at the waypoint + + deactivate : bool + whether the NPC is to deactivate while waiting at this waypoint + + trigger_distance : float + how close an EGO must approach for the NPC to continue + + trigger : Class (list of Effectors) + trigger data with effectors applied on this waypoint + effectors : Class (type, value) + typeName : string + effector type name + parameters : dictionary + parameters of the effector (for example "value", "max_distance", "radius") + + loop : bool + whether the NPC should loop through the waypoints after reaching the final one + """ + self.remote.command( + "vehicle/follow_waypoints", + { + "uid": self.uid, + "waypoints": [ + { + "position": wp.position.to_json(), + "speed": wp.speed, + "angle": wp.angle.to_json(), + "idle": wp.idle, + "deactivate": wp.deactivate, + "trigger_distance": wp.trigger_distance, + "timestamp": wp.timestamp, + "trigger": ( + None if wp.trigger is None else wp.trigger.to_json() + ), + } + for wp in waypoints + ], + "loop": loop, + }, + ) + + def follow_closest_lane(self, follow, max_speed, isLaneChange=True): + self.remote.command( + "vehicle/follow_closest_lane", + { + "uid": self.uid, + "follow": follow, + "max_speed": max_speed, + "isLaneChange": isLaneChange, + }, + ) + + def set_behaviour(self, behaviour): + self.remote.command( + "vehicle/behaviour", {"uid": self.uid, "behaviour": behaviour} + ) + + @accepts(bool) + def change_lane(self, isLeftChange): + self.remote.command( + "vehicle/change_lane", {"uid": self.uid, "isLeftChange": isLeftChange} + ) + + @accepts(NPCControl) + def apply_control(self, control): + args = {"uid": self.uid, "control": {}} + if control.headlights is not None: + if control.headlights not in [0, 1, 2]: + raise ValueError("unsupported intensity value") + args["control"]["headlights"] = control.headlights + if control.hazards is not None: + args["control"]["hazards"] = control.hazards + if control.e_stop is not None: + args["control"]["e_stop"] = control.e_stop + if ( + control.turn_signal_left is not None + or control.turn_signal_right is not None + ): + args["control"]["isLeftTurnSignal"] = control.turn_signal_left + args["control"]["isRightTurnSignal"] = control.turn_signal_right + self.remote.command("vehicle/apply_npc_control", args) + + def on_waypoint_reached(self, fn): + self.remote.command("agent/on_waypoint_reached", {"uid": self.uid}) + self.simulator._add_callback(self, "waypoint_reached", fn) + + def on_stop_line(self, fn): + self.remote.command("agent/on_stop_line", {"uid": self.uid}) + self.simulator._add_callback(self, "stop_line", fn) + + def on_lane_change(self, fn): + self.remote.command("agent/on_lane_change", {"uid": self.uid}) + self.simulator._add_callback(self, "lane_change", fn) class Pedestrian(Agent): - def __init__(self, uid, simulator): - super().__init__(uid, simulator) - - @accepts(bool) - def walk_randomly(self, enable): - self.remote.command("pedestrian/walk_randomly", {"uid": self.uid, "enable": enable}) - - @accepts(Iterable, bool) - def follow(self, waypoints, loop = False): - '''Tells the Pedestrian to follow the waypoints - - When a pedestrian reaches a waypoint, it will: - 1. Wait for an EGO vehicle to approach to within the trigger_distance [meters] (ignored if 0) - 2. Wait the idle time (ignored if 0) - 3. Walk to the next waypoint (if any) - - Parameters - ---------- - waypoints : list of WalkWaypoints - WalkWaypoint : Class (position, idle, trigger_distance, speed) - - position : lgsvl.Vector() - Unity coordinates of waypoint - - idle : float - time for the pedestrian to wait at the waypoint - - trigger_distance : float - how close an EGO must approach for the pedestrian to continue - - speed : float - how fast the pedestrian should drive to the waypoint (default value 1) - - loop : bool - whether the pedestrian should loop through the waypoints after reaching the final one - ''' - self.remote.command("pedestrian/follow_waypoints", { - "uid": self.uid, - "waypoints": [{ - "position": wp.position.to_json(), - "idle": wp.idle, - "trigger_distance": wp.trigger_distance, - "speed": wp.speed, - "trigger": (None if wp.trigger is None else wp.trigger.to_json()) - } for wp in waypoints], - "loop": loop, - }) - - @accepts(float) - def set_speed(self, speed): - self.remote.command("pedestrian/set_speed", {"uid": self.uid, "speed": speed}) - - @accepts(Callable) - def on_waypoint_reached(self, fn): - self.remote.command("agent/on_waypoint_reached", {"uid": self.uid}) - self.simulator._add_callback(self, "waypoint_reached", fn) - + def __init__(self, uid, simulator): + super().__init__(uid, simulator) + + @accepts(bool) + def walk_randomly(self, enable): + self.remote.command( + "pedestrian/walk_randomly", {"uid": self.uid, "enable": enable} + ) + + @accepts(Iterable, bool) + def follow(self, waypoints, loop=False): + """Tells the Pedestrian to follow the waypoints + + When a pedestrian reaches a waypoint, it will: + 1. Wait for an EGO vehicle to approach to within the trigger_distance [meters] (ignored if 0) + 2. Wait the idle time (ignored if 0) + 3. Walk to the next waypoint (if any) + + Parameters + ---------- + waypoints : list of WalkWaypoints + WalkWaypoint : Class (position, idle, trigger_distance, speed) + + position : lgsvl.Vector() + Unity coordinates of waypoint + + idle : float + time for the pedestrian to wait at the waypoint + + trigger_distance : float + how close an EGO must approach for the pedestrian to continue + + speed : float + how fast the pedestrian should drive to the waypoint (default value 1) + + loop : bool + whether the pedestrian should loop through the waypoints after reaching the final one + """ + self.remote.command( + "pedestrian/follow_waypoints", + { + "uid": self.uid, + "waypoints": [ + { + "position": wp.position.to_json(), + "idle": wp.idle, + "trigger_distance": wp.trigger_distance, + "speed": wp.speed, + "trigger": ( + None if wp.trigger is None else wp.trigger.to_json() + ), + } + for wp in waypoints + ], + "loop": loop, + }, + ) + + @accepts(float) + def set_speed(self, speed): + self.remote.command("pedestrian/set_speed", {"uid": self.uid, "speed": speed}) + + @accepts(Callable) + def on_waypoint_reached(self, fn): + self.remote.command("agent/on_waypoint_reached", {"uid": self.uid}) + self.simulator._add_callback(self, "waypoint_reached", fn) diff --git a/lgsvl/controllable.py b/lgsvl/controllable.py index 0b3e75d..42c30e7 100644 --- a/lgsvl/controllable.py +++ b/lgsvl/controllable.py @@ -1,61 +1,62 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # -from .geometry import Vector, Transform +from .geometry import Transform from .utils import accepts, ObjectState + class Controllable: - def __init__(self, remote, j): - self.remote = remote - self.uid = j["uid"] - self.type = j["type"] - self.transform = Transform.from_json(j) - self.valid_actions = j["valid_actions"] - self.default_control_policy = j["default_control_policy"] - - @property - def object_state(self): - j = self.remote.command("controllable/object_state/get", {"uid": self.uid}) - return ObjectState.from_json(j) - - @object_state.setter - @accepts(ObjectState) - def object_state(self, object_state): - self.remote.command("controllable/object_state/set", { - "uid": self.uid, - "state": object_state.to_json() - }) - - @property - def current_state(self): - j = self.remote.command("controllable/current_state/get", {"uid": self.uid}) - return j["state"] - - @property - def control_policy(self): - j = self.remote.command("controllable/control_policy/get", {"uid": self.uid}) - return j["control_policy"] - - @accepts(str) - def control(self, control_policy): - self.remote.command("controllable/control_policy/set", { - "uid": self.uid, - "control_policy": control_policy, - }) - - def __eq__(self, other): - return self.uid == other.uid - - def __hash__(self): - return hash(self.uid) - - def __repr__(self): - return str({ - "type": str(self.type), - "transform": str(self.transform), - "valid_actions": str(self.valid_actions), - "default_control_policy": str(self.default_control_policy), - }) + def __init__(self, remote, j): + self.remote = remote + self.uid = j["uid"] + self.type = j["type"] + self.transform = Transform.from_json(j) + self.valid_actions = j["valid_actions"] + self.default_control_policy = j["default_control_policy"] + + @property + def object_state(self): + j = self.remote.command("controllable/object_state/get", {"uid": self.uid}) + return ObjectState.from_json(j) + + @object_state.setter + @accepts(ObjectState) + def object_state(self, object_state): + self.remote.command("controllable/object_state/set", { + "uid": self.uid, + "state": object_state.to_json() + }) + + @property + def current_state(self): + j = self.remote.command("controllable/current_state/get", {"uid": self.uid}) + return j["state"] + + @property + def control_policy(self): + j = self.remote.command("controllable/control_policy/get", {"uid": self.uid}) + return j["control_policy"] + + @accepts(str) + def control(self, control_policy): + self.remote.command("controllable/control_policy/set", { + "uid": self.uid, + "control_policy": control_policy, + }) + + def __eq__(self, other): + return self.uid == other.uid + + def __hash__(self): + return hash(self.uid) + + def __repr__(self): + return str({ + "type": str(self.type), + "transform": str(self.transform), + "valid_actions": str(self.valid_actions), + "default_control_policy": str(self.default_control_policy), + }) diff --git a/lgsvl/geometry.py b/lgsvl/geometry.py index 40f9977..d51a1ce 100644 --- a/lgsvl/geometry.py +++ b/lgsvl/geometry.py @@ -1,106 +1,107 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # + from math import sqrt -import math class Vector: - def __init__(self, x = 0.0, y = 0.0, z = 0.0): - self.x = x - self.y = y - self.z = z - - @staticmethod - def from_json(j): - return Vector(j["x"], j["y"], j["z"]) - - def to_json(self): - return {"x": self.x, "y": self.y, "z": self.z} - - def __repr__(self): - return "Vector({}, {}, {})".format(self.x, self.y, self.z) - - def __add__(self, v): - if isinstance(v, Vector): - return Vector(self.x + v.x, self.y + v.y, self.z + v.z) - elif isinstance(v, (int, float)): - return Vector(self.x + v, self.y + v, self.z + v) - else: - raise TypeError("Vector addition only allowed between Vectors and numbers") - - def __sub__(self, v): - if isinstance(v, Vector): - return Vector(self.x - v.x, self.y - v.y, self.z - v.z) - elif isinstance(v, (int, float)): - return Vector(self.x - v, self.y - v, self.z - v) - else: - raise TypeError("Vector subtraction only allowed between Vectors and numbers") - - def __mul__(self, v): - if isinstance(v, Vector): - return Vector(self.x * v.x, self.y * v.y, self.z * v.z) - elif isinstance(v, (int, float)): - return Vector(self.x * v, self.y * v, self.z * v) - else: - raise TypeError("Vector multiplication only allowed between Vectors and numbers") - - def __rmul__(self, v): - return self * v - - def __neg__(self): - return Vector(-self.x, -self.y, -self.z) - - def magnitude(self): - return sqrt(self.x**2 + self.y**2 + self.z**2) + def __init__(self, x=0.0, y=0.0, z=0.0): + self.x = x + self.y = y + self.z = z + + @staticmethod + def from_json(j): + return Vector(j["x"], j["y"], j["z"]) + + def to_json(self): + return {"x": self.x, "y": self.y, "z": self.z} + + def __repr__(self): + return "Vector({}, {}, {})".format(self.x, self.y, self.z) + + def __add__(self, v): + if isinstance(v, Vector): + return Vector(self.x + v.x, self.y + v.y, self.z + v.z) + elif isinstance(v, (int, float)): + return Vector(self.x + v, self.y + v, self.z + v) + else: + raise TypeError("Vector addition only allowed between Vectors and numbers") + + def __sub__(self, v): + if isinstance(v, Vector): + return Vector(self.x - v.x, self.y - v.y, self.z - v.z) + elif isinstance(v, (int, float)): + return Vector(self.x - v, self.y - v, self.z - v) + else: + raise TypeError("Vector subtraction only allowed between Vectors and numbers") + + def __mul__(self, v): + if isinstance(v, Vector): + return Vector(self.x * v.x, self.y * v.y, self.z * v.z) + elif isinstance(v, (int, float)): + return Vector(self.x * v, self.y * v, self.z * v) + else: + raise TypeError("Vector multiplication only allowed between Vectors and numbers") + + def __rmul__(self, v): + return self * v + + def __neg__(self): + return Vector(-self.x, -self.y, -self.z) + + def magnitude(self): + return sqrt(self.x**2 + self.y**2 + self.z**2) + class BoundingBox: - def __init__(self, min, max): - self.min = min - self.max = max + def __init__(self, min, max): + self.min = min + self.max = max - @staticmethod - def from_json(j): - return BoundingBox(Vector.from_json(j["min"]), Vector.from_json(j["max"])) + @staticmethod + def from_json(j): + return BoundingBox(Vector.from_json(j["min"]), Vector.from_json(j["max"])) - def to_json(self): - return {"min": self.min.to_json(), "max": self.max.to_json()} + def to_json(self): + return {"min": self.min.to_json(), "max": self.max.to_json()} - def __repr__(self): - return "BoundingBox({}, {})".format(self.min, self.max) + def __repr__(self): + return "BoundingBox({}, {})".format(self.min, self.max) - @property - def center(self): - return Vector( - (self.max.x + self.min.x) * 0.5, - (self.max.y + self.min.y) * 0.5, - (self.max.z + self.min.z) * 0.5, - ) + @property + def center(self): + return Vector( + (self.max.x + self.min.x) * 0.5, + (self.max.y + self.min.y) * 0.5, + (self.max.z + self.min.z) * 0.5, + ) - @property - def size(self): - return Vector( - self.max.x - self.min.x, - self.max.y - self.min.y, - self.max.z - self.min.z, - ) + @property + def size(self): + return Vector( + self.max.x - self.min.x, + self.max.y - self.min.y, + self.max.z - self.min.z, + ) class Transform: - def __init__(self, position = None, rotation = None): - if position is None: position = Vector() - if rotation is None: rotation = Vector() - self.position = position - self.rotation = rotation + def __init__(self, position=None, rotation=None): + if position is None: position = Vector() + if rotation is None: rotation = Vector() + self.position = position + self.rotation = rotation - @staticmethod - def from_json(j): - return Transform(Vector.from_json(j["position"]), Vector.from_json(j["rotation"])) + @staticmethod + def from_json(j): + return Transform(Vector.from_json(j["position"]), Vector.from_json(j["rotation"])) - def to_json(self): - return {"position": self.position.to_json(), "rotation": self.rotation.to_json()} + def to_json(self): + return {"position": self.position.to_json(), "rotation": self.rotation.to_json()} - def __repr__(self): - return "Transform(position={}, rotation={})".format(self.position, self.rotation) + def __repr__(self): + return "Transform(position={}, rotation={})".format(self.position, self.rotation) diff --git a/lgsvl/remote.py b/lgsvl/remote.py index f8c35fa..5175bff 100644 --- a/lgsvl/remote.py +++ b/lgsvl/remote.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -9,61 +9,62 @@ import asyncio import json + class Remote(threading.Thread): - def __init__(self, host, port): - super().__init__(daemon=True) - self.endpoint = "ws://{}:{}".format(host, port) - self.lock = threading.Lock() - self.cv = threading.Condition() - self.data = None - self.sem = threading.Semaphore(0) - self.running = True - self.start() - self.sem.acquire() + def __init__(self, host, port): + super().__init__(daemon=True) + self.endpoint = "ws://{}:{}".format(host, port) + self.lock = threading.Lock() + self.cv = threading.Condition() + self.data = None + self.sem = threading.Semaphore(0) + self.running = True + self.start() + self.sem.acquire() - def run(self): - self.loop = asyncio.new_event_loop() - asyncio.set_event_loop(self.loop) - self.loop.run_until_complete(self.process()) + def run(self): + self.loop = asyncio.new_event_loop() + asyncio.set_event_loop(self.loop) + self.loop.run_until_complete(self.process()) - def close(self): - asyncio.run_coroutine_threadsafe(self.websocket.close(), self.loop) - self.join() - self.loop.close() + def close(self): + asyncio.run_coroutine_threadsafe(self.websocket.close(), self.loop) + self.join() + self.loop.close() - async def process(self): - self.websocket = await websockets.connect(self.endpoint, compression=None) - self.sem.release() + async def process(self): + self.websocket = await websockets.connect(self.endpoint, compression=None) + self.sem.release() - while True: - try: - data = await self.websocket.recv() - except Exception as e: - if isinstance(e, websockets.exceptions.ConnectionClosed): - break - with self.cv: - self.data = {"error": str(e)} - self.cv.notify() - break - with self.cv: - self.data = json.loads(data) - self.cv.notify() + while True: + try: + data = await self.websocket.recv() + except Exception as e: + if isinstance(e, websockets.exceptions.ConnectionClosed): + break + with self.cv: + self.data = {"error": str(e)} + self.cv.notify() + break + with self.cv: + self.data = json.loads(data) + self.cv.notify() - await self.websocket.close() + await self.websocket.close() - def command(self, name, args = {}): - if not self.websocket: - raise Exception("Not connected") - - data = json.dumps({"command": name, "arguments": args}) - asyncio.run_coroutine_threadsafe(self.websocket.send(data), self.loop) + def command(self, name, args={}): + if not self.websocket: + raise Exception("Not connected") - with self.cv: - self.cv.wait_for(lambda: self.data is not None) - data = self.data - self.data = None + data = json.dumps({"command": name, "arguments": args}) + asyncio.run_coroutine_threadsafe(self.websocket.send(data), self.loop) + + with self.cv: + self.cv.wait_for(lambda: self.data is not None) + data = self.data + self.data = None - if "error" in data: - raise Exception(data["error"]) - return data["result"] + if "error" in data: + raise Exception(data["error"]) + return data["result"] diff --git a/lgsvl/sensor.py b/lgsvl/sensor.py index 247af02..a6dd9b5 100644 --- a/lgsvl/sensor.py +++ b/lgsvl/sensor.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -11,142 +11,143 @@ GpsData = namedtuple("GpsData", "latitude longitude northing easting altitude orientation") + class Sensor: - def __init__(self, remote, uid, name): - self.remote = remote - self.uid = uid - self.name = name - - @property - def transform(self): - j = self.remote.command("sensor/transform/get", {"uid": self.uid}) - return Transform.from_json(j) - - @property - def enabled(self): - return self.remote.command("sensor/enabled/get", {"uid": self.uid}) - - @enabled.setter - @accepts(bool) - def enabled(self, value): - self.remote.command("sensor/enabled/set", {"uid": self.uid, "enabled": value}) - - def __eq__(self, other): - return self.uid == other.uid - - def __hash__(self): - return hash(self.uid) - - @staticmethod - def create(remote, j): - if j["type"] == "camera": - return CameraSensor(remote, j) - if j["type"] == "lidar": - return LidarSensor(remote, j) - if j["type"] == "imu": - return ImuSensor(remote, j) - if j["type"] == "gps": - return GpsSensor(remote, j) - if j["type"] == "radar": - return RadarSensor(remote, j) - if j["type"] == "canbus": - return CanBusSensor(remote, j) - if j["type"] == "recorder": - return VideoRecordingSensor(remote, j) - if j["type"] == "analysis": - return AnalysisSensor(remote, j) - raise ValueError("Sensor type '{}' not supported".format(j["type"])) + def __init__(self, remote, uid, name): + self.remote = remote + self.uid = uid + self.name = name + + @property + def transform(self): + j = self.remote.command("sensor/transform/get", {"uid": self.uid}) + return Transform.from_json(j) + + @property + def enabled(self): + return self.remote.command("sensor/enabled/get", {"uid": self.uid}) + + @enabled.setter + @accepts(bool) + def enabled(self, value): + self.remote.command("sensor/enabled/set", {"uid": self.uid, "enabled": value}) + + def __eq__(self, other): + return self.uid == other.uid + + def __hash__(self): + return hash(self.uid) + + @staticmethod + def create(remote, j): + if j["type"] == "camera": + return CameraSensor(remote, j) + if j["type"] == "lidar": + return LidarSensor(remote, j) + if j["type"] == "imu": + return ImuSensor(remote, j) + if j["type"] == "gps": + return GpsSensor(remote, j) + if j["type"] == "radar": + return RadarSensor(remote, j) + if j["type"] == "canbus": + return CanBusSensor(remote, j) + if j["type"] == "recorder": + return VideoRecordingSensor(remote, j) + if j["type"] == "analysis": + return AnalysisSensor(remote, j) + raise ValueError("Sensor type '{}' not supported".format(j["type"])) class CameraSensor(Sensor): - def __init__(self, remote, j): - super().__init__(remote, j["uid"], j["name"]) - self.frequency = j["frequency"] - self.width = j["width"] - self.height = j["height"] - self.fov = j["fov"] - self.near_plane = j["near_plane"] - self.far_plane = j["far_plane"] - """ - RGB - 24-bit color image - DEPTH - 8-bit grayscale depth buffer - SEMANTIC - 24-bit color image with semantic segmentation - """ - self.format = j["format"] - - @accepts(str, int, int) - def save(self, path, quality = 75, compression = 6): - success = self.remote.command("sensor/camera/save", { - "uid": self.uid, - "path": path, - "quality": quality, - "compression": compression, - }) - return success + def __init__(self, remote, j): + super().__init__(remote, j["uid"], j["name"]) + self.frequency = j["frequency"] + self.width = j["width"] + self.height = j["height"] + self.fov = j["fov"] + self.near_plane = j["near_plane"] + self.far_plane = j["far_plane"] + """ + RGB - 24-bit color image + DEPTH - 8-bit grayscale depth buffer + SEMANTIC - 24-bit color image with semantic segmentation + """ + self.format = j["format"] + + @accepts(str, int, int) + def save(self, path, quality=75, compression=6): + success = self.remote.command("sensor/camera/save", { + "uid": self.uid, + "path": path, + "quality": quality, + "compression": compression, + }) + return success class LidarSensor(Sensor): - def __init__(self, remote, j): - super().__init__(remote, j["uid"], j["name"]) - self.min_distance = j["min_distance"] - self.max_distance = j["max_distance"] - self.rays = j["rays"] - self.rotations = j["rotations"] # rotation frequency, Hz - self.measurements = j["measurements"] # how many measurements each ray does per one rotation - self.fov = j["fov"] - self.angle = j["angle"] - self.compensated = j["compensated"] - - @accepts(str) - def save(self, path): - success = self.remote.command("sensor/lidar/save", { - "uid": self.uid, - "path": path, - }) - return success + def __init__(self, remote, j): + super().__init__(remote, j["uid"], j["name"]) + self.min_distance = j["min_distance"] + self.max_distance = j["max_distance"] + self.rays = j["rays"] + self.rotations = j["rotations"] # rotation frequency, Hz + self.measurements = j["measurements"] # how many measurements each ray does per one rotation + self.fov = j["fov"] + self.angle = j["angle"] + self.compensated = j["compensated"] + + @accepts(str) + def save(self, path): + success = self.remote.command("sensor/lidar/save", { + "uid": self.uid, + "path": path, + }) + return success class ImuSensor(Sensor): - def __init__(self, remote, j): - super().__init__(remote, j["uid"], j["name"]) + def __init__(self, remote, j): + super().__init__(remote, j["uid"], j["name"]) class GpsSensor(Sensor): - def __init__(self, remote, j): - super().__init__(remote, j["uid"], j["name"]) - self.frequency = j["frequency"] + def __init__(self, remote, j): + super().__init__(remote, j["uid"], j["name"]) + self.frequency = j["frequency"] - @property - def data(self): - j = self.remote.command("sensor/gps/data", {"uid": self.uid}) - return GpsData(j["latitude"], j["longitude"], j["northing"], j["easting"], j["altitude"], j["orientation"]) + @property + def data(self): + j = self.remote.command("sensor/gps/data", {"uid": self.uid}) + return GpsData(j["latitude"], j["longitude"], j["northing"], j["easting"], j["altitude"], j["orientation"]) class RadarSensor(Sensor): - def __init__(self, remote, j): - super().__init__(remote, j["uid"], j["name"]) + def __init__(self, remote, j): + super().__init__(remote, j["uid"], j["name"]) class CanBusSensor(Sensor): - def __init__(self, remote, j): - super().__init__(remote, j["uid"], j["name"]) - self.frequency = j["frequency"] + def __init__(self, remote, j): + super().__init__(remote, j["uid"], j["name"]) + self.frequency = j["frequency"] class VideoRecordingSensor(Sensor): - def __init__(self, remote, j): - super().__init__(remote, j["uid"], j["name"]) - self.width = j["width"] - self.height = j["height"] - self.framerate = j["framerate"] + def __init__(self, remote, j): + super().__init__(remote, j["uid"], j["name"]) + self.width = j["width"] + self.height = j["height"] + self.framerate = j["framerate"] class AnalysisSensor(Sensor): - def __init__(self, remote, j): - super().__init__(remote, j["uid"], j["name"]) - self.suddenbrakemax = j["suddenbrakemax"] - self.suddensteermax = j["suddensteermax"] - self.stucktravelthreshold = j["stucktravelthreshold"] - self.stucktimethreshold = j["stucktimethreshold"] - self.minfps = j["minfps"] - self.minfpstime = j["minfpstime"] + def __init__(self, remote, j): + super().__init__(remote, j["uid"], j["name"]) + self.suddenbrakemax = j["suddenbrakemax"] + self.suddensteermax = j["suddensteermax"] + self.stucktravelthreshold = j["stucktravelthreshold"] + self.stucktimethreshold = j["stucktimethreshold"] + self.minfps = j["minfps"] + self.minfpstime = j["minfpstime"] diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index a1db875..39fb65c 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -20,276 +20,276 @@ class Simulator: - @accepts(str, int) - def __init__(self, address = "localhost", port = 8181): - if port <= 0 or port > 65535: raise ValueError("port value is out of range") - self.remote = Remote(address, port) - self.agents = {} - self.callbacks = {} - self.stopped = False - - def close(self): - self.remote.close() - - @accepts(str, int) - def load(self, scene, seed=None): - self.remote.command("simulator/load_scene", {"scene": scene, "seed": seed}) - self.agents.clear() - self.callbacks.clear() - - @property - def version(self): - return self.remote.command("simulator/version") - - @property - def current_scene(self): - return self.remote.command("simulator/current_scene") - - @property - def current_frame(self): - return self.remote.command("simulator/current_frame") - - @property - def current_time(self): - return self.remote.command("simulator/current_time") - - @property - def available_agents(self): - return self.remote.command("simulator/available_agents") - - @property - def available_npc_behaviours(self): - return self.remote.command("simulator/npc/available_behaviours") - - def agents_traversed_waypoints(self, fn): - self._add_callback(None, "agents_traversed_waypoints", fn) - - def reset(self): - self.remote.command("simulator/reset") - self.agents.clear() - self.callbacks.clear() - - def stop(self): - self.stopped = True - - @accepts((int, float), (int, float)) - def run(self, time_limit = 0.0, time_scale = None): - self._process("simulator/run", {"time_limit": time_limit, "time_scale": time_scale}) - - def _add_callback(self, agent, name, fn): - if agent not in self.callbacks: - self.callbacks[agent] = {} - if name not in self.callbacks[agent]: - self.callbacks[agent][name] = set() - self.callbacks[agent][name].add(fn) - - def _process_events(self, events): - self.stopped = False - for ev in events: - if "agent" in ev: - agent = self.agents[ev["agent"]] - if agent in self.callbacks: - callbacks = self.callbacks[agent] - event_type = ev["type"] - if event_type in callbacks: - for fn in callbacks[event_type]: - if event_type == "collision": - fn(agent, self.agents.get(ev["other"]), Vector.from_json(ev["contact"]) if ev["contact"] is not None else None) - elif event_type == "waypoint_reached": - fn(agent, ev["index"]) - elif event_type == "stop_line": - fn(agent) - elif event_type == "lane_change": - fn(agent) - elif event_type == "custom": - fn(agent, ev["kind"], ev["context"]) - if self.stopped: + @accepts(str, int) + def __init__(self, address="localhost", port=8181): + if port <= 0 or port > 65535: + raise ValueError("port value is out of range") + self.remote = Remote(address, port) + self.agents = {} + self.callbacks = {} + self.stopped = False + + def close(self): + self.remote.close() + + @accepts(str, int) + def load(self, scene, seed=None): + self.remote.command("simulator/load_scene", {"scene": scene, "seed": seed}) + self.agents.clear() + self.callbacks.clear() + + @property + def version(self): + return self.remote.command("simulator/version") + + @property + def current_scene(self): + return self.remote.command("simulator/current_scene") + + @property + def current_frame(self): + return self.remote.command("simulator/current_frame") + + @property + def current_time(self): + return self.remote.command("simulator/current_time") + + @property + def available_agents(self): + return self.remote.command("simulator/available_agents") + + @property + def available_npc_behaviours(self): + return self.remote.command("simulator/npc/available_behaviours") + + def agents_traversed_waypoints(self, fn): + self._add_callback(None, "agents_traversed_waypoints", fn) + + def reset(self): + self.remote.command("simulator/reset") + self.agents.clear() + self.callbacks.clear() + + def stop(self): + self.stopped = True + + @accepts((int, float), (int, float)) + def run(self, time_limit=0.0, time_scale=None): + self._process("simulator/run", {"time_limit": time_limit, "time_scale": time_scale}) + + def _add_callback(self, agent, name, fn): + if agent not in self.callbacks: + self.callbacks[agent] = {} + if name not in self.callbacks[agent]: + self.callbacks[agent][name] = set() + self.callbacks[agent][name].add(fn) + + def _process_events(self, events): + self.stopped = False + for ev in events: + if "agent" in ev: + agent = self.agents[ev["agent"]] + if agent in self.callbacks: + callbacks = self.callbacks[agent] + event_type = ev["type"] + if event_type in callbacks: + for fn in callbacks[event_type]: + if event_type == "collision": + fn(agent, self.agents.get(ev["other"]), Vector.from_json(ev["contact"]) if ev["contact"] is not None else None) + elif event_type == "waypoint_reached": + fn(agent, ev["index"]) + elif event_type == "stop_line": + fn(agent) + elif event_type == "lane_change": + fn(agent) + elif event_type == "custom": + fn(agent, ev["kind"], ev["context"]) + if self.stopped: + return + elif None in self.callbacks: + callbacks = self.callbacks[None] + event_type = ev["type"] + if event_type in callbacks: + for fn in callbacks[event_type]: + if event_type == "agents_traversed_waypoints": + fn() + + def _process(self, cmd, args): + j = self.remote.command(cmd, args) + while True: + if j is None: return - elif None in self.callbacks: - callbacks = self.callbacks[None] - event_type = ev["type"] - if event_type in callbacks: - for fn in callbacks[event_type]: - if event_type == "agents_traversed_waypoints": - fn() - - def _process(self, cmd, args): - j = self.remote.command(cmd, args) - while True: - if j is None: - return - if "events" in j: - self._process_events(j["events"]) - if self.stopped: - break - j = self.remote.command("simulator/continue") - - @accepts(str, AgentType, AgentState, Vector) - def add_agent(self, name, agent_type, state = None, color = None): - if state is None: state = AgentState() - if color is None: color = Vector(-1, -1, -1) - args = {"name": name, "type": agent_type.value, "state": state.to_json(), "color": color.to_json()} - uid = self.remote.command("simulator/add_agent", args) - agent = Agent.create(self, uid, agent_type) - agent.name = name - self.agents[uid] = agent - return agent - - @accepts(Agent) - def remove_agent(self, agent): - self.remote.command("simulator/agent/remove", {"uid": agent.uid}) - del self.agents[agent.uid] - if agent in self.callbacks: - del self.callbacks[agent] - - @accepts(AgentType) - def add_random_agents(self, agent_type): - args = {"type": agent_type.value} - self.remote.command("simulator/add_random_agents", args) - - def get_agents(self): - return list(self.agents.values()) - - @property - def weather(self): - j = self.remote.command("environment/weather/get") - return WeatherState(j["rain"], j["fog"], j["wetness"]) - - @weather.setter - @accepts(WeatherState) - def weather(self, state): - self.remote.command("environment/weather/set", {"rain": state.rain, "fog": state.fog, "wetness": state.wetness}) - - @property - def time_of_day(self): - return self.remote.command("environment/time/get") - - @accepts((int, float), bool) - def set_time_of_day(self, time, fixed = True): - self.remote.command("environment/time/set", {"time": time, "fixed": fixed}) - - def get_spawn(self): - spawns = self.remote.command("map/spawn/get") - return [Transform.from_json(spawn) for spawn in spawns] - - @accepts(Transform) - def map_to_gps(self, transform): - j = self.remote.command("map/to_gps", {"transform": transform.to_json()}) - return GpsData(j["latitude"], j["longitude"], j["northing"], j["easting"], j["altitude"], j["orientation"]) - - def map_from_gps(self, latitude = None, longitude = None, northing = None, easting = None, altitude = None, orientation = None): - c = [] - coord = { - "latitude": latitude, - "longitude": longitude, - "northing": northing, - "easting": easting, - "altitude": altitude, - "orientation": orientation - } - c.append(coord) - return self.map_from_gps_batch(c)[0] - - def map_from_gps_batch(self, coords): - # coords dictionary - jarr = [] - - for c in coords: - j = {} - numtype = (int, float) - if ("latitude" in c and c["latitude"] is not None) and ("longitude" in c and c["longitude"] is not None): - if not isinstance(c["latitude"], numtype): raise TypeError("Argument 'latitude' should have '{}' type".format(numtype)) - if not isinstance(c["longitude"], numtype): raise TypeError("Argument 'longitude' should have '{}' type".format(numtype)) - if c["latitude"] < -90 or c["latitude"] > 90: raise ValueError("Latitude is out of range") - if c["longitude"] < -180 or c["longitude"] > 180: raise ValueError("Longitude is out of range") - j["latitude"] = c["latitude"] - j["longitude"] = c["longitude"] - elif ("northing" in c and c["northing"] is not None) and ("easting" in c and c["easting"] is not None): - if not isinstance(c["northing"], numtype): raise TypeError("Argument 'northing' should have '{}' type".format(numtype)) - if not isinstance(c["easting"], numtype): raise TypeError("Argument 'easting' should have '{}' type".format(numtype)) - if c["northing"] < 0 or c["northing"] > 10000000: raise ValueError("Northing is out of range") - if c["easting"] < 160000 or c["easting"] > 834000 : raise ValueError("Easting is out of range") - j["northing"] = c["northing"] - j["easting"] = c["easting"] - else: - raise Exception("Either latitude and longitude or northing and easting should be specified") - if "altitude" in c and c["altitude"] is not None: - if not isinstance(c["altitude"], numtype): raise TypeError("Argument 'altitude' should have '{}' type".format(numtype)) - j["altitude"] = c["altitude"] - if "orientation" in c and c["orientation"] is not None: - if not isinstance(c["orientation"], numtype): raise TypeError("Argument 'orientation' should have '{}' type".format(numtype)) - j["orientation"] = c["orientation"] - jarr.append(j) - - jarr = self.remote.command("map/from_gps", jarr) - transforms = [] - for j in jarr: - transforms.append(Transform.from_json(j)) - return transforms - - @accepts(Vector) - def map_point_on_lane(self, point): - j = self.remote.command("map/point_on_lane", {"point": point.to_json()}) - return Transform.from_json(j) - - @accepts(Vector, Vector, int, float) - def raycast(self, origin, direction, layer_mask = -1, max_distance = float("inf")): - hit = self.remote.command("simulator/raycast", [{ - "origin": origin.to_json(), - "direction": direction.to_json(), - "layer_mask": layer_mask, - "max_distance": max_distance - }]) - if hit[0] is None: - return None - return RaycastHit(hit[0]["distance"], Vector.from_json(hit[0]["point"]), Vector.from_json(hit[0]["normal"])) - - - def raycast_batch(self, args): - jarr = [] - for arg in args: - jarr.append({ - "origin": arg["origin"].to_json(), - "direction": arg["direction"].to_json(), - "layer_mask": arg["layer_mask"], - "max_distance": arg["max_distance"] - }) - - hits = self.remote.command("simulator/raycast", jarr) - results = [] - for hit in hits: - if hit is None: - results.append(None) - else: - results.append(RaycastHit(hit["distance"], Vector.from_json(hit["point"]), Vector.from_json(hit["normal"]))) - - return results - - @accepts(str, ObjectState) - def controllable_add(self, name, object_state = None): - if object_state is None: object_state = ObjectState() - args = {"name": name, "state": object_state.to_json()} - j = self.remote.command("simulator/controllable_add", args) - controllable = Controllable(self.remote, j) - controllable.name = name - return controllable - - @accepts(Controllable) - def controllable_remove(self, controllable): - self.remote.command("simulator/controllable_remove", {"uid": controllable.uid}) - del self.controllables[controllable.uid] - - @accepts(str) - def get_controllables(self, control_type = None): - j = self.remote.command("controllable/get/all", { - "type": control_type, - }) - return [Controllable(self.remote, controllable) for controllable in j] - - @accepts(Vector, str) - def get_controllable(self, position, control_type = None): - j = self.remote.command("controllable/get", { - "position": position.to_json(), - "type": control_type, - }) - return Controllable(self.remote, j) + if "events" in j: + self._process_events(j["events"]) + if self.stopped: + break + j = self.remote.command("simulator/continue") + + @accepts(str, AgentType, AgentState, Vector) + def add_agent(self, name, agent_type, state=None, color=None): + if state is None: state = AgentState() + if color is None: color = Vector(-1, -1, -1) + args = {"name": name, "type": agent_type.value, "state": state.to_json(), "color": color.to_json()} + uid = self.remote.command("simulator/add_agent", args) + agent = Agent.create(self, uid, agent_type) + agent.name = name + self.agents[uid] = agent + return agent + + @accepts(Agent) + def remove_agent(self, agent): + self.remote.command("simulator/agent/remove", {"uid": agent.uid}) + del self.agents[agent.uid] + if agent in self.callbacks: + del self.callbacks[agent] + + @accepts(AgentType) + def add_random_agents(self, agent_type): + args = {"type": agent_type.value} + self.remote.command("simulator/add_random_agents", args) + + def get_agents(self): + return list(self.agents.values()) + + @property + def weather(self): + j = self.remote.command("environment/weather/get") + return WeatherState(j["rain"], j["fog"], j["wetness"]) + + @weather.setter + @accepts(WeatherState) + def weather(self, state): + self.remote.command("environment/weather/set", {"rain": state.rain, "fog": state.fog, "wetness": state.wetness}) + + @property + def time_of_day(self): + return self.remote.command("environment/time/get") + + @accepts((int, float), bool) + def set_time_of_day(self, time, fixed=True): + self.remote.command("environment/time/set", {"time": time, "fixed": fixed}) + + def get_spawn(self): + spawns = self.remote.command("map/spawn/get") + return [Transform.from_json(spawn) for spawn in spawns] + + @accepts(Transform) + def map_to_gps(self, transform): + j = self.remote.command("map/to_gps", {"transform": transform.to_json()}) + return GpsData(j["latitude"], j["longitude"], j["northing"], j["easting"], j["altitude"], j["orientation"]) + + def map_from_gps(self, latitude=None, longitude=None, northing=None, easting=None, altitude=None, orientation=None): + c = [] + coord = { + "latitude": latitude, + "longitude": longitude, + "northing": northing, + "easting": easting, + "altitude": altitude, + "orientation": orientation + } + c.append(coord) + return self.map_from_gps_batch(c)[0] + + def map_from_gps_batch(self, coords): + # coords dictionary + jarr = [] + + for c in coords: + j = {} + numtype = (int, float) + if ("latitude" in c and c["latitude"] is not None) and ("longitude" in c and c["longitude"] is not None): + if not isinstance(c["latitude"], numtype): raise TypeError("Argument 'latitude' should have '{}' type".format(numtype)) + if not isinstance(c["longitude"], numtype): raise TypeError("Argument 'longitude' should have '{}' type".format(numtype)) + if c["latitude"] < -90 or c["latitude"] > 90: raise ValueError("Latitude is out of range") + if c["longitude"] < -180 or c["longitude"] > 180: raise ValueError("Longitude is out of range") + j["latitude"] = c["latitude"] + j["longitude"] = c["longitude"] + elif ("northing" in c and c["northing"] is not None) and ("easting" in c and c["easting"] is not None): + if not isinstance(c["northing"], numtype): raise TypeError("Argument 'northing' should have '{}' type".format(numtype)) + if not isinstance(c["easting"], numtype): raise TypeError("Argument 'easting' should have '{}' type".format(numtype)) + if c["northing"] < 0 or c["northing"] > 10000000: raise ValueError("Northing is out of range") + if c["easting"] < 160000 or c["easting"] > 834000: raise ValueError("Easting is out of range") + j["northing"] = c["northing"] + j["easting"] = c["easting"] + else: + raise Exception("Either latitude and longitude or northing and easting should be specified") + if "altitude" in c and c["altitude"] is not None: + if not isinstance(c["altitude"], numtype): raise TypeError("Argument 'altitude' should have '{}' type".format(numtype)) + j["altitude"] = c["altitude"] + if "orientation" in c and c["orientation"] is not None: + if not isinstance(c["orientation"], numtype): raise TypeError("Argument 'orientation' should have '{}' type".format(numtype)) + j["orientation"] = c["orientation"] + jarr.append(j) + + jarr = self.remote.command("map/from_gps", jarr) + transforms = [] + for j in jarr: + transforms.append(Transform.from_json(j)) + return transforms + + @accepts(Vector) + def map_point_on_lane(self, point): + j = self.remote.command("map/point_on_lane", {"point": point.to_json()}) + return Transform.from_json(j) + + @accepts(Vector, Vector, int, float) + def raycast(self, origin, direction, layer_mask=-1, max_distance=float("inf")): + hit = self.remote.command("simulator/raycast", [{ + "origin": origin.to_json(), + "direction": direction.to_json(), + "layer_mask": layer_mask, + "max_distance": max_distance + }]) + if hit[0] is None: + return None + return RaycastHit(hit[0]["distance"], Vector.from_json(hit[0]["point"]), Vector.from_json(hit[0]["normal"])) + + def raycast_batch(self, args): + jarr = [] + for arg in args: + jarr.append({ + "origin": arg["origin"].to_json(), + "direction": arg["direction"].to_json(), + "layer_mask": arg["layer_mask"], + "max_distance": arg["max_distance"] + }) + + hits = self.remote.command("simulator/raycast", jarr) + results = [] + for hit in hits: + if hit is None: + results.append(None) + else: + results.append(RaycastHit(hit["distance"], Vector.from_json(hit["point"]), Vector.from_json(hit["normal"]))) + + return results + + @accepts(str, ObjectState) + def controllable_add(self, name, object_state=None): + if object_state is None: object_state = ObjectState() + args = {"name": name, "state": object_state.to_json()} + j = self.remote.command("simulator/controllable_add", args) + controllable = Controllable(self.remote, j) + controllable.name = name + return controllable + + @accepts(Controllable) + def controllable_remove(self, controllable): + self.remote.command("simulator/controllable_remove", {"uid": controllable.uid}) + del self.controllables[controllable.uid] + + @accepts(str) + def get_controllables(self, control_type=None): + j = self.remote.command("controllable/get/all", { + "type": control_type, + }) + return [Controllable(self.remote, controllable) for controllable in j] + + @accepts(Vector, str) + def get_controllable(self, position, control_type=None): + j = self.remote.command("controllable/get", { + "position": position.to_json(), + "type": control_type, + }) + return Controllable(self.remote, j) diff --git a/lgsvl/utils.py b/lgsvl/utils.py index 2556775..83775a6 100644 --- a/lgsvl/utils.py +++ b/lgsvl/utils.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -9,150 +9,164 @@ import math import inspect + def accepts(*types): - def check_accepts(f): - assert len(types) + 1 == f.__code__.co_argcount - def new_f(*args, **kwargs): - names = inspect.getfullargspec(f)[0] - it = zip(args[1:], types, names[1:]) - for (a, t, n) in it: - if not isinstance(a, t): - raise TypeError("Argument '{}' should have '{}' type".format(n, t)) - return f(*args, **kwargs) - new_f.__name__ = f.__name__ - return new_f - return check_accepts + def check_accepts(f): + assert len(types) + 1 == f.__code__.co_argcount + + def new_f(*args, **kwargs): + names = inspect.getfullargspec(f)[0] + it = zip(args[1:], types, names[1:]) + for (a, t, n) in it: + if not isinstance(a, t): + raise TypeError("Argument '{}' should have '{}' type".format(n, t)) + return f(*args, **kwargs) + new_f.__name__ = f.__name__ + return new_f + return check_accepts + class ObjectState: - def __init__(self, transform = None, velocity = None, angular_velocity = None): - if transform is None: transform = Transform() - if velocity is None: velocity = Vector() - if angular_velocity is None: angular_velocity = Vector() - self.transform = transform - self.velocity = velocity - self.angular_velocity = angular_velocity - - @property - def position(self): - return self.transform.position - - @property - def rotation(self): - return self.transform.rotation - - @property - def speed(self): - return math.sqrt( - self.velocity.x * self.velocity.x + - self.velocity.y * self.velocity.y + - self.velocity.z * self.velocity.z) - - @staticmethod - def from_json(j): - return ObjectState( - Transform.from_json(j["transform"]), - Vector.from_json(j["velocity"]), - Vector.from_json(j["angular_velocity"]), - ) - - def to_json(self): - return { - "transform": self.transform.to_json(), - "velocity": self.velocity.to_json(), - "angular_velocity": self.angular_velocity.to_json(), - } - - def __repr__(self): - return str({ - "transform": str(self.transform), - "velocity": str(self.velocity), - "angular_velocity": str(self.angular_velocity), - }) + def __init__(self, transform=None, velocity=None, angular_velocity=None): + if transform is None: + transform = Transform() + if velocity is None: + velocity = Vector() + if angular_velocity is None: + angular_velocity = Vector() + self.transform = transform + self.velocity = velocity + self.angular_velocity = angular_velocity + + @property + def position(self): + return self.transform.position + + @property + def rotation(self): + return self.transform.rotation + + @property + def speed(self): + return math.sqrt( + self.velocity.x * self.velocity.x + + self.velocity.y * self.velocity.y + + self.velocity.z * self.velocity.z + ) + + @staticmethod + def from_json(j): + return ObjectState( + Transform.from_json(j["transform"]), + Vector.from_json(j["velocity"]), + Vector.from_json(j["angular_velocity"]), + ) + + def to_json(self): + return { + "transform": self.transform.to_json(), + "velocity": self.velocity.to_json(), + "angular_velocity": self.angular_velocity.to_json(), + } + + def __repr__(self): + return str( + { + "transform": str(self.transform), + "velocity": str(self.velocity), + "angular_velocity": str(self.angular_velocity), + } + ) + def transform_to_matrix(tr): - px = tr.position.x - py = tr.position.y - pz = tr.position.z + px = tr.position.x + py = tr.position.y + pz = tr.position.z - ax = tr.rotation.x * math.pi / 180.0 - ay = tr.rotation.y * math.pi / 180.0 - az = tr.rotation.z * math.pi / 180.0 + ax = tr.rotation.x * math.pi / 180.0 + ay = tr.rotation.y * math.pi / 180.0 + az = tr.rotation.z * math.pi / 180.0 - sx, cx = math.sin(ax), math.cos(ax) - sy, cy = math.sin(ay), math.cos(ay) - sz, cz = math.sin(az), math.cos(az) + sx, cx = math.sin(ax), math.cos(ax) + sy, cy = math.sin(ay), math.cos(ay) + sz, cz = math.sin(az), math.cos(az) + + # Unity uses left-handed coordinate system, Rz * Rx * Ry order + return [ + [sx * sy * sz + cy * cz, cx * sz, sx * cy * sz - sy * cz, 0.0], + [sx * sy * cz - cy * sz, cx * cz, sy * sz + sx * cy * cz, 0.0], + [cx * sy, -sx, cx * cy, 0.0], + [px, py, pz, 1.0], + ] - # Unity uses left-handed coordinate system, Rz * Rx * Ry order - return [ [ sx * sy * sz + cy * cz, cx * sz, sx * cy * sz - sy * cz, 0.0 ], - [ sx * sy * cz - cy * sz, cx * cz, sy * sz + sx * cy * cz, 0.0 ], - [ cx * sy, -sx, cx * cy, 0.0 ], - [ px, py, pz, 1.0 ], - ] def transform_to_forward(tr): - ax = tr.rotation.x * math.pi / 180.0 - sx, cx = math.sin(ax), math.cos(ax) + ax = tr.rotation.x * math.pi / 180.0 + sx, cx = math.sin(ax), math.cos(ax) + + ay = tr.rotation.y * math.pi / 180.0 + sy, cy = math.sin(ay), math.cos(ay) - ay = tr.rotation.y * math.pi / 180.0 - sy, cy = math.sin(ay), math.cos(ay) + return Vector(cx * sy, -sx, cx * cy) - return Vector(cx * sy, -sx, cx * cy) def transform_to_up(tr): - ax = tr.rotation.x * math.pi / 180.0 - ay = tr.rotation.y * math.pi / 180.0 - az = tr.rotation.z * math.pi / 180.0 + ax = tr.rotation.x * math.pi / 180.0 + ay = tr.rotation.y * math.pi / 180.0 + az = tr.rotation.z * math.pi / 180.0 - sx, cx = math.sin(ax), math.cos(ax) - sy, cy = math.sin(ay), math.cos(ay) - sz, cz = math.sin(az), math.cos(az) + sx, cx = math.sin(ax), math.cos(ax) + sy, cy = math.sin(ay), math.cos(ay) + sz, cz = math.sin(az), math.cos(az) - return Vector(sx * sy * cz - cy * sz, cx * cz, sy * sz + sx * cy * cz) + return Vector(sx * sy * cz - cy * sz, cx * cz, sy * sz + sx * cy * cz) -def transform_to_right(tr): - ax = tr.rotation.x * math.pi / 180.0 - ay = tr.rotation.y * math.pi / 180.0 - az = tr.rotation.z * math.pi / 180.0 - sx, cx = math.sin(ax), math.cos(ax) - sy, cy = math.sin(ay), math.cos(ay) - sz, cz = math.sin(az), math.cos(az) +def transform_to_right(tr): + ax = tr.rotation.x * math.pi / 180.0 + ay = tr.rotation.y * math.pi / 180.0 + az = tr.rotation.z * math.pi / 180.0 - return Vector(sx * sy * sz + cy * cz, cx * sz, sx * cy * sz - sy * cz) + sx, cx = math.sin(ax), math.cos(ax) + sy, cy = math.sin(ay), math.cos(ay) + sz, cz = math.sin(az), math.cos(az) + return Vector(sx * sy * sz + cy * cz, cx * sz, sx * cy * sz - sy * cz) def vector_dot(a, b): - return a.x * b.x + a.y * b.y + a.z * b.z + return a.x * b.x + a.y * b.y + a.z * b.z # this works only with transformation matrices (no scaling, no projection) def matrix_inverse(m): - x = Vector(m[0][0], m[0][1], m[0][2]) - y = Vector(m[1][0], m[1][1], m[1][2]) - z = Vector(m[2][0], m[2][1], m[2][2]) - v = Vector(m[3][0], m[3][1], m[3][2]) - a = -vector_dot(v, x) - b = -vector_dot(v, y) - c = -vector_dot(v, z) - return [ [ x.x, y.x, z.x, 0.0 ], - [ x.y, y.y, z.y, 0.0 ], - [ x.z, y.z, z.z, 0.0 ], - [ a, b, c, 1.0 ], - ] + x = Vector(m[0][0], m[0][1], m[0][2]) + y = Vector(m[1][0], m[1][1], m[1][2]) + z = Vector(m[2][0], m[2][1], m[2][2]) + v = Vector(m[3][0], m[3][1], m[3][2]) + a = -vector_dot(v, x) + b = -vector_dot(v, y) + c = -vector_dot(v, z) + return [ + [x.x, y.x, z.x, 0.0], + [x.y, y.y, z.y, 0.0], + [x.z, y.z, z.z, 0.0], + [a, b, c, 1.0], + ] def matrix_multiply(a, b): - r = [[0, 0, 0, 0] for t in range(4)] - for i in range(4): - for j in range(4): - for k in range(4): - r[i][j] += a[i][k] * b[k][j] - return r + r = [[0, 0, 0, 0] for t in range(4)] + for i in range(4): + for j in range(4): + for k in range(4): + r[i][j] += a[i][k] * b[k][j] + return r def vector_multiply(v, m): - tmp = [None] * 3 - for i in range(3): - tmp[i] = v.x * m[0][i] + v.y * m[1][i] + v.z * m[2][i] + m[3][i] - return Vector(tmp[0], tmp[1], tmp[2]) + tmp = [None] * 3 + for i in range(3): + tmp[i] = v.x * m[0][i] + v.y * m[1][i] + v.z * m[2][i] + m[3][i] + return Vector(tmp[0], tmp[1], tmp[2]) diff --git a/quickstart/02-loading-scene-show-spawns.py b/quickstart/02-loading-scene-show-spawns.py index 3d50f50..07882a6 100755 --- a/quickstart/02-loading-scene-show-spawns.py +++ b/quickstart/02-loading-scene-show-spawns.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -14,13 +14,13 @@ # Loads the named map in the connected simulator. The available maps can be set up in web interface if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") print("Current Scene = {}".format(sim.current_scene)) # This will print out the position and rotation vectors for each of the spawn points in the loaded map spawns = sim.get_spawn() for spawn in sim.get_spawn(): - print(spawn) + print(spawn) diff --git a/quickstart/03-raycast.py b/quickstart/03-raycast.py index c0065fd..fe12799 100755 --- a/quickstart/03-raycast.py +++ b/quickstart/03-raycast.py @@ -10,9 +10,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") # The next few lines spawns an EGO vehicle in the map spawns = sim.get_spawn() @@ -37,31 +37,31 @@ # Included layers can be hit by the rays. Otherwise the ray will go through the layer layer_mask = 0 -for bit in [0, 10, 11, 12]: # do not put 9 here, to not hit EGO vehicle itself - layer_mask |= 1 << bit +for bit in [0, 10, 11, 12]: # do not put 9 here, to not hit EGO vehicle itself + layer_mask |= 1 << bit # raycast returns None if the ray doesn't collide with anything # hit also has the point property which is the Unity position vector of where the ray collided with something hit = sim.raycast(p, right, layer_mask) if hit: - print("Distance right:", hit.distance) + print("Distance right:", hit.distance) hit = sim.raycast(p, -right, layer_mask) if hit: - print("Distance left:", hit.distance) + print("Distance left:", hit.distance) hit = sim.raycast(p, -forward, layer_mask) if hit: - print("Distance back:", hit.distance) + print("Distance back:", hit.distance) hit = sim.raycast(p, forward, layer_mask) if hit: - print("Distance forward:", hit.distance) + print("Distance forward:", hit.distance) hit = sim.raycast(p, up, layer_mask) if hit: - print("Distance up:", hit.distance) + print("Distance up:", hit.distance) hit = sim.raycast(p, -up, layer_mask) if hit: - print("Distance down:", hit.distance) + print("Distance down:", hit.distance) diff --git a/quickstart/04-ego-drive-straight.py b/quickstart/04-ego-drive-straight.py index fffb250..1fe0046 100755 --- a/quickstart/04-ego-drive-straight.py +++ b/quickstart/04-ego-drive-straight.py @@ -10,9 +10,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() @@ -34,14 +34,14 @@ input("Press Enter to drive forward for 2 seconds") # The simulator can be run for a set amount of time. time_limit is optional and if omitted or set to 0, then the simulator will run indefinitely -sim.run(time_limit = 2.0) +sim.run(time_limit=2.0) print("Current time = ", sim.current_time) print("Current frame = ", sim.current_frame) input("Press Enter to continue driving for 2 seconds") -sim.run(time_limit = 2.0) +sim.run(time_limit=2.0) print("Current time = ", sim.current_time) print("Current frame = ", sim.current_frame) diff --git a/quickstart/05-ego-drive-in-circle.py b/quickstart/05-ego-drive-in-circle.py index 652b0ba..38b252e 100755 --- a/quickstart/05-ego-drive-in-circle.py +++ b/quickstart/05-ego-drive-in-circle.py @@ -10,16 +10,16 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) -state.transform.position += 5 * forward# 5m forwards +state.transform.position += 5 * forward # 5m forwards ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) print("Current time = ", sim.current_time) diff --git a/quickstart/06-save-camera-image.py b/quickstart/06-save-camera-image.py index 4e4559d..946dc8a 100755 --- a/quickstart/06-save-camera-image.py +++ b/quickstart/06-save-camera-image.py @@ -10,9 +10,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() @@ -23,8 +23,8 @@ # get_sensors returns a list of sensors on the EGO vehicle sensors = ego.get_sensors() for s in sensors: - if s.name == "Main Camera": - # Camera and LIDAR sensors can save data to the specified file path - s.save("main-camera.png", compression=0) - s.save("main-camera.jpg", quality=75) - break + if s.name == "Main Camera": + # Camera and LIDAR sensors can save data to the specified file path + s.save("main-camera.png", compression=0) + s.save("main-camera.jpg", quality=75) + break diff --git a/quickstart/07-save-lidar-point-cloud.py b/quickstart/07-save-lidar-point-cloud.py index f5980ca..2d75812 100755 --- a/quickstart/07-save-lidar-point-cloud.py +++ b/quickstart/07-save-lidar-point-cloud.py @@ -10,9 +10,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() @@ -22,6 +22,6 @@ sensors = ego.get_sensors() for s in sensors: - if s.name == "Lidar": - s.save("lidar.pcd") - break + if s.name == "Lidar": + s.save("lidar.pcd") + break diff --git a/quickstart/08-create-npc.py b/quickstart/08-create-npc.py index b935b1f..12a458a 100755 --- a/quickstart/08-create-npc.py +++ b/quickstart/08-create-npc.py @@ -10,9 +10,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() @@ -27,9 +27,9 @@ # The first will be created in front of the EGO and then they will be created to the left # The available types of NPCs can be found in NPCManager prefab for i, name in enumerate(["Sedan", "SUV", "Jeep", "Hatchback"]): - state = lgsvl.AgentState() + state = lgsvl.AgentState() - # Spawn NPC vehicles 10 meters ahead of the EGO - state.transform.position = spawns[0].position + (10 * forward) - (4.0 * i * right) - state.transform.rotation = spawns[0].rotation - sim.add_agent(name, lgsvl.AgentType.NPC, state) + # Spawn NPC vehicles 10 meters ahead of the EGO + state.transform.position = spawns[0].position + (10 * forward) - (4.0 * i * right) + state.transform.rotation = spawns[0].rotation + sim.add_agent(name, lgsvl.AgentType.NPC, state) diff --git a/quickstart/09-reset-scene.py b/quickstart/09-reset-scene.py index ad43933..9b1a498 100755 --- a/quickstart/09-reset-scene.py +++ b/quickstart/09-reset-scene.py @@ -13,9 +13,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() @@ -26,13 +26,12 @@ forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) - for i, name in enumerate(["Sedan", "SUV", "Jeep", "Hatchback"]): - state = lgsvl.AgentState() - # 10 meters ahead - state.transform.position = spawns[0].position + (10 * forward) - (4.0 * i * right) - state.transform.rotation = spawns[0].rotation - sim.add_agent(name, lgsvl.AgentType.NPC, state) + state = lgsvl.AgentState() + # 10 meters ahead + state.transform.position = spawns[0].position + (10 * forward) - (4.0 * i * right) + state.transform.rotation = spawns[0].rotation + sim.add_agent(name, lgsvl.AgentType.NPC, state) input("Press Enter to reset") diff --git a/quickstart/10-npc-follow-the-lane.py b/quickstart/10-npc-follow-the-lane.py index a790c71..0564e43 100755 --- a/quickstart/10-npc-follow-the-lane.py +++ b/quickstart/10-npc-follow-the-lane.py @@ -10,9 +10,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() @@ -37,7 +37,7 @@ state.transform.position = spawns[0].position + 4.0 * right + 10.0 * forward state.transform.rotation = spawns[0].rotation -npc2 = sim.add_agent("SUV", lgsvl.AgentType.NPC, state, lgsvl.Vector(1,1,0)) +npc2 = sim.add_agent("SUV", lgsvl.AgentType.NPC, state, lgsvl.Vector(1, 1, 0)) # If the passed bool is False, then the NPC will not moved # The float passed is the maximum speed the NPC will drive diff --git a/quickstart/11-collision-callbacks.py b/quickstart/11-collision-callbacks.py index 40032ea..1872824 100755 --- a/quickstart/11-collision-callbacks.py +++ b/quickstart/11-collision-callbacks.py @@ -10,9 +10,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() @@ -36,19 +36,21 @@ state.transform.rotation = spawns[0].rotation sedan = sim.add_agent("Sedan", lgsvl.AgentType.NPC, state) # Even though the sedan is commanded to follow the lane, obstacle avoidance takes precedence and it will not drive into the bus -sedan.follow_closest_lane(True, 11.1) # 11.1 m/s is ~40 km/h +sedan.follow_closest_lane(True, 11.1) # 11.1 m/s is ~40 km/h vehicles = { - ego: "EGO", - bus: "SchoolBus", - sedan: "Sedan", + ego: "EGO", + bus: "SchoolBus", + sedan: "Sedan", } + # This function gets called whenever any of the 3 vehicles above collides with anything def on_collision(agent1, agent2, contact): - name1 = vehicles[agent1] - name2 = vehicles[agent2] if agent2 is not None else "OBSTACLE" - print("{} collided with {} at {}".format(name1, name2, contact)) + name1 = vehicles[agent1] + name2 = vehicles[agent2] if agent2 is not None else "OBSTACLE" + print("{} collided with {} at {}".format(name1, name2, contact)) + # The above on_collision function needs to be added to the callback list of each vehicle ego.on_collision(on_collision) diff --git a/quickstart/12-create-npc-on-lane.py b/quickstart/12-create-npc-on-lane.py index 8d6863e..2bd1cb4 100755 --- a/quickstart/12-create-npc-on-lane.py +++ b/quickstart/12-create-npc-on-lane.py @@ -12,9 +12,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() @@ -32,15 +32,15 @@ random.seed(0) while True: - input("Press Enter to spawn NPC") + input("Press Enter to spawn NPC") -# Creates a random point around the EGO - angle = random.uniform(0.0, 2*math.pi) - dist = random.uniform(mindist, maxdist) + # Creates a random point around the EGO + angle = random.uniform(0.0, 2 * math.pi) + dist = random.uniform(mindist, maxdist) - point = lgsvl.Vector(sx + dist * math.cos(angle), sy, sz + dist * math.sin(angle)) + point = lgsvl.Vector(sx + dist * math.cos(angle), sy, sz + dist * math.sin(angle)) -# Creates an NPC on a lane that is closest to the random point - state = lgsvl.AgentState() - state.transform = sim.map_point_on_lane(point) - sim.add_agent("Sedan", lgsvl.AgentType.NPC, state) + # Creates an NPC on a lane that is closest to the random point + state = lgsvl.AgentState() + state.transform = sim.map_point_on_lane(point) + sim.add_agent("Sedan", lgsvl.AgentType.NPC, state) diff --git a/quickstart/13-npc-follow-waypoints.py b/quickstart/13-npc-follow-waypoints.py index d6dd701..0e77c38 100755 --- a/quickstart/13-npc-follow-waypoints.py +++ b/quickstart/13-npc-follow-waypoints.py @@ -7,14 +7,13 @@ import os import lgsvl -import math import copy sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -35,15 +34,17 @@ npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, npc_state) vehicles = { - ego: "EGO", - npc: "Sedan", + ego: "EGO", + npc: "Sedan", } + # Executed upon receiving collision callback -- NPC is expected to drive through colliding objects def on_collision(agent1, agent2, contact): - name1 = vehicles[agent1] - name2 = vehicles[agent2] if agent2 is not None else "OBSTACLE" - print("{} collided with {}".format(name1, name2)) + name1 = vehicles[agent1] + name2 = vehicles[agent2] if agent2 is not None else "OBSTACLE" + print("{} collided with {}".format(name1, name2)) + ego.on_collision(on_collision) npc.on_collision(on_collision) @@ -55,24 +56,28 @@ def on_collision(agent1, agent2, contact): z_delta = 12 layer_mask = 0 -layer_mask |= 1 << 0 # 0 is the layer for the road (default) +layer_mask |= 1 << 0 # 0 is the layer for the road (default) for i in range(20): - speed = 24# if i % 2 == 0 else 12 - px = 0 - pz = (i + 1) * z_delta - # Waypoint angles are input as Euler angles (roll, pitch, yaw) - angle = spawns[0].rotation - # Raycast the points onto the ground because BorregasAve is not flat - hit = sim.raycast(spawns[0].position + pz * forward, lgsvl.Vector(0,-1,0), layer_mask) - - # NPC will wait for 1 second at each waypoint - wp = lgsvl.DriveWaypoint(hit.point, speed, angle, 1) - waypoints.append(wp) + speed = 24 # if i % 2 == 0 else 12 + px = 0 + pz = (i + 1) * z_delta + # Waypoint angles are input as Euler angles (roll, pitch, yaw) + angle = spawns[0].rotation + # Raycast the points onto the ground because BorregasAve is not flat + hit = sim.raycast( + spawns[0].position + pz * forward, lgsvl.Vector(0, -1, 0), layer_mask + ) + + # NPC will wait for 1 second at each waypoint + wp = lgsvl.DriveWaypoint(hit.point, speed, angle, 1) + waypoints.append(wp) + # When the NPC is within 0.5m of the waypoint, this will be called def on_waypoint(agent, index): - print("waypoint {} reached".format(index)) + print("waypoint {} reached".format(index)) + # The above function needs to be added to the list of callbacks for the NPC npc.on_waypoint_reached(on_waypoint) diff --git a/quickstart/14-create-pedestrians.py b/quickstart/14-create-pedestrians.py index 992eb37..ab474da 100755 --- a/quickstart/14-create-pedestrians.py +++ b/quickstart/14-create-pedestrians.py @@ -12,9 +12,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() @@ -27,16 +27,30 @@ input("Press Enter to start creating pedestrians") # The list of available pedestrians can be found in PedestrianManager prefab -names = ["Bob", "EntrepreneurFemale", "Howard", "Johny", "Pamela", "Presley", "Robin", "Stephen", "Zoe"] +names = [ + "Bob", + "EntrepreneurFemale", + "Howard", + "Johny", + "Pamela", + "Presley", + "Robin", + "Stephen", + "Zoe", +] i = 0 while True: - state = lgsvl.AgentState() - - state.transform.position = spawns[0].position + (5 + (1.0 * (i//16))) * forward + (5 - (1.0 * (i % 16))) * right - state.transform.rotation = spawns[0].rotation - name = random.choice(names) - print("({}) adding {}".format(i+1, name)) - p = sim.add_agent(name, lgsvl.AgentType.PEDESTRIAN, state) - time.sleep(0.1) - i += 1 + state = lgsvl.AgentState() + + state.transform.position = ( + spawns[0].position + + (5 + (1.0 * (i // 16))) * forward + + (5 - (1.0 * (i % 16))) * right + ) + state.transform.rotation = spawns[0].rotation + name = random.choice(names) + print("({}) adding {}".format(i + 1, name)) + p = sim.add_agent(name, lgsvl.AgentType.PEDESTRIAN, state) + time.sleep(0.1) + i += 1 diff --git a/quickstart/15-pedestrian-walk-randomly.py b/quickstart/15-pedestrian-walk-randomly.py index 19d9ce6..71b4e9d 100755 --- a/quickstart/15-pedestrian-walk-randomly.py +++ b/quickstart/15-pedestrian-walk-randomly.py @@ -7,13 +7,12 @@ import os import lgsvl -import random sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) diff --git a/quickstart/16-pedestrian-follow-waypoints.py b/quickstart/16-pedestrian-follow-waypoints.py index 9367042..a3c8e94 100755 --- a/quickstart/16-pedestrian-follow-waypoints.py +++ b/quickstart/16-pedestrian-follow-waypoints.py @@ -7,14 +7,13 @@ import os import lgsvl -import time import math sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[1]) @@ -29,11 +28,13 @@ count = 8 wp = [] for i in range(count): - x = radius * math.cos(i * 2 * math.pi / count) - z = radius * math.sin(i * 2 * math.pi / count) - # idle is how much time the pedestrian will wait once it reaches the waypoint - idle = 1 if i < count//2 else 0 - wp.append(lgsvl.WalkWaypoint(spawns[1].position + x * right + (z + 8) * forward, idle)) + x = radius * math.cos(i * 2 * math.pi / count) + z = radius * math.sin(i * 2 * math.pi / count) + # idle is how much time the pedestrian will wait once it reaches the waypoint + idle = 1 if i < count // 2 else 0 + wp.append( + lgsvl.WalkWaypoint(spawns[1].position + x * right + (z + 8) * forward, idle) + ) state = lgsvl.AgentState() state.transform = spawns[1] @@ -41,8 +42,10 @@ p = sim.add_agent("Pamela", lgsvl.AgentType.PEDESTRIAN, state) + def on_waypoint(agent, index): - print("Waypoint {} reached".format(index)) + print("Waypoint {} reached".format(index)) + p.on_waypoint_reached(on_waypoint) diff --git a/quickstart/17-many-pedestrians-walking.py b/quickstart/17-many-pedestrians-walking.py index 2c06bbb..5dbfb32 100755 --- a/quickstart/17-many-pedestrians-walking.py +++ b/quickstart/17-many-pedestrians-walking.py @@ -11,9 +11,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() @@ -23,27 +23,39 @@ right = lgsvl.utils.transform_to_right(spawns[0]) ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) -names = ["Bob", "EntrepreneurFemale", "Howard", "Johny", "Pamela", "Presley", "Robin", "Stephen", "Zoe"] - -for i in range(20*6): - # Create peds in a block - start = spawns[0].position + (5 + (1.0 * (i//6))) * forward - (2 + (1.0 * (i % 6))) * right - end = start + 10 * forward - -# Give waypoints for the spawn location and 10m ahead - wp = [ lgsvl.WalkWaypoint(start, 0), - lgsvl.WalkWaypoint(end, 0), - ] - - state = lgsvl.AgentState() - state.transform.position = start - state.transform.rotation = spawns[0].rotation - name = random.choice(names) - -# Send the waypoints and make the pedestrian loop over the waypoints - p = sim.add_agent(name, lgsvl.AgentType.PEDESTRIAN, state) - p.follow(wp, True) - -input("Press Enter to start") +names = [ + "Bob", + "EntrepreneurFemale", + "Howard", + "Johny", + "Pamela", + "Presley", + "Robin", + "Stephen", + "Zoe", +] + +for i in range(20 * 6): + # Create peds in a block + start = ( + spawns[0].position + + (5 + (1.0 * (i // 6))) * forward + - (2 + (1.0 * (i % 6))) * right + ) + end = start + 10 * forward + + # Give waypoints for the spawn location and 10m ahead + wp = [lgsvl.WalkWaypoint(start, 0), lgsvl.WalkWaypoint(end, 0)] + + state = lgsvl.AgentState() + state.transform.position = start + state.transform.rotation = spawns[0].rotation + name = random.choice(names) + + # Send the waypoints and make the pedestrian loop over the waypoints + p = sim.add_agent(name, lgsvl.AgentType.PEDESTRIAN, state) + p.follow(wp, True) + + input("Press Enter to start") sim.run() diff --git a/quickstart/18-weather-effects.py b/quickstart/18-weather-effects.py index 86c3ae0..8aa43d3 100755 --- a/quickstart/18-weather-effects.py +++ b/quickstart/18-weather-effects.py @@ -10,9 +10,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() @@ -24,7 +24,7 @@ input("Press Enter to set rain to 80%") -# Each weather variable is a float from 0 to 1 +# Each weather variable is a float from 0 to 1 # There is no default value so each varible must be specified sim.weather = lgsvl.WeatherState(rain=0.8, fog=0, wetness=0) print(sim.weather) diff --git a/quickstart/19-time-of-day.py b/quickstart/19-time-of-day.py index 90f412f..c81e9be 100755 --- a/quickstart/19-time-of-day.py +++ b/quickstart/19-time-of-day.py @@ -7,13 +7,12 @@ import os import lgsvl -import time sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() diff --git a/quickstart/20-enable-sensors.py b/quickstart/20-enable-sensors.py index 31fb638..ebd69aa 100755 --- a/quickstart/20-enable-sensors.py +++ b/quickstart/20-enable-sensors.py @@ -10,9 +10,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() @@ -26,13 +26,13 @@ # By default all sensors are enabled # Disabling sensor will prevent it to send or receive messages to ROS or Cyber bridges for s in sensors: - print(type(s), s.enabled) + print(type(s), s.enabled) input("Press Enter to disable lidar") for s in sensors: - if isinstance(s, lgsvl.LidarSensor): - s.enabled = False + if isinstance(s, lgsvl.LidarSensor): + s.enabled = False for s in sensors: - print(type(s), s.enabled) + print(type(s), s.enabled) diff --git a/quickstart/21-map-coordinates.py b/quickstart/21-map-coordinates.py index e81afee..cb0aec1 100755 --- a/quickstart/21-map-coordinates.py +++ b/quickstart/21-map-coordinates.py @@ -10,9 +10,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() @@ -26,8 +26,13 @@ # This function can take either lat/long or northing/easting pairs as inputs and will provide equivalent position and rotation vectors # Altitude and orientation are optional -t1 = sim.map_from_gps(northing = gps.northing, easting = gps.easting, altitude = gps.altitude, orientation = gps.orientation) +t1 = sim.map_from_gps( + northing=gps.northing, + easting=gps.easting, + altitude=gps.altitude, + orientation=gps.orientation, +) print("Transform from northing/easting: {}".format(t1)) -t2 = sim.map_from_gps(latitude = gps.latitude, longitude = gps.longitude) +t2 = sim.map_from_gps(latitude=gps.latitude, longitude=gps.longitude) print("Transform from lat/long without altitude/orientation: {}".format(t2)) diff --git a/quickstart/22-connecting-bridge.py b/quickstart/22-connecting-bridge.py index bf1d085..90bd711 100755 --- a/quickstart/22-connecting-bridge.py +++ b/quickstart/22-connecting-bridge.py @@ -11,9 +11,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() @@ -30,7 +30,7 @@ print("Waiting for connection...") while not a.bridge_connected: - time.sleep(1) + time.sleep(1) print("Bridge connected:", a.bridge_connected) diff --git a/quickstart/23-npc-callbacks.py b/quickstart/23-npc-callbacks.py index b316f37..f76ae79 100755 --- a/quickstart/23-npc-callbacks.py +++ b/quickstart/23-npc-callbacks.py @@ -12,9 +12,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -29,26 +29,33 @@ random.seed(0) + # Along with collisions and waypoints, NPCs can send a callback when they change lanes and reach a stopline def on_stop_line(agent): - print(agent.name, "reached stop line") + print(agent.name, "reached stop line") + # This will be called when an NPC begins to change lanes def on_lane_change(agent): - print(agent.name, "is changing lanes") + print(agent.name, "is changing lanes") + # This creates 4 NPCs randomly in an area around the EGO for name in ["Sedan", "SUV", "Jeep", "Hatchback"]: - angle = random.uniform(0.0, 2*math.pi) - dist = random.uniform(mindist, maxdist) - - point = spawns[0].position + dist * math.sin(angle) * right + (225 + dist * math.cos(angle)) * forward - - state = lgsvl.AgentState() - state.transform = sim.map_point_on_lane(point) - npc = sim.add_agent(name, lgsvl.AgentType.NPC, state) - npc.follow_closest_lane(True, 10) - npc.on_lane_change(on_lane_change) - npc.on_stop_line(on_stop_line) + angle = random.uniform(0.0, 2 * math.pi) + dist = random.uniform(mindist, maxdist) + + point = ( + spawns[0].position + + dist * math.sin(angle) * right + + (225 + dist * math.cos(angle)) * forward + ) + + state = lgsvl.AgentState() + state.transform = sim.map_point_on_lane(point) + npc = sim.add_agent(name, lgsvl.AgentType.NPC, state) + npc.follow_closest_lane(True, 10) + npc.on_lane_change(on_lane_change) + npc.on_stop_line(on_stop_line) sim.run() diff --git a/quickstart/24-ego-drive-straight-non-realtime.py b/quickstart/24-ego-drive-straight-non-realtime.py index b262bcd..bbeed0a 100755 --- a/quickstart/24-ego-drive-straight-non-realtime.py +++ b/quickstart/24-ego-drive-straight-non-realtime.py @@ -11,9 +11,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() @@ -32,7 +32,7 @@ # The simulator can be run for a set amount of time. time_limit is optional and if omitted or set to 0, then the simulator will run indefinitely t0 = time.time() -sim.run(time_limit = 4, time_scale = 2) +sim.run(time_limit=4, time_scale=2) t1 = time.time() print("Real time elapsed =", t1 - t0) print("Simulation time =", sim.current_time) @@ -44,7 +44,7 @@ input("Press Enter to continue driving for 2 more seconds (0.5x)") t2 = time.time() -sim.run(time_limit = 2, time_scale = 0.5) +sim.run(time_limit=2, time_scale=0.5) t3 = time.time() print("Real time elapsed =", t3 - t2) diff --git a/quickstart/25-waypoint-flying-npc.py b/quickstart/25-waypoint-flying-npc.py index 5d61bb8..46937c6 100755 --- a/quickstart/25-waypoint-flying-npc.py +++ b/quickstart/25-waypoint-flying-npc.py @@ -10,9 +10,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() @@ -30,34 +30,41 @@ state.transform.rotation = spawns[0].rotation npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, state) - # This block creates the list of waypoints that the NPC will follow # Each waypoint consists of a position vector, speed, and an angular orientation vector waypoints = [] z_delta = 12 layer_mask = 0 -layer_mask |= 1 << 0 # 0 is the layer for the road (default) +layer_mask |= 1 << 0 # 0 is the layer for the road (default) px = 0 py = 0.5 for i in range(75): - speed = 6 - px = 0 - py = ((i + 1) * 0.05) if (i < 50) else (50 * 0.05 + (50 - i) * 0.05) - pz = i * z_delta * 0.05 + speed = 6 + px = 0 + py = ((i + 1) * 0.05) if (i < 50) else (50 * 0.05 + (50 - i) * 0.05) + pz = i * z_delta * 0.05 + + angle = lgsvl.Vector(i, 0, 3 * i) - angle = lgsvl.Vector(i, 0, 3*i) + # Raycast the points onto the ground because BorregasAve is not flat + hit = sim.raycast( + spawns[0].position + px * right + pz * forward, + lgsvl.Vector(0, -1, 0), + layer_mask, + ) - # Raycast the points onto the ground because BorregasAve is not flat - hit = sim.raycast(spawns[0].position + px * right + pz * forward, lgsvl.Vector(0,-1,0), layer_mask) + wp = lgsvl.DriveWaypoint( + spawns[0].position + px * right + py * up + pz * forward, speed, angle, 0, 0 + ) + waypoints.append(wp) - wp = lgsvl.DriveWaypoint(spawns[0].position + px * right + py * up + pz * forward, speed, angle, 0, 0) - waypoints.append(wp) # When the NPC is within 1m of the waypoint, this will be called def on_waypoint(agent, index): - print("waypoint {} reached".format(index)) + print("waypoint {} reached".format(index)) + # The above function needs to be added to the list of callbacks for the NPC npc.on_waypoint_reached(on_waypoint) diff --git a/quickstart/26-npc-trigger-waypoints.py b/quickstart/26-npc-trigger-waypoints.py index f3f291f..4b9921c 100755 --- a/quickstart/26-npc-trigger-waypoints.py +++ b/quickstart/26-npc-trigger-waypoints.py @@ -10,9 +10,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() @@ -30,15 +30,17 @@ npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, state) vehicles = { - ego: "EGO", - npc: "Sedan", + ego: "EGO", + npc: "Sedan", } + # Executed upon receiving collision callback -- NPC is expected to drive through colliding objects def on_collision(agent1, agent2, contact): - name1 = vehicles[agent1] - name2 = vehicles[agent2] if agent2 is not None else "OBSTACLE" - print("{} collided with {}".format(name1, name2)) + name1 = vehicles[agent1] + name2 = vehicles[agent2] if agent2 is not None else "OBSTACLE" + print("{} collided with {}".format(name1, name2)) + ego.on_collision(on_collision) npc.on_collision(on_collision) @@ -49,27 +51,35 @@ def on_collision(agent1, agent2, contact): z_delta = 12 layer_mask = 0 -layer_mask |= 1 << 0 # 0 is the layer for the road (default) +layer_mask |= 1 << 0 # 0 is the layer for the road (default) for i in range(20): - speed = 24# if i % 2 == 0 else 12 - px = 0 - pz = (i + 1) * z_delta - # Waypoint angles are input as Euler angles (roll, pitch, yaw) - angle = spawns[0].rotation - # Raycast the points onto the ground because BorregasAve is not flat - hit = sim.raycast(spawns[0].position + px * right + pz * forward, lgsvl.Vector(0,-1,0), layer_mask) - - # Trigger is set to 10 meters for every other waypoint (0 means no trigger) - tr = 0 - if (i % 2): - tr = 10 - wp = lgsvl.DriveWaypoint(position=hit.point, speed=speed, angle=angle, idle=0, trigger_distance=tr) - waypoints.append(wp) + speed = 24 # if i % 2 == 0 else 12 + px = 0 + pz = (i + 1) * z_delta + # Waypoint angles are input as Euler angles (roll, pitch, yaw) + angle = spawns[0].rotation + # Raycast the points onto the ground because BorregasAve is not flat + hit = sim.raycast( + spawns[0].position + px * right + pz * forward, + lgsvl.Vector(0, -1, 0), + layer_mask, + ) + + # Trigger is set to 10 meters for every other waypoint (0 means no trigger) + tr = 0 + if i % 2: + tr = 10 + wp = lgsvl.DriveWaypoint( + position=hit.point, speed=speed, angle=angle, idle=0, trigger_distance=tr + ) + waypoints.append(wp) + # When the NPC is within 0.5m of the waypoint, this will be called def on_waypoint(agent, index): - print("waypoint {} reached".format(index)) + print("waypoint {} reached".format(index)) + # The above function needs to be added to the list of callbacks for the NPC npc.on_waypoint_reached(on_waypoint) diff --git a/quickstart/27-control-traffic-lights.py b/quickstart/27-control-traffic-lights.py index 8773760..a0aefec 100755 --- a/quickstart/27-control-traffic-lights.py +++ b/quickstart/27-control-traffic-lights.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -13,9 +13,9 @@ scene_name = "BorregasAve" if sim.current_scene == scene_name: - sim.reset() + sim.reset() else: - sim.load(scene_name, 42) + sim.load(scene_name, 42) spawns = sim.get_spawn() @@ -31,7 +31,7 @@ controllables = sim.get_controllables("signal") print("\n# List of controllable objects in {} scene:".format(scene_name)) for c in controllables: - print(c) + print(c) signal = sim.get_controllable(lgsvl.Vector(15.5, 4.7, -23.9), "signal") print("\n# Signal of interest:") diff --git a/quickstart/28-control-traffic-cone.py b/quickstart/28-control-traffic-cone.py index c2e1ac2..67332b2 100755 --- a/quickstart/28-control-traffic-cone.py +++ b/quickstart/28-control-traffic-cone.py @@ -13,9 +13,9 @@ scene_name = "CubeTown" if sim.current_scene == scene_name: - sim.reset() + sim.reset() else: - sim.load(scene_name, 42) + sim.load(scene_name, 42) spawns = sim.get_spawn() @@ -29,20 +29,24 @@ print("Python API Quickstart #28: How to Add/Control Traffic Cone") -for i in range(10*3): - # Create controllables in a block - start = spawns[0].position + (5 + (1.0 * (i//6))) * forward - (2 + (1.0 * (i % 6))) * right - end = start + 10 * forward - - state = lgsvl.ObjectState() - state.transform.position = start - state.transform.rotation = spawns[0].rotation - # Set velocity and angular_velocity - state.velocity = 10 * up - state.angular_velocity = 6.5 * right - - # add controllable - o = sim.controllable_add("TrafficCone", state) +for i in range(10 * 3): + # Create controllables in a block + start = ( + spawns[0].position + + (5 + (1.0 * (i // 6))) * forward + - (2 + (1.0 * (i % 6))) * right + ) + end = start + 10 * forward + + state = lgsvl.ObjectState() + state.transform.position = start + state.transform.rotation = spawns[0].rotation + # Set velocity and angular_velocity + state.velocity = 10 * up + state.angular_velocity = 6.5 * right + + # add controllable + o = sim.controllable_add("TrafficCone", state) print("\nAdded {} Traffic Cones".format(i + 1)) diff --git a/quickstart/29-add-random-agents.py b/quickstart/29-add-random-agents.py index 4c66cb5..a049014 100755 --- a/quickstart/29-add-random-agents.py +++ b/quickstart/29-add-random-agents.py @@ -10,9 +10,9 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) diff --git a/quickstart/30-time-to-collision-trigger.py b/quickstart/30-time-to-collision-trigger.py index 3cea290..07aa8a7 100755 --- a/quickstart/30-time-to-collision-trigger.py +++ b/quickstart/30-time-to-collision-trigger.py @@ -10,44 +10,48 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() layer_mask = 0 -layer_mask |= 1 << 0 # 0 is the layer for the road (default) +layer_mask |= 1 << 0 # 0 is the layer for the road (default) # EGO state = lgsvl.AgentState() forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) spawn_state = spawns[0] -hit = sim.raycast(spawn_state.position+forward*40, lgsvl.Vector(0,-1,0), layer_mask) +hit = sim.raycast( + spawn_state.position + forward * 40, lgsvl.Vector(0, -1, 0), layer_mask +) spawn_state.position = hit.point state.transform = spawn_state -state.velocity = forward*2 +state.velocity = forward * 2 ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() -npc_position = lgsvl.Vector(-4,-1,-48) -hit = sim.raycast(npc_position, lgsvl.Vector(0,-1,0), layer_mask) -npc_rotation = lgsvl.Vector(0,16, 0) +npc_position = lgsvl.Vector(-4, -1, -48) +hit = sim.raycast(npc_position, lgsvl.Vector(0, -1, 0), layer_mask) +npc_rotation = lgsvl.Vector(0, 16, 0) state.transform.position = hit.point state.transform.rotation = npc_rotation npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, state) vehicles = { - ego: "EGO", - npc: "Sedan", + ego: "EGO", + npc: "Sedan", } + # Executed upon receiving collision callback -- NPC is expected to drive through colliding objects def on_collision(agent1, agent2, contact): - name1 = vehicles[agent1] - name2 = vehicles[agent2] if agent2 is not None else "OBSTACLE" - print("{} collided with {}".format(name1, name2)) + name1 = vehicles[agent1] + name2 = vehicles[agent2] if agent2 is not None else "OBSTACLE" + print("{} collided with {}".format(name1, name2)) + ego.on_collision(on_collision) npc.on_collision(on_collision) @@ -57,27 +61,37 @@ def on_collision(agent1, agent2, contact): waypoints = [] for i in range(2): - speed = 8 - # Waypoint angles are input as Euler angles (roll, pitch, yaw) - angle = npc_rotation - # Raycast the points onto the ground because BorregasAve is not flat - npc_position.x += 6 - npc_position.z += 21 - hit = sim.raycast(npc_position, lgsvl.Vector(0,-1,0), layer_mask) - - trigger = None - if i == 0: - effector = lgsvl.TriggerEffector("TimeToCollision", {}) - trigger = lgsvl.WaypointTrigger([effector]) - wp = lgsvl.DriveWaypoint(position=hit.point, speed=speed, angle=angle, idle=0, trigger_distance=0, trigger = trigger) - waypoints.append(wp) + speed = 8 + # Waypoint angles are input as Euler angles (roll, pitch, yaw) + angle = npc_rotation + # Raycast the points onto the ground because BorregasAve is not flat + npc_position.x += 6 + npc_position.z += 21 + hit = sim.raycast(npc_position, lgsvl.Vector(0, -1, 0), layer_mask) + + trigger = None + if i == 0: + effector = lgsvl.TriggerEffector("TimeToCollision", {}) + trigger = lgsvl.WaypointTrigger([effector]) + wp = lgsvl.DriveWaypoint( + position=hit.point, + speed=speed, + angle=angle, + idle=0, + trigger_distance=0, + trigger=trigger, + ) + waypoints.append(wp) + def on_waypoint(agent, index): - print("waypoint {} reached".format(index)) + print("waypoint {} reached".format(index)) + def agents_traversed_waypoints(): - print("All agents traversed their waypoints.") - sim.stop() + print("All agents traversed their waypoints.") + sim.stop() + # The above function needs to be added to the list of callbacks for the NPC npc.on_waypoint_reached(on_waypoint) diff --git a/quickstart/31-wait-for-distance-trigger.py b/quickstart/31-wait-for-distance-trigger.py index 3d86d3a..7bc4774 100755 --- a/quickstart/31-wait-for-distance-trigger.py +++ b/quickstart/31-wait-for-distance-trigger.py @@ -10,44 +10,48 @@ sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": - sim.reset() + sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve") spawns = sim.get_spawn() layer_mask = 0 -layer_mask |= 1 << 0 # 0 is the layer for the road (default) +layer_mask |= 1 << 0 # 0 is the layer for the road (default) # EGO state = lgsvl.AgentState() forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) spawn_state = spawns[0] -hit = sim.raycast(spawn_state.position+forward*40, lgsvl.Vector(0,-1,0), layer_mask) +hit = sim.raycast( + spawn_state.position + forward * 40, lgsvl.Vector(0, -1, 0), layer_mask +) spawn_state.position = hit.point state.transform = spawn_state -state.velocity = forward*2 +state.velocity = forward * 2 ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() -npc_position = lgsvl.Vector(-4,-1,-48) -hit = sim.raycast(npc_position, lgsvl.Vector(0,-1,0), layer_mask) -npc_rotation = lgsvl.Vector(0,16, 0) +npc_position = lgsvl.Vector(-4, -1, -48) +hit = sim.raycast(npc_position, lgsvl.Vector(0, -1, 0), layer_mask) +npc_rotation = lgsvl.Vector(0, 16, 0) state.transform.position = hit.point state.transform.rotation = npc_rotation npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, state) vehicles = { - ego: "EGO", - npc: "Sedan", + ego: "EGO", + npc: "Sedan", } + # Executed upon receiving collision callback -- NPC is expected to drive through colliding objects def on_collision(agent1, agent2, contact): - name1 = vehicles[agent1] - name2 = vehicles[agent2] if agent2 is not None else "OBSTACLE" - print("{} collided with {}".format(name1, name2)) + name1 = vehicles[agent1] + name2 = vehicles[agent2] if agent2 is not None else "OBSTACLE" + print("{} collided with {}".format(name1, name2)) + ego.on_collision(on_collision) npc.on_collision(on_collision) @@ -57,28 +61,38 @@ def on_collision(agent1, agent2, contact): waypoints = [] for i in range(2): - speed = 8# if i % 2 == 0 else 12 - # Waypoint angles are input as Euler angles (roll, pitch, yaw) - angle = npc_rotation - # Raycast the points onto the ground because BorregasAve is not flat - npc_position.x += 6 - npc_position.z += 21 - hit = sim.raycast(npc_position, lgsvl.Vector(0,-1,0), layer_mask) - - trigger = None - if i == 0: - parameters = {"max_distance": 4.0} - effector = lgsvl.TriggerEffector("WaitForDistance", parameters) - trigger = lgsvl.WaypointTrigger([effector]) - wp = lgsvl.DriveWaypoint(position=hit.point, speed=speed, angle=angle, idle=0, trigger_distance=0, trigger = trigger) - waypoints.append(wp) + speed = 8 # if i % 2 == 0 else 12 + # Waypoint angles are input as Euler angles (roll, pitch, yaw) + angle = npc_rotation + # Raycast the points onto the ground because BorregasAve is not flat + npc_position.x += 6 + npc_position.z += 21 + hit = sim.raycast(npc_position, lgsvl.Vector(0, -1, 0), layer_mask) + + trigger = None + if i == 0: + parameters = {"max_distance": 4.0} + effector = lgsvl.TriggerEffector("WaitForDistance", parameters) + trigger = lgsvl.WaypointTrigger([effector]) + wp = lgsvl.DriveWaypoint( + position=hit.point, + speed=speed, + angle=angle, + idle=0, + trigger_distance=0, + trigger=trigger, + ) + waypoints.append(wp) + def on_waypoint(agent, index): - print("waypoint {} reached".format(index)) + print("waypoint {} reached".format(index)) + def agents_traversed_waypoints(): - print("All agents traversed their waypoints.") - sim.stop() + print("All agents traversed their waypoints.") + sim.stop() + # The above function needs to be added to the list of callbacks for the NPC npc.on_waypoint_reached(on_waypoint) diff --git a/quickstart/32-pedestrian-time-to-collision.py b/quickstart/32-pedestrian-time-to-collision.py index 1aa98d5..fa2e84f 100644 --- a/quickstart/32-pedestrian-time-to-collision.py +++ b/quickstart/32-pedestrian-time-to-collision.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -25,7 +25,7 @@ state.transform.position = hit.point state.transform.rotation = lgsvl.Vector(0.0, 15.0, 0.0) forward = lgsvl.Vector(0.2, 0.0, 0.8) -state.velocity = forward*15 +state.velocity = forward * 15 a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) # Pedestrian @@ -37,10 +37,7 @@ state.transform.rotation = pedestrian_rotation pedestrian = sim.add_agent("Bob", lgsvl.AgentType.PEDESTRIAN, state) -agents = { - a: "EGO", - pedestrian: "Bob" -} +agents = {a: "EGO", pedestrian: "Bob"} # Executed upon receiving collision callback -- pedestrian is expected to walk into colliding objects @@ -59,14 +56,26 @@ def on_collision(agent1, agent2, contact): trigger = None speed = 3 -hit = sim.raycast(pedestrian_position+lgsvl.Vector(7.4, 0.0, -2.2), lgsvl.Vector(0, -1, 0), layer_mask) +hit = sim.raycast( + pedestrian_position + lgsvl.Vector(7.4, 0.0, -2.2), + lgsvl.Vector(0, -1, 0), + layer_mask, +) effector = lgsvl.TriggerEffector("TimeToCollision", {}) trigger = lgsvl.WaypointTrigger([effector]) -wp = lgsvl.WalkWaypoint(position=hit.point, speed=speed, idle=0, trigger_distance=0, trigger=trigger) +wp = lgsvl.WalkWaypoint( + position=hit.point, speed=speed, idle=0, trigger_distance=0, trigger=trigger +) waypoints.append(wp) -hit = sim.raycast(pedestrian_position+lgsvl.Vector(12.4, 0.0, -3.4), lgsvl.Vector(0, -1, 0), layer_mask) -wp = lgsvl.WalkWaypoint(position=hit.point, speed=speed, idle=0, trigger_distance=0, trigger=None) +hit = sim.raycast( + pedestrian_position + lgsvl.Vector(12.4, 0.0, -3.4), + lgsvl.Vector(0, -1, 0), + layer_mask, +) +wp = lgsvl.WalkWaypoint( + position=hit.point, speed=speed, idle=0, trigger_distance=0, trigger=None +) waypoints.append(wp) diff --git a/quickstart/98-npc-behaviour.py b/quickstart/98-npc-behaviour.py index 4ba51c1..4f7774d 100755 --- a/quickstart/98-npc-behaviour.py +++ b/quickstart/98-npc-behaviour.py @@ -18,26 +18,38 @@ print("Current Scene = {}".format(sim.current_scene)) # Loads the named map in the connected simulator. The available maps can be set up in web interface if sim.current_scene == map: - sim.reset() + sim.reset() else: - print("Loading Scene = {}".format(map)) - sim.load(map) + print("Loading Scene = {}".format(map)) + sim.load(map) agents = sim.available_agents print("agents:") for i in range(len(agents)): agent = agents[i] - if agent["name"]=="TrailerTruckTest": trailerAvailable |= 1 - if agent["name"]=="MackAnthemStandupSleeperCab2018": trailerAvailable |= 2 - print("#{:>2}: {} {:40} ({:9}) {}".format(i, ("✔️" if agent["loaded"] else "❌"), agent["name"], agent["NPCType"], agent["AssetGuid"])) + if agent["name"] == "TrailerTruckTest": + trailerAvailable |= 1 + if agent["name"] == "MackAnthemStandupSleeperCab2018": + trailerAvailable |= 2 + print( + "#{:>2}: {} {:40} ({:9}) {}".format( + i, + ("✔️" if agent["loaded"] else "❌"), + agent["name"], + agent["NPCType"], + agent["AssetGuid"], + ) + ) behaviours = sim.available_npc_behaviours print("behaviours:") for i in range(len(behaviours)): - if behaviours[i]["name"]=="NPCDrunkDriverBehaviour": drunkDriverAvailable = True - if behaviours[i]["name"]=="NPCTrailerBehaviour": trailerAvailable |= 4 + if behaviours[i]["name"] == "NPCDrunkDriverBehaviour": + drunkDriverAvailable = True + if behaviours[i]["name"] == "NPCTrailerBehaviour": + trailerAvailable |= 4 print("#{:>2}: {}".format(i, behaviours[i]["name"])) spawns = sim.get_spawn() @@ -50,19 +62,25 @@ maxdist = 40.0 random.seed(0) -trailerAvailable = (trailerAvailable==(1|2|4)) +trailerAvailable = trailerAvailable == (1 | 2 | 4) -print("Trailer support: {} Drunk Driver support: {}".format("✔️" if trailerAvailable else "❌", "✔️" if drunkDriverAvailable else "❌")) +print( + "Trailer support: {} Drunk Driver support: {}".format( + "✔️" if trailerAvailable else "❌", "✔️" if drunkDriverAvailable else "❌" + ) +) while True: if trailerAvailable: - inp = input("Enter index of Agent to spawn, t to spawn truck and trailer, r to run:") + inp = input( + "Enter index of Agent to spawn, t to spawn truck and trailer, r to run:" + ) else: inp = input("Enter index of Agent to spawn, r to run:") - angle = random.uniform(0.0, 2*math.pi) + angle = random.uniform(0.0, 2 * math.pi) dist = random.uniform(mindist, maxdist) - spawn = random.choice(spawns); + spawn = random.choice(spawns) sx = spawn.position.x sy = spawn.position.y sz = spawn.position.z @@ -70,21 +88,25 @@ state = lgsvl.AgentState() state.transform = sim.map_point_on_lane(point) - if (inp == "r"): + if inp == "r": print("running.") sim.run() - if (inp == "t" and trailerAvailable): - truck = sim.add_agent("MackAnthemStandupSleeperCab2018", lgsvl.AgentType.NPC, state) + if inp == "t" and trailerAvailable: + truck = sim.add_agent( + "MackAnthemStandupSleeperCab2018", lgsvl.AgentType.NPC, state + ) truck.follow_closest_lane(True, 5.6) trailer = sim.add_agent("TrailerTruckTest", lgsvl.AgentType.NPC, state) trailer.set_behaviour("NPCTrailerBehaviour") - sim.remote.command("agent/trailer/attach", {"trailer_uid": trailer.uid, "truck_uid": truck.uid}) + sim.remote.command( + "agent/trailer/attach", {"trailer_uid": trailer.uid, "truck_uid": truck.uid} + ) else: try: agentIndex = int(inp) - if (agentIndex > len(agents)): + if agentIndex > len(agents): print("index out of range") continue @@ -94,13 +116,21 @@ if drunkDriverAvailable: inp = input("make drunk driver? yN") - if (inp == "y" or inp == "Y"): + if inp == "y" or inp == "Y": npc.set_behaviour("NPCDrunkDriverBehaviour") - npc.remote.command("agent/drunk/config", { "uid": npc.uid, "correctionMinTime":0.0, "correctionMaxTime":0.6, "steerDriftMin": 0.00, "steerDriftMax":0.09}) + npc.remote.command( + "agent/drunk/config", + { + "uid": npc.uid, + "correctionMinTime": 0.0, + "correctionMaxTime": 0.6, + "steerDriftMin": 0.00, + "steerDriftMax": 0.09, + }, + ) npc.follow_closest_lane(True, 5.6) print("spawned agent {}, uid {}".format(agent, npc.uid)) except ValueError: print("expected a number") - diff --git a/quickstart/99-utils-examples.py b/quickstart/99-utils-examples.py index 3f968c4..9a482a3 100755 --- a/quickstart/99-utils-examples.py +++ b/quickstart/99-utils-examples.py @@ -5,8 +5,13 @@ # This software contains code licensed as described in LICENSE. # -from lgsvl import * -from lgsvl.utils import * +from lgsvl import Transform, Vector +from lgsvl.utils import ( + transform_to_matrix, + matrix_inverse, + matrix_multiply, + vector_multiply, +) # global "world" transform (for example, car position) world = Transform(Vector(10, 20, 30), Vector(11, 22, 33)) diff --git a/tests/__init__.py b/tests/__init__.py index 9fba5bb..49d8b69 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -13,6 +13,7 @@ from .test_peds import TestPeds from .test_utils import TestUtils + def load_tests(loader, standard_tests, pattern): suite = unittest.TestSuite() suite.addTests(loader.loadTestsFromTestCase(TestNPC)) # must be first diff --git a/tests/common.py b/tests/common.py index 33f0370..c7517a5 100644 --- a/tests/common.py +++ b/tests/common.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -8,58 +8,65 @@ import lgsvl import os + class TestTimeout(Exception): pass + class TestException(Exception): pass + class SimConnection: - def __init__(self, seconds=30, scene="BorregasAve", error_message=None, load_scene=True): - if error_message is None: - error_message = 'test timed out after {}s.'.format(seconds) - self.seconds = seconds - self.error_message = error_message - self.scene = scene - self.load_scene = load_scene - - def handle_timeout(self, signum, frame): - raise TestTimeout(self.error_message) - - def __enter__(self): - signal.signal(signal.SIGALRM, self.handle_timeout) - signal.alarm(self.seconds) - - self.sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) - if self.load_scene: - if self.sim.current_scene == self.scene: - self.sim.reset() - signal.alarm(self.seconds - 20) - else: - self.sim.load(self.scene) - return self.sim - - def __exit__(self, exc_type, exc_val, exc_tb): - signal.alarm(0) - # agents = self.sim.get_agents() - # for a in agents: - # self.sim.remove_agent(a) - self.sim.close() + def __init__(self, seconds=30, scene="BorregasAve", error_message=None, load_scene=True): + if error_message is None: + error_message = 'test timed out after {}s.'.format(seconds) + self.seconds = seconds + self.error_message = error_message + self.scene = scene + self.load_scene = load_scene + + def handle_timeout(self, signum, frame): + raise TestTimeout(self.error_message) + + def __enter__(self): + signal.signal(signal.SIGALRM, self.handle_timeout) + signal.alarm(self.seconds) + + self.sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) + if self.load_scene: + if self.sim.current_scene == self.scene: + self.sim.reset() + signal.alarm(self.seconds - 20) + else: + self.sim.load(self.scene) + return self.sim + + def __exit__(self, exc_type, exc_val, exc_tb): + signal.alarm(0) + # agents = self.sim.get_agents() + # for a in agents: + # self.sim.remove_agent(a) + self.sim.close() + def spawnState(sim, index=0): - state = lgsvl.AgentState() - state.transform = sim.get_spawn()[index] - return state + state = lgsvl.AgentState() + state.transform = sim.get_spawn()[index] + return state + + +def cmEqual(self, a, b, msg): # Test vectors within 1cm + self.assertAlmostEqual(a.x, b.x, 2, msg) + self.assertAlmostEqual(a.y, b.y, 2, msg) + self.assertAlmostEqual(a.z, b.z, 2, msg) + -def cmEqual(self, a, b, msg): # Test vectors within 1cm - self.assertAlmostEqual(a.x, b.x, 2, msg) - self.assertAlmostEqual(a.y, b.y, 2, msg) - self.assertAlmostEqual(a.z, b.z, 2, msg) +def mEqual(self, a, b, msg): # Test vectors within 1cm + self.assertAlmostEqual(a.x, b.x, delta=1.5, msg=msg) + self.assertAlmostEqual(a.y, b.y, delta=1.5, msg=msg) + self.assertAlmostEqual(a.z, b.z, delta=1.5, msg=msg) -def mEqual(self, a, b, msg): # Test vectors within 1cm - self.assertAlmostEqual(a.x, b.x, delta=1.5, msg=msg) - self.assertAlmostEqual(a.y, b.y, delta=1.5, msg=msg) - self.assertAlmostEqual(a.z, b.z, delta=1.5, msg=msg) def notAlmostEqual(a,b): - return round(a-b,7) != 0 + return round(a-b,7) != 0 diff --git a/tests/test_EGO.py b/tests/test_EGO.py index 392dfe9..df7240f 100644 --- a/tests/test_EGO.py +++ b/tests/test_EGO.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -8,18 +8,19 @@ import math import lgsvl -from .common import SimConnection, spawnState, cmEqual, notAlmostEqual +from .common import SimConnection, spawnState, cmEqual # TODO add tests for bridge connection + class TestEGO(unittest.TestCase): - def test_agent_name(self): # Check if EGO Apollo is created + def test_agent_name(self): # Check if EGO Apollo is created with SimConnection() as sim: agent = self.create_EGO(sim) self.assertEqual(agent.name, "Jaguar2015XE (Apollo 3.0)") - def test_different_spawns(self): # Check if EGO is spawned in the spawn positions + def test_different_spawns(self): # Check if EGO is spawned in the spawn positions with SimConnection() as sim: spawns = sim.get_spawn() agent = self.create_EGO(sim) @@ -33,7 +34,7 @@ def test_different_spawns(self): # Check if EGO is spawned in the spawn position cmEqual(self, agent2.state.position, spawns[1].position, "Spawn Position 1") cmEqual(self, agent2.state.rotation, spawns[1].rotation, "Spawn Rotation 1") - def test_agent_velocity(self): # Check EGO velocity + def test_agent_velocity(self): # Check EGO velocity with SimConnection(60) as sim: state = spawnState(sim) agent = self.create_EGO(sim) @@ -43,10 +44,10 @@ def test_agent_velocity(self): # Check EGO velocity right = lgsvl.utils.transform_to_right(state.transform) state.velocity = -50 * right agent = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) - + cmEqual(self, agent.state.velocity, state.velocity, "50 Velocity") - def test_ego_different_directions(self): # Check that the xyz velocities equate to xyz changes in position + def test_ego_different_directions(self): # Check that the xyz velocities equate to xyz changes in position with SimConnection(60) as sim: state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) @@ -59,7 +60,7 @@ def test_ego_different_directions(self): # Check that the xyz velocities equate target = state.position - 3 * right self.assertLess((ego.state.position - target).magnitude(), 1) sim.remove_agent(ego) - + state.velocity = 10 * up ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) sim.run(.5) @@ -73,7 +74,7 @@ def test_ego_different_directions(self): # Check that the xyz velocities equate target = state.position + 4 * forward self.assertLess((ego.state.position - target).magnitude(), 1) - def test_speed(self): # check that speed returns a reasonable number + def test_speed(self): # check that speed returns a reasonable number with SimConnection() as sim: state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) @@ -84,7 +85,7 @@ def test_speed(self): # check that speed returns a reasonable number self.assertAlmostEqual(ego.state.speed, math.sqrt(300), places=3) @unittest.skip("No highway in currents maps") - def test_rotation_on_highway_ramp(self): # Check that vehicle is rotated when spawned on the highway ramp + def test_rotation_on_highway_ramp(self): # Check that vehicle is rotated when spawned on the highway ramp with SimConnection() as sim: state = spawnState(sim) state.transform.position = lgsvl.Vector(469.6401, 15.67488, 100.4229) @@ -93,7 +94,7 @@ def test_rotation_on_highway_ramp(self): # Check that vehicle is rotated when sp sim.run(0.5) self.assertAlmostEqual(ego.state.rotation.z, 356, delta=0.5) - def test_ego_steering(self): # Check that a steering command can be given to an EGO vehicle, and the car turns + 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("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() @@ -105,7 +106,7 @@ def test_ego_steering(self): # Check that a steering command can be given to an finalRotation = ego.state.rotation self.assertNotAlmostEqual(initialRotation.y, finalRotation.y) - def test_ego_throttle(self): # Check that a throttle command can be given to an EGO vehicle, and the car accelerates + 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("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() @@ -116,7 +117,7 @@ def test_ego_throttle(self): # Check that a throttle command can be given to an finalSpeed = ego.state.speed self.assertGreater(finalSpeed, initialSpeed) - 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 + 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) @@ -128,7 +129,7 @@ def test_ego_braking(self): # Check that a brake command can be given to an EGO 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() @@ -142,7 +143,7 @@ def test_ego_braking(self): # Check that a brake command can be given to an EGO brakeDistance = (ego.state.position - state.position).magnitude() self.assertLess(brakeDistance, noBrakeDistance) - def test_ego_handbrake(self): # Check that the handbrake can be enable on an EGO vehicle, and the car stops sooner than without brakes + 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("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) @@ -154,7 +155,7 @@ def test_ego_handbrake(self): # Check that the handbrake can be enable on an EGO 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() @@ -167,8 +168,8 @@ def test_ego_handbrake(self): # Check that the handbrake can be enable on an EGO sim.run(3) brakeDistance = (ego.state.position - state.position).magnitude() self.assertLess(brakeDistance, noBrakeDistance) - - def test_ego_reverse(self): # Check that the gear can be changed in an EGO vehicle, and the car moves in reverse + + 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) @@ -182,7 +183,7 @@ def test_ego_reverse(self): # Check that the gear can be changed in an EGO vehic diff = ego.state.position - target self.assertLess((diff).magnitude(), 1) - def test_not_sticky_control(self): # Check that the a non sticky control is removed + 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("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) @@ -203,7 +204,7 @@ def test_not_sticky_control(self): # Check that the a non sticky control is remo finalSpeed = ego.state.speed self.assertGreater(stickySpeed, finalSpeed) - def test_vary_throttle(self): # Check that different throttle values accelerate differently + def test_vary_throttle(self): # Check that different throttle values accelerate differently with SimConnection(40) as sim: ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() @@ -220,7 +221,7 @@ def test_vary_throttle(self): # Check that different throttle values accelerate sim.run(1) self.assertLess(ego.state.speed, initialSpeed) - def test_vary_steering(self): # Check that different steering values turn the car differently + def test_vary_steering(self): # Check that different steering values turn the car differently with SimConnection(40) as sim: ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() @@ -239,7 +240,7 @@ def test_vary_steering(self): # Check that different steering values turn the ca sim.run(1) self.assertGreater(ego.state.rotation.y, initialAngle) - def test_bounding_box_size(self): # Check that the bounding box is calculated properly and is reasonable + def test_bounding_box_size(self): # Check that the bounding box is calculated properly and is reasonable with SimConnection() as sim: ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) bBox = ego.bounding_box @@ -250,7 +251,7 @@ def test_bounding_box_size(self): # Check that the bounding box is calculated pr self.assertLess(bBox.size.y, 10) self.assertLess(bBox.size.z, 10) - def test_bounding_box_center(self): # Check that the bounding box center is calcualted properly + def test_bounding_box_center(self): # Check that the bounding box center is calcualted properly with SimConnection() as sim: ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) bBox = ego.bounding_box @@ -258,7 +259,7 @@ def test_bounding_box_center(self): # Check that the bounding box center is calc self.assertAlmostEqual(bBox.center.y, (bBox.max.y+bBox.min.y)/2) self.assertAlmostEqual(bBox.center.z, (bBox.max.z+bBox.min.z)/2) - def test_equality(self): # Check that agent == operation works + def test_equality(self): # Check that agent == operation works with SimConnection() as sim: ego1 = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) ego2 = sim.add_agent("Jaguar2015XE (Autoware)", lgsvl.AgentType.EGO, spawnState(sim)) @@ -274,7 +275,7 @@ def test_set_fixed_speed(self): sim.run(5) self.assertAlmostEqual(ego.state.speed, 15, delta=1) - def create_EGO(self, sim): # Only create an EGO is none are already spawned + def create_EGO(self, sim): # Only create an EGO is none are already spawned return sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) # def test_large_throttle(self): diff --git a/tests/test_NPC.py b/tests/test_NPC.py index 6a07979..a4988c6 100644 --- a/tests/test_NPC.py +++ b/tests/test_NPC.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -7,15 +7,16 @@ import unittest import time import lgsvl -from .common import SimConnection, spawnState, cmEqual, mEqual, TestTimeout, TestException +from .common import SimConnection, spawnState, cmEqual, mEqual, TestException PROBLEM = "Object reference not set to an instance of an object" # TODO Add tests for callbacks for when NPC changes lanes, reaches stop line + class TestNPC(unittest.TestCase): -# THIS TEST RUNS FIRST + # THIS TEST RUNS FIRST def test_AAA_NPC_no_scene(self): with SimConnection(load_scene=False) as sim: with self.assertRaises(Exception) as e: @@ -24,7 +25,7 @@ def test_AAA_NPC_no_scene(self): agent.state.position self.assertFalse(repr(e.exception).startswith(PROBLEM)) - def test_NPC_creation(self): # Check if the different types of NPCs can be created + def test_NPC_creation(self): # Check if the different types of NPCs can be created with SimConnection(60) as sim: state = spawnState(sim) right = lgsvl.utils.transform_to_right(state.transform) @@ -57,7 +58,7 @@ def test_get_agents(self): with self.subTest(a): self.assertEqual(agentCounter[a], 1) - def test_NPC_follow_lane(self): #Check if NPC can follow lane + def test_NPC_follow_lane(self): # Check if NPC can follow lane with SimConnection() as sim: state = spawnState(sim) right = lgsvl.utils.transform_to_right(state.transform) @@ -68,10 +69,10 @@ def test_NPC_follow_lane(self): #Check if NPC can follow lane sim.run(2.0) agentState = agent.state self.assertGreater(agentState.speed, 0) - # self.assertAlmostEqual(agent.state.speed, 5.6, delta=1) + # self.assertAlmostEqual(agent.state.speed, 5.6, delta=1) self.assertLess(agent.state.position.x - sim.get_spawn()[0].position.x, 5.6*2) - def test_rotate_NPC(self): # Check if NPC can be rotated + def test_rotate_NPC(self): # Check if NPC can be rotated with SimConnection() as sim: state = spawnState(sim) right = lgsvl.utils.transform_to_right(state.transform) @@ -84,28 +85,28 @@ def test_rotate_NPC(self): # Check if NPC can be rotated agent.state = x self.assertAlmostEqual(agent.state.transform.rotation.y, 10, delta=0.1) - def test_blank_agent(self): # Check that an exception is raised if a blank name is given + def test_blank_agent(self): # Check that an exception is raised if a blank name is given with SimConnection() as sim: with self.assertRaises(Exception) as e: self.create_NPC(sim, "") self.assertFalse(repr(e.exception).startswith(PROBLEM)) - def test_int_agent(self): # Check that an exception is raised if an integer name is given + def test_int_agent(self): # Check that an exception is raised if an integer name is given with SimConnection() as sim: with self.assertRaises(TypeError): self.create_NPC(sim, 1) - def test_wrong_type_NPC(self): # Check that an exception is raised if 4 is given as the agent type + def test_wrong_type_NPC(self): # Check that an exception is raised if 4 is given as the agent type with SimConnection() as sim: with self.assertRaises(TypeError): sim.add_agent("SUV", 4, spawnState(sim)) - + def test_wrong_type_value(self): with SimConnection() as sim: with self.assertRaises(ValueError): sim.add_agent("SUV", lgsvl.AgentType(9), spawnState(sim)) - def test_upsidedown_NPC(self): # Check that an upside-down NPC keeps falling + def test_upsidedown_NPC(self): # Check that an upside-down NPC keeps falling with SimConnection() as sim: state = spawnState(sim) right = lgsvl.utils.transform_to_right(state.transform) @@ -119,7 +120,7 @@ def test_upsidedown_NPC(self): # Check that an upside-down NPC keeps falling final_height = agent.state.position.y self.assertLess(final_height, initial_height) - def test_flying_NPC(self): # Check if an NPC created above the map falls + def test_flying_NPC(self): # Check if an NPC created above the map falls with SimConnection() as sim: state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) @@ -134,7 +135,7 @@ def test_flying_NPC(self): # Check if an NPC created above the map falls final_height = agent.state.position.y self.assertLess(final_height, initial_height) - def test_underground_NPC(self): # Check if an NPC created below the map keeps falling + def test_underground_NPC(self): # Check if an NPC created below the map keeps falling with SimConnection() as sim: state = spawnState(sim) up = lgsvl.utils.transform_to_up(state.transform) @@ -145,7 +146,7 @@ def test_underground_NPC(self): # Check if an NPC created below the map keeps fa final_height = agent.state.position.y self.assertLess(final_height, initial_height) - def test_access_removed_NPC(self): # Check that and exception is raised when trying to access position of a removed NPC + def test_access_removed_NPC(self): # Check that and exception is raised when trying to access position of a removed NPC with SimConnection() as sim: state = spawnState(sim) agent = sim.add_agent("Hatchback", lgsvl.AgentType.NPC, state) @@ -155,7 +156,7 @@ def test_access_removed_NPC(self): # Check that and exception is raised when try agent.state.position self.assertFalse(repr(e.exception).startswith(PROBLEM)) - def test_follow_waypoints(self): # Check that the NPC can follow waypoints + def test_follow_waypoints(self): # Check that the NPC can follow waypoints with SimConnection(60) as sim: state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) @@ -164,7 +165,7 @@ def test_follow_waypoints(self): # Check that the NPC can follow waypoints sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) spawns = sim.get_spawn() agent = self.create_NPC(sim, "Sedan") - + # snake-drive layer_mask = 0 layer_mask |= 1 << 0 @@ -194,7 +195,7 @@ def on_waypoint(agent, index): sim.run() - def test_high_waypoint(self): # Check that a NPC will drive to under a high waypoint + def test_high_waypoint(self): # Check that a NPC will drive to under a high waypoint with SimConnection(15) as sim: state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) @@ -221,7 +222,7 @@ def on_waypoint(agent,index): self.assertLess((agent.state.position - destination).magnitude(), 1) - def test_npc_different_directions(self): # Check that specified velocities match the NPC's movement + def test_npc_different_directions(self): # Check that specified velocities match the NPC's movement with SimConnection() as sim: state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) @@ -251,7 +252,7 @@ def test_npc_different_directions(self): # Check that specified velocities match target = state.position + 4 * forward self.assertLess((npc.state.position - target).magnitude(), 1) - def test_stopline_callback(self): # Check that the stopline call back works properly + def test_stopline_callback(self): # Check that the stopline call back works properly with self.assertRaises(TestException) as e: with SimConnection(60) as sim: state = spawnState(sim) @@ -270,7 +271,7 @@ def on_stop_line(agent): sim.run(60) self.assertIn("Waypoint reached", repr(e.exception)) - def test_remove_npc_with_callback(self): # Check that an NPC with callbacks is removed properly + def test_remove_npc_with_callback(self): # Check that an NPC with callbacks is removed properly with SimConnection() as sim: npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, spawnState(sim)) @@ -287,7 +288,7 @@ def on_stop_line(agent): with self.assertRaises(KeyError): sim.callbacks[npc] - def test_spawn_speed(self): # Checks that a spawned agent keeps the correct speed when spawned + def test_spawn_speed(self): # Checks that a spawned agent keeps the correct speed when spawned with SimConnection() as sim: sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim, 1)) npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, spawnState(sim)) @@ -310,9 +311,10 @@ def test_lane_change_right(self): npc.follow_closest_lane(True, 10) agents = [] + def on_lane_change(agent): agents.append(agent) - + npc.on_lane_change(on_lane_change) sim.run(2) npc.change_lane(False) @@ -335,9 +337,10 @@ def test_lane_change_right_missing_lane(self): npc.follow_closest_lane(True, 10) agents = [] + def on_lane_change(agent): agents.append(agent) - + npc.on_lane_change(on_lane_change) sim.run(2) npc.change_lane(False) @@ -360,9 +363,10 @@ def test_lane_change_left(self): npc.follow_closest_lane(True, 10) agents = [] + def on_lane_change(agent): agents.append(agent) - + npc.on_lane_change(on_lane_change) sim.run(2) npc.change_lane(True) @@ -385,9 +389,10 @@ def test_lane_change_left_opposing_traffic(self): npc.follow_closest_lane(True, 10) agents = [] + def on_lane_change(agent): agents.append(agent) - + npc.on_lane_change(on_lane_change) sim.run(2) npc.change_lane(True) @@ -412,6 +417,7 @@ def test_multiple_lane_changes(self): npc.follow_closest_lane(True, 10) agents = [] + def on_lane_change(agent): agents.append(agent) @@ -441,7 +447,7 @@ def test_set_lights_exceptions(self): control = lgsvl.NPCControl() control.headlights = 2 npc.apply_control(control) - + with self.assertRaises(ValueError): control.headlights = 15 npc.apply_control(control) @@ -535,5 +541,5 @@ def on_waypoint(agent, index): # sim.run(2) # self.assertAlmostEqual(npc.state.speed, 8, delta=1) - def create_NPC(self, sim, name): # Create the specified NPC + def create_NPC(self, sim, name): # Create the specified NPC return sim.add_agent(name, lgsvl.AgentType.NPC, spawnState(sim)) diff --git a/tests/test_collisions.py b/tests/test_collisions.py index 8f79a1e..a254c61 100644 --- a/tests/test_collisions.py +++ b/tests/test_collisions.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -11,8 +11,9 @@ # TODO add tests for collisions between NPCs, EGO & obstacles + class TestCollisions(unittest.TestCase): - def test_ego_collision(self): # Check that a collision between Ego and NPC is reported + def test_ego_collision(self): # Check that a collision between Ego and NPC is reported with SimConnection() as sim: mover, bus = self.setup_collision(sim, "Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, "SchoolBus", lgsvl.AgentType.NPC) collisions = [] @@ -20,7 +21,7 @@ def test_ego_collision(self): # Check that a collision between Ego and NPC is re def on_collision(agent1, agent2, contact): collisions.append([agent1, agent2, contact]) sim.stop() - + mover.on_collision(on_collision) bus.on_collision(on_collision) @@ -32,7 +33,7 @@ def on_collision(agent1, agent2, contact): self.assertTrue(collisions[0][0].name == "Jaguar2015XE (Apollo 3.0)" or collisions[0][1].name == "Jaguar2015XE (Apollo 3.0)") self.assertTrue(True) - def test_sim_stop(self): # Check that sim.stop works properly + def test_sim_stop(self): # Check that sim.stop works properly with SimConnection() as sim: mover, bus = self.setup_collision(sim, "Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, "SchoolBus", lgsvl.AgentType.NPC) collisions = [] @@ -40,7 +41,7 @@ def test_sim_stop(self): # Check that sim.stop works properly def on_collision(agent1, agent2, contact): collisions.append([agent1, agent2, contact]) sim.stop() - + mover.on_collision(on_collision) bus.on_collision(on_collision) @@ -48,7 +49,7 @@ def on_collision(agent1, agent2, contact): self.assertLess(sim.current_time, 15.0) - def test_ped_collision(self): # Check if a collision between EGO and pedestrian is reported + def test_ped_collision(self): # Check if a collision between EGO and pedestrian is reported with SimConnection() as sim: ego, ped = self.setup_collision(sim, "Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, "Howard", lgsvl.AgentType.PEDESTRIAN) self.assertTrue(isinstance(ego, lgsvl.EgoVehicle)) @@ -67,7 +68,7 @@ def on_collision(agent1, agent2, contact): self.assertTrue(collisions[0][0].name == "Jaguar2015XE (Apollo 3.0)" or collisions[0][1].name == "Jaguar2015XE (Apollo 3.0)") @unittest.skip("NPCs ignore collisions with Pedestrians, activate this when NPCs use real physics") - def test_ped_npc_collisions(self): # Check that collision between NPC and Pedestrian is reported + def test_ped_npc_collisions(self): # Check that collision between NPC and Pedestrian is reported with SimConnection() as sim: state = spawnState(sim) state.position.y += 10 @@ -82,13 +83,13 @@ def on_collision(agent1, agent2, contact): ped.on_collision(on_collision) bus.on_collision(on_collision) sim.run(15) - + self.assertGreater(len(collisions), 0) self.assertInBetween(collisions[0][2], collisions[0][0].state.position, collisions[0][1].state.position, "Ped/NPC Collision") self.assertTrue(collisions[0][0].name == "Bob" or collisions[0][1].name == "Bob") @unittest.skip("NPCs ignore collisions with other NPCs, activate this when NPCs use real physics") - def test_npc_collision(self): # Check that collision between NPC and NPC is reported + def test_npc_collision(self): # Check that collision between NPC and NPC is reported with SimConnection() as sim: state = spawnState(sim) state.position.x += 10 @@ -99,7 +100,7 @@ def test_npc_collision(self): # Check that collision between NPC and NPC is repo def on_collision(agent1, agent2, contact): collisions.append([agent1, agent2, contact]) sim.stop() - + jeep.on_collision(on_collision) bus.on_collision(on_collision) @@ -110,7 +111,7 @@ def on_collision(agent1, agent2, contact): self.assertTrue(collisions[0][0].name == "Jeep" or collisions[0][1].name == "Jeep") self.assertTrue(collisions[0][0].name == "SchoolBus" or collisions[0][1].name == "SchoolBus") - def test_wall_collision(self): # Check that an EGO collision with a wall is reported properly + def test_wall_collision(self): # Check that an EGO collision with a wall is reported properly with SimConnection() as sim: state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) @@ -124,7 +125,7 @@ def test_wall_collision(self): # Check that an EGO collision with a wall is repo def on_collision(agent1, agent2, contact): collisions.append([agent1, agent2, contact]) sim.stop() - + ego.on_collision(on_collision) sim.run(15) @@ -137,7 +138,7 @@ def on_collision(agent1, agent2, contact): else: self.fail("Collision not with object") - def setup_collision(self, sim, mover_name, agent_type, still_name, still_type): + def setup_collision(self, sim, mover_name, agent_type, still_name, still_type): # Creates 2 agents, the mover is created with a forward velocity # still is rotated 90 degree in and in front of the mover state = spawnState(sim) @@ -154,12 +155,12 @@ def setup_collision(self, sim, mover_name, agent_type, still_name, still_type): return mover, still - def assertInBetween(self, position, a, b, msg): # Tests that at least one component of the input position vector is between the a and b vectors + def assertInBetween(self, position, a, b, msg): # Tests that at least one component of the input position vector is between the a and b vectors xmid = (a.x+b.x)/2 xdiff = abs(a.x-xmid) xmin = xmid-xdiff xmax = xmid+xdiff - + ymid = (a.y+b.y)/2 ydiff = abs(a.y-ymid) ymin = ymid-ydiff diff --git a/tests/test_manual_features.py b/tests/test_manual_features.py index a01c038..f630424 100644 --- a/tests/test_manual_features.py +++ b/tests/test_manual_features.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -7,11 +7,11 @@ # DO NOT INCLUDE IN __init__.py import unittest -import math import lgsvl from .common import SimConnection, spawnState, TestTimeout + class TestManual(unittest.TestCase): def test_wipers(self): try: @@ -36,7 +36,7 @@ def test_wipers(self): input("Press Enter if wipers are on high") except TestTimeout: self.fail("Wipers were not on") - + def test_headlights(self): try: with SimConnection() as sim: diff --git a/tests/test_peds.py b/tests/test_peds.py index ed77ce9..d1fabec 100644 --- a/tests/test_peds.py +++ b/tests/test_peds.py @@ -1,18 +1,18 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # import unittest import math -import time import lgsvl from .common import SimConnection, cmEqual, mEqual, spawnState + class TestPeds(unittest.TestCase): - def test_ped_creation(self): # Check if the different types of Peds can be created + def test_ped_creation(self): # Check if the different types of Peds can be created with SimConnection() as sim: state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) @@ -23,8 +23,8 @@ def test_ped_creation(self): # Check if the different types of Peds can be creat agent = self.create_ped(sim, name, spawnState(sim)) cmEqual(self, agent.state.position, sim.get_spawn()[0].position, name) self.assertEqual(agent.name, name) - - def test_ped_random_walk(self): # Check if pedestrians can walk randomly + + def test_ped_random_walk(self): # Check if pedestrians can walk randomly with SimConnection(40) as sim: state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) @@ -47,7 +47,7 @@ def test_ped_random_walk(self): # Check if pedestrians can walk randomly cmEqual(self, randPoint, bob.state.transform.position, "Ped random walk") - def test_ped_circle_waypoints(self): # Check if pedestrians can follow waypoints + def test_ped_circle_waypoints(self): # Check if pedestrians can follow waypoints with SimConnection(60) as sim: state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) @@ -71,6 +71,7 @@ def test_ped_circle_waypoints(self): # Check if pedestrians can follow waypoints state.transform.position = waypoints[0] zoe = self.create_ped(sim, "Zoe", state) + def on_waypoint(agent,index): msg = "Waypoint " + str(index) mEqual(self, zoe.state.position, waypoints[index], msg) @@ -123,5 +124,5 @@ def on_waypoint(agent, index): self.assertAlmostEqual(idleTime-noIdleTime, 2.0, delta=0.5) - def create_ped(self, sim, name, state): # create the specified Pedestrian + def create_ped(self, sim, name, state): # create the specified Pedestrian return sim.add_agent(name, lgsvl.AgentType.PEDESTRIAN, state) diff --git a/tests/test_sensors.py b/tests/test_sensors.py index 545ec71..94d9920 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -11,8 +11,9 @@ # TODO add tests for bridge to check if enabled sensor actually sends data + class TestSensors(unittest.TestCase): - def test_apollo_5_sensors(self): # Check that Apollo 3.5 sensors are created and are positioned reasonably + def test_apollo_5_sensors(self): # Check that Apollo 3.5 sensors are created and are positioned reasonably with SimConnection(60) as sim: agent = self.create_EGO(sim, "Lincoln2017MKZ (Apollo 5.0)") expectedSensors = ['Lidar', 'GPS', 'Telephoto Camera', \ @@ -30,7 +31,7 @@ def test_apollo_5_sensors(self): # Check that Apollo 3.5 sensors are created and self.valid_sensor(s, msg) @unittest.skip("No SF vehicle") - def test_santafe_sensors(self): # Check that Apollo Santa Fe sensors are created and are positioned reasonably + def test_santafe_sensors(self): # Check that Apollo Santa Fe sensors are created and are positioned reasonably with SimConnection() as sim: agent = self.create_EGO(sim, "Lincoln2017MKZ (Apollo 5.0)") expectedSensors = ['velodyne', 'GPS', 'Telephoto Camera', 'Main Camera', \ @@ -48,7 +49,7 @@ def test_santafe_sensors(self): # Check that Apollo Santa Fe sensors are created self.valid_sensor(s, msg) @unittest.skip("No LGSVL Vehicle") - def test_lgsvl_sensors(self): # Check that LGSVL sensors are created and are positioned reasonably + def test_lgsvl_sensors(self): # Check that LGSVL sensors are created and are positioned reasonably with SimConnection() as sim: agent = self.create_EGO(sim, "Lincoln2017MKZ (Apollo 5.0)") expectedSensors = ['velodyne', 'GPS', 'Telephoto Camera', 'Main Camera', \ @@ -66,14 +67,14 @@ def test_lgsvl_sensors(self): # Check that LGSVL sensors are created and are pos self.valid_sensor(s, msg) @unittest.skip("No EP Vehicle") - def test_ep_sensors(self): # Check that Apollo EP sensors are created and are positioned reasonably + def test_ep_sensors(self): # Check that Apollo EP sensors are created and are positioned reasonably with SimConnection() as sim: agent = self.create_EGO(sim, "EP_Rigged-apollo") expectedSensors = ['velodyne', 'GPS', 'Telephoto Camera', 'Main Camera', \ 'IMU', 'RADAR', 'CANBUS', 'Segmentation Camera', 'Left Camera', 'Right Camera'] sensors = agent.get_sensors() sensorNames = [s.name for s in sensors] - + for sensor in expectedSensors: with self.subTest(sensor): self.assertIn(sensor, sensorNames) @@ -83,7 +84,7 @@ def test_ep_sensors(self): # Check that Apollo EP sensors are created and are po with self.subTest(msg): self.valid_sensor(s, msg) - def test_apollo_sensors(self): # Check that all the Apollo sensors are there + def test_apollo_sensors(self): # Check that all the Apollo sensors are there with SimConnection() as sim: agent = self.create_EGO(sim, "Jaguar2015XE (Apollo 3.0)") expectedSensors = ["Lidar", "GPS", "Telephoto Camera", "Main Camera", "IMU", \ @@ -101,7 +102,7 @@ def test_apollo_sensors(self): # Check that all the Apollo sensors are there with self.subTest(msg): self.valid_sensor(s, msg) - def test_autoware_sensors(self): # Check that all Autoware sensors are there + def test_autoware_sensors(self): # Check that all Autoware sensors are there with SimConnection() as sim: agent = self.create_EGO(sim, "Jaguar2015XE (Autoware)") expectedSensors = ["Lidar", "GPS", "Main Camera", "IMU"] @@ -118,7 +119,7 @@ def test_autoware_sensors(self): # Check that all Autoware sensors are there with self.subTest(msg): self.valid_sensor(s, msg ) - def test_save_sensor(self): # Check that sensor results can be saved + def test_save_sensor(self): # Check that sensor results can be saved with SimConnection(120) as sim: path = "main-camera.png" @@ -146,7 +147,7 @@ def test_save_sensor(self): # Check that sensor results can be saved self.assertGreater(os.path.getsize(path), 0) os.remove(path) - def test_save_lidar(self): # Check that LIDAR sensor results can be saved + def test_save_lidar(self): # Check that LIDAR sensor results can be saved with SimConnection(240) as sim: path = "lidar.pcd" islocal = os.environ.get("SIMULATOR_HOST", "127.0.0.1") == "127.0.0.1" @@ -172,8 +173,7 @@ def test_save_lidar(self): # Check that LIDAR sensor results can be saved self.assertGreater(os.path.getsize(path), 0) os.remove(path) - - def test_GPS(self): # Check that the GPS sensor works + def test_GPS(self): # Check that the GPS sensor works with SimConnection() as sim: state = lgsvl.AgentState() state.transform = sim.get_spawn()[0] @@ -203,13 +203,13 @@ def test_GPS(self): # Check that the GPS sensor works self.assertNotAlmostEqual(gps.data.altitude, 0) self.assertNotAlmostEqual(gps.data.orientation, 0) - def test_sensor_disabling(self): # Check if sensors can be enabled + def test_sensor_disabling(self): # Check if sensors can be enabled with SimConnection() as sim: agent = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) for s in agent.get_sensors(): if s.name == "Lidar": s.enabled = False - + for s in agent.get_sensors(): with self.subTest(s.name): if (s.name == "Lidar"): @@ -217,7 +217,7 @@ def test_sensor_disabling(self): # Check if sensors can be enabled else: self.assertTrue(s.enabled) - def test_sensor_equality(self): # Check that sensor == operator works + def test_sensor_equality(self): # Check that sensor == operator works with SimConnection() as sim: agent = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) prevSensor = None @@ -227,14 +227,14 @@ def test_sensor_equality(self): # Check that sensor == operator works self.assertFalse(s == prevSensor) prevSensor = s - def create_EGO(self, sim, name): # Creates the speicified EGO and removes any others + def create_EGO(self, sim, name): # Creates the speicified EGO and removes any others return sim.add_agent(name, lgsvl.AgentType.EGO, spawnState(sim)) - def valid_sensor(self, sensor, msg): # Checks that the sensor is close to the EGO and not overly rotated + def valid_sensor(self, sensor, msg): # Checks that the sensor is close to the EGO and not overly rotated self.assertBetween(sensor.transform.rotation, 0, 360, msg) self.assertBetween(sensor.transform.position, -5, 5, msg) - def assertBetween(self, vector, min, max, msg): # Tests that the given vectors components are within the min and max + def assertBetween(self, vector, min, max, msg): # Tests that the given vectors components are within the min and max self.assertGreaterEqual(vector.x, min, msg) self.assertLessEqual(vector.x, max, msg) diff --git a/tests/test_simulator.py b/tests/test_simulator.py index 40bd9e5..4b70b43 100644 --- a/tests/test_simulator.py +++ b/tests/test_simulator.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -7,30 +7,30 @@ import unittest import lgsvl -import time -from .common import SimConnection, spawnState, TestTimeout +from .common import SimConnection, spawnState PROBLEM = "Object reference not set to an instance of an object" + class TestSimulator(unittest.TestCase): - def test_scene(self): # Check if the right scene was loaded + def test_scene(self): # Check if the right scene was loaded with SimConnection() as sim: self.assertEqual(sim.current_scene, "BorregasAve") - - def test_unload_scene(self): # Check if a different scene gets loaded + + def test_unload_scene(self): # Check if a different scene gets loaded with SimConnection() as sim: self.assertEqual(sim.current_scene, "BorregasAve") sim.load("CubeTown") self.assertEqual(sim.current_scene, "CubeTown") - def test_spawns(self): # Check if there is at least 1 spawn point for Ego Vehicles + def test_spawns(self): # Check if there is at least 1 spawn point for Ego Vehicles with SimConnection() as sim: spawns = sim.get_spawn() self.assertGreater(len(spawns), 0) - def test_run_time(self): # Check if the simulator runs 2 seconds + def test_run_time(self): # Check if the simulator runs 2 seconds with SimConnection() as sim: sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) time = 2.0 @@ -39,14 +39,14 @@ def test_run_time(self): # Check if the simulator runs 2 seconds sim.run(time) self.assertAlmostEqual(sim.current_time - initial_time, time, delta=0.1) - def test_non_realtime(self): # Check if non-realtime simulation runs + def test_non_realtime(self): # Check if non-realtime simulation runs with SimConnection() as sim: initial_time = sim.current_time sim.run(time_limit=3, time_scale=2) self.assertAlmostEqual(sim.current_time-initial_time, 3, delta=0.1) - def test_reset(self): # Check if sim.reset resets the time and frame + def test_reset(self): # Check if sim.reset resets the time and frame with SimConnection() as sim: sim.run(1.0) @@ -55,7 +55,7 @@ def test_reset(self): # Check if sim.reset resets the time and frame self.assertAlmostEqual(sim.current_time, 0) self.assertEqual(sim.current_frame, 0) - def test_raycast(self): # Check if raycasting works + def test_raycast(self): # Check if raycasting works with SimConnection() as sim: spawns = sim.get_spawn() state = lgsvl.AgentState() @@ -68,7 +68,7 @@ def test_raycast(self): # Check if raycasting works p = spawns[0].position p.y += 1 layer_mask = 0 - for bit in [0, 4, 13, 14, 18]: # do not put 8 here, to not hit EGO vehicle itself + for bit in [0, 4, 13, 14, 18]: # do not put 8 here, to not hit EGO vehicle itself layer_mask |= 1 << bit # Right @@ -76,16 +76,16 @@ def test_raycast(self): # Check if raycasting works self.assertTrue(hit) self.assertAlmostEqual(hit.distance, 15.089282989502, places=3) - #Left + # Left hit = sim.raycast(p, -right, layer_mask) self.assertTrue(hit) self.assertAlmostEqual(hit.distance, 19.7292556762695, places=3) - #Back + # Back hit = sim.raycast(p, -forward, layer_mask) self.assertFalse(hit) - #Front + # Front hit = sim.raycast(p, forward, layer_mask) self.assertFalse(hit) @@ -98,12 +98,12 @@ def test_raycast(self): # Check if raycasting works self.assertTrue(hit) self.assertAlmostEqual(hit.distance, 1.0837641954422, places=3) - def test_weather(self): # Check that the weather state can be read properly and changed + def test_weather(self): # Check that the weather state can be read properly and changed with SimConnection() as sim: rain = sim.weather.rain fog = sim.weather.fog wetness = sim.weather.wetness - + self.assertAlmostEqual(rain, 0) self.assertAlmostEqual(fog, 0) self.assertAlmostEqual(wetness, 0) @@ -113,17 +113,17 @@ def test_weather(self): # Check that the weather state can be read properly and rain = sim.weather.rain fog = sim.weather.fog wetness = sim.weather.wetness - + self.assertAlmostEqual(rain, 0.5) self.assertAlmostEqual(fog, 0.3) self.assertAlmostEqual(wetness, 0.8) - def test_invalid_weather(self): # Check that the API/Unity properly handles unexpected inputs + def test_invalid_weather(self): # Check that the API/Unity properly handles unexpected inputs with SimConnection() as sim: rain = sim.weather.rain fog = sim.weather.fog wetness = sim.weather.wetness - + self.assertAlmostEqual(rain, 0) self.assertAlmostEqual(fog, 0) self.assertAlmostEqual(wetness, 0) @@ -133,7 +133,7 @@ def test_invalid_weather(self): # Check that the API/Unity properly handles unex rain = sim.weather.rain fog = sim.weather.fog wetness = sim.weather.wetness - + self.assertAlmostEqual(rain, 1) self.assertAlmostEqual(fog, 0) self.assertAlmostEqual(wetness, 0) @@ -143,7 +143,7 @@ def test_invalid_weather(self): # Check that the API/Unity properly handles unex rain = sim.weather.rain self.assertAlmostEqual(rain, 0) - def test_time_of_day(self): # Check that the time of day is reported properly and can be set + def test_time_of_day(self): # Check that the time of day is reported properly and can be set with SimConnection() as sim: # self.assertAlmostEqual(sim.time_of_day, 9, delta=0.5) sim.set_time_of_day(18.00) @@ -154,14 +154,14 @@ def test_time_of_day(self): # Check that the time of day is reported properly an sim.run(3) self.assertGreater(sim.time_of_day, 13.5) - def test_wrong_time_of_day(self): # Check that the time of day is not broken with inappropriate inputs + def test_wrong_time_of_day(self): # Check that the time of day is not broken with inappropriate inputs with SimConnection() as sim: sim.set_time_of_day(40) self.assertAlmostEqual(sim.time_of_day, 0) with self.assertRaises(TypeError): sim.set_time_of_day("asdf") - - def test_reset_weather(self): # Check that reset sets the weather variables back to 0 + + def test_reset_weather(self): # Check that reset sets the weather variables back to 0 with SimConnection() as sim: rain = sim.weather.rain fog = sim.weather.fog @@ -186,29 +186,29 @@ def test_reset_weather(self): # Check that reset sets the weather variables back self.assertAlmostEqual(fog, 0) self.assertAlmostEqual(wetness, 0) - def test_reset_time(self): # Check that reset sets time back to the default + def test_reset_time(self): # Check that reset sets time back to the default with SimConnection() as sim: default_time = sim.time_of_day sim.set_time_of_day((default_time+5)%24) sim.reset() self.assertAlmostEqual(default_time, sim.time_of_day) -# THIS TEST RUNS LAST - def test_ztypo_map(self): # Check if an exception is raised with a misspelled map name is loaded + # THIS TEST RUNS LAST + def test_ztypo_map(self): # Check if an exception is raised with a misspelled map name is loaded #with self.assertRaises(TestTimeout): with SimConnection() as sim: with self.assertRaises(Exception) as e: sim.load("SF") self.assertFalse(repr(e.exception).startswith(PROBLEM)) - def test_negative_time(self): # Check that a negative time can be handled properly + def test_negative_time(self): # Check that a negative time can be handled properly with SimConnection() as sim: initial_time = sim.current_time sim.run(-5) post_time = sim.current_time self.assertAlmostEqual(initial_time, post_time) - def test_get_gps(self): # Checks that GPS reports the correct values + def test_get_gps(self): # Checks that GPS reports the correct values with SimConnection() as sim: spawn = sim.get_spawn()[0] gps = sim.map_to_gps(spawn) @@ -219,36 +219,36 @@ def test_get_gps(self): # Checks that GPS reports the correct values self.assertAlmostEqual(gps.altitude, -1.03600001335144) self.assertAlmostEqual(gps.orientation, -104.823394775391) - def test_from_northing(self): # Check that position vectors are correctly generated given northing and easting + def test_from_northing(self): # Check that position vectors are correctly generated given northing and easting with SimConnection() as sim: spawn = sim.get_spawn()[0] location = sim.map_from_gps(northing=4141627.34000015, easting=587060.970000267) self.assertAlmostEqual(spawn.position.x, location.position.x, places=1) self.assertAlmostEqual(spawn.position.z, location.position.z, places=1) - def test_from_latlong(self): # Check that position vectors are correctly generated given latitude and longitude + def test_from_latlong(self): # Check that position vectors are correctly generated given latitude and longitude with SimConnection() as sim: spawn = sim.get_spawn()[0] location = sim.map_from_gps(latitude=37.4173601699318, longitude=-122.016132757826) self.assertAlmostEqual(spawn.position.x, location.position.x, places=1) self.assertAlmostEqual(spawn.position.z, location.position.z, places=1) - def test_from_alt_orient(self): # Check that position vectors are correctly generated with altitude and orientation + def test_from_alt_orient(self): # Check that position vectors are correctly generated with altitude and orientation with SimConnection() as sim: spawn = sim.get_spawn()[0] location = sim.map_from_gps(northing=4141627.34000015, easting=587060.970000267, altitude=-1.03600001335144, orientation=-104.823371887207) self.assertAlmostEqual(spawn.position.y, location.position.y, places=1) self.assertAlmostEqual(spawn.rotation.y, location.rotation.y, places=1) - def test_false_latlong(self): # Check that exceptions are thrown when inputting invalid lat long values + def test_false_latlong(self): # Check that exceptions are thrown when inputting invalid lat long values with SimConnection() as sim: with self.assertRaises(ValueError): sim.map_from_gps(latitude=91, longitude=0) - + with self.assertRaises(ValueError): sim.map_from_gps(latitude=0, longitude=200) - def test_false_easting(self): # Check that exceptions are thrown when inputting invalid northing easting values + def test_false_easting(self): # Check that exceptions are thrown when inputting invalid northing easting values with SimConnection() as sim: with self.assertRaises(ValueError): sim.map_from_gps(easting=1000000000, northing=500000) @@ -256,13 +256,13 @@ def test_false_easting(self): # Check that exceptions are thrown when inputting with self.assertRaises(ValueError): sim.map_from_gps(northing=-50, easting=500000) - def test_version_info(self): # Check that the sim reports a numerical version number + def test_version_info(self): # Check that the sim reports a numerical version number with SimConnection() as sim: version = sim.version self.assertTrue(isinstance(version, str)) self.assertTrue(isinstance(float(version[:4]), float)) - def test_lat_northing(self): # Checks that exceptions are thrown if an invalid pair of gps values are given + def test_lat_northing(self): # Checks that exceptions are thrown if an invalid pair of gps values are given with SimConnection() as sim: with self.assertRaises(Exception) as e: sim.map_from_gps(northing=4812775, latitude=37.7) @@ -272,33 +272,33 @@ def test_lat_northing(self): # Checks that exceptions are thrown if an invalid p # with SimConnection() as sim: # with self.assertRaises(Exception) as e: # sim.map_from_gps(northing=1, easting=2, latitude=3, longitude=4) - - def test_lat_str(self): # Checks that exceptions are thrown if a string is given for latitude + + def test_lat_str(self): # Checks that exceptions are thrown if a string is given for latitude with SimConnection() as sim: with self.assertRaises(TypeError): sim.map_from_gps(latitude="asdf", longitude=2) - def test_long_str(self): # Checks that exceptions are thrown if a string is given for longitude + def test_long_str(self): # Checks that exceptions are thrown if a string is given for longitude with SimConnection() as sim: with self.assertRaises(TypeError): sim.map_from_gps(latitude=1, longitude="asdf") - def test_northing_str(self): # Checks that exceptions are thrown if a string is given for northing + def test_northing_str(self): # Checks that exceptions are thrown if a string is given for northing with SimConnection() as sim: with self.assertRaises(TypeError): sim.map_from_gps(northing="asdf", easting=2) - def test_easting_str(self): # Checks that exceptions are thrown if a string is given for easting + def test_easting_str(self): # Checks that exceptions are thrown if a string is given for easting with SimConnection() as sim: with self.assertRaises(TypeError): sim.map_from_gps(northing=1, easting="asdF") - def test_altitude_str(self): # Checks that exceptions are thrown if a string is given for altitude + def test_altitude_str(self): # Checks that exceptions are thrown if a string is given for altitude with SimConnection() as sim: with self.assertRaises(TypeError): sim.map_from_gps(latitude=1, longitude=2, altitude="asd") - def test_orientation_str(self): # Checks that exceptions are thrown if a string is given for orientation + def test_orientation_str(self): # Checks that exceptions are thrown if a string is given for orientation with SimConnection() as sim: with self.assertRaises(TypeError): sim.map_from_gps(latitude=1, longitude=2, orientation="asdf") diff --git a/tests/test_utils.py b/tests/test_utils.py index 899d20b..91d8f66 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -9,46 +9,47 @@ import lgsvl import lgsvl.utils -from .common import SimConnection -class TestUtils(unittest.TestCase): # Check that transform_to_matrix calculates the right values +class TestUtils(unittest.TestCase): # Check that transform_to_matrix calculates the right values def test_transform_to_matrix(self): - transform = lgsvl.Transform(lgsvl.Vector(1,2,3), lgsvl.Vector(4,5,6)) - expectedMatrix = [[0.9913729386253347, 0.10427383718471564, -0.07941450396586013, 0.0], \ - [-0.0980843287345578, 0.9920992900156518, 0.07822060602635744, 0.0], \ - [0.08694343573875718, -0.0697564737441253, 0.9937680178757644, 0.0], \ - [1, 2, 3, 1.0]] + transform = lgsvl.Transform(lgsvl.Vector(1, 2, 3), lgsvl.Vector(4, 5, 6)) + expectedMatrix = [[0.9913729386253347, 0.10427383718471564, -0.07941450396586013, 0.0], + [-0.0980843287345578, 0.9920992900156518, 0.07822060602635744, 0.0], + [0.08694343573875718, -0.0697564737441253, 0.9937680178757644, 0.0], + [1, 2, 3, 1.0]] matrix = lgsvl.utils.transform_to_matrix(transform) for i in range(4): for j in range(4): - self.assertAlmostEqual(matrix[i][j], expectedMatrix[i][j]) - - def test_matrix_multiply(self): # Check that matrix_multiply calculates the right values - inputMatrix = lgsvl.utils.transform_to_matrix(lgsvl.Transform(lgsvl.Vector(1,2,3), lgsvl.Vector(4,5,6))) - expectedMatrix = [[0.9656881042915112, 0.21236393599051254, -0.1494926216255657, 0.0], \ - [-0.18774677387638924, 0.9685769782741936, 0.1631250626244768, 0.0], \ - [0.1794369920860106, -0.12946117505974142, 0.9752139098799174, 0.0], \ - [2.0560345883724906, 3.8792029959836434, 6.058330761714148, 1.0]] + self.assertAlmostEqual(matrix[i][j], expectedMatrix[i][j]) + + def test_matrix_multiply(self): # Check that matrix_multiply calculates the right values + inputMatrix = lgsvl.utils.transform_to_matrix(lgsvl.Transform(lgsvl.Vector(1, 2, 3), lgsvl.Vector(4, 5, 6))) + expectedMatrix = [[0.9656881042915112, 0.21236393599051254, -0.1494926216255657, 0.0], + [-0.18774677387638924, 0.9685769782741936, 0.1631250626244768, 0.0], + [0.1794369920860106, -0.12946117505974142, 0.9752139098799174, 0.0], + [2.0560345883724906, 3.8792029959836434, 6.058330761714148, 1.0]] + matrix = lgsvl.utils.matrix_multiply(inputMatrix, inputMatrix) for i in range(4): for j in range(4): - self.assertAlmostEqual(matrix[i][j], expectedMatrix[i][j]) - - def test_matrix_inverse(self): # Check that matrix_inverse calculates the right values - inputMatrix = lgsvl.utils.transform_to_matrix(lgsvl.Transform(lgsvl.Vector(1,2,3), lgsvl.Vector(4,5,6))) - expectedMatrix = [[0.9913729386253347, -0.0980843287345578, 0.08694343573875718, 0.0], \ - [0.10427383718471564, 0.9920992900156518, -0.0697564737441253, 0.0], \ - [-0.07941450396586013, 0.07822060602635744, 0.9937680178757644, 0.0], \ - [-0.9616771010971856, -2.120776069375818, -2.9287345418778, 1.0]] + self.assertAlmostEqual(matrix[i][j], expectedMatrix[i][j]) + + def test_matrix_inverse(self): # Check that matrix_inverse calculates the right values + inputMatrix = lgsvl.utils.transform_to_matrix(lgsvl.Transform(lgsvl.Vector(1, 2, 3), lgsvl.Vector(4, 5, 6))) + expectedMatrix = [[0.9913729386253347, -0.0980843287345578, 0.08694343573875718, 0.0], + [0.10427383718471564, 0.9920992900156518, -0.0697564737441253, 0.0], + [-0.07941450396586013, 0.07822060602635744, 0.9937680178757644, 0.0], + [-0.9616771010971856, -2.120776069375818, -2.9287345418778, 1.0]] + matrix = lgsvl.utils.matrix_inverse(inputMatrix) for i in range(4): for j in range(4): - self.assertAlmostEqual(matrix[i][j], expectedMatrix[i][j]) + self.assertAlmostEqual(matrix[i][j], expectedMatrix[i][j]) - def test_vector_multiply(self): # Check that vector_multiply calculates the right values - inputMatrix = lgsvl.utils.transform_to_matrix(lgsvl.Transform(lgsvl.Vector(1,2,3), lgsvl.Vector(4,5,6))) - inputVector = lgsvl.Vector(10,20,30) + def test_vector_multiply(self): # Check that vector_multiply calculates the right values + inputMatrix = lgsvl.utils.transform_to_matrix(lgsvl.Transform(lgsvl.Vector(1, 2, 3), lgsvl.Vector(4, 5, 6))) + inputVector = lgsvl.Vector(10, 20, 30) expectedVector = lgsvl.Vector(11.560345883724906, 20.792029959836434, 33.58330761714148) vector = lgsvl.utils.vector_multiply(inputVector, inputMatrix) @@ -56,6 +57,6 @@ def test_vector_multiply(self): # Check that vector_multiply calculates the righ self.assertAlmostEqual(vector.y, expectedVector.y) self.assertAlmostEqual(vector.z, expectedVector.z) - def test_vector_dot(self): # Check that vector_dot calculates the right values - result = lgsvl.utils.vector_dot(lgsvl.Vector(1,2,3), lgsvl.Vector(4,5,6)) + def test_vector_dot(self): # Check that vector_dot calculates the right values + result = lgsvl.utils.vector_dot(lgsvl.Vector(1, 2, 3), lgsvl.Vector(4, 5, 6)) self.assertAlmostEqual(result, 32) From 373f30398c3eb70134f64d13436ed3a09761813d Mon Sep 17 00:00:00 2001 From: Hadi Tabatabaee Date: Thu, 3 Sep 2020 16:32:34 -0700 Subject: [PATCH 022/115] Add destinations to spawn points --- lgsvl/geometry.py | 26 ++++++++++++++++++++++++++ lgsvl/simulator.py | 4 ++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lgsvl/geometry.py b/lgsvl/geometry.py index d51a1ce..93355f2 100644 --- a/lgsvl/geometry.py +++ b/lgsvl/geometry.py @@ -105,3 +105,29 @@ def to_json(self): def __repr__(self): return "Transform(position={}, rotation={})".format(self.position, self.rotation) + + +class Spawn: + def __init__(self, transform=None, destinations=None): + if transform is None: transform = Transform() + if destinations is None: destinations = [] + self.position = transform.position + self.rotation = transform.rotation + self.destinations = destinations + + @staticmethod + def from_json(j): + spawn_point = Transform.from_json(j) + destinations = [] + for d in j["destinations"]: + destinations.append(Transform.from_json(d)) + + return Spawn(spawn_point, destinations) + + def to_json(self): + return {"position": self.position.to_json(), "rotation": self.rotation.to_json()} + + def __repr__(self): + return "Spawn(position={}, rotation={}, destinations={})".format( + self.transform.position, self.transform.rotation, self.destinations + ) diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index 39fb65c..f6b2039 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -7,7 +7,7 @@ from .remote import Remote from .agent import Agent, AgentType, AgentState from .sensor import GpsData -from .geometry import Vector, Transform +from .geometry import Vector, Transform, Spawn from .utils import accepts, ObjectState from .controllable import Controllable @@ -171,7 +171,7 @@ def set_time_of_day(self, time, fixed=True): def get_spawn(self): spawns = self.remote.command("map/spawn/get") - return [Transform.from_json(spawn) for spawn in spawns] + return [Spawn.from_json(spawn) for spawn in spawns] @accepts(Transform) def map_to_gps(self, transform): From a96fe9ff54314f86f1ea486bdd171bba2e738816 Mon Sep 17 00:00:00 2001 From: "hadi.tabatabaee" Date: Thu, 10 Sep 2020 14:33:02 -0700 Subject: [PATCH 023/115] Add flake8 style enforcement --- .gitlab-ci.yml | 12 ++++++++++++ requirements.txt | 1 + 2 files changed, 13 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..bc1053a --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,12 @@ +image: "python:3.6.9" + +before_script: + - pip install -r requirements.txt + +stages: + - Style Guide Enforcement + +flake8: + stage: Style Guide Enforcement + script: + - flake8 diff --git a/requirements.txt b/requirements.txt index 5a2721d..13067fd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ websockets>=7.0 +flake8>=3.7.0 \ No newline at end of file From 3e007c9dd3185bbd5e4f6c409368249976c167c4 Mon Sep 17 00:00:00 2001 From: Steve Lemke Date: Wed, 9 Sep 2020 01:54:56 -0700 Subject: [PATCH 024/115] AUTO-2854: Fix hardcoded bridge address --- quickstart/22-connecting-bridge.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/quickstart/22-connecting-bridge.py b/quickstart/22-connecting-bridge.py index 90bd711..1c4f274 100755 --- a/quickstart/22-connecting-bridge.py +++ b/quickstart/22-connecting-bridge.py @@ -19,19 +19,19 @@ state = lgsvl.AgentState() state.transform = spawns[0] -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) # An EGO will not connect to a bridge unless commanded to -print("Bridge connected:", a.bridge_connected) +print("Bridge connected:", ego.bridge_connected) # The EGO is now looking for a bridge at the specified IP and port -a.connect_bridge("10.195.248.183", 9090) +ego.connect_bridge(os.environ.get("AUTOPILOT_HOST", "127.0.0.1"), 9090) print("Waiting for connection...") -while not a.bridge_connected: +while not ego.bridge_connected: time.sleep(1) -print("Bridge connected:", a.bridge_connected) +print("Bridge connected:", ego.bridge_connected) sim.run() From 8686d7493f6d7d9ec3c74e412593103b4490e42e Mon Sep 17 00:00:00 2001 From: Steve Lemke Date: Wed, 9 Sep 2020 02:11:01 -0700 Subject: [PATCH 025/115] change AUTOPILOT_HOST to BRIDGE_HOST --- quickstart/22-connecting-bridge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickstart/22-connecting-bridge.py b/quickstart/22-connecting-bridge.py index 1c4f274..fd1c428 100755 --- a/quickstart/22-connecting-bridge.py +++ b/quickstart/22-connecting-bridge.py @@ -25,7 +25,7 @@ print("Bridge connected:", ego.bridge_connected) # The EGO is now looking for a bridge at the specified IP and port -ego.connect_bridge(os.environ.get("AUTOPILOT_HOST", "127.0.0.1"), 9090) +ego.connect_bridge(os.environ.get("BRIDGE_HOST", "127.0.0.1"), 9090) print("Waiting for connection...") From a1d76c89c19866d21ebe8bfa7961717b31cfc1d1 Mon Sep 17 00:00:00 2001 From: Hadi Tabatabaee Date: Mon, 14 Sep 2020 17:34:29 -0700 Subject: [PATCH 026/115] Allow map_to_gps to accept Spawns as well as Transforms as input --- lgsvl/geometry.py | 2 +- lgsvl/simulator.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lgsvl/geometry.py b/lgsvl/geometry.py index 93355f2..472f9bb 100644 --- a/lgsvl/geometry.py +++ b/lgsvl/geometry.py @@ -129,5 +129,5 @@ def to_json(self): def __repr__(self): return "Spawn(position={}, rotation={}, destinations={})".format( - self.transform.position, self.transform.rotation, self.destinations + self.position, self.rotation, self.destinations ) diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index f6b2039..aa96b49 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -173,7 +173,7 @@ def get_spawn(self): spawns = self.remote.command("map/spawn/get") return [Spawn.from_json(spawn) for spawn in spawns] - @accepts(Transform) + @accepts((Transform, Spawn)) def map_to_gps(self, transform): j = self.remote.command("map/to_gps", {"transform": transform.to_json()}) return GpsData(j["latitude"], j["longitude"], j["northing"], j["easting"], j["altitude"], j["orientation"]) From 788b5c22bf1c301a8270cc3515282e2c9fb468bf Mon Sep 17 00:00:00 2001 From: "hadi.tabatabaee" Date: Fri, 18 Sep 2020 10:33:42 -0700 Subject: [PATCH 027/115] AUTO-4679: Add dreamview api as a subpackage --- .flake8 | 1 + lgsvl/__init__.py | 5 +- lgsvl/dreamview/__init__.py | 7 + lgsvl/dreamview/dreamview.py | 328 +++++++++++++++++++++++++++++++++++ requirements.txt | 3 +- setup.py | 5 +- 6 files changed, 346 insertions(+), 3 deletions(-) create mode 100644 lgsvl/dreamview/__init__.py create mode 100644 lgsvl/dreamview/dreamview.py diff --git a/.flake8 b/.flake8 index 845f6ca..020a205 100644 --- a/.flake8 +++ b/.flake8 @@ -9,3 +9,4 @@ exclude = per-file-ignores = lgsvl/__init__.py:F401 + lgsvl/dreamview/__init__.py:F401 diff --git a/lgsvl/__init__.py b/lgsvl/__init__.py index 33458e6..17d68e4 100644 --- a/lgsvl/__init__.py +++ b/lgsvl/__init__.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2020 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -23,3 +23,6 @@ ) from .controllable import Controllable from .utils import ObjectState + +# Subpackages +import lgsvl.dreamview diff --git a/lgsvl/dreamview/__init__.py b/lgsvl/dreamview/__init__.py new file mode 100644 index 0000000..baf9390 --- /dev/null +++ b/lgsvl/dreamview/__init__.py @@ -0,0 +1,7 @@ +# +# Copyright (c) 2019-2020 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +from .dreamview import Connection, CoordType diff --git a/lgsvl/dreamview/dreamview.py b/lgsvl/dreamview/dreamview.py new file mode 100644 index 0000000..8dead4a --- /dev/null +++ b/lgsvl/dreamview/dreamview.py @@ -0,0 +1,328 @@ +# +# Copyright (c) 2019-2020 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +from websocket import create_connection +from enum import Enum +import json +import lgsvl +import math +import logging +import sys + +log = logging.getLogger(__name__) + + +class CoordType(Enum): + Unity = 1 + Northing = 2 + Latitude = 3 + + +class Connection: + def __init__(self, simulator, ego_agent, ip="localhost", port="8888"): + """ + simulator: is an lgsvl.Simulator object + ego_agent: an lgsvl.EgoVehicle object, this is intended to be used with a vehicle equipped with Apollo 5.0 + ip: address of the machine where the Apollo stack is running + port: the port number for Dreamview + """ + self.url = "ws://" + ip + ":" + port + "/websocket" + self.sim = simulator + self.ego = ego_agent + self.ws = create_connection(self.url) + self.gps_offset = lgsvl.Vector() + + def set_destination(self, x_long_east, z_lat_north, y=0, coord_type=CoordType.Unity): + """ + This function can accept a variety of Coordinate systems + + If using Unity World Coordinate System: + x_long_east = x + z_lat_north = z + y = y + + If using Latitude/Longitude: + x_long_east = Longitude + z_lat_north = Latitude + + If using Easting/Northing: + x_long_east = Easting + z_lat_north = Northing + """ + current_pos = self.ego.state.transform + current_gps = self.sim.map_to_gps(current_pos) + heading = math.radians(current_gps.orientation) + + # Start position should be the position of the GPS + # Unity returns the position of the center of the vehicle so adjustment is required + northing_adjustment = ( + math.sin(heading) * self.gps_offset.z - math.cos(heading) * self.gps_offset.x + ) + easting_adjustment = ( + math.cos(heading) * self.gps_offset.z + math.sin(heading) * self.gps_offset.x + ) + + if coord_type == CoordType.Unity: + transform = lgsvl.Transform( + lgsvl.Vector(x_long_east, y, z_lat_north), lgsvl.Vector(0, 0, 0) + ) + gps = self.sim.map_to_gps(transform) + dest_x = gps.easting + dest_y = gps.northing + + elif coord_type == CoordType.Northing: + dest_x = x_long_east + dest_y = z_lat_north + + elif coord_type == CoordType.Latitude: + transform = self.sim.map_from_gps(longitude=x_long_east, latitude=z_lat_north) + gps = self.sim.map_to_gps(transform) + dest_x = gps.easting + dest_y = gps.northing + + else: + log.error( + "Please input a valid Coordinate Type: Unity position, Easting/Northing, or Longitude/Latitude" + ) + return + + self.ws.send( + json.dumps( + { + "type": "SendRoutingRequest", + "start": { + "x": current_gps.easting + easting_adjustment, + "y": current_gps.northing + northing_adjustment, + "z": 0, + }, + "end": {"x": dest_x, "y": dest_y, "z": 0}, + "waypoint": "[]", + } + ) + ) + + return + + def enable_module(self, module): + """ + module is the name of the Apollo 5.0 module as seen in the "Module Controller" tab of Dreamview + """ + self.ws.send( + json.dumps({"type": "HMIAction", "action": "START_MODULE", "value": module}) + ) + return + + def disable_module(self, module): + """ + module is the name of the Apollo 5.0 module as seen in the "Module Controller" tab of Dreamview + """ + self.ws.send( + json.dumps({"type": "HMIAction", "action": "STOP_MODULE", "value": module}) + ) + return + + def set_hd_map(self, map): + """ + Folders in /apollo/modules/map/data/ are the available HD maps + Map options in Dreamview are the folder names with the following changes: + - underscores (_) are replaced with spaces + - the first letter of each word is capitalized + + map parameter is the modified folder name. + map should match one of the options in the right-most drop down in the top-right corner of Dreamview. + """ + self.ws.send( + json.dumps({"type": "HMIAction", "action": "CHANGE_MAP", "value": map}) + ) + + if not self.get_current_map() == map: + folder_name = map.replace(" ", "_") + error_message = ( + "HD Map {0} was not set. Verify the files exist in " + "/apollo/modules/map/data/{1} and restart Dreamview -- Aborting..." + ) + log.error( + error_message.format( + map, folder_name + ) + ) + sys.exit(1) + return + + def set_vehicle(self, vehicle, gps_offset_x=0.0, gps_offset_y=0.0, gps_offset_z=-1.348): + # Lincoln2017MKZ from LGSVL has a GPS offset of 1.348m behind the center of the vehicle, lgsvl.Vector(0.0, 0.0, -1.348) + """ + Folders in /apollo/modules/calibration/data/ are the available vehicle calibrations + Vehicle options in Dreamview are the folder names with the following changes: + - underscores (_) are replaced with spaces + - the first letter of each word is capitalized + + vehicle parameter is the modified folder name. + vehicle should match one of the options in the middle drop down in the top-right corner of Dreamview. + """ + self.ws.send( + json.dumps( + {"type": "HMIAction", "action": "CHANGE_VEHICLE", "value": vehicle} + ) + ) + + self.gps_offset = lgsvl.Vector(gps_offset_x, gps_offset_y, gps_offset_z) + + if not self.get_current_vehicle() == vehicle: + folder_name = vehicle.replace(" ", "_") + error_message = ( + "Vehicle calibration {0} was not set. Verify the files exist in " + "/apollo/modules/calibration/data/{1} and restart Dreamview -- Aborting..." + ) + log.error( + error_message.format( + vehicle, folder_name + ) + ) + sys.exit(1) + return + + def set_setup_mode(self, mode): + """ + mode is the name of the Apollo 5.0 mode as seen in the left-most drop down in the top-right corner of Dreamview + """ + self.ws.send( + json.dumps({"type": "HMIAction", "action": "CHANGE_MODE", "value": mode}) + ) + return + + def get_module_status(self): + """ + Returns a dict where the key is the name of the module and value is a bool based on the module's current status + """ + self.reconnect() + data = json.loads( + self.ws.recv() + ) # This first recv() call returns the SimControlStatus in the form '{"enabled":false,"type":"SimControlStatus"}' + while data["type"] != "HMIStatus": + data = json.loads(self.ws.recv()) + + # The second recv() call also contains other information: + # the current map, vehicle, and mode: + # data["data"]["currentMap"], data["data"]["currentVehicle"], data["data"]["currentMode"] + # + # the available maps, vehicles, and modes: + # data["data"]["maps"], data["data"]["vehicles"], data["data"]["modes"] + # + # the status of monitors components: + # data["data"]["monitoredComponents"] + + return data["data"]["modules"] + + def get_current_map(self): + """ + Returns the current HD Map loaded in Dreamview + """ + self.reconnect() + data = json.loads(self.ws.recv()) + while data["type"] != "HMIStatus": + data = json.loads(self.ws.recv()) + return data["data"]["currentMap"] + + def get_current_vehicle(self): + """ + Returns the current Vehicle configuration loaded in Dreamview + """ + self.reconnect() + data = json.loads(self.ws.recv()) + while data["type"] != "HMIStatus": + data = json.loads(self.ws.recv()) + return data["data"]["currentVehicle"] + + def reconnect(self): + """ + Closes the websocket connection and re-creates it so that data can be received again + """ + self.ws.close() + self.ws = create_connection(self.url) + return + + def enable_apollo(self, dest_x, dest_z, modules): + """ + Enables a list of modules and then sets the destination + """ + for mod in modules: + log.info("Starting {} module...".format(mod)) + self.enable_module(mod) + + self.set_destination(dest_x, dest_z) + + def disable_apollo(self): + """ + Disables all Apollo modules + """ + module_status = self.get_module_status() + for module in module_status.keys(): + self.disable_module(module) + + def check_module_status(self, modules): + """ + Checks if all modules in a provided list are enabled + """ + module_status = self.get_module_status() + for module, status in module_status.items(): + if not status and module in modules: + log.warning( + "Warning: Apollo module {} is not running!!!".format(module) + ) + + def setup_apollo(self, dest_x, dest_z, modules): + """ + Starts a list of Apollo modules and sets the destination. Will wait for Control module to send a message before returning. + Control sending a message indicates that all modules are working and Apollo is ready to continue. + """ + initial_state = self.ego.state + mod_status = self.get_module_status() + + # If any module is not enabled, Control may still send a message even though Apollo is not ready + if not all(mod_status[mod] for mod in modules): + self.disable_apollo() + + self.enable_apollo(dest_x, dest_z, modules) + self.ego.is_control_received = False + + def on_control_received(agent, kind, context): + if kind == "checkControl": + agent.is_control_received = True + log.info("Control message recieved") + + self.ego.on_custom(on_control_received) + + for i in range(20): + self.sim.run(2) + + if self.ego.is_control_received: + break + + if i > 0 and i % 2 == 0: + self.check_module_status(modules) + log.info( + "{} seconds has passed, Ego hasn't received any control messages".format( + i * 2 + ) + ) + log.info( + "Please also check if your route has been set correctly in Dreamview." + ) + else: + log.error("No control message from Apollo within 40 seconds. Aborting...") + self.disable_apollo() + raise WaitApolloError() + + self.ego.state = initial_state + + +class WaitApolloError(Exception): + """ + Raised when Apollo control message is not recieved in time + """ + + pass diff --git a/requirements.txt b/requirements.txt index 13067fd..a8f42aa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ websockets>=7.0 -flake8>=3.7.0 \ No newline at end of file +websocket-client==0.57.0 # for dreamview +flake8>=3.7.0 diff --git a/setup.py b/setup.py index 8731ccc..14b3131 100755 --- a/setup.py +++ b/setup.py @@ -10,7 +10,10 @@ python_requires=">=3.5.0", url="https://github.com/lgsvl/simulator", packages=["lgsvl"], - install_requires=["websockets==7.0"], + install_requires=[ + "websockets==7.0", + "websocket-client==0.57.0" + ], license="Other", classifiers=[ "License :: Other/Proprietary License", From 0a65b078094556a8f0f29e69f17814141ee8f2d3 Mon Sep 17 00:00:00 2001 From: "shalin.mehta" Date: Fri, 18 Sep 2020 12:36:22 -0700 Subject: [PATCH 028/115] AUTO-4614: Add evaluator module for test script use in docker --- .flake8 | 1 + lgsvl/__init__.py | 1 + lgsvl/evaluator/__init__.py | 7 +++++++ lgsvl/evaluator/utils.py | 42 +++++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 lgsvl/evaluator/__init__.py create mode 100644 lgsvl/evaluator/utils.py diff --git a/.flake8 b/.flake8 index 020a205..9ea05cb 100644 --- a/.flake8 +++ b/.flake8 @@ -10,3 +10,4 @@ exclude = per-file-ignores = lgsvl/__init__.py:F401 lgsvl/dreamview/__init__.py:F401 + lgsvl/evaluator/__init__.py:F401 diff --git a/lgsvl/__init__.py b/lgsvl/__init__.py index 17d68e4..bea00ef 100644 --- a/lgsvl/__init__.py +++ b/lgsvl/__init__.py @@ -26,3 +26,4 @@ # Subpackages import lgsvl.dreamview +import lgsvl.evaluator diff --git a/lgsvl/evaluator/__init__.py b/lgsvl/evaluator/__init__.py new file mode 100644 index 0000000..ba0ecb6 --- /dev/null +++ b/lgsvl/evaluator/__init__.py @@ -0,0 +1,7 @@ +# +# Copyright (c) 2020 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +from .utils import TestException, right_lane_check, separation diff --git a/lgsvl/evaluator/utils.py b/lgsvl/evaluator/utils.py new file mode 100644 index 0000000..1b47d0b --- /dev/null +++ b/lgsvl/evaluator/utils.py @@ -0,0 +1,42 @@ +# +# Copyright (c) 2020 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +import lgsvl +import numpy + + +class TestException(Exception): + pass + + +def right_lane_check(simulator, ego_transform): + egoLane = simulator.map_point_on_lane(ego_transform.position) + right = lgsvl.utils.transform_to_right(ego_transform) + rightLane = simulator.map_point_on_lane(ego_transform.position + 3.6 * right) + + return almost_equal(egoLane.position.x, rightLane.position.x) and \ + almost_equal(egoLane.position.y, rightLane.position.y) and \ + almost_equal(egoLane.position.z, rightLane.position.z) + + +def in_parking_zone(beginning, end, ego_transform): + forward = lgsvl.utils.transform_to_forward(ego_transform) + b2e = ego_transform.position - beginning # Vector from beginning of parking zone to EGO's position + b2e = b2e * 1 / b2e.magnitude # Make is a Unit vector to simplify dot product result + e2e = end - ego_transform.position # Vector from EGO's position to end of parking zone + e2e = e2e * 1 / e2e.magnitue + return ( + numpy.dot([forward.x, forward.y, forward.z], [b2e.x, b2e.y, b2e.z]) > 0.9 + and numpy.dot([forward.x, forward.y, forward.z], [e2e.x, e2e.y, e2e.z]) > 0.9 + ) + + +def almost_equal(a, b, diff=0.5): + return abs(a - b) <= diff + + +def separation(V1, V2): + return (V1 - V2).magnitude() From 630df2740b70995522a7917d6597231232fa8e38 Mon Sep 17 00:00:00 2001 From: Shalin Mehta Date: Wed, 16 Sep 2020 13:32:20 -0700 Subject: [PATCH 029/115] AUTO-4402: add 'heading' back into RoutingRequest' --- lgsvl/dreamview/dreamview.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lgsvl/dreamview/dreamview.py b/lgsvl/dreamview/dreamview.py index 8dead4a..b119dac 100644 --- a/lgsvl/dreamview/dreamview.py +++ b/lgsvl/dreamview/dreamview.py @@ -97,6 +97,7 @@ def set_destination(self, x_long_east, z_lat_north, y=0, coord_type=CoordType.Un "x": current_gps.easting + easting_adjustment, "y": current_gps.northing + northing_adjustment, "z": 0, + "heading": heading, }, "end": {"x": dest_x, "y": dest_y, "z": 0}, "waypoint": "[]", From 1b5326ea44119a06e5320d6afaea17583ae9e2a5 Mon Sep 17 00:00:00 2001 From: Hadi Tabatabaee Date: Mon, 21 Sep 2020 15:01:19 -0700 Subject: [PATCH 030/115] Fix indentation in first test in test_NPC --- tests/test_NPC.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_NPC.py b/tests/test_NPC.py index a4988c6..e64a49b 100644 --- a/tests/test_NPC.py +++ b/tests/test_NPC.py @@ -23,7 +23,7 @@ def test_AAA_NPC_no_scene(self): state = lgsvl.AgentState() agent = sim.add_agent("Jeep", lgsvl.AgentType.NPC, state) agent.state.position - self.assertFalse(repr(e.exception).startswith(PROBLEM)) + self.assertFalse(repr(e.exception).startswith(PROBLEM)) def test_NPC_creation(self): # Check if the different types of NPCs can be created with SimConnection(60) as sim: From 2eaec7a8e881815275c9525473ec34e4a9a86cea Mon Sep 17 00:00:00 2001 From: Hadi Tabatabaee Date: Thu, 24 Sep 2020 02:20:06 -0700 Subject: [PATCH 031/115] Make quickstart #32 executable --- quickstart/32-pedestrian-time-to-collision.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 quickstart/32-pedestrian-time-to-collision.py diff --git a/quickstart/32-pedestrian-time-to-collision.py b/quickstart/32-pedestrian-time-to-collision.py old mode 100644 new mode 100755 From 4ccf138960969f838d726db33b45aeef601cb94e Mon Sep 17 00:00:00 2001 From: Hadi Tabatabaee Date: Mon, 21 Sep 2020 14:35:32 -0700 Subject: [PATCH 032/115] Ensure compatibility with simulator builds that predate destinations --- lgsvl/geometry.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lgsvl/geometry.py b/lgsvl/geometry.py index 472f9bb..9b129ce 100644 --- a/lgsvl/geometry.py +++ b/lgsvl/geometry.py @@ -119,8 +119,9 @@ def __init__(self, transform=None, destinations=None): def from_json(j): spawn_point = Transform.from_json(j) destinations = [] - for d in j["destinations"]: - destinations.append(Transform.from_json(d)) + if "destinations" in j: + for d in j["destinations"]: + destinations.append(Transform.from_json(d)) return Spawn(spawn_point, destinations) From 21be16f4b178fe82a4ef5365320552d49b909d66 Mon Sep 17 00:00:00 2001 From: Hadi Tabatabaee Date: Thu, 24 Sep 2020 01:00:01 -0700 Subject: [PATCH 033/115] Add subpackages to setup file --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 14b3131..1b675e5 100755 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ author_email="contact@lgsvlsimulator.com", python_requires=">=3.5.0", url="https://github.com/lgsvl/simulator", - packages=["lgsvl"], + packages=["lgsvl", "lgsvl.dreamview", "lgsvl.evaluator"], install_requires=[ "websockets==7.0", "websocket-client==0.57.0" From 0d4619b108f3d57ae2355a59dfe479f3094e56cb Mon Sep 17 00:00:00 2001 From: Hadi Tabatabaee Date: Thu, 24 Sep 2020 13:53:28 -0700 Subject: [PATCH 034/115] Add numpy as requirement --- requirements.txt | 1 + setup.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a8f42aa..9fd3f76 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ websockets>=7.0 websocket-client==0.57.0 # for dreamview flake8>=3.7.0 +numpy # for evaluator diff --git a/setup.py b/setup.py index 1b675e5..cefa1c6 100755 --- a/setup.py +++ b/setup.py @@ -12,7 +12,8 @@ packages=["lgsvl", "lgsvl.dreamview", "lgsvl.evaluator"], install_requires=[ "websockets==7.0", - "websocket-client==0.57.0" + "websocket-client==0.57.0", + "numpy" ], license="Other", classifiers=[ From 0791c2cfd802f5e4a62e37437a3020d93c88bf33 Mon Sep 17 00:00:00 2001 From: Shalin Mehta Date: Fri, 25 Sep 2020 13:52:09 -0700 Subject: [PATCH 035/115] Fix typos, add functions to init, fix order of operations --- lgsvl/evaluator/__init__.py | 2 +- lgsvl/evaluator/utils.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lgsvl/evaluator/__init__.py b/lgsvl/evaluator/__init__.py index ba0ecb6..49ea0db 100644 --- a/lgsvl/evaluator/__init__.py +++ b/lgsvl/evaluator/__init__.py @@ -4,4 +4,4 @@ # This software contains code licensed as described in LICENSE. # -from .utils import TestException, right_lane_check, separation +from .utils import TestException, right_lane_check, separation, almost_equal, in_parking_zone diff --git a/lgsvl/evaluator/utils.py b/lgsvl/evaluator/utils.py index 1b47d0b..bdf4dff 100644 --- a/lgsvl/evaluator/utils.py +++ b/lgsvl/evaluator/utils.py @@ -25,9 +25,9 @@ def right_lane_check(simulator, ego_transform): def in_parking_zone(beginning, end, ego_transform): forward = lgsvl.utils.transform_to_forward(ego_transform) b2e = ego_transform.position - beginning # Vector from beginning of parking zone to EGO's position - b2e = b2e * 1 / b2e.magnitude # Make is a Unit vector to simplify dot product result + b2e = b2e * (1 / b2e.magnitude()) # Make it a Unit vector to simplify dot product result e2e = end - ego_transform.position # Vector from EGO's position to end of parking zone - e2e = e2e * 1 / e2e.magnitue + e2e = e2e * (1 / e2e.magnitude()) return ( numpy.dot([forward.x, forward.y, forward.z], [b2e.x, b2e.y, b2e.z]) > 0.9 and numpy.dot([forward.x, forward.y, forward.z], [e2e.x, e2e.y, e2e.z]) > 0.9 From f79830766e01ccbd3a060e1588a29b34d5cd1af9 Mon Sep 17 00:00:00 2001 From: "shalin.mehta" Date: Tue, 29 Sep 2020 18:42:23 -0700 Subject: [PATCH 036/115] [AUTO-4849] Add Cloudiness and Damage to weather params --- lgsvl/simulator.py | 6 +++--- quickstart/18-weather-effects.py | 8 ++++---- tests/test_simulator.py | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index aa96b49..a786a15 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -15,7 +15,7 @@ RaycastHit = namedtuple("RaycastHit", "distance point normal") -WeatherState = namedtuple("WeatherState", "rain fog wetness") +WeatherState = namedtuple("WeatherState", "rain fog wetness cloudiness damage") class Simulator: @@ -154,12 +154,12 @@ def get_agents(self): @property def weather(self): j = self.remote.command("environment/weather/get") - return WeatherState(j["rain"], j["fog"], j["wetness"]) + return WeatherState(j["rain"], j["fog"], j["wetness"], j["cloudiness"], j["damage"]) @weather.setter @accepts(WeatherState) def weather(self, state): - self.remote.command("environment/weather/set", {"rain": state.rain, "fog": state.fog, "wetness": state.wetness}) + self.remote.command("environment/weather/set", {"rain": state.rain, "fog": state.fog, "wetness": state.wetness, "cloudiness": state.cloudiness, "damage": state.damage}) @property def time_of_day(self): diff --git a/quickstart/18-weather-effects.py b/quickstart/18-weather-effects.py index 8aa43d3..2d9a610 100755 --- a/quickstart/18-weather-effects.py +++ b/quickstart/18-weather-effects.py @@ -26,28 +26,28 @@ # Each weather variable is a float from 0 to 1 # There is no default value so each varible must be specified -sim.weather = lgsvl.WeatherState(rain=0.8, fog=0, wetness=0) +sim.weather = lgsvl.WeatherState(rain=0.8, fog=0, wetness=0, cloudiness=0, damage=0) print(sim.weather) sim.run(5) input("Press Enter to set fog to 50%") -sim.weather = lgsvl.WeatherState(rain=0, fog=0.5, wetness=0) +sim.weather = lgsvl.WeatherState(rain=0, fog=0.5, wetness=0, cloudiness=0, damage=0) print(sim.weather) sim.run(5) input("Press Enter to set wetness to 50%") -sim.weather = lgsvl.WeatherState(rain=0, fog=0, wetness=0.5) +sim.weather = lgsvl.WeatherState(rain=0, fog=0, wetness=0.5, cloudiness=0, damage=0) print(sim.weather) sim.run(5) input("Press Enter to reset to 0") -sim.weather = lgsvl.WeatherState(rain=0, fog=0, wetness=0) +sim.weather = lgsvl.WeatherState(rain=0, fog=0, wetness=0, cloudiness=0, damage=0) print(sim.weather) sim.run(5) diff --git a/tests/test_simulator.py b/tests/test_simulator.py index 4b70b43..ecbfec6 100644 --- a/tests/test_simulator.py +++ b/tests/test_simulator.py @@ -108,7 +108,7 @@ def test_weather(self): # Check that the weather state can be read properly and self.assertAlmostEqual(fog, 0) self.assertAlmostEqual(wetness, 0) - sim.weather = lgsvl.WeatherState(rain=0.5, fog=0.3, wetness=0.8) + sim.weather = lgsvl.WeatherState(rain=0.5, fog=0.3, wetness=0.8, cloudiness=0, damage=0) rain = sim.weather.rain fog = sim.weather.fog @@ -128,7 +128,7 @@ def test_invalid_weather(self): # Check that the API/Unity properly handles une self.assertAlmostEqual(fog, 0) self.assertAlmostEqual(wetness, 0) - sim.weather = lgsvl.WeatherState(rain=1.4, fog=-3, wetness="a") + sim.weather = lgsvl.WeatherState(rain=1.4, fog=-3, wetness="a", cloudiness=0, damage=0) rain = sim.weather.rain fog = sim.weather.fog @@ -138,7 +138,7 @@ def test_invalid_weather(self): # Check that the API/Unity properly handles une self.assertAlmostEqual(fog, 0) self.assertAlmostEqual(wetness, 0) - sim.weather = lgsvl.WeatherState(rain=True, fog=0, wetness=0) + sim.weather = lgsvl.WeatherState(rain=True, fog=0, wetness=0, cloudiness=0, damage=0) rain = sim.weather.rain self.assertAlmostEqual(rain, 0) @@ -170,7 +170,7 @@ def test_reset_weather(self): # Check that reset sets the weather variables bac self.assertAlmostEqual(fog, 0) self.assertAlmostEqual(wetness, 0) - sim.weather = lgsvl.WeatherState(rain=0.5, fog=0.3, wetness=0.8) + sim.weather = lgsvl.WeatherState(rain=0.5, fog=0.3, wetness=0.8, cloudiness=0, damage=0) rain = sim.weather.rain fog = sim.weather.fog wetness = sim.weather.wetness From f8ef1611c3012cc768aebc7c4459a7bca32d14aa Mon Sep 17 00:00:00 2001 From: "shalin.mehta" Date: Wed, 30 Sep 2020 15:50:55 -0700 Subject: [PATCH 037/115] Have DREAMVIEW_CONTROL_MESSAGE_TIMEOUT_SECS override 60s setupApollo() timeout --- lgsvl/dreamview/dreamview.py | 37 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/lgsvl/dreamview/dreamview.py b/lgsvl/dreamview/dreamview.py index b119dac..2aeaf1a 100644 --- a/lgsvl/dreamview/dreamview.py +++ b/lgsvl/dreamview/dreamview.py @@ -11,6 +11,7 @@ import math import logging import sys +import os log = logging.getLogger(__name__) @@ -275,7 +276,7 @@ def check_module_status(self, modules): "Warning: Apollo module {} is not running!!!".format(module) ) - def setup_apollo(self, dest_x, dest_z, modules): + def setup_apollo(self, dest_x, dest_z, modules, default_timeout=60.0): """ Starts a list of Apollo modules and sets the destination. Will wait for Control module to send a message before returning. Control sending a message indicates that all modules are working and Apollo is ready to continue. @@ -293,28 +294,32 @@ def setup_apollo(self, dest_x, dest_z, modules): def on_control_received(agent, kind, context): if kind == "checkControl": agent.is_control_received = True - log.info("Control message recieved") + log.info("Control message received") self.ego.on_custom(on_control_received) - for i in range(20): - self.sim.run(2) + try: + timeout = float(os.environ.get("DREAMVIEW_CONTROL_MESSAGE_TIMEOUT_SECS", default_timeout)) + except Exception: + timeout = default_timeout + log.warning("Invalid DREAMVIEW_CONTROL_MESSAGE_TIMEOUT_SECS, using default {0}s".format(default_timeout)) + + run_time = 2 + elapsed = 0 + while timeout <= 0.0 or float(elapsed) < timeout: + self.sim.run(run_time) if self.ego.is_control_received: break - if i > 0 and i % 2 == 0: - self.check_module_status(modules) - log.info( - "{} seconds has passed, Ego hasn't received any control messages".format( - i * 2 - ) - ) - log.info( - "Please also check if your route has been set correctly in Dreamview." - ) + if elapsed > 0 and elapsed % (run_time * 5) == 0: + self.checkModuleStatus(modules) + log.info("{} seconds have passed but Ego hasn't received any control messages.".format(elapsed)) + log.info("Please also check if your route has been set correctly in Dreamview.") + + elapsed += run_time else: - log.error("No control message from Apollo within 40 seconds. Aborting...") + log.error("No control message from Apollo within {} seconds. Aborting...".format(timeout)) self.disable_apollo() raise WaitApolloError() @@ -323,7 +328,7 @@ def on_control_received(agent, kind, context): class WaitApolloError(Exception): """ - Raised when Apollo control message is not recieved in time + Raised when Apollo control message is not received in time """ pass From faa502d39c9bfd91d58a7b21bf2840e976aead3c Mon Sep 17 00:00:00 2001 From: Shalin Mehta Date: Mon, 5 Oct 2020 14:52:51 -0700 Subject: [PATCH 038/115] Fix function call to updated function name --- lgsvl/dreamview/dreamview.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsvl/dreamview/dreamview.py b/lgsvl/dreamview/dreamview.py index 2aeaf1a..5480bfd 100644 --- a/lgsvl/dreamview/dreamview.py +++ b/lgsvl/dreamview/dreamview.py @@ -313,7 +313,7 @@ def on_control_received(agent, kind, context): break if elapsed > 0 and elapsed % (run_time * 5) == 0: - self.checkModuleStatus(modules) + self.check_module_status(modules) log.info("{} seconds have passed but Ego hasn't received any control messages.".format(elapsed)) log.info("Please also check if your route has been set correctly in Dreamview.") From 2d9e350df9b80d7f74d699c2024e5c386eac28c2 Mon Sep 17 00:00:00 2001 From: "hadi.tabatabaee" Date: Wed, 7 Oct 2020 14:55:54 -0700 Subject: [PATCH 039/115] Allow some sim.xxx functions to accept arguments of type(None) --- lgsvl/simulator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index a786a15..a2dc2ce 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -125,7 +125,7 @@ def _process(self, cmd, args): break j = self.remote.command("simulator/continue") - @accepts(str, AgentType, AgentState, Vector) + @accepts(str, AgentType, (AgentState, type(None)), (Vector, type(None))) def add_agent(self, name, agent_type, state=None, color=None): if state is None: state = AgentState() if color is None: color = Vector(-1, -1, -1) @@ -265,7 +265,7 @@ def raycast_batch(self, args): return results - @accepts(str, ObjectState) + @accepts(str, (ObjectState, type(None))) def controllable_add(self, name, object_state=None): if object_state is None: object_state = ObjectState() args = {"name": name, "state": object_state.to_json()} From 9a17e0d5b32da73dc751bb32d7d7bd79ecb20ebc Mon Sep 17 00:00:00 2001 From: Hadi Tabatabaee Date: Fri, 9 Oct 2020 15:21:45 -0700 Subject: [PATCH 040/115] Add default values for weather/road conditions --- lgsvl/simulator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index a2dc2ce..9cc7afb 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -16,6 +16,7 @@ RaycastHit = namedtuple("RaycastHit", "distance point normal") WeatherState = namedtuple("WeatherState", "rain fog wetness cloudiness damage") +WeatherState.__new__.__defaults__ = (0,) * len(WeatherState._fields) class Simulator: @@ -154,7 +155,7 @@ def get_agents(self): @property def weather(self): j = self.remote.command("environment/weather/get") - return WeatherState(j["rain"], j["fog"], j["wetness"], j["cloudiness"], j["damage"]) + return WeatherState(j.get("rain", 0), j.get("fog", 0), j.get("wetness", 0), j.get("cloudiness", 0), j.get("damage", 0)) @weather.setter @accepts(WeatherState) From 67ebc9ccb37af8842f005a76c153d660d23a1227 Mon Sep 17 00:00:00 2001 From: eric_boise Date: Thu, 15 Oct 2020 19:14:43 -0400 Subject: [PATCH 041/115] edit analysis sensor after refactor --- lgsvl/sensor.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lgsvl/sensor.py b/lgsvl/sensor.py index a6dd9b5..359520a 100644 --- a/lgsvl/sensor.py +++ b/lgsvl/sensor.py @@ -145,9 +145,6 @@ def __init__(self, remote, j): class AnalysisSensor(Sensor): def __init__(self, remote, j): super().__init__(remote, j["uid"], j["name"]) - self.suddenbrakemax = j["suddenbrakemax"] - self.suddensteermax = j["suddensteermax"] self.stucktravelthreshold = j["stucktravelthreshold"] self.stucktimethreshold = j["stucktimethreshold"] - self.minfps = j["minfps"] - self.minfpstime = j["minfpstime"] + self.stoplinethreshold = j["stoplinethreshold"] From 3f27101695bd4eeb52e3746b95658e1f2dc77414 Mon Sep 17 00:00:00 2001 From: "eric.boise" Date: Thu, 22 Oct 2020 12:19:49 -0700 Subject: [PATCH 042/115] [FEATURE] [AUTO-4891] Get used unity layers --- lgsvl/simulator.py | 4 ++++ quickstart/03-raycast.py | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index 9cc7afb..392c514 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -43,6 +43,10 @@ def load(self, scene, seed=None): def version(self): return self.remote.command("simulator/version") + @property + def layers(self): + return self.remote.command("simulator/layers/get") + @property def current_scene(self): return self.remote.command("simulator/current_scene") diff --git a/quickstart/03-raycast.py b/quickstart/03-raycast.py index fe12799..2a0dece 100755 --- a/quickstart/03-raycast.py +++ b/quickstart/03-raycast.py @@ -28,17 +28,21 @@ p = spawns[0].position p.y += 1 +#use layers property to get all layers used in simulator # useful bits in layer mask # 0 - Default (road & ground) # 9 - EGO vehicles # 10 - NPC vehicles # 11 - Pedestrian # 12 - Obstacle +layers = sim.layers +print(layers) # Included layers can be hit by the rays. Otherwise the ray will go through the layer layer_mask = 0 -for bit in [0, 10, 11, 12]: # do not put 9 here, to not hit EGO vehicle itself - layer_mask |= 1 << bit +tohitlayers = ["Default", "NPC", "Pedestrian", "Obstacle"] +for l in tohitlayers: + layer_mask |= 1 << layers[l] # raycast returns None if the ray doesn't collide with anything # hit also has the point property which is the Unity position vector of where the ray collided with something From 2bd841bfa699f79063f3ef77ca365c6ea153fec8 Mon Sep 17 00:00:00 2001 From: eric_boise Date: Thu, 22 Oct 2020 15:25:36 -0400 Subject: [PATCH 043/115] fix missing space in layers comment --- quickstart/03-raycast.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickstart/03-raycast.py b/quickstart/03-raycast.py index 2a0dece..9930362 100755 --- a/quickstart/03-raycast.py +++ b/quickstart/03-raycast.py @@ -28,7 +28,7 @@ p = spawns[0].position p.y += 1 -#use layers property to get all layers used in simulator +# use layers property to get all layers used in simulator # useful bits in layer mask # 0 - Default (road & ground) # 9 - EGO vehicles From 9b5cccd2100930e84679a8ae655482342309f550 Mon Sep 17 00:00:00 2001 From: eric_boise Date: Thu, 22 Oct 2020 15:33:19 -0400 Subject: [PATCH 044/115] fix var name issue in quick start 03 --- quickstart/03-raycast.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quickstart/03-raycast.py b/quickstart/03-raycast.py index 9930362..a5f291a 100755 --- a/quickstart/03-raycast.py +++ b/quickstart/03-raycast.py @@ -41,8 +41,8 @@ # Included layers can be hit by the rays. Otherwise the ray will go through the layer layer_mask = 0 tohitlayers = ["Default", "NPC", "Pedestrian", "Obstacle"] -for l in tohitlayers: - layer_mask |= 1 << layers[l] +for layer in tohitlayers: + layer_mask |= 1 << layers[layer] # raycast returns None if the ray doesn't collide with anything # hit also has the point property which is the Unity position vector of where the ray collided with something From 4a9402c51314b65c1226ad151136f4e43b887d59 Mon Sep 17 00:00:00 2001 From: "shalin.mehta" Date: Tue, 27 Oct 2020 14:52:21 -0700 Subject: [PATCH 045/115] Use updated environment variables --- lgsvl/dreamview/dreamview.py | 6 +++--- lgsvl/simulator.py | 5 ++++- quickstart/01-connecting-to-simulator.py | 10 +++++++--- quickstart/02-loading-scene-show-spawns.py | 6 ++++-- quickstart/03-raycast.py | 8 +++++--- quickstart/04-ego-drive-straight.py | 8 +++++--- quickstart/05-ego-drive-in-circle.py | 8 +++++--- quickstart/06-save-camera-image.py | 8 +++++--- quickstart/07-save-lidar-point-cloud.py | 8 +++++--- quickstart/08-create-npc.py | 8 +++++--- quickstart/09-reset-scene.py | 10 ++++++---- quickstart/10-npc-follow-the-lane.py | 8 +++++--- quickstart/11-collision-callbacks.py | 8 +++++--- quickstart/12-create-npc-on-lane.py | 10 ++++++---- quickstart/13-npc-follow-waypoints.py | 10 ++++++---- quickstart/14-create-pedestrians.py | 10 ++++++---- quickstart/15-pedestrian-walk-randomly.py | 8 +++++--- quickstart/16-pedestrian-follow-waypoints.py | 10 ++++++---- quickstart/17-many-pedestrians-walking.py | 10 ++++++---- quickstart/18-weather-effects.py | 8 +++++--- quickstart/19-time-of-day.py | 8 +++++--- quickstart/20-enable-sensors.py | 8 +++++--- quickstart/21-map-coordinates.py | 6 ++++-- quickstart/22-connecting-bridge.py | 12 +++++++----- quickstart/23-npc-callbacks.py | 10 ++++++---- quickstart/24-ego-drive-straight-non-realtime.py | 10 ++++++---- quickstart/25-waypoint-flying-npc.py | 8 +++++--- quickstart/26-npc-trigger-waypoints.py | 8 +++++--- quickstart/27-control-traffic-lights.py | 15 +++++++-------- quickstart/28-control-traffic-cone.py | 13 ++++++------- quickstart/29-add-random-agents.py | 10 ++++++---- quickstart/30-time-to-collision-trigger.py | 10 ++++++---- quickstart/31-wait-for-distance-trigger.py | 10 ++++++---- quickstart/32-pedestrian-time-to-collision.py | 14 ++++++++------ quickstart/98-npc-behaviour.py | 11 +++++++---- requirements.txt | 1 + setup.py | 3 ++- 37 files changed, 196 insertions(+), 128 deletions(-) diff --git a/lgsvl/dreamview/dreamview.py b/lgsvl/dreamview/dreamview.py index 5480bfd..1280d52 100644 --- a/lgsvl/dreamview/dreamview.py +++ b/lgsvl/dreamview/dreamview.py @@ -23,7 +23,7 @@ class CoordType(Enum): class Connection: - def __init__(self, simulator, ego_agent, ip="localhost", port="8888"): + def __init__(self, simulator, ego_agent, ip=os.environ.get("LGSVL__AUTOPILOT_0_HOST", "localhost"), port="8888"): """ simulator: is an lgsvl.Simulator object ego_agent: an lgsvl.EgoVehicle object, this is intended to be used with a vehicle equipped with Apollo 5.0 @@ -299,10 +299,10 @@ def on_control_received(agent, kind, context): self.ego.on_custom(on_control_received) try: - timeout = float(os.environ.get("DREAMVIEW_CONTROL_MESSAGE_TIMEOUT_SECS", default_timeout)) + timeout = float(os.environ.get("LGSVL__DREAMVIEW__CONTROL_MESSAGE_TIMEOUT_SECS", default_timeout)) except Exception: timeout = default_timeout - log.warning("Invalid DREAMVIEW_CONTROL_MESSAGE_TIMEOUT_SECS, using default {0}s".format(default_timeout)) + log.warning("Invalid LGSVL__DREAMVIEW__CONTROL_MESSAGE_TIMEOUT_SECS, using default {0}s".format(default_timeout)) run_time = 2 elapsed = 0 diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index 392c514..0ea9209 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -12,17 +12,20 @@ from .controllable import Controllable from collections import namedtuple +from environs import Env RaycastHit = namedtuple("RaycastHit", "distance point normal") WeatherState = namedtuple("WeatherState", "rain fog wetness cloudiness damage") WeatherState.__new__.__defaults__ = (0,) * len(WeatherState._fields) +env = Env() + class Simulator: @accepts(str, int) - def __init__(self, address="localhost", port=8181): + def __init__(self, address=env.str("LGSVL__SIMULATOR_HOST", "localhost"), port=env.int("LGSVL__SIMULATOR_PORT", 8181)): if port <= 0 or port > 65535: raise ValueError("port value is out of range") self.remote = Remote(address, port) diff --git a/quickstart/01-connecting-to-simulator.py b/quickstart/01-connecting-to-simulator.py index 220b7fb..f30e635 100755 --- a/quickstart/01-connecting-to-simulator.py +++ b/quickstart/01-connecting-to-simulator.py @@ -5,11 +5,15 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -# Connects to the simulator instance at the ip defined by SIMULATOR_HOST, default is localhost or 127.0.0.1 -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +# Connects to the simulator instance at the ip defined by LGSVL__SIMULATOR_HOST, default is localhost or 127.0.0.1 +# env.str() is equivalent to os.environ.get() +# env.int() is equivalent to int(os.environ.get()) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) print("Version =", sim.version) print("Current Time =", sim.current_time) diff --git a/quickstart/02-loading-scene-show-spawns.py b/quickstart/02-loading-scene-show-spawns.py index 07882a6..3e66755 100755 --- a/quickstart/02-loading-scene-show-spawns.py +++ b/quickstart/02-loading-scene-show-spawns.py @@ -5,10 +5,12 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) print("Current Scene = {}".format(sim.current_scene)) diff --git a/quickstart/03-raycast.py b/quickstart/03-raycast.py index a5f291a..7a800ce 100755 --- a/quickstart/03-raycast.py +++ b/quickstart/03-raycast.py @@ -5,10 +5,12 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -22,7 +24,7 @@ forward = lgsvl.utils.transform_to_forward(state.transform) right = lgsvl.utils.transform_to_right(state.transform) up = lgsvl.utils.transform_to_up(state.transform) -sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) # This is the point from which the rays will originate from. It is raised 1m from the ground p = spawns[0].position diff --git a/quickstart/04-ego-drive-straight.py b/quickstart/04-ego-drive-straight.py index 1fe0046..9c18df1 100755 --- a/quickstart/04-ego-drive-straight.py +++ b/quickstart/04-ego-drive-straight.py @@ -5,10 +5,12 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -23,7 +25,7 @@ # Agents can be spawned with a velocity. Default is to spawn with 0 velocity state.velocity = 20 * forward -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) # The bounding box of an agent are 2 points (min and max) such that the box formed from those 2 points completely encases the agent print("Vehicle bounding box =", ego.bounding_box) diff --git a/quickstart/05-ego-drive-in-circle.py b/quickstart/05-ego-drive-in-circle.py index 38b252e..ec7ee31 100755 --- a/quickstart/05-ego-drive-in-circle.py +++ b/quickstart/05-ego-drive-in-circle.py @@ -5,10 +5,12 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -20,7 +22,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) state.transform.position += 5 * forward # 5m forwards -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) print("Current time = ", sim.current_time) print("Current frame = ", sim.current_frame) diff --git a/quickstart/06-save-camera-image.py b/quickstart/06-save-camera-image.py index 946dc8a..7b161e7 100755 --- a/quickstart/06-save-camera-image.py +++ b/quickstart/06-save-camera-image.py @@ -5,10 +5,12 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -18,7 +20,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) # get_sensors returns a list of sensors on the EGO vehicle sensors = ego.get_sensors() diff --git a/quickstart/07-save-lidar-point-cloud.py b/quickstart/07-save-lidar-point-cloud.py index 2d75812..a9d6b9a 100755 --- a/quickstart/07-save-lidar-point-cloud.py +++ b/quickstart/07-save-lidar-point-cloud.py @@ -5,10 +5,12 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -18,7 +20,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) sensors = ego.get_sensors() for s in sensors: diff --git a/quickstart/08-create-npc.py b/quickstart/08-create-npc.py index 12a458a..10d2900 100755 --- a/quickstart/08-create-npc.py +++ b/quickstart/08-create-npc.py @@ -5,10 +5,12 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -18,7 +20,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) diff --git a/quickstart/09-reset-scene.py b/quickstart/09-reset-scene.py index 9b1a498..00f11fa 100755 --- a/quickstart/09-reset-scene.py +++ b/quickstart/09-reset-scene.py @@ -5,13 +5,15 @@ # This software contains code licensed as described in LICENSE. # -import os -import lgsvl import random +from environs import Env +import lgsvl + +env = Env() random.seed(0) -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -21,7 +23,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) diff --git a/quickstart/10-npc-follow-the-lane.py b/quickstart/10-npc-follow-the-lane.py index 0564e43..6c4b820 100755 --- a/quickstart/10-npc-follow-the-lane.py +++ b/quickstart/10-npc-follow-the-lane.py @@ -5,10 +5,12 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -18,7 +20,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) state = lgsvl.AgentState() diff --git a/quickstart/11-collision-callbacks.py b/quickstart/11-collision-callbacks.py index 1872824..97adb63 100755 --- a/quickstart/11-collision-callbacks.py +++ b/quickstart/11-collision-callbacks.py @@ -5,10 +5,12 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -19,7 +21,7 @@ # ego vehicle state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) diff --git a/quickstart/12-create-npc-on-lane.py b/quickstart/12-create-npc-on-lane.py index 2bd1cb4..3d02a67 100755 --- a/quickstart/12-create-npc-on-lane.py +++ b/quickstart/12-create-npc-on-lane.py @@ -5,12 +5,14 @@ # This software contains code licensed as described in LICENSE. # -import os -import lgsvl import math import random +from environs import Env +import lgsvl + +env = Env() -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -20,7 +22,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) sx = spawns[0].position.x sy = spawns[0].position.y diff --git a/quickstart/13-npc-follow-waypoints.py b/quickstart/13-npc-follow-waypoints.py index 0e77c38..2f12112 100755 --- a/quickstart/13-npc-follow-waypoints.py +++ b/quickstart/13-npc-follow-waypoints.py @@ -5,11 +5,13 @@ # This software contains code licensed as described in LICENSE. # -import os -import lgsvl import copy +from environs import Env +import lgsvl + +env = Env() -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -26,7 +28,7 @@ # Ego ego_state = copy.deepcopy(state) ego_state.transform.position += 50 * forward -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, ego_state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) # NPC npc_state = copy.deepcopy(state) diff --git a/quickstart/14-create-pedestrians.py b/quickstart/14-create-pedestrians.py index ab474da..c1222e3 100755 --- a/quickstart/14-create-pedestrians.py +++ b/quickstart/14-create-pedestrians.py @@ -5,12 +5,14 @@ # This software contains code licensed as described in LICENSE. # -import os -import lgsvl import random import time +from environs import Env +import lgsvl + +env = Env() -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -22,7 +24,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) input("Press Enter to start creating pedestrians") diff --git a/quickstart/15-pedestrian-walk-randomly.py b/quickstart/15-pedestrian-walk-randomly.py index 71b4e9d..dba73b3 100755 --- a/quickstart/15-pedestrian-walk-randomly.py +++ b/quickstart/15-pedestrian-walk-randomly.py @@ -5,10 +5,12 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -22,7 +24,7 @@ state.transform.position = spawns[0].position + 40 * forward state.transform.rotation = spawns[0].rotation -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) state = lgsvl.AgentState() # Spawn the pedestrian in front of car diff --git a/quickstart/16-pedestrian-follow-waypoints.py b/quickstart/16-pedestrian-follow-waypoints.py index a3c8e94..2e76252 100755 --- a/quickstart/16-pedestrian-follow-waypoints.py +++ b/quickstart/16-pedestrian-follow-waypoints.py @@ -5,11 +5,13 @@ # This software contains code licensed as described in LICENSE. # -import os -import lgsvl import math +from environs import Env +import lgsvl + +env = Env() -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -21,7 +23,7 @@ state = lgsvl.AgentState() state.transform = spawns[1] -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) # This will create waypoints in a circle for the pedestrian to follow radius = 4 diff --git a/quickstart/17-many-pedestrians-walking.py b/quickstart/17-many-pedestrians-walking.py index 5dbfb32..43251d9 100755 --- a/quickstart/17-many-pedestrians-walking.py +++ b/quickstart/17-many-pedestrians-walking.py @@ -5,11 +5,13 @@ # This software contains code licensed as described in LICENSE. # -import os -import lgsvl import random +from environs import Env +import lgsvl + +env = Env() -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -21,7 +23,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) names = [ "Bob", diff --git a/quickstart/18-weather-effects.py b/quickstart/18-weather-effects.py index 2d9a610..1d30132 100755 --- a/quickstart/18-weather-effects.py +++ b/quickstart/18-weather-effects.py @@ -5,10 +5,12 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -18,7 +20,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) print(sim.weather) diff --git a/quickstart/19-time-of-day.py b/quickstart/19-time-of-day.py index c81e9be..c58c83e 100755 --- a/quickstart/19-time-of-day.py +++ b/quickstart/19-time-of-day.py @@ -5,10 +5,12 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -18,7 +20,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) print("Current time:", sim.time_of_day) diff --git a/quickstart/20-enable-sensors.py b/quickstart/20-enable-sensors.py index ebd69aa..cfc859a 100755 --- a/quickstart/20-enable-sensors.py +++ b/quickstart/20-enable-sensors.py @@ -5,10 +5,12 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -18,7 +20,7 @@ state = lgsvl.AgentState() state.transform = spawns[1] -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) sensors = ego.get_sensors() diff --git a/quickstart/21-map-coordinates.py b/quickstart/21-map-coordinates.py index cb0aec1..674ac2c 100755 --- a/quickstart/21-map-coordinates.py +++ b/quickstart/21-map-coordinates.py @@ -5,10 +5,12 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: diff --git a/quickstart/22-connecting-bridge.py b/quickstart/22-connecting-bridge.py index fd1c428..073dbfe 100755 --- a/quickstart/22-connecting-bridge.py +++ b/quickstart/22-connecting-bridge.py @@ -5,11 +5,13 @@ # This software contains code licensed as described in LICENSE. # -import os -import lgsvl import time +from environs import Env +import lgsvl + +env = Env() -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -19,13 +21,13 @@ state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) # An EGO will not connect to a bridge unless commanded to print("Bridge connected:", ego.bridge_connected) # The EGO is now looking for a bridge at the specified IP and port -ego.connect_bridge(os.environ.get("BRIDGE_HOST", "127.0.0.1"), 9090) +ego.connect_bridge(env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1"), env.int("LGSVL__AUTOPILOT_0_PORT", 9090)) print("Waiting for connection...") diff --git a/quickstart/23-npc-callbacks.py b/quickstart/23-npc-callbacks.py index f76ae79..9439971 100755 --- a/quickstart/23-npc-callbacks.py +++ b/quickstart/23-npc-callbacks.py @@ -5,12 +5,14 @@ # This software contains code licensed as described in LICENSE. # -import os -import lgsvl import math import random +from environs import Env +import lgsvl + +env = Env() -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -22,7 +24,7 @@ state = lgsvl.AgentState() state.transform = sim.map_point_on_lane(spawns[0].position + 200 * forward) -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) mindist = 10.0 maxdist = 40.0 diff --git a/quickstart/24-ego-drive-straight-non-realtime.py b/quickstart/24-ego-drive-straight-non-realtime.py index bbeed0a..a56bf01 100755 --- a/quickstart/24-ego-drive-straight-non-realtime.py +++ b/quickstart/24-ego-drive-straight-non-realtime.py @@ -5,11 +5,13 @@ # This software contains code licensed as described in LICENSE. # -import os -import lgsvl import time +from environs import Env +import lgsvl + +env = Env() -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -22,7 +24,7 @@ forward = lgsvl.utils.transform_to_forward(spawns[0]) # Agents can be spawned with a velocity. Default is to spawn with 0 velocity state.velocity = 20 * forward -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) print("Real time elapsed =", 0) print("Simulation time =", sim.current_time) diff --git a/quickstart/25-waypoint-flying-npc.py b/quickstart/25-waypoint-flying-npc.py index 46937c6..b7ec422 100755 --- a/quickstart/25-waypoint-flying-npc.py +++ b/quickstart/25-waypoint-flying-npc.py @@ -5,10 +5,12 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -22,7 +24,7 @@ right = lgsvl.utils.transform_to_right(spawns[0]) up = lgsvl.utils.transform_to_up(spawns[0]) state.transform = spawns[0] -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() diff --git a/quickstart/26-npc-trigger-waypoints.py b/quickstart/26-npc-trigger-waypoints.py index 4b9921c..ce1c81f 100755 --- a/quickstart/26-npc-trigger-waypoints.py +++ b/quickstart/26-npc-trigger-waypoints.py @@ -5,10 +5,12 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: @@ -21,7 +23,7 @@ forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) state.transform = spawns[0] -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() diff --git a/quickstart/27-control-traffic-lights.py b/quickstart/27-control-traffic-lights.py index a0aefec..05069a5 100755 --- a/quickstart/27-control-traffic-lights.py +++ b/quickstart/27-control-traffic-lights.py @@ -5,17 +5,16 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() -scene_name = "BorregasAve" - -if sim.current_scene == scene_name: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) +if sim.current_scene == "BorregasAve": sim.reset() else: - sim.load(scene_name, 42) + sim.load("BorregasAve", 42) spawns = sim.get_spawn() @@ -23,13 +22,13 @@ forward = lgsvl.utils.transform_to_forward(spawns[0]) state.transform = spawns[0] state.transform.position = spawns[0].position + 20 * forward -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) print("Python API Quickstart #27: How to Control Traffic Light") # # Get a list of controllable objects controllables = sim.get_controllables("signal") -print("\n# List of controllable objects in {} scene:".format(scene_name)) +print("\n# List of controllable objects in {} scene:".format("BorregasAve")) for c in controllables: print(c) diff --git a/quickstart/28-control-traffic-cone.py b/quickstart/28-control-traffic-cone.py index 67332b2..40ab183 100755 --- a/quickstart/28-control-traffic-cone.py +++ b/quickstart/28-control-traffic-cone.py @@ -5,17 +5,16 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() -scene_name = "CubeTown" - -if sim.current_scene == scene_name: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) +if sim.current_scene == "BorregasAve": sim.reset() else: - sim.load(scene_name, 42) + sim.load("BorregasAve", 42) spawns = sim.get_spawn() @@ -25,7 +24,7 @@ up = lgsvl.utils.transform_to_up(spawns[0]) state.transform = spawns[0] -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) print("Python API Quickstart #28: How to Add/Control Traffic Cone") diff --git a/quickstart/29-add-random-agents.py b/quickstart/29-add-random-agents.py index a049014..ab224a3 100755 --- a/quickstart/29-add-random-agents.py +++ b/quickstart/29-add-random-agents.py @@ -5,14 +5,16 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve", 42) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -22,7 +24,7 @@ state.transform.position = spawns[0].position + 40 * forward state.transform.rotation = spawns[0].rotation -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) sim.add_random_agents(lgsvl.AgentType.NPC) sim.add_random_agents(lgsvl.AgentType.PEDESTRIAN) diff --git a/quickstart/30-time-to-collision-trigger.py b/quickstart/30-time-to-collision-trigger.py index 07aa8a7..7b979ed 100755 --- a/quickstart/30-time-to-collision-trigger.py +++ b/quickstart/30-time-to-collision-trigger.py @@ -5,14 +5,16 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve", 42) spawns = sim.get_spawn() layer_mask = 0 @@ -29,7 +31,7 @@ spawn_state.position = hit.point state.transform = spawn_state state.velocity = forward * 2 -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() diff --git a/quickstart/31-wait-for-distance-trigger.py b/quickstart/31-wait-for-distance-trigger.py index 7bc4774..1465170 100755 --- a/quickstart/31-wait-for-distance-trigger.py +++ b/quickstart/31-wait-for-distance-trigger.py @@ -5,14 +5,16 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve", 42) spawns = sim.get_spawn() layer_mask = 0 @@ -29,7 +31,7 @@ spawn_state.position = hit.point state.transform = spawn_state state.velocity = forward * 2 -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() diff --git a/quickstart/32-pedestrian-time-to-collision.py b/quickstart/32-pedestrian-time-to-collision.py index fa2e84f..7ab9419 100755 --- a/quickstart/32-pedestrian-time-to-collision.py +++ b/quickstart/32-pedestrian-time-to-collision.py @@ -5,14 +5,16 @@ # This software contains code licensed as described in LICENSE. # -import os +from environs import Env import lgsvl -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) if sim.current_scene == "BorregasAve": sim.reset() else: - sim.load("BorregasAve") + sim.load("BorregasAve", 42) spawns = sim.get_spawn() layer_mask = 0 @@ -26,7 +28,7 @@ state.transform.rotation = lgsvl.Vector(0.0, 15.0, 0.0) forward = lgsvl.Vector(0.2, 0.0, 0.8) state.velocity = forward * 15 -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) # Pedestrian state = lgsvl.AgentState() @@ -37,7 +39,7 @@ state.transform.rotation = pedestrian_rotation pedestrian = sim.add_agent("Bob", lgsvl.AgentType.PEDESTRIAN, state) -agents = {a: "EGO", pedestrian: "Bob"} +agents = {ego: "EGO", pedestrian: "Bob"} # Executed upon receiving collision callback -- pedestrian is expected to walk into colliding objects @@ -47,7 +49,7 @@ def on_collision(agent1, agent2, contact): print("{} collided with {}".format(name1, name2)) -a.on_collision(on_collision) +ego.on_collision(on_collision) pedestrian.on_collision(on_collision) # This block creates the list of waypoints that the pedestrian will follow diff --git a/quickstart/98-npc-behaviour.py b/quickstart/98-npc-behaviour.py index 4f7774d..9aa1796 100755 --- a/quickstart/98-npc-behaviour.py +++ b/quickstart/98-npc-behaviour.py @@ -5,12 +5,15 @@ # This software contains code licensed as described in LICENSE. # -import os -import lgsvl import math import random +from environs import Env +import lgsvl + +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) drunkDriverAvailable = False trailerAvailable = 0 map = "CubeTown" @@ -56,7 +59,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) mindist = 10.0 maxdist = 40.0 diff --git a/requirements.txt b/requirements.txt index 9fd3f76..040786e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ websockets>=7.0 websocket-client==0.57.0 # for dreamview flake8>=3.7.0 numpy # for evaluator +environs diff --git a/setup.py b/setup.py index cefa1c6..ab75a87 100755 --- a/setup.py +++ b/setup.py @@ -13,7 +13,8 @@ install_requires=[ "websockets==7.0", "websocket-client==0.57.0", - "numpy" + "numpy", + "environs" ], license="Other", classifiers=[ From ef94a3735111d8ae290bcd165d219ada15d0392c Mon Sep 17 00:00:00 2001 From: Shalin Mehta Date: Fri, 16 Oct 2020 15:06:55 -0700 Subject: [PATCH 046/115] Update params of VideoRecordingSensor --- lgsvl/sensor.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lgsvl/sensor.py b/lgsvl/sensor.py index 359520a..2b96a8c 100644 --- a/lgsvl/sensor.py +++ b/lgsvl/sensor.py @@ -140,6 +140,12 @@ def __init__(self, remote, j): self.width = j["width"] self.height = j["height"] self.framerate = j["framerate"] + self.min_distance = j["near_plane"] + self.max_distance = j["far_plane"] + self.fov = j["fov"] + self.quality = j["quality"] + self.bitrate = j["bitrate"] + self.max_bitrate = j["max_bitrate"] class AnalysisSensor(Sensor): From eeeb3e22c787d73b2233370c2199214f31d3a90c Mon Sep 17 00:00:00 2001 From: Shalin Mehta Date: Mon, 26 Oct 2020 13:58:56 -0700 Subject: [PATCH 047/115] AUTO-5127: Perform mapping on config options before sending to Dreamview --- lgsvl/dreamview/dreamview.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lgsvl/dreamview/dreamview.py b/lgsvl/dreamview/dreamview.py index 1280d52..e02f0a2 100644 --- a/lgsvl/dreamview/dreamview.py +++ b/lgsvl/dreamview/dreamview.py @@ -126,29 +126,36 @@ def disable_module(self, module): ) return - def set_hd_map(self, map): + def set_hd_map(self, hd_map): """ Folders in /apollo/modules/map/data/ are the available HD maps Map options in Dreamview are the folder names with the following changes: - underscores (_) are replaced with spaces - the first letter of each word is capitalized - map parameter is the modified folder name. - map should match one of the options in the right-most drop down in the top-right corner of Dreamview. + hd_map parameter is the modified folder name. + hd_map should match one of the options in the right-most drop down in the top-right corner of Dreamview. """ + + word_list = [] + for s in hd_map.split('_'): + word_list.append(s[0].upper() + s[1:]) + + mapped_map = ' '.join(word_list) + self.ws.send( - json.dumps({"type": "HMIAction", "action": "CHANGE_MAP", "value": map}) + json.dumps({"type": "HMIAction", "action": "CHANGE_MAP", "value": mapped_map}) ) - if not self.get_current_map() == map: - folder_name = map.replace(" ", "_") + if not self.get_current_map() == mapped_map: + folder_name = hd_map.replace(" ", "_") error_message = ( "HD Map {0} was not set. Verify the files exist in " "/apollo/modules/map/data/{1} and restart Dreamview -- Aborting..." ) log.error( error_message.format( - map, folder_name + mapped_map, folder_name ) ) sys.exit(1) @@ -165,15 +172,22 @@ def set_vehicle(self, vehicle, gps_offset_x=0.0, gps_offset_y=0.0, gps_offset_z= vehicle parameter is the modified folder name. vehicle should match one of the options in the middle drop down in the top-right corner of Dreamview. """ + + word_list = [] + for s in vehicle.split('_'): + word_list.append(s[0].upper() + s[1:]) + + mapped_vehicle = ' '.join(word_list) + self.ws.send( json.dumps( - {"type": "HMIAction", "action": "CHANGE_VEHICLE", "value": vehicle} + {"type": "HMIAction", "action": "CHANGE_VEHICLE", "value": mapped_vehicle} ) ) self.gps_offset = lgsvl.Vector(gps_offset_x, gps_offset_y, gps_offset_z) - if not self.get_current_vehicle() == vehicle: + if not self.get_current_vehicle() == mapped_vehicle: folder_name = vehicle.replace(" ", "_") error_message = ( "Vehicle calibration {0} was not set. Verify the files exist in " @@ -181,7 +195,7 @@ def set_vehicle(self, vehicle, gps_offset_x=0.0, gps_offset_y=0.0, gps_offset_z= ) log.error( error_message.format( - vehicle, folder_name + mapped_vehicle, folder_name ) ) sys.exit(1) From fa091466244106a0a247c8645fed31cefb04dc4c Mon Sep 17 00:00:00 2001 From: "eric.boise" Date: Tue, 3 Nov 2020 14:24:46 -0800 Subject: [PATCH 048/115] [Update] [AUTO-5176] Get current scene id --- lgsvl/simulator.py | 4 ++++ quickstart/02-loading-scene-show-spawns.py | 1 + 2 files changed, 5 insertions(+) diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index 0ea9209..4c876b6 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -54,6 +54,10 @@ def layers(self): def current_scene(self): return self.remote.command("simulator/current_scene") + @property + def current_scene_id(self): + return self.remote.command("simulator/current_scene_id") + @property def current_frame(self): return self.remote.command("simulator/current_frame") diff --git a/quickstart/02-loading-scene-show-spawns.py b/quickstart/02-loading-scene-show-spawns.py index 3e66755..b72422d 100755 --- a/quickstart/02-loading-scene-show-spawns.py +++ b/quickstart/02-loading-scene-show-spawns.py @@ -21,6 +21,7 @@ sim.load("BorregasAve") print("Current Scene = {}".format(sim.current_scene)) +print("Current Scene ID = {}".format(sim.current_scene_id)) # This will print out the position and rotation vectors for each of the spawn points in the loaded map spawns = sim.get_spawn() From 1dde6de0f82172a436a037bd549a1bc7046cdacf Mon Sep 17 00:00:00 2001 From: "hadi.tabatabaee" Date: Wed, 4 Nov 2020 13:38:05 -0800 Subject: [PATCH 049/115] AUTO-5174: Add support for setting date as well as time --- lgsvl/simulator.py | 21 +++++++++++++++++++++ quickstart/19-time-of-day.py | 12 ++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index 4c876b6..4d606dd 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -13,6 +13,8 @@ from collections import namedtuple from environs import Env +from datetime import datetime +import re RaycastHit = namedtuple("RaycastHit", "distance point normal") @@ -177,10 +179,29 @@ def weather(self, state): def time_of_day(self): return self.remote.command("environment/time/get") + @property + def current_datetime(self): + date_time_str = self.remote.command("simulator/datetime/get") + date_time_arr = list(map(int, re.split('[. :]', date_time_str))) + date_time = datetime( + date_time_arr[2], + date_time_arr[1], + date_time_arr[0], + date_time_arr[3], + date_time_arr[4], + date_time_arr[5] + ) + return date_time + @accepts((int, float), bool) def set_time_of_day(self, time, fixed=True): self.remote.command("environment/time/set", {"time": time, "fixed": fixed}) + @accepts(datetime, bool) + def set_date_time(self, date_time, fixed=True): + date_time = date_time.__str__() + self.remote.command("environment/datetime/set", {"datetime": date_time, "fixed": fixed}) + def get_spawn(self): spawns = self.remote.command("map/spawn/get") return [Spawn.from_json(spawn) for spawn in spawns] diff --git a/quickstart/19-time-of-day.py b/quickstart/19-time-of-day.py index c58c83e..c9c30f0 100755 --- a/quickstart/19-time-of-day.py +++ b/quickstart/19-time-of-day.py @@ -7,6 +7,7 @@ from environs import Env import lgsvl +from datetime import datetime env = Env() @@ -40,3 +41,14 @@ sim.run(5) print(sim.time_of_day) + +input("Press Enter to set date to July 1 2020 and time to 19:00") +dt = datetime(2020, 7, 1, 19, 0, 0, 0) +sim.set_date_time(dt, False) +print(sim.time_of_day) +print(sim.current_datetime) + +sim.run(5) + +print(sim.time_of_day) +print(sim.current_datetime) From 0bd3d36cc5f4ed40e4eba5e47856c3c859334e30 Mon Sep 17 00:00:00 2001 From: Shalin Mehta Date: Wed, 4 Nov 2020 14:20:03 -0800 Subject: [PATCH 050/115] Skip Windshield wiper tests because they are not supported anymore --- tests/test_manual_features.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_manual_features.py b/tests/test_manual_features.py index f630424..8c386ac 100644 --- a/tests/test_manual_features.py +++ b/tests/test_manual_features.py @@ -13,6 +13,7 @@ class TestManual(unittest.TestCase): + @unittest.skip("Windshield wipers no longer supported") def test_wipers(self): try: with SimConnection() as sim: @@ -73,6 +74,7 @@ def test_blinkers(self): except TestTimeout: self.fail("Turn signals were not on") + @unittest.skip("Windshield wipers no longer supported") def test_wiper_large_value(self): try: with SimConnection() as sim: @@ -85,6 +87,7 @@ def test_wiper_large_value(self): except TestTimeout: self.fail("Wipers were on") + @unittest.skip("Windshield wipers no longer supported") def test_wiper_str(self): try: with SimConnection() as sim: From 1e92ccda933fe8f443f2ebca6f238e00fa50a7fe Mon Sep 17 00:00:00 2001 From: Steve Lemke Date: Tue, 15 Sep 2020 10:19:51 -0700 Subject: [PATCH 051/115] AUTO-4595: Add quickstart 33 to demonstrate simulator with (or without) Apollo in Stepped Simulation mode --- quickstart/33-ego-drive-stepped.py | 115 +++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100755 quickstart/33-ego-drive-stepped.py diff --git a/quickstart/33-ego-drive-stepped.py b/quickstart/33-ego-drive-stepped.py new file mode 100755 index 0000000..989b592 --- /dev/null +++ b/quickstart/33-ego-drive-stepped.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2020 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +import os +import lgsvl +import time + +sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +if sim.current_scene == "BorregasAve": + sim.reset() +# Re-load scene and set random seed +sim.load("BorregasAve", seed=123) + +spawns = sim.get_spawn() + +state = lgsvl.AgentState() +state.transform = spawns[0] +forward = lgsvl.utils.transform_to_forward(spawns[0]) + +# Agents can be spawned with a velocity. Default is to spawn with 0 velocity +# state.velocity = 20 * forward + +# In order for Apollo to drive with stepped simulation we must add the clock sensor +# and we must also set clock_mode to MODE_MOCK in Apollo's cyber/conf/cyber.pb.conf +# Note that MODE_MOCK is only supported in Apollo master (6.0 or later)! +# Refer to https://www.lgsvlsimulator.com/docs/sensor-json-options/#clock + +# We can test Apollo with standard MKZ or MKZ with ground truth sensors +# Refer to https://www.lgsvlsimulator.com/docs/modular-testing/ +# ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0gt)", lgsvl.AgentType.EGO, state) + +# An EGO will not connect to a bridge unless commanded to +print("Bridge connected:", ego.bridge_connected) + +# The EGO looks for a (Cyber) bridge at the specified IP and port +ego.connect_bridge("127.0.0.1", 9090) +# uncomment to wait for bridge connection; script will drive ego if bridge not found +# print("Waiting for connection...") +# while not ego.bridge_connected: +time.sleep(1) + +print("Bridge connected:", ego.bridge_connected) + +# spawn random NPCs +sim.add_random_agents(lgsvl.AgentType.NPC) +sim.add_random_agents(lgsvl.AgentType.PEDESTRIAN) + +t0 = time.time() +s0 = sim.current_time +print() +print("Total real time elapsed = {:5.3f}".format(0)) +print("Simulation time = {:5.1f}".format(s0)) +print("Simulation frames =", sim.current_frame) + +# let simulator initialize and settle a bit before starting +sim.run(time_limit=2) + +t1 = time.time() +s1 = sim.current_time +print() +print("Total real time elapsed = {:5.3f}".format(t1 - t0)) +print("Simulation settle time = {:5.1f}".format(s1 - s0)) +print("Simulation settle frames =", sim.current_frame) + +# tell ego to drive forward, or not (if apollo is driving) +if not ego.bridge_connected: + state = ego.state + forward = lgsvl.utils.transform_to_forward(state.transform) + state.velocity = 20 * forward + ego.state = state + duration = 15 +else: + duration = 45 + +step_time = 0.10 + +step_rate = int(1.0 / step_time) +steps = duration * step_rate +print() +print("Stepping forward for {} steps of {}s per step" .format(steps, step_time)) +input("Press Enter to start:") + +# The simulator can be run for a set amount of time. +# time_limit is optional and if omitted or set to 0, then the simulator will run indefinitely +t0 = time.time() +for i in range(steps): + t1 = time.time() + sim.run(time_limit=step_time) + t2 = time.time() + s2 = sim.current_time + + state = ego.state + pos = state.position + speed = state.speed * 3.6 + + # if Apollo is not driving + if not ego.bridge_connected: + state.velocity = 20 * forward + ego.state = state + + print("Sim time = {:5.2f}".format(s2 - s1) + "; Real time elapsed = {:5.3f}; ".format(t2 - t1), end='') + print("Speed = {:4.1f}; Position = {:5.3f},{:5.3f},{:5.3f}".format(speed, pos.x, pos.y, pos.z)) + time.sleep(0.2) + +t3 = time.time() + +# Final statistics +print("Total real time elapsed = {:5.3f}".format(t3 - t0)) +print("Simulation time = {:5.1f}".format(sim.current_time)) +print("Simulation frames =", sim.current_frame) From 6c1ccd220d84f8b502cc209893d3bd986db7115e Mon Sep 17 00:00:00 2001 From: Hadi Tabatabaee Date: Mon, 28 Dec 2020 16:10:00 -0800 Subject: [PATCH 052/115] Change SIMULATOR_HOST to LGSVL__SIMULATOR_HOST --- README.md | 2 +- .../Encroaching-Oncoming-Vehicles/EOV_S_25_20.py | 2 +- .../Encroaching-Oncoming-Vehicles/EOV_S_45_40.py | 2 +- .../Encroaching-Oncoming-Vehicles/EOV_S_65_60.py | 2 +- examples/NHTSA-sample-tests/Vehicle-Following/VF_S_25_Slow.py | 2 +- examples/NHTSA-sample-tests/Vehicle-Following/VF_S_45_Slow.py | 2 +- examples/NHTSA-sample-tests/Vehicle-Following/VF_S_65_Slow.py | 2 +- examples/kitti_parser.py | 4 ++-- quickstart/33-ego-drive-stepped.py | 2 +- tests/common.py | 2 +- tests/test_sensors.py | 4 ++-- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a808229..fb2bac5 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Look into `quickstart` folder for simple usages. To run these examples first start the simulator and leave it in main menu. By default examples connect to Simulator on `localhost` address. To change it, adjust first argument of `Simulator` constructor, or set up -`SIMULATOR_HOST` environment variable with hostname. +`LGSVL__SIMULATOR_HOST` environment variable with hostname. # Documentation diff --git a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py index 34452eb..357dfb2 100755 --- a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py +++ b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py @@ -21,7 +21,7 @@ print("EOV_S_25_20 - ", end='') -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "SingleLaneRoad": sim.reset() else: diff --git a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py index b8708a0..77ee5bb 100755 --- a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py +++ b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py @@ -21,7 +21,7 @@ print("EOV_S_45_40 - ", end='') -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "SingleLaneRoad": sim.reset() else: diff --git a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py index 2c64aa9..a508585 100755 --- a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py +++ b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py @@ -21,7 +21,7 @@ print("EOV_S_65_60 - ", end='') -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "SingleLaneRoad": sim.reset() else: diff --git a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_25_Slow.py b/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_25_Slow.py index 50a5b8b..ad07090 100755 --- a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_25_Slow.py +++ b/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_25_Slow.py @@ -22,7 +22,7 @@ print("VF_S_25_Slow - ", end='') -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "SingleLaneRoad": sim.reset() else: diff --git a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_45_Slow.py b/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_45_Slow.py index 1b5e5fe..08f7bfa 100755 --- a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_45_Slow.py +++ b/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_45_Slow.py @@ -22,7 +22,7 @@ print("VF_S_45_Slow - ", end='') -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "SingleLaneRoad": sim.reset() else: diff --git a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_65_Slow.py b/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_65_Slow.py index 26dfd34..5a54098 100755 --- a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_65_Slow.py +++ b/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_65_Slow.py @@ -22,7 +22,7 @@ print("VF_S_65_Slow - ", end='') -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "SingleLaneRoad": sim.reset() else: diff --git a/examples/kitti_parser.py b/examples/kitti_parser.py index 9943981..cc00a43 100755 --- a/examples/kitti_parser.py +++ b/examples/kitti_parser.py @@ -11,7 +11,7 @@ # The data format is defined in a readme.txt downloadable from: https://s3.eu-central-1.amazonaws.com/avg-kitti/devkit_object.zip # Install numpy and PIL before running this script -# SIMULATOR_HOST environment variable also needs to be set before running the script +# LGSVL__SIMULATOR_HOST environment variable also needs to be set before running the script # 3 command line arguements are required when running this script. The arguements are: # number of data points to collect (int) @@ -70,7 +70,7 @@ def bootstrap(self): os.makedirs(LIDAR_BIN_PATH, exist_ok=True) os.makedirs(LABEL_PATH, exist_ok=True) - self.sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) + self.sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1"), 8181) self.load_scene() self.sim.reset() self.ego = self.sim.add_agent(self.agent_name, lgsvl.AgentType.EGO) diff --git a/quickstart/33-ego-drive-stepped.py b/quickstart/33-ego-drive-stepped.py index 989b592..b2f406a 100755 --- a/quickstart/33-ego-drive-stepped.py +++ b/quickstart/33-ego-drive-stepped.py @@ -9,7 +9,7 @@ import lgsvl import time -sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) +sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1"), 8181) if sim.current_scene == "BorregasAve": sim.reset() # Re-load scene and set random seed diff --git a/tests/common.py b/tests/common.py index c7517a5..93c2ace 100644 --- a/tests/common.py +++ b/tests/common.py @@ -33,7 +33,7 @@ def __enter__(self): signal.signal(signal.SIGALRM, self.handle_timeout) signal.alarm(self.seconds) - self.sim = lgsvl.Simulator(os.environ.get("SIMULATOR_HOST", "127.0.0.1"), 8181) + self.sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1"), 8181) if self.load_scene: if self.sim.current_scene == self.scene: self.sim.reset() diff --git a/tests/test_sensors.py b/tests/test_sensors.py index 94d9920..e729191 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -123,7 +123,7 @@ def test_save_sensor(self): # Check that sensor results can be saved with SimConnection(120) as sim: path = "main-camera.png" - islocal = os.environ.get("SIMULATOR_HOST", "127.0.0.1") == "127.0.0.1" + islocal = os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1") == "127.0.0.1" if islocal: path = os.getcwd() + path @@ -150,7 +150,7 @@ def test_save_sensor(self): # Check that sensor results can be saved def test_save_lidar(self): # Check that LIDAR sensor results can be saved with SimConnection(240) as sim: path = "lidar.pcd" - islocal = os.environ.get("SIMULATOR_HOST", "127.0.0.1") == "127.0.0.1" + islocal = os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1") == "127.0.0.1" if islocal: path = os.getcwd() + path From c2199ce04facc7096b21fe2d57aa50f6f7f10153 Mon Sep 17 00:00:00 2001 From: "eric.boise" Date: Wed, 20 Jan 2021 22:33:50 -0800 Subject: [PATCH 053/115] [FEATURE] [AUTO-5633] Set simulator camera free state and transform --- lgsvl/simulator.py | 6 ++++- quickstart/34-simulator-cam-set.py | 35 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100755 quickstart/34-simulator-cam-set.py diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index 4d606dd..ca8a298 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -76,6 +76,10 @@ def available_agents(self): def available_npc_behaviours(self): return self.remote.command("simulator/npc/available_behaviours") + @accepts(Transform) + def set_sim_camera(self, transform): + self.remote.command("simulator/camera/set", {"transform": transform.to_json()}) + def agents_traversed_waypoints(self, fn): self._add_callback(None, "agents_traversed_waypoints", fn) diff --git a/quickstart/34-simulator-cam-set.py b/quickstart/34-simulator-cam-set.py new file mode 100755 index 0000000..e94d0d0 --- /dev/null +++ b/quickstart/34-simulator-cam-set.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +from environs import Env +import lgsvl + +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) +if sim.current_scene == "BorregasAve": + sim.reset() +else: + sim.load("BorregasAve") + +# This creates a transform in Unity world coordinates +tr = lgsvl.Transform(lgsvl.Vector(10, 50, 0), lgsvl.Vector(90, 0, 0)) + +spawns = sim.get_spawn() + +state = lgsvl.AgentState() +state.transform = spawns[0] +forward = lgsvl.utils.transform_to_forward(spawns[0]) +state.velocity = 20 * forward +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) + +# This function sets the camera to free state and applies the transform to the camera rig +sim.set_sim_camera(tr) +print("Set transform: {}".format(tr)) + +input("Press Enter to drive forward for 4 seconds") +sim.run(time_limit=4.0) From 5f9376895e3579ee3fb60502c325bb7a197c85fe Mon Sep 17 00:00:00 2001 From: Karol Byczkowski Date: Tue, 2 Feb 2021 12:54:10 +0100 Subject: [PATCH 054/115] Controllables control method now accepts ControlAction list. Fetching controllables by their uid. --- lgsvl/controllable.py | 4 ++-- lgsvl/simulator.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lgsvl/controllable.py b/lgsvl/controllable.py index 42c30e7..16f116d 100644 --- a/lgsvl/controllable.py +++ b/lgsvl/controllable.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -40,7 +40,7 @@ def control_policy(self): j = self.remote.command("controllable/control_policy/get", {"uid": self.uid}) return j["control_policy"] - @accepts(str) + @accepts((str, list)) def control(self, control_policy): self.remote.command("controllable/control_policy/set", { "uid": self.uid, diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index ca8a298..35b389b 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -323,6 +323,13 @@ def get_controllables(self, control_type=None): }) return [Controllable(self.remote, controllable) for controllable in j] + @accepts(str) + def get_controllable_by_uid(self, uid): + j = self.remote.command("controllable/get", { + "uid": uid, + }) + return Controllable(self.remote, j) + @accepts(Vector, str) def get_controllable(self, position, control_type=None): j = self.remote.command("controllable/get", { From e950ff19bbe6c3d27bf8e112cd84e3a512a1ed11 Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Tue, 23 Feb 2021 14:59:48 -0800 Subject: [PATCH 055/115] setup.py: Set minimum Python version to 3.6 Python 3.5 reached its EOL in September 2020 and that of Ubuntu 16.04 (which supplies 3.5) is just a few months away (April 2021), so bump the minimum Python version requirement to 3.6 (which is supplied by Ubuntu 18.04). --- README.md | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fb2bac5..1e0b6cf 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Documentation is available on our website: https://www.lgsvlsimulator.com/docs/p # Requirements -* Python 3.5 or higher +* Python 3.6 or higher # Installing diff --git a/setup.py b/setup.py index ab75a87..6e8fca1 100755 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ description="LGSVL Simulator Api", author="LGSVL", author_email="contact@lgsvlsimulator.com", - python_requires=">=3.5.0", + python_requires=">=3.6.0", url="https://github.com/lgsvl/simulator", packages=["lgsvl", "lgsvl.dreamview", "lgsvl.evaluator"], install_requires=[ From e7c768394ce728c2881a44b9b58e32918866ca35 Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Tue, 23 Feb 2021 15:03:09 -0800 Subject: [PATCH 056/115] setup.py: Set "url" to the correct location --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6e8fca1..fa5ed89 100755 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ author="LGSVL", author_email="contact@lgsvlsimulator.com", python_requires=">=3.6.0", - url="https://github.com/lgsvl/simulator", + url="https://github.com/lgsvl/PythonAPI", packages=["lgsvl", "lgsvl.dreamview", "lgsvl.evaluator"], install_requires=[ "websockets==7.0", From c37a9d0067f60623374c195a541f33c2cc4c5402 Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Tue, 2 Mar 2021 22:40:44 -0800 Subject: [PATCH 057/115] setup.py: Set "classifiers" to Python 3.6 This should have been part of commit e950ff19bbe6c3d27bf8e112cd84e3a512a1ed11. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index fa5ed89..5a1d181 100755 --- a/setup.py +++ b/setup.py @@ -20,6 +20,6 @@ classifiers=[ "License :: Other/Proprietary License", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", ], ) From 1b0fc154cbbb069cc2f1435fe4a871c5e529dc7c Mon Sep 17 00:00:00 2001 From: Karol Byczkowski Date: Fri, 26 Feb 2021 17:39:06 +0100 Subject: [PATCH 058/115] Added settings file for common variables used in the quickstart scripts. Added initial information log about executed Python API Quickstart. Changed case of triggers parameter names to camel case. 11-collision-callbacks - added velocity to the ego vehicle so it cases a collision. 17-many-pedestrians-walking - all pedestrians are spawned at once, does not wait for an user input between spawns. --- lgsvl/agent.py | 4 +-- quickstart/01-connecting-to-simulator.py | 6 ++-- quickstart/02-loading-scene-show-spawns.py | 10 +++--- quickstart/03-raycast.py | 12 ++++--- quickstart/04-ego-drive-straight.py | 12 ++++--- quickstart/05-ego-drive-in-circle.py | 12 ++++--- quickstart/06-save-camera-image.py | 12 ++++--- quickstart/07-save-lidar-point-cloud.py | 12 ++++--- quickstart/08-create-npc.py | 12 ++++--- quickstart/09-reset-scene.py | 12 ++++--- quickstart/10-npc-follow-the-lane.py | 12 ++++--- quickstart/11-collision-callbacks.py | 18 +++++----- quickstart/12-create-npc-on-lane.py | 12 ++++--- quickstart/13-npc-follow-waypoints.py | 12 ++++--- quickstart/14-create-pedestrians.py | 12 ++++--- quickstart/15-pedestrian-walk-randomly.py | 12 ++++--- quickstart/16-pedestrian-follow-waypoints.py | 12 ++++--- quickstart/17-many-pedestrians-walking.py | 15 +++++---- quickstart/18-weather-effects.py | 12 ++++--- quickstart/19-time-of-day.py | 12 ++++--- quickstart/20-enable-sensors.py | 12 ++++--- quickstart/21-map-coordinates.py | 10 +++--- quickstart/22-connecting-bridge.py | 14 ++++---- quickstart/23-npc-callbacks.py | 12 ++++--- .../24-ego-drive-straight-non-realtime.py | 12 ++++--- quickstart/25-waypoint-flying-npc.py | 12 ++++--- quickstart/26-npc-trigger-waypoints.py | 12 ++++--- quickstart/27-control-traffic-lights.py | 16 ++++----- quickstart/28-control-traffic-cone.py | 14 ++++---- quickstart/29-add-random-agents.py | 12 ++++--- quickstart/30-time-to-collision-trigger.py | 12 ++++--- quickstart/31-wait-for-distance-trigger.py | 14 ++++---- quickstart/32-pedestrian-time-to-collision.py | 12 ++++--- quickstart/33-ego-drive-stepped.py | 14 ++++---- quickstart/34-simulator-cam-set.py | 10 +++--- quickstart/98-npc-behaviour.py | 8 +++-- quickstart/99-utils-examples.py | 3 +- quickstart/settings.py | 33 +++++++++++++++++++ 38 files changed, 282 insertions(+), 183 deletions(-) create mode 100644 quickstart/settings.py diff --git a/lgsvl/agent.py b/lgsvl/agent.py index 346eeb9..b05b515 100644 --- a/lgsvl/agent.py +++ b/lgsvl/agent.py @@ -66,10 +66,10 @@ def __init__(self, type_name, parameters): @staticmethod def from_json(j): - return TriggerEffector(j["type_name"], j["parameters"]) + return TriggerEffector(j["typeName"], j["parameters"]) def to_json(self): - return {"type_name": self.type_name, "parameters": self.parameters} + return {"typeName": self.type_name, "parameters": self.parameters} class AgentType(Enum): diff --git a/quickstart/01-connecting-to-simulator.py b/quickstart/01-connecting-to-simulator.py index f30e635..7fcdf05 100755 --- a/quickstart/01-connecting-to-simulator.py +++ b/quickstart/01-connecting-to-simulator.py @@ -1,19 +1,21 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #1: Connecting to the Simulator") env = Env() # Connects to the simulator instance at the ip defined by LGSVL__SIMULATOR_HOST, default is localhost or 127.0.0.1 # env.str() is equivalent to os.environ.get() # env.int() is equivalent to int(os.environ.get()) -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) print("Version =", sim.version) print("Current Time =", sim.current_time) diff --git a/quickstart/02-loading-scene-show-spawns.py b/quickstart/02-loading-scene-show-spawns.py index b72422d..e291aec 100755 --- a/quickstart/02-loading-scene-show-spawns.py +++ b/quickstart/02-loading-scene-show-spawns.py @@ -1,24 +1,26 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #2: Loading the scene spawn points") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) print("Current Scene = {}".format(sim.current_scene)) # Loads the named map in the connected simulator. The available maps can be set up in web interface -if sim.current_scene == "BorregasAve": +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) print("Current Scene = {}".format(sim.current_scene)) print("Current Scene ID = {}".format(sim.current_scene_id)) diff --git a/quickstart/03-raycast.py b/quickstart/03-raycast.py index 7a800ce..7ae791f 100755 --- a/quickstart/03-raycast.py +++ b/quickstart/03-raycast.py @@ -1,20 +1,22 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #3: Using raycasts in the Simulator") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) # The next few lines spawns an EGO vehicle in the map spawns = sim.get_spawn() @@ -24,7 +26,7 @@ forward = lgsvl.utils.transform_to_forward(state.transform) right = lgsvl.utils.transform_to_right(state.transform) up = lgsvl.utils.transform_to_up(state.transform) -sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) # This is the point from which the rays will originate from. It is raised 1m from the ground p = spawns[0].position diff --git a/quickstart/04-ego-drive-straight.py b/quickstart/04-ego-drive-straight.py index 9c18df1..d010ee1 100755 --- a/quickstart/04-ego-drive-straight.py +++ b/quickstart/04-ego-drive-straight.py @@ -1,20 +1,22 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #4: Ego vehicle driving straight") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() @@ -25,7 +27,7 @@ # Agents can be spawned with a velocity. Default is to spawn with 0 velocity state.velocity = 20 * forward -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) # The bounding box of an agent are 2 points (min and max) such that the box formed from those 2 points completely encases the agent print("Vehicle bounding box =", ego.bounding_box) diff --git a/quickstart/05-ego-drive-in-circle.py b/quickstart/05-ego-drive-in-circle.py index ec7ee31..5415d85 100755 --- a/quickstart/05-ego-drive-in-circle.py +++ b/quickstart/05-ego-drive-in-circle.py @@ -1,20 +1,22 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #5: Ego vehicle driving in circle") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() @@ -22,7 +24,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) state.transform.position += 5 * forward # 5m forwards -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) print("Current time = ", sim.current_time) print("Current frame = ", sim.current_frame) diff --git a/quickstart/06-save-camera-image.py b/quickstart/06-save-camera-image.py index 7b161e7..d4f3991 100755 --- a/quickstart/06-save-camera-image.py +++ b/quickstart/06-save-camera-image.py @@ -1,26 +1,28 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #6: Saving an image from the Main Camera sensor") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) # get_sensors returns a list of sensors on the EGO vehicle sensors = ego.get_sensors() diff --git a/quickstart/07-save-lidar-point-cloud.py b/quickstart/07-save-lidar-point-cloud.py index a9d6b9a..81a7f5a 100755 --- a/quickstart/07-save-lidar-point-cloud.py +++ b/quickstart/07-save-lidar-point-cloud.py @@ -1,26 +1,28 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #7: Saving a point cloud from the Lidar sensor") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicleWithLidar), lgsvl.AgentType.EGO, state) sensors = ego.get_sensors() for s in sensors: diff --git a/quickstart/08-create-npc.py b/quickstart/08-create-npc.py index 10d2900..f7b7a4b 100755 --- a/quickstart/08-create-npc.py +++ b/quickstart/08-create-npc.py @@ -1,26 +1,28 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #8: Creating various NPCs") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) diff --git a/quickstart/09-reset-scene.py b/quickstart/09-reset-scene.py index 00f11fa..99871df 100755 --- a/quickstart/09-reset-scene.py +++ b/quickstart/09-reset-scene.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -8,22 +8,24 @@ import random from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #9: Resetting the scene to it's initial state") env = Env() random.seed(0) -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) diff --git a/quickstart/10-npc-follow-the-lane.py b/quickstart/10-npc-follow-the-lane.py index 6c4b820..86104ce 100755 --- a/quickstart/10-npc-follow-the-lane.py +++ b/quickstart/10-npc-follow-the-lane.py @@ -1,26 +1,28 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #10: NPC following the lane") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) state = lgsvl.AgentState() diff --git a/quickstart/11-collision-callbacks.py b/quickstart/11-collision-callbacks.py index 97adb63..47e76f9 100755 --- a/quickstart/11-collision-callbacks.py +++ b/quickstart/11-collision-callbacks.py @@ -1,30 +1,32 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #11: Handling the collision callbacks") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() +forward = lgsvl.utils.transform_to_forward(spawns[0]) +right = lgsvl.utils.transform_to_right(spawns[0]) # ego vehicle state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) - -forward = lgsvl.utils.transform_to_forward(spawns[0]) -right = lgsvl.utils.transform_to_right(spawns[0]) +state.velocity = 8 * forward +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) # school bus, 20m ahead, perpendicular to road, stopped state = lgsvl.AgentState() diff --git a/quickstart/12-create-npc-on-lane.py b/quickstart/12-create-npc-on-lane.py index 3d02a67..b4fa575 100755 --- a/quickstart/12-create-npc-on-lane.py +++ b/quickstart/12-create-npc-on-lane.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -9,20 +9,22 @@ import random from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #12: Creating NPCs on lanes") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) sx = spawns[0].position.x sy = spawns[0].position.y diff --git a/quickstart/13-npc-follow-waypoints.py b/quickstart/13-npc-follow-waypoints.py index 2f12112..e9b8270 100755 --- a/quickstart/13-npc-follow-waypoints.py +++ b/quickstart/13-npc-follow-waypoints.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -8,14 +8,16 @@ import copy from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #13: NPC following waypoints") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -28,7 +30,7 @@ # Ego ego_state = copy.deepcopy(state) ego_state.transform.position += 50 * forward -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) # NPC npc_state = copy.deepcopy(state) diff --git a/quickstart/14-create-pedestrians.py b/quickstart/14-create-pedestrians.py index c1222e3..f90603a 100755 --- a/quickstart/14-create-pedestrians.py +++ b/quickstart/14-create-pedestrians.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -9,14 +9,16 @@ import time from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #14: Creating pedestrians on the map") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() @@ -24,7 +26,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) -sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) input("Press Enter to start creating pedestrians") diff --git a/quickstart/15-pedestrian-walk-randomly.py b/quickstart/15-pedestrian-walk-randomly.py index dba73b3..ebbf4ed 100755 --- a/quickstart/15-pedestrian-walk-randomly.py +++ b/quickstart/15-pedestrian-walk-randomly.py @@ -1,20 +1,22 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #15: Pedestrian walking randomly") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -24,7 +26,7 @@ state.transform.position = spawns[0].position + 40 * forward state.transform.rotation = spawns[0].rotation -sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) state = lgsvl.AgentState() # Spawn the pedestrian in front of car diff --git a/quickstart/16-pedestrian-follow-waypoints.py b/quickstart/16-pedestrian-follow-waypoints.py index 2e76252..7ba6085 100755 --- a/quickstart/16-pedestrian-follow-waypoints.py +++ b/quickstart/16-pedestrian-follow-waypoints.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -8,14 +8,16 @@ import math from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #16: Pedestrian following waypoints") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[1]) @@ -23,7 +25,7 @@ state = lgsvl.AgentState() state.transform = spawns[1] -sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) # This will create waypoints in a circle for the pedestrian to follow radius = 4 diff --git a/quickstart/17-many-pedestrians-walking.py b/quickstart/17-many-pedestrians-walking.py index 43251d9..88e1af6 100755 --- a/quickstart/17-many-pedestrians-walking.py +++ b/quickstart/17-many-pedestrians-walking.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -8,14 +8,16 @@ import random from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #17: Many pedestrians walking simultaneously") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() @@ -23,7 +25,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) -sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) names = [ "Bob", @@ -58,6 +60,5 @@ p = sim.add_agent(name, lgsvl.AgentType.PEDESTRIAN, state) p.follow(wp, True) - input("Press Enter to start") - +input("Press Enter to start") sim.run() diff --git a/quickstart/18-weather-effects.py b/quickstart/18-weather-effects.py index 1d30132..e833b1c 100755 --- a/quickstart/18-weather-effects.py +++ b/quickstart/18-weather-effects.py @@ -1,26 +1,28 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #18: Changing the weather effects") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) print(sim.weather) diff --git a/quickstart/19-time-of-day.py b/quickstart/19-time-of-day.py index c9c30f0..86f5dc6 100755 --- a/quickstart/19-time-of-day.py +++ b/quickstart/19-time-of-day.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -8,20 +8,22 @@ from environs import Env import lgsvl from datetime import datetime +from settings import * +print("Python API Quickstart #19: Changing the time of day") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) print("Current time:", sim.time_of_day) diff --git a/quickstart/20-enable-sensors.py b/quickstart/20-enable-sensors.py index cfc859a..470ef99 100755 --- a/quickstart/20-enable-sensors.py +++ b/quickstart/20-enable-sensors.py @@ -1,26 +1,28 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #20: Enabling and disabling sensors") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[1] -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicleWithLidar), lgsvl.AgentType.EGO, state) sensors = ego.get_sensors() diff --git a/quickstart/21-map-coordinates.py b/quickstart/21-map-coordinates.py index 674ac2c..c208233 100755 --- a/quickstart/21-map-coordinates.py +++ b/quickstart/21-map-coordinates.py @@ -1,20 +1,22 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #21: Converting the map coordinates") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() diff --git a/quickstart/22-connecting-bridge.py b/quickstart/22-connecting-bridge.py index 073dbfe..63808a5 100755 --- a/quickstart/22-connecting-bridge.py +++ b/quickstart/22-connecting-bridge.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -8,26 +8,28 @@ import time from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #22: Connecting to a bridge") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicleWithBridge), lgsvl.AgentType.EGO, state) # An EGO will not connect to a bridge unless commanded to print("Bridge connected:", ego.bridge_connected) # The EGO is now looking for a bridge at the specified IP and port -ego.connect_bridge(env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1"), env.int("LGSVL__AUTOPILOT_0_PORT", 9090)) +ego.connect_bridge(env.str("LGSVL__AUTOPILOT_0_HOST", SimulatorSettings.bridgeHost), env.int("LGSVL__AUTOPILOT_0_PORT", SimulatorSettings.bridgePort)) print("Waiting for connection...") diff --git a/quickstart/23-npc-callbacks.py b/quickstart/23-npc-callbacks.py index 9439971..f8b961f 100755 --- a/quickstart/23-npc-callbacks.py +++ b/quickstart/23-npc-callbacks.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -9,14 +9,16 @@ import random from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #23: Handling NPCs callbacks") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -24,7 +26,7 @@ state = lgsvl.AgentState() state.transform = sim.map_point_on_lane(spawns[0].position + 200 * forward) -sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) mindist = 10.0 maxdist = 40.0 diff --git a/quickstart/24-ego-drive-straight-non-realtime.py b/quickstart/24-ego-drive-straight-non-realtime.py index a56bf01..18cf05c 100755 --- a/quickstart/24-ego-drive-straight-non-realtime.py +++ b/quickstart/24-ego-drive-straight-non-realtime.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -8,14 +8,16 @@ import time from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #24: Changing the Simulator timescale") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() @@ -24,7 +26,7 @@ forward = lgsvl.utils.transform_to_forward(spawns[0]) # Agents can be spawned with a velocity. Default is to spawn with 0 velocity state.velocity = 20 * forward -sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) print("Real time elapsed =", 0) print("Simulation time =", sim.current_time) diff --git a/quickstart/25-waypoint-flying-npc.py b/quickstart/25-waypoint-flying-npc.py index b7ec422..5dbc634 100755 --- a/quickstart/25-waypoint-flying-npc.py +++ b/quickstart/25-waypoint-flying-npc.py @@ -1,20 +1,22 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #25: NPC flying to waypoints") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() @@ -24,7 +26,7 @@ right = lgsvl.utils.transform_to_right(spawns[0]) up = lgsvl.utils.transform_to_up(spawns[0]) state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() diff --git a/quickstart/26-npc-trigger-waypoints.py b/quickstart/26-npc-trigger-waypoints.py index ce1c81f..19d7021 100755 --- a/quickstart/26-npc-trigger-waypoints.py +++ b/quickstart/26-npc-trigger-waypoints.py @@ -1,20 +1,22 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #26: NPC triggering the waypoints callbacks") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() @@ -23,7 +25,7 @@ forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) state.transform = spawns[0] -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() diff --git a/quickstart/27-control-traffic-lights.py b/quickstart/27-control-traffic-lights.py index 05069a5..b886dcb 100755 --- a/quickstart/27-control-traffic-lights.py +++ b/quickstart/27-control-traffic-lights.py @@ -1,20 +1,22 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #27: How to Control Traffic Light") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve", 42) + sim.load(SimulatorSettings.mapName, 42) spawns = sim.get_spawn() @@ -22,13 +24,11 @@ forward = lgsvl.utils.transform_to_forward(spawns[0]) state.transform = spawns[0] state.transform.position = spawns[0].position + 20 * forward -sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) - -print("Python API Quickstart #27: How to Control Traffic Light") +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) # # Get a list of controllable objects controllables = sim.get_controllables("signal") -print("\n# List of controllable objects in {} scene:".format("BorregasAve")) +print("\n# List of controllable objects in {} scene:".format(SimulatorSettings.mapName)) for c in controllables: print(c) diff --git a/quickstart/28-control-traffic-cone.py b/quickstart/28-control-traffic-cone.py index 40ab183..fda33ba 100755 --- a/quickstart/28-control-traffic-cone.py +++ b/quickstart/28-control-traffic-cone.py @@ -1,20 +1,22 @@ #!/usr/bin/env python3 # -# Copyright (c) 2020 LG Electronics, Inc. +# Copyright (c) 2020-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #28: How to Add/Control Traffic Cone") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve", 42) + sim.load(SimulatorSettings.mapName, 42) spawns = sim.get_spawn() @@ -24,9 +26,7 @@ up = lgsvl.utils.transform_to_up(spawns[0]) state.transform = spawns[0] -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) - -print("Python API Quickstart #28: How to Add/Control Traffic Cone") +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) for i in range(10 * 3): # Create controllables in a block diff --git a/quickstart/29-add-random-agents.py b/quickstart/29-add-random-agents.py index ab224a3..dab8be8 100755 --- a/quickstart/29-add-random-agents.py +++ b/quickstart/29-add-random-agents.py @@ -1,20 +1,22 @@ #!/usr/bin/env python3 # -# Copyright (c) 2020 LG Electronics, Inc. +# Copyright (c) 2020-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #29: Adding random agents to a simulation") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve", 42) + sim.load(SimulatorSettings.mapName, 42) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -24,7 +26,7 @@ state.transform.position = spawns[0].position + 40 * forward state.transform.rotation = spawns[0].rotation -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) sim.add_random_agents(lgsvl.AgentType.NPC) sim.add_random_agents(lgsvl.AgentType.PEDESTRIAN) diff --git a/quickstart/30-time-to-collision-trigger.py b/quickstart/30-time-to-collision-trigger.py index 7b979ed..1194440 100755 --- a/quickstart/30-time-to-collision-trigger.py +++ b/quickstart/30-time-to-collision-trigger.py @@ -1,20 +1,22 @@ #!/usr/bin/env python3 # -# Copyright (c) 2020 LG Electronics, Inc. +# Copyright (c) 2020-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #30: Using the time to collision trigger") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve", 42) + sim.load(SimulatorSettings.mapName, 42) spawns = sim.get_spawn() layer_mask = 0 @@ -31,7 +33,7 @@ spawn_state.position = hit.point state.transform = spawn_state state.velocity = forward * 2 -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() diff --git a/quickstart/31-wait-for-distance-trigger.py b/quickstart/31-wait-for-distance-trigger.py index 1465170..53d7468 100755 --- a/quickstart/31-wait-for-distance-trigger.py +++ b/quickstart/31-wait-for-distance-trigger.py @@ -1,20 +1,22 @@ #!/usr/bin/env python3 # -# Copyright (c) 2020 LG Electronics, Inc. +# Copyright (c) 2020-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #31: Using the wait for distance trigger") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve", 42) + sim.load(SimulatorSettings.mapName, 42) spawns = sim.get_spawn() layer_mask = 0 @@ -31,7 +33,7 @@ spawn_state.position = hit.point state.transform = spawn_state state.velocity = forward * 2 -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() @@ -73,7 +75,7 @@ def on_collision(agent1, agent2, contact): trigger = None if i == 0: - parameters = {"max_distance": 4.0} + parameters = {"maxDistance": 4.0} effector = lgsvl.TriggerEffector("WaitForDistance", parameters) trigger = lgsvl.WaypointTrigger([effector]) wp = lgsvl.DriveWaypoint( diff --git a/quickstart/32-pedestrian-time-to-collision.py b/quickstart/32-pedestrian-time-to-collision.py index 7ab9419..df74b38 100755 --- a/quickstart/32-pedestrian-time-to-collision.py +++ b/quickstart/32-pedestrian-time-to-collision.py @@ -1,20 +1,22 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #1: Using the time to collision trigger with a pedestrian") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve", 42) + sim.load(SimulatorSettings.mapName, 42) spawns = sim.get_spawn() layer_mask = 0 @@ -28,7 +30,7 @@ state.transform.rotation = lgsvl.Vector(0.0, 15.0, 0.0) forward = lgsvl.Vector(0.2, 0.0, 0.8) state.velocity = forward * 15 -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) # Pedestrian state = lgsvl.AgentState() diff --git a/quickstart/33-ego-drive-stepped.py b/quickstart/33-ego-drive-stepped.py index b2f406a..491d388 100755 --- a/quickstart/33-ego-drive-stepped.py +++ b/quickstart/33-ego-drive-stepped.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2020 LG Electronics, Inc. +# Copyright (c) 2020-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -8,12 +8,14 @@ import os import lgsvl import time +from settings import * -sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1"), 8181) -if sim.current_scene == "BorregasAve": +print("Python API Quickstart #33: Stepping a simulation") +sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), SimulatorSettings.simulatorPort) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() # Re-load scene and set random seed -sim.load("BorregasAve", seed=123) +sim.load(SimulatorSettings.mapName, seed=123) spawns = sim.get_spawn() @@ -32,13 +34,13 @@ # We can test Apollo with standard MKZ or MKZ with ground truth sensors # Refer to https://www.lgsvlsimulator.com/docs/modular-testing/ # ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) -ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0gt)", lgsvl.AgentType.EGO, state) +ego = sim.add_agent(SimulatorSettings.egoVehicleWithBridge, lgsvl.AgentType.EGO, state) # An EGO will not connect to a bridge unless commanded to print("Bridge connected:", ego.bridge_connected) # The EGO looks for a (Cyber) bridge at the specified IP and port -ego.connect_bridge("127.0.0.1", 9090) +ego.connect_bridge(SimulatorSettings.bridgeHost, SimulatorSettings.bridgePort) # uncomment to wait for bridge connection; script will drive ego if bridge not found # print("Waiting for connection...") # while not ego.bridge_connected: diff --git a/quickstart/34-simulator-cam-set.py b/quickstart/34-simulator-cam-set.py index e94d0d0..635a0e5 100755 --- a/quickstart/34-simulator-cam-set.py +++ b/quickstart/34-simulator-cam-set.py @@ -7,14 +7,16 @@ from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #34: Setting the fixed camera position") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -if sim.current_scene == "BorregasAve": +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load("BorregasAve") + sim.load(SimulatorSettings.mapName) # This creates a transform in Unity world coordinates tr = lgsvl.Transform(lgsvl.Vector(10, 50, 0), lgsvl.Vector(90, 0, 0)) @@ -25,7 +27,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) state.velocity = 20 * forward -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) # This function sets the camera to free state and applies the transform to the camera rig sim.set_sim_camera(tr) diff --git a/quickstart/98-npc-behaviour.py b/quickstart/98-npc-behaviour.py index 9aa1796..dc56be7 100755 --- a/quickstart/98-npc-behaviour.py +++ b/quickstart/98-npc-behaviour.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -9,10 +9,12 @@ import random from environs import Env import lgsvl +from settings import * +print("Python API Quickstart #98: Simulating different NPCs behaviours") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) drunkDriverAvailable = False trailerAvailable = 0 @@ -59,7 +61,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", "Lincoln2017MKZ (Apollo 5.0)"), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) mindist = 10.0 maxdist = 40.0 diff --git a/quickstart/99-utils-examples.py b/quickstart/99-utils-examples.py index 9a482a3..7002f92 100755 --- a/quickstart/99-utils-examples.py +++ b/quickstart/99-utils-examples.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2019 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -13,6 +13,7 @@ vector_multiply, ) +print("Python API Quickstart #99: Using the LGSVL utilities") # global "world" transform (for example, car position) world = Transform(Vector(10, 20, 30), Vector(11, 22, 33)) diff --git a/quickstart/settings.py b/quickstart/settings.py new file mode 100644 index 0000000..a54a18f --- /dev/null +++ b/quickstart/settings.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + + +# Settings class with common variables used in the quickstart scripts +class SimulatorSettings: + # IP address of the endpoint running the Simulator. Default value is "127.0.0.1" + simulatorHost = "127.0.0.1" + + # Port used by the Simulator for the Python API connection. Default value is 8181 + simulatorPort = 8181 + + # IP address of the endpoint running the bridge. Default value is "127.0.0.1" + bridgeHost = "127.0.0.1" + + # Port used by the Simulator for the bridge connection. Default value is 9090 + bridgePort = 9090 + + # Map loaded in the quickstart scripts. Changing the map may lead to unexpected behaviour in the quickstart scripts. Default value is "BorregasAve" + mapName = "BorregasAve" + + # Ego vehicle that is loaded in most of the quickstart scripts. Default value is "Lincoln2017MKZ" + egoVehicle = "Lincoln2017MKZ" + + # Ego vehicle that is loaded in quickstart scripts where the bridge connection is required. Default value is "Lincoln2017MKZ" + egoVehicleWithBridge = "Lincoln2017MKZ" + + # Ego vehicle that is loaded in quickstart scripts where the LIDAR sensor is required. Default value is "Lincoln2017MKZ" + egoVehicleWithLidar = "Lincoln2017MKZ" \ No newline at end of file From 18aee82396444f3a94320a836ba8aaaf4893cae7 Mon Sep 17 00:00:00 2001 From: Karol Byczkowski Date: Mon, 1 Mar 2021 17:27:40 +0100 Subject: [PATCH 059/115] Every quickstart script now finishes after fixed time. Fixed 26-npc-trigger-waypoints, ego vehicle chases the NPC to trigger next waypoints. Removed fixed seed from the 29-add-random-agents script so spawned agents are randomized. --- quickstart/05-ego-drive-in-circle.py | 4 ++-- quickstart/10-npc-follow-the-lane.py | 4 ++-- quickstart/11-collision-callbacks.py | 8 ++++---- quickstart/12-create-npc-on-lane.py | 5 +++-- quickstart/13-npc-follow-waypoints.py | 4 ++-- quickstart/14-create-pedestrians.py | 4 ++-- quickstart/16-pedestrian-follow-waypoints.py | 4 ++-- quickstart/17-many-pedestrians-walking.py | 5 +++-- quickstart/22-connecting-bridge.py | 3 ++- quickstart/25-waypoint-flying-npc.py | 4 ++-- quickstart/26-npc-trigger-waypoints.py | 7 ++++--- quickstart/29-add-random-agents.py | 6 +++--- 12 files changed, 31 insertions(+), 27 deletions(-) diff --git a/quickstart/05-ego-drive-in-circle.py b/quickstart/05-ego-drive-in-circle.py index 5415d85..e143f3f 100755 --- a/quickstart/05-ego-drive-in-circle.py +++ b/quickstart/05-ego-drive-in-circle.py @@ -29,7 +29,7 @@ print("Current time = ", sim.current_time) print("Current frame = ", sim.current_frame) -input("Press Enter to start driving") +input("Press Enter to start driving for 30 seconds") # VehicleControl objects can only be applied to EGO vehicles # You can set the steering (-1 ... 1), throttle and braking (0 ... 1), handbrake and reverse (bool) @@ -39,4 +39,4 @@ # a True in apply_control means the control will be continuously applied ("sticky"). False means the control will be applied for 1 frame ego.apply_control(c, True) -sim.run() +sim.run(30) diff --git a/quickstart/10-npc-follow-the-lane.py b/quickstart/10-npc-follow-the-lane.py index 86104ce..0a8c00b 100755 --- a/quickstart/10-npc-follow-the-lane.py +++ b/quickstart/10-npc-follow-the-lane.py @@ -51,6 +51,6 @@ # 5.6 m/s is ~20 km/h npc2.follow_closest_lane(True, 5.6) -input("Press Enter to run") +input("Press Enter to run the simulation for 40 seconds") -sim.run() +sim.run(40) diff --git a/quickstart/11-collision-callbacks.py b/quickstart/11-collision-callbacks.py index 47e76f9..2a8491b 100755 --- a/quickstart/11-collision-callbacks.py +++ b/quickstart/11-collision-callbacks.py @@ -25,7 +25,7 @@ # ego vehicle state = lgsvl.AgentState() state.transform = spawns[0] -state.velocity = 8 * forward +state.velocity = 6 * forward ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) # school bus, 20m ahead, perpendicular to road, stopped @@ -61,7 +61,7 @@ def on_collision(agent1, agent2, contact): bus.on_collision(on_collision) sedan.on_collision(on_collision) -input("Press Enter to run") +input("Press Enter to run the simulation for 10 seconds") -# Manually drive into the sedan, bus, or obstacle to get a callback -sim.run() +# Drive into the sedan, bus, or obstacle to get a callback +sim.run(10) diff --git a/quickstart/12-create-npc-on-lane.py b/quickstart/12-create-npc-on-lane.py index b4fa575..6d01a85 100755 --- a/quickstart/12-create-npc-on-lane.py +++ b/quickstart/12-create-npc-on-lane.py @@ -35,8 +35,9 @@ random.seed(0) -while True: - input("Press Enter to spawn NPC") +print("Spawn 10 random NPCs on lanes") +for i in range(10): + input("Press Enter to spawn NPC ({})".format(i+1)) # Creates a random point around the EGO angle = random.uniform(0.0, 2 * math.pi) diff --git a/quickstart/13-npc-follow-waypoints.py b/quickstart/13-npc-follow-waypoints.py index e9b8270..a8b5d7c 100755 --- a/quickstart/13-npc-follow-waypoints.py +++ b/quickstart/13-npc-follow-waypoints.py @@ -90,6 +90,6 @@ def on_waypoint(agent, index): # A bool can be passed as the 2nd argument that controls whether or not the NPC loops over the waypoints (default false) npc.follow(waypoints) -input("Press Enter to run\n") +input("Press Enter to run the simulation for 30 seconds") -sim.run() +sim.run(30) diff --git a/quickstart/14-create-pedestrians.py b/quickstart/14-create-pedestrians.py index f90603a..53ea3aa 100755 --- a/quickstart/14-create-pedestrians.py +++ b/quickstart/14-create-pedestrians.py @@ -28,7 +28,7 @@ right = lgsvl.utils.transform_to_right(spawns[0]) sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) -input("Press Enter to start creating pedestrians") +input("Press Enter to create 100 pedestrians") # The list of available pedestrians can be found in PedestrianManager prefab names = [ @@ -44,7 +44,7 @@ ] i = 0 -while True: +while i < 100: state = lgsvl.AgentState() state.transform.position = ( diff --git a/quickstart/16-pedestrian-follow-waypoints.py b/quickstart/16-pedestrian-follow-waypoints.py index 7ba6085..b5b02f3 100755 --- a/quickstart/16-pedestrian-follow-waypoints.py +++ b/quickstart/16-pedestrian-follow-waypoints.py @@ -56,6 +56,6 @@ def on_waypoint(agent, index): # This sends the list of waypoints to the pedestrian. The bool controls whether or not the pedestrian will continue walking (default false) p.follow(wp, True) -input("Press Enter to walk in circle") +input("Press Enter to walk in circle for 60 seconds") -sim.run() +sim.run(60) diff --git a/quickstart/17-many-pedestrians-walking.py b/quickstart/17-many-pedestrians-walking.py index 88e1af6..854d089 100755 --- a/quickstart/17-many-pedestrians-walking.py +++ b/quickstart/17-many-pedestrians-walking.py @@ -39,6 +39,7 @@ "Zoe", ] +print("Creating 120 pedestrians") for i in range(20 * 6): # Create peds in a block start = ( @@ -60,5 +61,5 @@ p = sim.add_agent(name, lgsvl.AgentType.PEDESTRIAN, state) p.follow(wp, True) -input("Press Enter to start") -sim.run() +input("Press Enter to start the simulation for 30 seconds") +sim.run(30) diff --git a/quickstart/22-connecting-bridge.py b/quickstart/22-connecting-bridge.py index 63808a5..c6ad69c 100755 --- a/quickstart/22-connecting-bridge.py +++ b/quickstart/22-connecting-bridge.py @@ -37,5 +37,6 @@ time.sleep(1) print("Bridge connected:", ego.bridge_connected) +print("Running the simulation for 30 seconds") -sim.run() +sim.run(30) diff --git a/quickstart/25-waypoint-flying-npc.py b/quickstart/25-waypoint-flying-npc.py index 5dbc634..6450e32 100755 --- a/quickstart/25-waypoint-flying-npc.py +++ b/quickstart/25-waypoint-flying-npc.py @@ -77,6 +77,6 @@ def on_waypoint(agent, index): # A bool can be passed as the 2nd argument that controls whether or not the NPC loops over the waypoints (default false) npc.follow(waypoints) -input("Press Enter to run") +input("Press Enter to run the simulation for 12 seconds") -sim.run() +sim.run(12) diff --git a/quickstart/26-npc-trigger-waypoints.py b/quickstart/26-npc-trigger-waypoints.py index 19d7021..a437a46 100755 --- a/quickstart/26-npc-trigger-waypoints.py +++ b/quickstart/26-npc-trigger-waypoints.py @@ -25,6 +25,7 @@ forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) state.transform = spawns[0] +state.velocity = 12 * forward ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) # NPC @@ -82,7 +83,7 @@ def on_collision(agent1, agent2, contact): # When the NPC is within 0.5m of the waypoint, this will be called def on_waypoint(agent, index): - print("waypoint {} reached".format(index)) + print("waypoint {} reached, waiting for ego to get closer".format(index)) # The above function needs to be added to the list of callbacks for the NPC @@ -92,6 +93,6 @@ def on_waypoint(agent, index): # A bool can be passed as the 2nd argument that controls whether or not the NPC loops over the waypoints (default false) npc.follow(waypoints) -input("Press Enter to run") +input("Press Enter to run simulation for 22 seconds") -sim.run() +sim.run(22) diff --git a/quickstart/29-add-random-agents.py b/quickstart/29-add-random-agents.py index dab8be8..fad61d0 100755 --- a/quickstart/29-add-random-agents.py +++ b/quickstart/29-add-random-agents.py @@ -16,7 +16,7 @@ if sim.current_scene == SimulatorSettings.mapName: sim.reset() else: - sim.load(SimulatorSettings.mapName, 42) + sim.load(SimulatorSettings.mapName) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -31,6 +31,6 @@ sim.add_random_agents(lgsvl.AgentType.NPC) sim.add_random_agents(lgsvl.AgentType.PEDESTRIAN) -input("Press Enter to start") +input("Press Enter to start the simulation for 30 seconds") -sim.run() +sim.run(30) From df759657e8787aa765055f53bd719e0021f14984 Mon Sep 17 00:00:00 2001 From: Lokesh Kumar Goel Date: Tue, 2 Mar 2021 14:48:19 -0800 Subject: [PATCH 060/115] Update simulator settings Change-Id: I558c68dcf8c4aa65e924a0eaba280fa101196ded --- quickstart/02-loading-scene-show-spawns.py | 4 ++-- quickstart/03-raycast.py | 6 +++--- quickstart/04-ego-drive-straight.py | 6 +++--- quickstart/05-ego-drive-in-circle.py | 6 +++--- quickstart/06-save-camera-image.py | 6 +++--- quickstart/07-save-lidar-point-cloud.py | 6 +++--- quickstart/08-create-npc.py | 6 +++--- quickstart/09-reset-scene.py | 6 +++--- quickstart/10-npc-follow-the-lane.py | 6 +++--- quickstart/11-collision-callbacks.py | 6 +++--- quickstart/12-create-npc-on-lane.py | 6 +++--- quickstart/13-npc-follow-waypoints.py | 6 +++--- quickstart/14-create-pedestrians.py | 6 +++--- quickstart/15-pedestrian-walk-randomly.py | 6 +++--- quickstart/16-pedestrian-follow-waypoints.py | 6 +++--- quickstart/17-many-pedestrians-walking.py | 6 +++--- quickstart/18-weather-effects.py | 6 +++--- quickstart/19-time-of-day.py | 6 +++--- quickstart/20-enable-sensors.py | 6 +++--- quickstart/21-map-coordinates.py | 4 ++-- quickstart/22-connecting-bridge.py | 6 +++--- quickstart/23-npc-callbacks.py | 6 +++--- quickstart/24-ego-drive-straight-non-realtime.py | 6 +++--- quickstart/25-waypoint-flying-npc.py | 6 +++--- quickstart/26-npc-trigger-waypoints.py | 6 +++--- quickstart/27-control-traffic-lights.py | 8 ++++---- quickstart/28-control-traffic-cone.py | 6 +++--- quickstart/29-add-random-agents.py | 6 +++--- quickstart/30-time-to-collision-trigger.py | 6 +++--- quickstart/31-wait-for-distance-trigger.py | 6 +++--- quickstart/32-pedestrian-time-to-collision.py | 6 +++--- quickstart/33-ego-drive-stepped.py | 6 +++--- quickstart/34-simulator-cam-set.py | 6 +++--- quickstart/98-npc-behaviour.py | 2 +- quickstart/settings.py => settings.py | 14 +++++--------- 35 files changed, 104 insertions(+), 108 deletions(-) rename quickstart/settings.py => settings.py (63%) diff --git a/quickstart/02-loading-scene-show-spawns.py b/quickstart/02-loading-scene-show-spawns.py index e291aec..bc040a1 100755 --- a/quickstart/02-loading-scene-show-spawns.py +++ b/quickstart/02-loading-scene-show-spawns.py @@ -17,10 +17,10 @@ print("Current Scene = {}".format(sim.current_scene)) # Loads the named map in the connected simulator. The available maps can be set up in web interface -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) print("Current Scene = {}".format(sim.current_scene)) print("Current Scene ID = {}".format(sim.current_scene_id)) diff --git a/quickstart/03-raycast.py b/quickstart/03-raycast.py index 7ae791f..87e09d0 100755 --- a/quickstart/03-raycast.py +++ b/quickstart/03-raycast.py @@ -13,10 +13,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) # The next few lines spawns an EGO vehicle in the map spawns = sim.get_spawn() @@ -26,7 +26,7 @@ forward = lgsvl.utils.transform_to_forward(state.transform) right = lgsvl.utils.transform_to_right(state.transform) up = lgsvl.utils.transform_to_up(state.transform) -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # This is the point from which the rays will originate from. It is raised 1m from the ground p = spawns[0].position diff --git a/quickstart/04-ego-drive-straight.py b/quickstart/04-ego-drive-straight.py index d010ee1..05a7249 100755 --- a/quickstart/04-ego-drive-straight.py +++ b/quickstart/04-ego-drive-straight.py @@ -13,10 +13,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() @@ -27,7 +27,7 @@ # Agents can be spawned with a velocity. Default is to spawn with 0 velocity state.velocity = 20 * forward -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # The bounding box of an agent are 2 points (min and max) such that the box formed from those 2 points completely encases the agent print("Vehicle bounding box =", ego.bounding_box) diff --git a/quickstart/05-ego-drive-in-circle.py b/quickstart/05-ego-drive-in-circle.py index e143f3f..319ce53 100755 --- a/quickstart/05-ego-drive-in-circle.py +++ b/quickstart/05-ego-drive-in-circle.py @@ -13,10 +13,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() @@ -24,7 +24,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) state.transform.position += 5 * forward # 5m forwards -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) print("Current time = ", sim.current_time) print("Current frame = ", sim.current_frame) diff --git a/quickstart/06-save-camera-image.py b/quickstart/06-save-camera-image.py index d4f3991..561f02c 100755 --- a/quickstart/06-save-camera-image.py +++ b/quickstart/06-save-camera-image.py @@ -13,16 +13,16 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # get_sensors returns a list of sensors on the EGO vehicle sensors = ego.get_sensors() diff --git a/quickstart/07-save-lidar-point-cloud.py b/quickstart/07-save-lidar-point-cloud.py index 81a7f5a..02c2822 100755 --- a/quickstart/07-save-lidar-point-cloud.py +++ b/quickstart/07-save-lidar-point-cloud.py @@ -13,16 +13,16 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicleWithLidar), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) sensors = ego.get_sensors() for s in sensors: diff --git a/quickstart/08-create-npc.py b/quickstart/08-create-npc.py index f7b7a4b..faa3b46 100755 --- a/quickstart/08-create-npc.py +++ b/quickstart/08-create-npc.py @@ -13,16 +13,16 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) diff --git a/quickstart/09-reset-scene.py b/quickstart/09-reset-scene.py index 99871df..3eb6fa2 100755 --- a/quickstart/09-reset-scene.py +++ b/quickstart/09-reset-scene.py @@ -16,16 +16,16 @@ random.seed(0) sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) diff --git a/quickstart/10-npc-follow-the-lane.py b/quickstart/10-npc-follow-the-lane.py index 0a8c00b..71d5eb2 100755 --- a/quickstart/10-npc-follow-the-lane.py +++ b/quickstart/10-npc-follow-the-lane.py @@ -13,16 +13,16 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) state = lgsvl.AgentState() diff --git a/quickstart/11-collision-callbacks.py b/quickstart/11-collision-callbacks.py index 2a8491b..67a29f8 100755 --- a/quickstart/11-collision-callbacks.py +++ b/quickstart/11-collision-callbacks.py @@ -13,10 +13,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -26,7 +26,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] state.velocity = 6 * forward -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # school bus, 20m ahead, perpendicular to road, stopped state = lgsvl.AgentState() diff --git a/quickstart/12-create-npc-on-lane.py b/quickstart/12-create-npc-on-lane.py index 6d01a85..f51c0c7 100755 --- a/quickstart/12-create-npc-on-lane.py +++ b/quickstart/12-create-npc-on-lane.py @@ -15,16 +15,16 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) sx = spawns[0].position.x sy = spawns[0].position.y diff --git a/quickstart/13-npc-follow-waypoints.py b/quickstart/13-npc-follow-waypoints.py index a8b5d7c..d3a18f9 100755 --- a/quickstart/13-npc-follow-waypoints.py +++ b/quickstart/13-npc-follow-waypoints.py @@ -14,10 +14,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -30,7 +30,7 @@ # Ego ego_state = copy.deepcopy(state) ego_state.transform.position += 50 * forward -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # NPC npc_state = copy.deepcopy(state) diff --git a/quickstart/14-create-pedestrians.py b/quickstart/14-create-pedestrians.py index 53ea3aa..2532551 100755 --- a/quickstart/14-create-pedestrians.py +++ b/quickstart/14-create-pedestrians.py @@ -15,10 +15,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() @@ -26,7 +26,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) input("Press Enter to create 100 pedestrians") diff --git a/quickstart/15-pedestrian-walk-randomly.py b/quickstart/15-pedestrian-walk-randomly.py index ebbf4ed..c50150e 100755 --- a/quickstart/15-pedestrian-walk-randomly.py +++ b/quickstart/15-pedestrian-walk-randomly.py @@ -13,10 +13,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -26,7 +26,7 @@ state.transform.position = spawns[0].position + 40 * forward state.transform.rotation = spawns[0].rotation -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) state = lgsvl.AgentState() # Spawn the pedestrian in front of car diff --git a/quickstart/16-pedestrian-follow-waypoints.py b/quickstart/16-pedestrian-follow-waypoints.py index b5b02f3..45e67d3 100755 --- a/quickstart/16-pedestrian-follow-waypoints.py +++ b/quickstart/16-pedestrian-follow-waypoints.py @@ -14,10 +14,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[1]) @@ -25,7 +25,7 @@ state = lgsvl.AgentState() state.transform = spawns[1] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # This will create waypoints in a circle for the pedestrian to follow radius = 4 diff --git a/quickstart/17-many-pedestrians-walking.py b/quickstart/17-many-pedestrians-walking.py index 854d089..b641de8 100755 --- a/quickstart/17-many-pedestrians-walking.py +++ b/quickstart/17-many-pedestrians-walking.py @@ -14,10 +14,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() @@ -25,7 +25,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) names = [ "Bob", diff --git a/quickstart/18-weather-effects.py b/quickstart/18-weather-effects.py index e833b1c..66f1737 100755 --- a/quickstart/18-weather-effects.py +++ b/quickstart/18-weather-effects.py @@ -13,16 +13,16 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) print(sim.weather) diff --git a/quickstart/19-time-of-day.py b/quickstart/19-time-of-day.py index 86f5dc6..365685b 100755 --- a/quickstart/19-time-of-day.py +++ b/quickstart/19-time-of-day.py @@ -14,16 +14,16 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) print("Current time:", sim.time_of_day) diff --git a/quickstart/20-enable-sensors.py b/quickstart/20-enable-sensors.py index 470ef99..af6bcc2 100755 --- a/quickstart/20-enable-sensors.py +++ b/quickstart/20-enable-sensors.py @@ -13,16 +13,16 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[1] -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicleWithLidar), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) sensors = ego.get_sensors() diff --git a/quickstart/21-map-coordinates.py b/quickstart/21-map-coordinates.py index c208233..a17e6d3 100755 --- a/quickstart/21-map-coordinates.py +++ b/quickstart/21-map-coordinates.py @@ -13,10 +13,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() diff --git a/quickstart/22-connecting-bridge.py b/quickstart/22-connecting-bridge.py index c6ad69c..afaa549 100755 --- a/quickstart/22-connecting-bridge.py +++ b/quickstart/22-connecting-bridge.py @@ -14,16 +14,16 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicleWithBridge), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # An EGO will not connect to a bridge unless commanded to print("Bridge connected:", ego.bridge_connected) diff --git a/quickstart/23-npc-callbacks.py b/quickstart/23-npc-callbacks.py index f8b961f..62c1b90 100755 --- a/quickstart/23-npc-callbacks.py +++ b/quickstart/23-npc-callbacks.py @@ -15,10 +15,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -26,7 +26,7 @@ state = lgsvl.AgentState() state.transform = sim.map_point_on_lane(spawns[0].position + 200 * forward) -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) mindist = 10.0 maxdist = 40.0 diff --git a/quickstart/24-ego-drive-straight-non-realtime.py b/quickstart/24-ego-drive-straight-non-realtime.py index 18cf05c..a5db32d 100755 --- a/quickstart/24-ego-drive-straight-non-realtime.py +++ b/quickstart/24-ego-drive-straight-non-realtime.py @@ -14,10 +14,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() @@ -26,7 +26,7 @@ forward = lgsvl.utils.transform_to_forward(spawns[0]) # Agents can be spawned with a velocity. Default is to spawn with 0 velocity state.velocity = 20 * forward -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) print("Real time elapsed =", 0) print("Simulation time =", sim.current_time) diff --git a/quickstart/25-waypoint-flying-npc.py b/quickstart/25-waypoint-flying-npc.py index 6450e32..c591348 100755 --- a/quickstart/25-waypoint-flying-npc.py +++ b/quickstart/25-waypoint-flying-npc.py @@ -13,10 +13,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() @@ -26,7 +26,7 @@ right = lgsvl.utils.transform_to_right(spawns[0]) up = lgsvl.utils.transform_to_up(spawns[0]) state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() diff --git a/quickstart/26-npc-trigger-waypoints.py b/quickstart/26-npc-trigger-waypoints.py index a437a46..9b38814 100755 --- a/quickstart/26-npc-trigger-waypoints.py +++ b/quickstart/26-npc-trigger-waypoints.py @@ -13,10 +13,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() @@ -26,7 +26,7 @@ right = lgsvl.utils.transform_to_right(spawns[0]) state.transform = spawns[0] state.velocity = 12 * forward -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() diff --git a/quickstart/27-control-traffic-lights.py b/quickstart/27-control-traffic-lights.py index b886dcb..17395f9 100755 --- a/quickstart/27-control-traffic-lights.py +++ b/quickstart/27-control-traffic-lights.py @@ -13,10 +13,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName, 42) + sim.load(SimulatorSettings.map_borregasave, 42) spawns = sim.get_spawn() @@ -24,11 +24,11 @@ forward = lgsvl.utils.transform_to_forward(spawns[0]) state.transform = spawns[0] state.transform.position = spawns[0].position + 20 * forward -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # # Get a list of controllable objects controllables = sim.get_controllables("signal") -print("\n# List of controllable objects in {} scene:".format(SimulatorSettings.mapName)) +print("\n# List of controllable objects in {} scene:".format(SimulatorSettings.map_borregasave)) for c in controllables: print(c) diff --git a/quickstart/28-control-traffic-cone.py b/quickstart/28-control-traffic-cone.py index fda33ba..b93d09a 100755 --- a/quickstart/28-control-traffic-cone.py +++ b/quickstart/28-control-traffic-cone.py @@ -13,10 +13,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName, 42) + sim.load(SimulatorSettings.map_borregasave, 42) spawns = sim.get_spawn() @@ -26,7 +26,7 @@ up = lgsvl.utils.transform_to_up(spawns[0]) state.transform = spawns[0] -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) for i in range(10 * 3): # Create controllables in a block diff --git a/quickstart/29-add-random-agents.py b/quickstart/29-add-random-agents.py index fad61d0..19d4547 100755 --- a/quickstart/29-add-random-agents.py +++ b/quickstart/29-add-random-agents.py @@ -13,10 +13,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -26,7 +26,7 @@ state.transform.position = spawns[0].position + 40 * forward state.transform.rotation = spawns[0].rotation -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) sim.add_random_agents(lgsvl.AgentType.NPC) sim.add_random_agents(lgsvl.AgentType.PEDESTRIAN) diff --git a/quickstart/30-time-to-collision-trigger.py b/quickstart/30-time-to-collision-trigger.py index 1194440..ecd50fc 100755 --- a/quickstart/30-time-to-collision-trigger.py +++ b/quickstart/30-time-to-collision-trigger.py @@ -13,10 +13,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName, 42) + sim.load(SimulatorSettings.map_borregasave, 42) spawns = sim.get_spawn() layer_mask = 0 @@ -33,7 +33,7 @@ spawn_state.position = hit.point state.transform = spawn_state state.velocity = forward * 2 -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() diff --git a/quickstart/31-wait-for-distance-trigger.py b/quickstart/31-wait-for-distance-trigger.py index 53d7468..6ee670d 100755 --- a/quickstart/31-wait-for-distance-trigger.py +++ b/quickstart/31-wait-for-distance-trigger.py @@ -13,10 +13,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName, 42) + sim.load(SimulatorSettings.map_borregasave, 42) spawns = sim.get_spawn() layer_mask = 0 @@ -33,7 +33,7 @@ spawn_state.position = hit.point state.transform = spawn_state state.velocity = forward * 2 -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() diff --git a/quickstart/32-pedestrian-time-to-collision.py b/quickstart/32-pedestrian-time-to-collision.py index df74b38..9d37369 100755 --- a/quickstart/32-pedestrian-time-to-collision.py +++ b/quickstart/32-pedestrian-time-to-collision.py @@ -13,10 +13,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName, 42) + sim.load(SimulatorSettings.map_borregasave, 42) spawns = sim.get_spawn() layer_mask = 0 @@ -30,7 +30,7 @@ state.transform.rotation = lgsvl.Vector(0.0, 15.0, 0.0) forward = lgsvl.Vector(0.2, 0.0, 0.8) state.velocity = forward * 15 -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # Pedestrian state = lgsvl.AgentState() diff --git a/quickstart/33-ego-drive-stepped.py b/quickstart/33-ego-drive-stepped.py index 491d388..c3a5873 100755 --- a/quickstart/33-ego-drive-stepped.py +++ b/quickstart/33-ego-drive-stepped.py @@ -12,10 +12,10 @@ print("Python API Quickstart #33: Stepping a simulation") sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), SimulatorSettings.simulatorPort) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() # Re-load scene and set random seed -sim.load(SimulatorSettings.mapName, seed=123) +sim.load(SimulatorSettings.map_borregasave, seed=123) spawns = sim.get_spawn() @@ -34,7 +34,7 @@ # We can test Apollo with standard MKZ or MKZ with ground truth sensors # Refer to https://www.lgsvlsimulator.com/docs/modular-testing/ # ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) -ego = sim.add_agent(SimulatorSettings.egoVehicleWithBridge, lgsvl.AgentType.EGO, state) +ego = sim.add_agent(SimulatorSettings.ego_lincoln2017mkz_apollo5, lgsvl.AgentType.EGO, state) # An EGO will not connect to a bridge unless commanded to print("Bridge connected:", ego.bridge_connected) diff --git a/quickstart/34-simulator-cam-set.py b/quickstart/34-simulator-cam-set.py index 635a0e5..6a7beca 100755 --- a/quickstart/34-simulator-cam-set.py +++ b/quickstart/34-simulator-cam-set.py @@ -13,10 +13,10 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) -if sim.current_scene == SimulatorSettings.mapName: +if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.mapName) + sim.load(SimulatorSettings.map_borregasave) # This creates a transform in Unity world coordinates tr = lgsvl.Transform(lgsvl.Vector(10, 50, 0), lgsvl.Vector(90, 0, 0)) @@ -27,7 +27,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) state.velocity = 20 * forward -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # This function sets the camera to free state and applies the transform to the camera rig sim.set_sim_camera(tr) diff --git a/quickstart/98-npc-behaviour.py b/quickstart/98-npc-behaviour.py index dc56be7..61b62af 100755 --- a/quickstart/98-npc-behaviour.py +++ b/quickstart/98-npc-behaviour.py @@ -61,7 +61,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.egoVehicle), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) mindist = 10.0 maxdist = 40.0 diff --git a/quickstart/settings.py b/settings.py similarity index 63% rename from quickstart/settings.py rename to settings.py index a54a18f..c528a71 100644 --- a/quickstart/settings.py +++ b/settings.py @@ -21,13 +21,9 @@ class SimulatorSettings: bridgePort = 9090 # Map loaded in the quickstart scripts. Changing the map may lead to unexpected behaviour in the quickstart scripts. Default value is "BorregasAve" - mapName = "BorregasAve" + # https://wise.svlsimulator.com/maps/profile/aae03d2a-b7ca-4a88-9e41-9035287a12cc + map_borregasave = "aae03d2a-b7ca-4a88-9e41-9035287a12cc" - # Ego vehicle that is loaded in most of the quickstart scripts. Default value is "Lincoln2017MKZ" - egoVehicle = "Lincoln2017MKZ" - - # Ego vehicle that is loaded in quickstart scripts where the bridge connection is required. Default value is "Lincoln2017MKZ" - egoVehicleWithBridge = "Lincoln2017MKZ" - - # Ego vehicle that is loaded in quickstart scripts where the LIDAR sensor is required. Default value is "Lincoln2017MKZ" - egoVehicleWithLidar = "Lincoln2017MKZ" \ No newline at end of file + # Ego vehicle that is loaded in most of the quickstart scripts. Default value is "Lincoln2017MKZ". This includes a bridge connection if needed and also bunch of sensors including LIDAR. + # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 + ego_lincoln2017mkz_apollo5 = "47b529db-0593-4908-b3e7-4b24a32a0f70" From 7d6a5f63ebaef19a92d95cd6e6e93fd33c09a440 Mon Sep 17 00:00:00 2001 From: Hadi Tabatabaee Date: Tue, 2 Mar 2021 15:17:31 -0800 Subject: [PATCH 061/115] Fix style and importing issues --- lgsvl/agent.py | 4 +-- quickstart/01-connecting-to-simulator.py | 4 +-- quickstart/02-loading-scene-show-spawns.py | 4 +-- quickstart/03-raycast.py | 4 +-- quickstart/04-ego-drive-straight.py | 4 +-- quickstart/05-ego-drive-in-circle.py | 4 +-- quickstart/06-save-camera-image.py | 4 +-- quickstart/07-save-lidar-point-cloud.py | 4 +-- quickstart/08-create-npc.py | 4 +-- quickstart/09-reset-scene.py | 4 +-- quickstart/10-npc-follow-the-lane.py | 4 +-- quickstart/11-collision-callbacks.py | 4 +-- quickstart/12-create-npc-on-lane.py | 6 ++-- quickstart/13-npc-follow-waypoints.py | 4 +-- quickstart/14-create-pedestrians.py | 4 +-- quickstart/15-pedestrian-walk-randomly.py | 4 +-- quickstart/16-pedestrian-follow-waypoints.py | 4 +-- quickstart/17-many-pedestrians-walking.py | 4 +-- quickstart/18-weather-effects.py | 4 +-- quickstart/19-time-of-day.py | 4 +-- quickstart/20-enable-sensors.py | 4 +-- quickstart/21-map-coordinates.py | 4 +-- quickstart/22-connecting-bridge.py | 6 ++-- quickstart/23-npc-callbacks.py | 4 +-- .../24-ego-drive-straight-non-realtime.py | 4 +-- quickstart/25-waypoint-flying-npc.py | 4 +-- quickstart/26-npc-trigger-waypoints.py | 4 +-- quickstart/27-control-traffic-lights.py | 4 +-- quickstart/28-control-traffic-cone.py | 4 +-- quickstart/29-add-random-agents.py | 4 +-- quickstart/30-time-to-collision-trigger.py | 4 +-- quickstart/31-wait-for-distance-trigger.py | 4 +-- quickstart/32-pedestrian-time-to-collision.py | 4 +-- quickstart/33-ego-drive-stepped.py | 6 ++-- quickstart/34-simulator-cam-set.py | 4 +-- quickstart/98-npc-behaviour.py | 4 +-- settings.py | 28 +++++++++---------- 37 files changed, 89 insertions(+), 89 deletions(-) diff --git a/lgsvl/agent.py b/lgsvl/agent.py index b05b515..346eeb9 100644 --- a/lgsvl/agent.py +++ b/lgsvl/agent.py @@ -66,10 +66,10 @@ def __init__(self, type_name, parameters): @staticmethod def from_json(j): - return TriggerEffector(j["typeName"], j["parameters"]) + return TriggerEffector(j["type_name"], j["parameters"]) def to_json(self): - return {"typeName": self.type_name, "parameters": self.parameters} + return {"type_name": self.type_name, "parameters": self.parameters} class AgentType(Enum): diff --git a/quickstart/01-connecting-to-simulator.py b/quickstart/01-connecting-to-simulator.py index 7fcdf05..c9ca2c8 100755 --- a/quickstart/01-connecting-to-simulator.py +++ b/quickstart/01-connecting-to-simulator.py @@ -7,7 +7,7 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #1: Connecting to the Simulator") env = Env() @@ -15,7 +15,7 @@ # Connects to the simulator instance at the ip defined by LGSVL__SIMULATOR_HOST, default is localhost or 127.0.0.1 # env.str() is equivalent to os.environ.get() # env.int() is equivalent to int(os.environ.get()) -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) print("Version =", sim.version) print("Current Time =", sim.current_time) diff --git a/quickstart/02-loading-scene-show-spawns.py b/quickstart/02-loading-scene-show-spawns.py index bc040a1..d0329c6 100755 --- a/quickstart/02-loading-scene-show-spawns.py +++ b/quickstart/02-loading-scene-show-spawns.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #2: Loading the scene spawn points") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) print("Current Scene = {}".format(sim.current_scene)) diff --git a/quickstart/03-raycast.py b/quickstart/03-raycast.py index 87e09d0..11cdac7 100755 --- a/quickstart/03-raycast.py +++ b/quickstart/03-raycast.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #3: Using raycasts in the Simulator") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/04-ego-drive-straight.py b/quickstart/04-ego-drive-straight.py index 05a7249..70bddbb 100755 --- a/quickstart/04-ego-drive-straight.py +++ b/quickstart/04-ego-drive-straight.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #4: Ego vehicle driving straight") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/05-ego-drive-in-circle.py b/quickstart/05-ego-drive-in-circle.py index 319ce53..e23d8b7 100755 --- a/quickstart/05-ego-drive-in-circle.py +++ b/quickstart/05-ego-drive-in-circle.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #5: Ego vehicle driving in circle") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/06-save-camera-image.py b/quickstart/06-save-camera-image.py index 561f02c..babdbc3 100755 --- a/quickstart/06-save-camera-image.py +++ b/quickstart/06-save-camera-image.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #6: Saving an image from the Main Camera sensor") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/07-save-lidar-point-cloud.py b/quickstart/07-save-lidar-point-cloud.py index 02c2822..6adb26a 100755 --- a/quickstart/07-save-lidar-point-cloud.py +++ b/quickstart/07-save-lidar-point-cloud.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #7: Saving a point cloud from the Lidar sensor") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/08-create-npc.py b/quickstart/08-create-npc.py index faa3b46..23e161b 100755 --- a/quickstart/08-create-npc.py +++ b/quickstart/08-create-npc.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #8: Creating various NPCs") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/09-reset-scene.py b/quickstart/09-reset-scene.py index 3eb6fa2..6bb11c8 100755 --- a/quickstart/09-reset-scene.py +++ b/quickstart/09-reset-scene.py @@ -8,14 +8,14 @@ import random from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #9: Resetting the scene to it's initial state") env = Env() random.seed(0) -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/10-npc-follow-the-lane.py b/quickstart/10-npc-follow-the-lane.py index 71d5eb2..deaecfc 100755 --- a/quickstart/10-npc-follow-the-lane.py +++ b/quickstart/10-npc-follow-the-lane.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #10: NPC following the lane") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/11-collision-callbacks.py b/quickstart/11-collision-callbacks.py index 67a29f8..59edb26 100755 --- a/quickstart/11-collision-callbacks.py +++ b/quickstart/11-collision-callbacks.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #11: Handling the collision callbacks") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/12-create-npc-on-lane.py b/quickstart/12-create-npc-on-lane.py index f51c0c7..84b0625 100755 --- a/quickstart/12-create-npc-on-lane.py +++ b/quickstart/12-create-npc-on-lane.py @@ -9,12 +9,12 @@ import random from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #12: Creating NPCs on lanes") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: @@ -37,7 +37,7 @@ print("Spawn 10 random NPCs on lanes") for i in range(10): - input("Press Enter to spawn NPC ({})".format(i+1)) + input("Press Enter to spawn NPC ({})".format(i + 1)) # Creates a random point around the EGO angle = random.uniform(0.0, 2 * math.pi) diff --git a/quickstart/13-npc-follow-waypoints.py b/quickstart/13-npc-follow-waypoints.py index d3a18f9..ad3a643 100755 --- a/quickstart/13-npc-follow-waypoints.py +++ b/quickstart/13-npc-follow-waypoints.py @@ -8,12 +8,12 @@ import copy from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #13: NPC following waypoints") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/14-create-pedestrians.py b/quickstart/14-create-pedestrians.py index 2532551..0e49ef7 100755 --- a/quickstart/14-create-pedestrians.py +++ b/quickstart/14-create-pedestrians.py @@ -9,12 +9,12 @@ import time from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #14: Creating pedestrians on the map") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/15-pedestrian-walk-randomly.py b/quickstart/15-pedestrian-walk-randomly.py index c50150e..0bac766 100755 --- a/quickstart/15-pedestrian-walk-randomly.py +++ b/quickstart/15-pedestrian-walk-randomly.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #15: Pedestrian walking randomly") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/16-pedestrian-follow-waypoints.py b/quickstart/16-pedestrian-follow-waypoints.py index 45e67d3..45a058f 100755 --- a/quickstart/16-pedestrian-follow-waypoints.py +++ b/quickstart/16-pedestrian-follow-waypoints.py @@ -8,12 +8,12 @@ import math from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #16: Pedestrian following waypoints") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/17-many-pedestrians-walking.py b/quickstart/17-many-pedestrians-walking.py index b641de8..c0083e9 100755 --- a/quickstart/17-many-pedestrians-walking.py +++ b/quickstart/17-many-pedestrians-walking.py @@ -8,12 +8,12 @@ import random from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #17: Many pedestrians walking simultaneously") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/18-weather-effects.py b/quickstart/18-weather-effects.py index 66f1737..7ba2c8f 100755 --- a/quickstart/18-weather-effects.py +++ b/quickstart/18-weather-effects.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #18: Changing the weather effects") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/19-time-of-day.py b/quickstart/19-time-of-day.py index 365685b..4aeee9a 100755 --- a/quickstart/19-time-of-day.py +++ b/quickstart/19-time-of-day.py @@ -8,12 +8,12 @@ from environs import Env import lgsvl from datetime import datetime -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #19: Changing the time of day") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/20-enable-sensors.py b/quickstart/20-enable-sensors.py index af6bcc2..4c79cff 100755 --- a/quickstart/20-enable-sensors.py +++ b/quickstart/20-enable-sensors.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #20: Enabling and disabling sensors") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/21-map-coordinates.py b/quickstart/21-map-coordinates.py index a17e6d3..9106230 100755 --- a/quickstart/21-map-coordinates.py +++ b/quickstart/21-map-coordinates.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #21: Converting the map coordinates") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/22-connecting-bridge.py b/quickstart/22-connecting-bridge.py index afaa549..ca4024b 100755 --- a/quickstart/22-connecting-bridge.py +++ b/quickstart/22-connecting-bridge.py @@ -8,12 +8,12 @@ import time from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #22: Connecting to a bridge") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: @@ -29,7 +29,7 @@ print("Bridge connected:", ego.bridge_connected) # The EGO is now looking for a bridge at the specified IP and port -ego.connect_bridge(env.str("LGSVL__AUTOPILOT_0_HOST", SimulatorSettings.bridgeHost), env.int("LGSVL__AUTOPILOT_0_PORT", SimulatorSettings.bridgePort)) +ego.connect_bridge(env.str("LGSVL__AUTOPILOT_0_HOST", SimulatorSettings.bridge_host), env.int("LGSVL__AUTOPILOT_0_PORT", SimulatorSettings.bridgePort)) print("Waiting for connection...") diff --git a/quickstart/23-npc-callbacks.py b/quickstart/23-npc-callbacks.py index 62c1b90..4570a02 100755 --- a/quickstart/23-npc-callbacks.py +++ b/quickstart/23-npc-callbacks.py @@ -9,12 +9,12 @@ import random from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #23: Handling NPCs callbacks") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/24-ego-drive-straight-non-realtime.py b/quickstart/24-ego-drive-straight-non-realtime.py index a5db32d..e000813 100755 --- a/quickstart/24-ego-drive-straight-non-realtime.py +++ b/quickstart/24-ego-drive-straight-non-realtime.py @@ -8,12 +8,12 @@ import time from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #24: Changing the Simulator timescale") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/25-waypoint-flying-npc.py b/quickstart/25-waypoint-flying-npc.py index c591348..9cae166 100755 --- a/quickstart/25-waypoint-flying-npc.py +++ b/quickstart/25-waypoint-flying-npc.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #25: NPC flying to waypoints") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/26-npc-trigger-waypoints.py b/quickstart/26-npc-trigger-waypoints.py index 9b38814..65110ef 100755 --- a/quickstart/26-npc-trigger-waypoints.py +++ b/quickstart/26-npc-trigger-waypoints.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #26: NPC triggering the waypoints callbacks") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/27-control-traffic-lights.py b/quickstart/27-control-traffic-lights.py index 17395f9..926178d 100755 --- a/quickstart/27-control-traffic-lights.py +++ b/quickstart/27-control-traffic-lights.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #27: How to Control Traffic Light") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/28-control-traffic-cone.py b/quickstart/28-control-traffic-cone.py index b93d09a..2b65ab9 100755 --- a/quickstart/28-control-traffic-cone.py +++ b/quickstart/28-control-traffic-cone.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #28: How to Add/Control Traffic Cone") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/29-add-random-agents.py b/quickstart/29-add-random-agents.py index 19d4547..6324c9f 100755 --- a/quickstart/29-add-random-agents.py +++ b/quickstart/29-add-random-agents.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #29: Adding random agents to a simulation") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/30-time-to-collision-trigger.py b/quickstart/30-time-to-collision-trigger.py index ecd50fc..594c67f 100755 --- a/quickstart/30-time-to-collision-trigger.py +++ b/quickstart/30-time-to-collision-trigger.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #30: Using the time to collision trigger") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/31-wait-for-distance-trigger.py b/quickstart/31-wait-for-distance-trigger.py index 6ee670d..effac06 100755 --- a/quickstart/31-wait-for-distance-trigger.py +++ b/quickstart/31-wait-for-distance-trigger.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #31: Using the wait for distance trigger") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/32-pedestrian-time-to-collision.py b/quickstart/32-pedestrian-time-to-collision.py index 9d37369..1702b4a 100755 --- a/quickstart/32-pedestrian-time-to-collision.py +++ b/quickstart/32-pedestrian-time-to-collision.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #1: Using the time to collision trigger with a pedestrian") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/33-ego-drive-stepped.py b/quickstart/33-ego-drive-stepped.py index c3a5873..c152d2f 100755 --- a/quickstart/33-ego-drive-stepped.py +++ b/quickstart/33-ego-drive-stepped.py @@ -8,10 +8,10 @@ import os import lgsvl import time -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #33: Stepping a simulation") -sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), SimulatorSettings.simulatorPort) +sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), SimulatorSettings.simulator_port) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() # Re-load scene and set random seed @@ -40,7 +40,7 @@ print("Bridge connected:", ego.bridge_connected) # The EGO looks for a (Cyber) bridge at the specified IP and port -ego.connect_bridge(SimulatorSettings.bridgeHost, SimulatorSettings.bridgePort) +ego.connect_bridge(SimulatorSettings.bridge_host, SimulatorSettings.bridgePort) # uncomment to wait for bridge connection; script will drive ego if bridge not found # print("Waiting for connection...") # while not ego.bridge_connected: diff --git a/quickstart/34-simulator-cam-set.py b/quickstart/34-simulator-cam-set.py index 6a7beca..aa2eff7 100755 --- a/quickstart/34-simulator-cam-set.py +++ b/quickstart/34-simulator-cam-set.py @@ -7,12 +7,12 @@ from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #34: Setting the fixed camera position") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) if sim.current_scene == SimulatorSettings.map_borregasave: sim.reset() else: diff --git a/quickstart/98-npc-behaviour.py b/quickstart/98-npc-behaviour.py index 61b62af..f4e8b98 100755 --- a/quickstart/98-npc-behaviour.py +++ b/quickstart/98-npc-behaviour.py @@ -9,12 +9,12 @@ import random from environs import Env import lgsvl -from settings import * +from settings import SimulatorSettings print("Python API Quickstart #98: Simulating different NPCs behaviours") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulatorHost), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulatorPort)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) drunkDriverAvailable = False trailerAvailable = 0 diff --git a/settings.py b/settings.py index c528a71..12023e2 100644 --- a/settings.py +++ b/settings.py @@ -8,22 +8,22 @@ # Settings class with common variables used in the quickstart scripts class SimulatorSettings: - # IP address of the endpoint running the Simulator. Default value is "127.0.0.1" - simulatorHost = "127.0.0.1" + # IP address of the endpoint running the Simulator. Default value is "127.0.0.1" + simulator_host = "127.0.0.1" - # Port used by the Simulator for the Python API connection. Default value is 8181 - simulatorPort = 8181 + # Port used by the Simulator for the Python API connection. Default value is 8181 + simulator_port = 8181 - # IP address of the endpoint running the bridge. Default value is "127.0.0.1" - bridgeHost = "127.0.0.1" + # IP address of the endpoint running the bridge. Default value is "127.0.0.1" + bridge_host = "127.0.0.1" - # Port used by the Simulator for the bridge connection. Default value is 9090 - bridgePort = 9090 + # Port used by the Simulator for the bridge connection. Default value is 9090 + bridge_port = 9090 - # Map loaded in the quickstart scripts. Changing the map may lead to unexpected behaviour in the quickstart scripts. Default value is "BorregasAve" - # https://wise.svlsimulator.com/maps/profile/aae03d2a-b7ca-4a88-9e41-9035287a12cc - map_borregasave = "aae03d2a-b7ca-4a88-9e41-9035287a12cc" + # Map loaded in the quickstart scripts. Changing the map may lead to unexpected behaviour in the quickstart scripts. Default value is "BorregasAve" + # https://wise.svlsimulator.com/maps/profile/aae03d2a-b7ca-4a88-9e41-9035287a12cc + map_borregasave = "aae03d2a-b7ca-4a88-9e41-9035287a12cc" - # Ego vehicle that is loaded in most of the quickstart scripts. Default value is "Lincoln2017MKZ". This includes a bridge connection if needed and also bunch of sensors including LIDAR. - # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 - ego_lincoln2017mkz_apollo5 = "47b529db-0593-4908-b3e7-4b24a32a0f70" + # Ego vehicle that is loaded in most of the quickstart scripts. Default value is "Lincoln2017MKZ". This includes a bridge connection if needed and also bunch of sensors including LIDAR. + # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 + ego_lincoln2017mkz_apollo5 = "47b529db-0593-4908-b3e7-4b24a32a0f70" From 45dcda4d4582f4c9bc2d429e251bead387d37608 Mon Sep 17 00:00:00 2001 From: Lokesh Kumar Goel Date: Tue, 2 Mar 2021 14:18:32 -0800 Subject: [PATCH 062/115] Unittest: Update to use sensor config id instead of vehicle name Change-Id: I427946b737b6b45c9c9ffeef65b3b7adff2ef70f --- settings.py | 8 +++++ tests/common.py | 1 + tests/test_EGO.py | 56 ++++++++++++++++++----------------- tests/test_NPC.py | 41 ++++++++++++------------- tests/test_collisions.py | 19 ++++++------ tests/test_manual_features.py | 16 +++++----- tests/test_peds.py | 9 +++--- tests/test_sensors.py | 23 +++++++------- tests/test_simulator.py | 5 ++-- 9 files changed, 97 insertions(+), 81 deletions(-) diff --git a/settings.py b/settings.py index 12023e2..d71bead 100644 --- a/settings.py +++ b/settings.py @@ -27,3 +27,11 @@ class SimulatorSettings: # Ego vehicle that is loaded in most of the quickstart scripts. Default value is "Lincoln2017MKZ". This includes a bridge connection if needed and also bunch of sensors including LIDAR. # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego_lincoln2017mkz_apollo5 = "47b529db-0593-4908-b3e7-4b24a32a0f70" + + # Ego vehicle that is loaded in quickstart/tests scripts. Default value is "Jaguar2015XE - Apollo 5". + # https://wise.svlsimulator.com/vehicles/profile/3f4211dc-e5d7-42dc-94c5-c4832b1331bb/edit/configuration/c06d4932-5928-4730-8a91-ba64ac5f1813 + ego_jaguar2015xe_apollo5 = "c06d4932-5928-4730-8a91-ba64ac5f1813" + + # Ego vehicle that is loaded in quickstart/tests scripts. Default value is "Jaguar2015XE - AutowareAI". + # https://wise.svlsimulator.com/vehicles/profile/3f4211dc-e5d7-42dc-94c5-c4832b1331bb/edit/configuration/05cbb194-d095-4a0e-ae66-ff56c331ca83 + ego_jaguae2015xe_autowareai = "05cbb194-d095-4a0e-ae66-ff56c331ca83" diff --git a/tests/common.py b/tests/common.py index 93c2ace..707de20 100644 --- a/tests/common.py +++ b/tests/common.py @@ -70,3 +70,4 @@ def mEqual(self, a, b, msg): # Test vectors within 1cm def notAlmostEqual(a,b): return round(a-b,7) != 0 + diff --git a/tests/test_EGO.py b/tests/test_EGO.py index df7240f..133b540 100644 --- a/tests/test_EGO.py +++ b/tests/test_EGO.py @@ -10,6 +10,8 @@ import lgsvl from .common import SimConnection, spawnState, cmEqual +from settings import SimulatorSettings + # TODO add tests for bridge connection @@ -18,7 +20,7 @@ def test_agent_name(self): # Check if EGO Apollo is created with SimConnection() as sim: agent = self.create_EGO(sim) - self.assertEqual(agent.name, "Jaguar2015XE (Apollo 3.0)") + self.assertEqual(agent.name, SimulatorSettings.ego_jaguar2015xe_apollo5) def test_different_spawns(self): # Check if EGO is spawned in the spawn positions with SimConnection() as sim: @@ -29,7 +31,7 @@ def test_different_spawns(self): # Check if EGO is spawned in the spawn positio state = spawnState(sim) state.transform = spawns[1] - agent2 = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + agent2 = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) cmEqual(self, agent2.state.position, spawns[1].position, "Spawn Position 1") cmEqual(self, agent2.state.rotation, spawns[1].rotation, "Spawn Rotation 1") @@ -43,7 +45,7 @@ def test_agent_velocity(self): # Check EGO velocity sim.reset() right = lgsvl.utils.transform_to_right(state.transform) state.velocity = -50 * right - agent = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + agent = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) cmEqual(self, agent.state.velocity, state.velocity, "50 Velocity") @@ -55,21 +57,21 @@ def test_ego_different_directions(self): # Check that the xyz velocities equate right = lgsvl.utils.transform_to_right(state.transform) state.velocity = -10 * right - ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) sim.run(.5) target = state.position - 3 * right self.assertLess((ego.state.position - target).magnitude(), 1) sim.remove_agent(ego) state.velocity = 10 * up - ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) sim.run(.5) target = state.position + 3 * up self.assertLess((ego.state.position - target).magnitude(), 1) sim.remove_agent(ego) state.velocity = 10 * forward - ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) sim.run(.5) target = state.position + 4 * forward self.assertLess((ego.state.position - target).magnitude(), 1) @@ -81,7 +83,7 @@ def test_speed(self): # check that speed returns a reasonable number up = lgsvl.utils.transform_to_up(state.transform) right = lgsvl.utils.transform_to_right(state.transform) state.velocity = -10 * right + 10 * up + 10 * forward - ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) self.assertAlmostEqual(ego.state.speed, math.sqrt(300), places=3) @unittest.skip("No highway in currents maps") @@ -89,14 +91,14 @@ def test_rotation_on_highway_ramp(self): # Check that vehicle is rotated when s with SimConnection() as sim: state = spawnState(sim) state.transform.position = lgsvl.Vector(469.6401, 15.67488, 100.4229) - ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) self.assertAlmostEqual(ego.state.rotation.z, state.rotation.z) sim.run(0.5) self.assertAlmostEqual(ego.state.rotation.z, 356, delta=0.5) 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("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.throttle = 0.3 control.steering = -1.0 @@ -108,7 +110,7 @@ def test_ego_steering(self): # Check that a steering command can be given to an 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("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.throttle = 0.5 ego.apply_control(control, True) @@ -120,7 +122,7 @@ def test_ego_throttle(self): # Check that a throttle command can be given to an 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) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) control = lgsvl.VehicleControl() control.throttle = 1 ego.apply_control(control, True) @@ -131,7 +133,7 @@ def test_ego_braking(self): # Check that a brake command can be given to an EGO noBrakeDistance = (ego.state.position - state.position).magnitude() sim.reset() - ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) control = lgsvl.VehicleControl() control.throttle = 1 ego.apply_control(control, True) @@ -146,7 +148,7 @@ def test_ego_braking(self): # Check that a brake command can be given to an EGO 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("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) control = lgsvl.VehicleControl() control.throttle = 1 ego.apply_control(control, True) @@ -157,7 +159,7 @@ def test_ego_handbrake(self): # Check that the handbrake can be enable on an EG noBrakeDistance = (ego.state.position - state.position).magnitude() sim.reset() - ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) control = lgsvl.VehicleControl() control.throttle = 1 ego.apply_control(control, True) @@ -172,7 +174,7 @@ def test_ego_handbrake(self): # Check that the handbrake can be enable on an EG 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) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) control = lgsvl.VehicleControl() control.throttle = 0.5 control.reverse = True @@ -186,7 +188,7 @@ def test_ego_reverse(self): # Check that the gear can be changed in an EGO vehi 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("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) control = lgsvl.VehicleControl() control.throttle = 1 ego.apply_control(control, True) @@ -194,7 +196,7 @@ def test_not_sticky_control(self): # Check that the a non sticky control is rem stickySpeed = ego.state.speed sim.reset() - ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) control = lgsvl.VehicleControl() control.throttle = 1 ego.apply_control(control, True) @@ -206,7 +208,7 @@ def test_not_sticky_control(self): # Check that the a non sticky control is rem def test_vary_throttle(self): # Check that different throttle values accelerate differently with SimConnection(40) as sim: - ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.throttle = 0.5 ego.apply_control(control, True) @@ -214,7 +216,7 @@ def test_vary_throttle(self): # Check that different throttle values accelerate initialSpeed = ego.state.speed sim.reset() - ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.throttle = 0.1 ego.apply_control(control, True) @@ -223,7 +225,7 @@ def test_vary_throttle(self): # Check that different throttle values accelerate def test_vary_steering(self): # Check that different steering values turn the car differently with SimConnection(40) as sim: - ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.throttle = 0.5 control.steering = -0.8 @@ -232,7 +234,7 @@ def test_vary_steering(self): # Check that different steering values turn the c initialAngle = ego.state.rotation.y sim.reset() - ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.throttle = 0.5 control.steering = -0.3 @@ -242,7 +244,7 @@ def test_vary_steering(self): # Check that different steering values turn the c def test_bounding_box_size(self): # Check that the bounding box is calculated properly and is reasonable with SimConnection() as sim: - ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) bBox = ego.bounding_box self.assertAlmostEqual(bBox.size.x, abs(bBox.max.x-bBox.min.x)) self.assertAlmostEqual(bBox.size.y, abs(bBox.max.y-bBox.min.y)) @@ -253,7 +255,7 @@ def test_bounding_box_size(self): # Check that the bounding box is calculated p def test_bounding_box_center(self): # Check that the bounding box center is calcualted properly with SimConnection() as sim: - ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) bBox = ego.bounding_box self.assertAlmostEqual(bBox.center.x, (bBox.max.x+bBox.min.x)/2) self.assertAlmostEqual(bBox.center.y, (bBox.max.y+bBox.min.y)/2) @@ -261,22 +263,22 @@ def test_bounding_box_center(self): # Check that the bounding box center is cal def test_equality(self): # Check that agent == operation works with SimConnection() as sim: - ego1 = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) - ego2 = sim.add_agent("Jaguar2015XE (Autoware)", lgsvl.AgentType.EGO, spawnState(sim)) + ego1 = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + ego2 = sim.add_agent(SimulatorSettings.ego_jaguae2015xe_autowareai, lgsvl.AgentType.EGO, spawnState(sim)) self.assertTrue(ego1 == ego1) self.assertFalse(ego1 == ego2) @unittest.skip("Cruise Control not implemented yet") def test_set_fixed_speed(self): with SimConnection(60) as sim: - ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) ego.set_fixed_speed(True, 15.0) self.assertAlmostEqual(ego.state.speed, 0, delta=0.001) sim.run(5) self.assertAlmostEqual(ego.state.speed, 15, delta=1) def create_EGO(self, sim): # Only create an EGO is none are already spawned - return sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) + return sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) # def test_large_throttle(self): # with SimConnection(60) as sim: diff --git a/tests/test_NPC.py b/tests/test_NPC.py index e64a49b..5f78ea2 100644 --- a/tests/test_NPC.py +++ b/tests/test_NPC.py @@ -8,6 +8,7 @@ import time import lgsvl from .common import SimConnection, spawnState, cmEqual, mEqual, TestException +from settings import SimulatorSettings PROBLEM = "Object reference not set to an instance of an object" @@ -30,7 +31,7 @@ def test_NPC_creation(self): # Check if the different types of NPCs can be crea state = spawnState(sim) right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position + 10 * right - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) spawns = sim.get_spawn() for name in ["Sedan", "SUV", "Jeep", "Hatchback", "SchoolBus", "BoxTruck"]: agent = self.create_NPC(sim, name) @@ -43,17 +44,17 @@ def test_get_agents(self): state = spawnState(sim) right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position + 10 * right - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) for name in ["Sedan", "SUV", "Jeep", "Hatchback", "SchoolBus", "BoxTruck"]: self.create_NPC(sim, name) agentCount += 1 agents = sim.get_agents() self.assertEqual(len(agents), agentCount) - agentCounter = {"Jaguar2015XE (Apollo 3.0)":0, "Sedan":0, "SUV":0, "Jeep":0, "Hatchback":0, "SchoolBus":0, "BoxTruck":0} + agentCounter = {SimulatorSettings.ego_jaguar2015xe_apollo5:0, "Sedan":0, "SUV":0, "Jeep":0, "Hatchback":0, "SchoolBus":0, "BoxTruck":0} for a in agents: agentCounter[a.name] += 1 - expectedAgents = ["Jaguar2015XE (Apollo 3.0)", "Sedan", "SUV", "Jeep", "Hatchback", "SchoolBus", "BoxTruck"] + expectedAgents = [SimulatorSettings.ego_jaguar2015xe_apollo5, "Sedan", "SUV", "Jeep", "Hatchback", "SchoolBus", "BoxTruck"] for a in expectedAgents: with self.subTest(a): self.assertEqual(agentCounter[a], 1) @@ -63,7 +64,7 @@ def test_NPC_follow_lane(self): # Check if NPC can follow lane state = spawnState(sim) right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position - 5 * right - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) agent = self.create_NPC(sim, "Sedan") agent.follow_closest_lane(True, 5.6) sim.run(2.0) @@ -77,7 +78,7 @@ def test_rotate_NPC(self): # Check if NPC can be rotated state = spawnState(sim) right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position - 5 * right - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) agent = self.create_NPC(sim, "SUV") self.assertAlmostEqual(agent.state.transform.rotation.y, 104.823394, places=3) x = agent.state @@ -111,7 +112,7 @@ def test_upsidedown_NPC(self): # Check that an upside-down NPC keeps falling state = spawnState(sim) right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position + 10 * right - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) state = spawnState(sim) state.rotation.z += 180 agent = sim.add_agent("Hatchback", lgsvl.AgentType.NPC, state) @@ -126,7 +127,7 @@ def test_flying_NPC(self): # Check if an NPC created above the map falls forward = lgsvl.utils.transform_to_forward(state.transform) up = lgsvl.utils.transform_to_up(state.transform) state.transform.position = state.position - 10 * forward + 200 * up - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) state = spawnState(sim) state.transform.position = state.position + 200 * up agent = sim.add_agent("Hatchback", lgsvl.AgentType.NPC, state) @@ -162,7 +163,7 @@ def test_follow_waypoints(self): # Check that the NPC can follow waypoints forward = lgsvl.utils.transform_to_forward(state.transform) right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position - 5 * right - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) spawns = sim.get_spawn() agent = self.create_NPC(sim, "Sedan") @@ -202,7 +203,7 @@ def test_high_waypoint(self): # Check that a NPC will drive to under a high way right = lgsvl.utils.transform_to_right(state.transform) up = lgsvl.utils.transform_to_up(state.transform) state.transform.position = state.position - 5 * right - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) spawns = sim.get_spawn() agent = self.create_NPC(sim, "Sedan") @@ -230,7 +231,7 @@ def test_npc_different_directions(self): # Check that specified velocities matc right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position - 5 * right - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) state = spawnState(sim) state.velocity = -10 * right npc = sim.add_agent("SUV", lgsvl.AgentType.NPC, state) @@ -267,7 +268,7 @@ def on_stop_line(agent): right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position - 5 * right - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) sim.run(60) self.assertIn("Waypoint reached", repr(e.exception)) @@ -290,7 +291,7 @@ def on_stop_line(agent): def test_spawn_speed(self): # Checks that a spawned agent keeps the correct speed when spawned with SimConnection() as sim: - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim, 1)) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim, 1)) npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, spawnState(sim)) self.assertEqual(npc.state.speed,0) @@ -304,7 +305,7 @@ def test_lane_change_right(self): npc = sim.add_agent("SUV", lgsvl.AgentType.NPC, state) state.transform = sim.map_point_on_lane(lgsvl.Vector(0.63, -1.57, 42.73)) - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(state.transform) target = state.position + 31 * forward @@ -332,7 +333,7 @@ def test_lane_change_right_missing_lane(self): target = state.position + 42.75 * forward state.transform = sim.map_point_on_lane(lgsvl.Vector(4.49, -1.57, 40.85)) - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) npc.follow_closest_lane(True, 10) @@ -356,7 +357,7 @@ def test_lane_change_left(self): npc = sim.add_agent("SUV", lgsvl.AgentType.NPC, state) state.transform = sim.map_point_on_lane(lgsvl.Vector(9.82, -1.79, 42.02)) - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(state.transform) target = state.position + 31 * forward @@ -384,7 +385,7 @@ def test_lane_change_left_opposing_traffic(self): target = state.position + 42.75 * forward state.transform.position = state.position - 10 * forward - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) npc.follow_closest_lane(True, 10) @@ -407,7 +408,7 @@ def test_multiple_lane_changes(self): state = lgsvl.AgentState() state.transform.position = lgsvl.Vector(-180,10,239) state.transform.rotation = lgsvl.Vector(0,90,0) - sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguae2015xe_autowareai, lgsvl.AgentType.EGO, state) state = lgsvl.AgentState() state.transform.position = lgsvl.Vector(-175, 10, 234.5) @@ -464,7 +465,7 @@ def test_e_stop(self): with SimConnection(60) as sim: state = lgsvl.AgentState() state.transform = sim.map_point_on_lane(lgsvl.Vector(78.962, -3.363, -40.292)) - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(state.transform) state.transform.position = state.position + 10 * forward npc = sim.add_agent("Jeep", lgsvl.AgentType.NPC, state) @@ -485,7 +486,7 @@ def test_waypoint_speed(self): with SimConnection(60) as sim: state = lgsvl.AgentState() state.transform = sim.map_point_on_lane(lgsvl.Vector(78.962, -3.363, -40.292)) - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(state.transform) up = lgsvl.utils.transform_to_up(state.transform) state.transform.position = state.position + 10 * forward diff --git a/tests/test_collisions.py b/tests/test_collisions.py index a254c61..2da0f8a 100644 --- a/tests/test_collisions.py +++ b/tests/test_collisions.py @@ -8,6 +8,7 @@ import lgsvl from .common import SimConnection, spawnState +from settings import SimulatorSettings # TODO add tests for collisions between NPCs, EGO & obstacles @@ -15,7 +16,7 @@ class TestCollisions(unittest.TestCase): def test_ego_collision(self): # Check that a collision between Ego and NPC is reported with SimConnection() as sim: - mover, bus = self.setup_collision(sim, "Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, "SchoolBus", lgsvl.AgentType.NPC) + mover, bus = self.setup_collision(sim, SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, "SchoolBus", lgsvl.AgentType.NPC) collisions = [] def on_collision(agent1, agent2, contact): @@ -30,12 +31,12 @@ def on_collision(agent1, agent2, contact): self.assertGreater(len(collisions), 0) self.assertInBetween(collisions[0][2], collisions[0][0].state.position, collisions[0][1].state.position, "Ego Collision") - self.assertTrue(collisions[0][0].name == "Jaguar2015XE (Apollo 3.0)" or collisions[0][1].name == "Jaguar2015XE (Apollo 3.0)") + self.assertTrue(collisions[0][0].name == SimulatorSettings.ego_jaguar2015xe_apollo5 or collisions[0][1].name == SimulatorSettings.ego_jaguar2015xe_apollo5) self.assertTrue(True) def test_sim_stop(self): # Check that sim.stop works properly with SimConnection() as sim: - mover, bus = self.setup_collision(sim, "Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, "SchoolBus", lgsvl.AgentType.NPC) + mover, bus = self.setup_collision(sim, SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, "SchoolBus", lgsvl.AgentType.NPC) collisions = [] def on_collision(agent1, agent2, contact): @@ -51,7 +52,7 @@ def on_collision(agent1, agent2, contact): def test_ped_collision(self): # Check if a collision between EGO and pedestrian is reported with SimConnection() as sim: - ego, ped = self.setup_collision(sim, "Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, "Howard", lgsvl.AgentType.PEDESTRIAN) + ego, ped = self.setup_collision(sim, SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, "Howard", lgsvl.AgentType.PEDESTRIAN) self.assertTrue(isinstance(ego, lgsvl.EgoVehicle)) self.assertTrue(isinstance(ped, lgsvl.Pedestrian)) collisions = [] @@ -65,7 +66,7 @@ def on_collision(agent1, agent2, contact): sim.run(15) self.assertGreater(len(collisions), 0) self.assertInBetween(collisions[0][2], collisions[0][0].state.position, collisions[0][1].state.position, "Ped Collision") - self.assertTrue(collisions[0][0].name == "Jaguar2015XE (Apollo 3.0)" or collisions[0][1].name == "Jaguar2015XE (Apollo 3.0)") + self.assertTrue(collisions[0][0].name == SimulatorSettings.ego_jaguar2015xe_apollo5 or collisions[0][1].name == SimulatorSettings.ego_jaguar2015xe_apollo5) @unittest.skip("NPCs ignore collisions with Pedestrians, activate this when NPCs use real physics") def test_ped_npc_collisions(self): # Check that collision between NPC and Pedestrian is reported @@ -93,7 +94,7 @@ def test_npc_collision(self): # Check that collision between NPC and NPC is rep with SimConnection() as sim: state = spawnState(sim) state.position.x += 10 - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) jeep, bus = self.setup_collision(sim, "Jeep", lgsvl.AgentType.NPC, "SchoolBus", lgsvl.AgentType.NPC) collisions = [] @@ -119,7 +120,7 @@ def test_wall_collision(self): # Check that an EGO collision with a wall is rep right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position + 30 * right - 1 * up + 140 * forward state.velocity = 50 * forward - ego = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) collisions = [] def on_collision(agent1, agent2, contact): @@ -132,9 +133,9 @@ def on_collision(agent1, agent2, contact): self.assertGreater(len(collisions), 0) if collisions[0][0] is None: - self.assertTrue(collisions[0][1].name == "Jaguar2015XE (Apollo 3.0)") + self.assertTrue(collisions[0][1].name == SimulatorSettings.ego_jaguar2015xe_apollo5) elif collisions[0][1] is None: - self.assertTrue(collisions[0][0].name == "Jaguar2015XE (Apollo 3.0)") + self.assertTrue(collisions[0][0].name == SimulatorSettings.ego_jaguar2015xe_apollo5) else: self.fail("Collision not with object") diff --git a/tests/test_manual_features.py b/tests/test_manual_features.py index 8c386ac..597d03c 100644 --- a/tests/test_manual_features.py +++ b/tests/test_manual_features.py @@ -10,14 +10,14 @@ import lgsvl from .common import SimConnection, spawnState, TestTimeout - +from settings import SimulatorSettings class TestManual(unittest.TestCase): @unittest.skip("Windshield wipers no longer supported") def test_wipers(self): try: with SimConnection() as sim: - ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.windshield_wipers = 1 ego.apply_control(control, True) @@ -41,7 +41,7 @@ def test_wipers(self): def test_headlights(self): try: with SimConnection() as sim: - ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.headlights = 1 ego.apply_control(control, True) @@ -59,7 +59,7 @@ def test_headlights(self): def test_blinkers(self): try: with SimConnection() as sim: - ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.turn_signal_left = True ego.apply_control(control, True) @@ -78,7 +78,7 @@ def test_blinkers(self): def test_wiper_large_value(self): try: with SimConnection() as sim: - ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.windshield_wipers = 4 ego.apply_control(control, True) @@ -91,7 +91,7 @@ def test_wiper_large_value(self): def test_wiper_str(self): try: with SimConnection() as sim: - ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.windshield_wipers = "on" ego.apply_control(control, True) @@ -103,7 +103,7 @@ def test_wiper_str(self): def test_headlights_large_value(self): try: with SimConnection() as sim: - ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.headlights = 123 ego.apply_control(control, True) @@ -115,7 +115,7 @@ def test_headlights_large_value(self): def test_headlights_str(self): try: with SimConnection() as sim: - ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.headlights = "123" ego.apply_control(control, True) diff --git a/tests/test_peds.py b/tests/test_peds.py index d1fabec..f9e3b82 100644 --- a/tests/test_peds.py +++ b/tests/test_peds.py @@ -9,6 +9,7 @@ import lgsvl from .common import SimConnection, cmEqual, mEqual, spawnState +from settings import SimulatorSettings class TestPeds(unittest.TestCase): @@ -17,7 +18,7 @@ def test_ped_creation(self): # Check if the different types of Peds can be crea state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) state.transform.position = state.position - 4 * forward - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) for name in ["Bob", "EntrepreneurFemale", "Howard", "Johny", \ "Pamela", "Presley", "Robin", "Stephen", "Zoe"]: agent = self.create_ped(sim, name, spawnState(sim)) @@ -29,7 +30,7 @@ def test_ped_random_walk(self): # Check if pedestrians can walk randomly state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) state.transform.position = state.position - 4 * forward - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) state = spawnState(sim) spawnPoint = state.transform.position @@ -53,7 +54,7 @@ def test_ped_circle_waypoints(self): # Check if pedestrians can follow waypoint forward = lgsvl.utils.transform_to_forward(state.transform) right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position - 4 * forward - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) state = spawnState(sim) state.transform.position = state.position + 10 * forward radius = 5 @@ -84,7 +85,7 @@ def on_waypoint(agent,index): def test_waypoint_idle_time(self): with SimConnection(60) as sim: - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) right = lgsvl.utils.transform_to_right(state.transform) diff --git a/tests/test_sensors.py b/tests/test_sensors.py index e729191..b0cb37f 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -8,6 +8,7 @@ import os import lgsvl from .common import SimConnection, spawnState, notAlmostEqual +from settings import SimulatorSettings # TODO add tests for bridge to check if enabled sensor actually sends data @@ -15,7 +16,7 @@ class TestSensors(unittest.TestCase): def test_apollo_5_sensors(self): # Check that Apollo 3.5 sensors are created and are positioned reasonably with SimConnection(60) as sim: - agent = self.create_EGO(sim, "Lincoln2017MKZ (Apollo 5.0)") + agent = self.create_EGO(sim, SimulatorSettings.ego_lincoln2017mkz_apollo5) expectedSensors = ['Lidar', 'GPS', 'Telephoto Camera', \ 'Main Camera', 'IMU', 'CAN Bus', 'Radar'] sensors = agent.get_sensors() @@ -33,7 +34,7 @@ def test_apollo_5_sensors(self): # Check that Apollo 3.5 sensors are created an @unittest.skip("No SF vehicle") def test_santafe_sensors(self): # Check that Apollo Santa Fe sensors are created and are positioned reasonably with SimConnection() as sim: - agent = self.create_EGO(sim, "Lincoln2017MKZ (Apollo 5.0)") + agent = self.create_EGO(sim, SimulatorSettings.ego_lincoln2017mkz_apollo5) expectedSensors = ['velodyne', 'GPS', 'Telephoto Camera', 'Main Camera', \ 'IMU', 'RADAR', 'CANBUS', 'Segmentation Camera', 'Left Camera', 'Right Camera'] sensors = agent.get_sensors() @@ -51,7 +52,7 @@ def test_santafe_sensors(self): # Check that Apollo Santa Fe sensors are create @unittest.skip("No LGSVL Vehicle") def test_lgsvl_sensors(self): # Check that LGSVL sensors are created and are positioned reasonably with SimConnection() as sim: - agent = self.create_EGO(sim, "Lincoln2017MKZ (Apollo 5.0)") + agent = self.create_EGO(sim, SimulatorSettings.ego_lincoln2017mkz_apollo5) expectedSensors = ['velodyne', 'GPS', 'Telephoto Camera', 'Main Camera', \ 'IMU', 'RADAR', 'CANBUS', 'Segmentation Camera', 'Left Camera', 'Right Camera'] sensors = agent.get_sensors() @@ -86,7 +87,7 @@ def test_ep_sensors(self): # Check that Apollo EP sensors are created and are p def test_apollo_sensors(self): # Check that all the Apollo sensors are there with SimConnection() as sim: - agent = self.create_EGO(sim, "Jaguar2015XE (Apollo 3.0)") + agent = self.create_EGO(sim, SimulatorSettings.ego_jaguar2015xe_apollo5) expectedSensors = ["Lidar", "GPS", "Telephoto Camera", "Main Camera", "IMU", \ "CAN Bus", "Radar"] @@ -104,7 +105,7 @@ def test_apollo_sensors(self): # Check that all the Apollo sensors are there def test_autoware_sensors(self): # Check that all Autoware sensors are there with SimConnection() as sim: - agent = self.create_EGO(sim, "Jaguar2015XE (Autoware)") + agent = self.create_EGO(sim, SimulatorSettings.ego_jaguae2015xe_autowareai) expectedSensors = ["Lidar", "GPS", "Main Camera", "IMU"] sensors = agent.get_sensors() @@ -130,7 +131,7 @@ def test_save_sensor(self): # Check that sensor results can be saved if os.path.isfile(path): os.remove(path) - agent = self.create_EGO(sim, "Jaguar2015XE (Apollo 3.0)") + agent = self.create_EGO(sim, SimulatorSettings.ego_jaguar2015xe_apollo5) sensors = agent.get_sensors() savedSuccess = False @@ -157,7 +158,7 @@ def test_save_lidar(self): # Check that LIDAR sensor results can be saved if os.path.isfile(path): os.remove(path) - agent = self.create_EGO(sim, "Jaguar2015XE (Apollo 3.0)") + agent = self.create_EGO(sim, SimulatorSettings.ego_jaguar2015xe_apollo5) sensors = agent.get_sensors() savedSuccess = False @@ -179,7 +180,7 @@ def test_GPS(self): # Check that the GPS sensor works state.transform = sim.get_spawn()[0] right = lgsvl.utils.transform_to_right(state.transform) state.velocity = -50 * right - agent = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + agent = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) sensors = agent.get_sensors() initialGPSData = None gps = None @@ -205,7 +206,7 @@ def test_GPS(self): # Check that the GPS sensor works def test_sensor_disabling(self): # Check if sensors can be enabled with SimConnection() as sim: - agent = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) + agent = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) for s in agent.get_sensors(): if s.name == "Lidar": s.enabled = False @@ -219,7 +220,7 @@ def test_sensor_disabling(self): # Check if sensors can be enabled def test_sensor_equality(self): # Check that sensor == operator works with SimConnection() as sim: - agent = sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) + agent = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) prevSensor = None for s in agent.get_sensors(): self.assertTrue(s == s) @@ -232,7 +233,7 @@ def create_EGO(self, sim, name): # Creates the speicified EGO and removes any o def valid_sensor(self, sensor, msg): # Checks that the sensor is close to the EGO and not overly rotated self.assertBetween(sensor.transform.rotation, 0, 360, msg) - self.assertBetween(sensor.transform.position, -5, 5, msg) + self.assertBetween(sensor.transform.position, -10, 10, msg) def assertBetween(self, vector, min, max, msg): # Tests that the given vectors components are within the min and max self.assertGreaterEqual(vector.x, min, msg) diff --git a/tests/test_simulator.py b/tests/test_simulator.py index ecbfec6..38f08ab 100644 --- a/tests/test_simulator.py +++ b/tests/test_simulator.py @@ -9,6 +9,7 @@ import lgsvl from .common import SimConnection, spawnState +from settings import SimulatorSettings PROBLEM = "Object reference not set to an instance of an object" @@ -32,7 +33,7 @@ def test_spawns(self): # Check if there is at least 1 spawn point for Ego Vehic def test_run_time(self): # Check if the simulator runs 2 seconds with SimConnection() as sim: - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, spawnState(sim)) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) time = 2.0 initial_time = sim.current_time @@ -63,7 +64,7 @@ def test_raycast(self): # Check if raycasting works forward = lgsvl.utils.transform_to_forward(state.transform) right = lgsvl.utils.transform_to_right(state.transform) up = lgsvl.utils.transform_to_up(state.transform) - sim.add_agent("Jaguar2015XE (Apollo 3.0)", lgsvl.AgentType.EGO, state) + sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) p = spawns[0].position p.y += 1 From 24da05632d4209563dbb9df59e7d655ed691a930 Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Tue, 2 Mar 2021 22:50:59 -0800 Subject: [PATCH 063/115] AUTO-6281: Update for change of product name to "SVL Simulator" --- README.md | 6 +++--- setup.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1e0b6cf..bb08428 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Python API for LGSVL Simulator +# Python API for SVL Simulator -This folder contains Python API for LGSVL Simulator. +This folder contains the Python API for the SVL Simulator. # Usage @@ -12,7 +12,7 @@ To change it, adjust first argument of `Simulator` constructor, or set up # Documentation -Documentation is available on our website: https://www.lgsvlsimulator.com/docs/python-api/ +Documentation is available on our website: https://www.svlsimulator.com/docs/python-api/ # Requirements diff --git a/setup.py b/setup.py index 5a1d181..4c46208 100755 --- a/setup.py +++ b/setup.py @@ -4,9 +4,9 @@ setup( name="lgsvl", - description="LGSVL Simulator Api", + description="Python API for SVL Simulator", author="LGSVL", - author_email="contact@lgsvlsimulator.com", + author_email="contact@svlsimulator.com", python_requires=">=3.6.0", url="https://github.com/lgsvl/PythonAPI", packages=["lgsvl", "lgsvl.dreamview", "lgsvl.evaluator"], From b036c9d93cf32de9da08bac9db4cbab1f79dd144 Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Mon, 8 Mar 2021 13:12:41 -0800 Subject: [PATCH 064/115] README.md: Update copyright year This should have been done in commit 24da05632d4209563dbb9df59e7d655ed691a930. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bb08428..289447d 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,6 @@ Documentation is available on our website: https://www.svlsimulator.com/docs/pyt # Copyright and License -Copyright (c) 2018-2020 LG Electronics, Inc. +Copyright (c) 2018-2021 LG Electronics, Inc. This software contains code licensed as described in LICENSE. From 56990517d089b7a972398fba39e583ec1299fc4a Mon Sep 17 00:00:00 2001 From: Lokesh Kumar Goel Date: Mon, 8 Mar 2021 09:28:17 -0800 Subject: [PATCH 065/115] Update website link Change-Id: Ifcc4f1b65bd61c03ad5a03de1e6b33a4ba5a5a18 --- quickstart/33-ego-drive-stepped.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/quickstart/33-ego-drive-stepped.py b/quickstart/33-ego-drive-stepped.py index c152d2f..8df387a 100755 --- a/quickstart/33-ego-drive-stepped.py +++ b/quickstart/33-ego-drive-stepped.py @@ -29,11 +29,10 @@ # In order for Apollo to drive with stepped simulation we must add the clock sensor # and we must also set clock_mode to MODE_MOCK in Apollo's cyber/conf/cyber.pb.conf # Note that MODE_MOCK is only supported in Apollo master (6.0 or later)! -# Refer to https://www.lgsvlsimulator.com/docs/sensor-json-options/#clock +# Refer to https://www.svlsimulator.com/docs/sensor-json-options/#clock # We can test Apollo with standard MKZ or MKZ with ground truth sensors -# Refer to https://www.lgsvlsimulator.com/docs/modular-testing/ -# ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state) +# Refer to https://www.svlsimulator.com/docs/modular-testing/ ego = sim.add_agent(SimulatorSettings.ego_lincoln2017mkz_apollo5, lgsvl.AgentType.EGO, state) # An EGO will not connect to a bridge unless commanded to From 6eb1300f0a2d54da17b4c1a514e2f472b15c6f15 Mon Sep 17 00:00:00 2001 From: Lokesh Kumar Goel Date: Mon, 8 Mar 2021 20:35:22 -0800 Subject: [PATCH 066/115] Drop old NHTSA-sample-tests Change-Id: Id9c1ce4221065f305d75437d2b441b22bbcc30a3 --- .../EOV_S_25_20.py | 78 ----------------- .../EOV_S_45_40.py | 78 ----------------- .../EOV_S_65_60.py | 78 ----------------- .../evaluator/__init__.py | 7 -- .../evaluator/utils.py | 18 ---- .../Vehicle-Following/VF_S_25_Slow.py | 85 ------------------- .../Vehicle-Following/VF_S_45_Slow.py | 84 ------------------ .../Vehicle-Following/VF_S_65_Slow.py | 84 ------------------ .../Vehicle-Following/VF_test_runner.sh | 10 --- .../Vehicle-Following/evaluator/__init__.py | 7 -- .../Vehicle-Following/evaluator/utils.py | 18 ---- 11 files changed, 547 deletions(-) delete mode 100755 examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py delete mode 100755 examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py delete mode 100755 examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py delete mode 100644 examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/evaluator/__init__.py delete mode 100644 examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/evaluator/utils.py delete mode 100755 examples/NHTSA-sample-tests/Vehicle-Following/VF_S_25_Slow.py delete mode 100755 examples/NHTSA-sample-tests/Vehicle-Following/VF_S_45_Slow.py delete mode 100755 examples/NHTSA-sample-tests/Vehicle-Following/VF_S_65_Slow.py delete mode 100755 examples/NHTSA-sample-tests/Vehicle-Following/VF_test_runner.sh delete mode 100644 examples/NHTSA-sample-tests/Vehicle-Following/evaluator/__init__.py delete mode 100644 examples/NHTSA-sample-tests/Vehicle-Following/evaluator/utils.py diff --git a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py deleted file mode 100755 index 357dfb2..0000000 --- a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (c) 2019-2020 LG Electronics, Inc. -# -# This software contains code licensed as described in LICENSE. -# - -# See EOV_C_25_20.py for a commented script - -import os -import lgsvl -import time -import evaluator - -MAX_EGO_SPEED = 11.111 # (40 km/h, 25 mph) -MAX_POV_SPEED = 8.889 # (32 km/h, 20 mph) -INITIAL_HEADWAY = 100 # spec says >30m -SPEED_VARIANCE = 4 -TIME_LIMIT = 30 -TIME_DELAY = 3 - -print("EOV_S_25_20 - ", end='') - -sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1"), 8181) -if sim.current_scene == "SingleLaneRoad": - sim.reset() -else: - sim.load("SingleLaneRoad") - -# spawn EGO in the 2nd to right lane -egoState = lgsvl.AgentState() -# A point close to the desired lane was found in Editor. This method returns the position and orientation of the closest lane to the point. -egoState.transform = sim.get_spawn()[0] -ego = sim.add_agent("Jaguar2015XE (Apollo 5.0)", lgsvl.AgentType.EGO, egoState) - -ego.connect_bridge(os.environ.get("BRIDGE_HOST", "127.0.0.1"), 9090) - -finalPOVWaypointPosition = lgsvl.Vector(0, 0, -125) - -POVState = lgsvl.AgentState() -POVState.transform.position = lgsvl.Vector(finalPOVWaypointPosition.x, finalPOVWaypointPosition.y, finalPOVWaypointPosition.z + 4.5 + INITIAL_HEADWAY) -POVState.transform.rotation = lgsvl.Vector(0, 180, 0) -POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) - -POVWaypoints = [] -POVWaypoints.append(lgsvl.DriveWaypoint(finalPOVWaypointPosition, MAX_POV_SPEED)) - - -def on_collision(agent1, agent2, contact): - raise evaluator.TestException("Ego collided with {}".format(agent2)) - - -ego.on_collision(on_collision) -POV.on_collision(on_collision) - -try: - t0 = time.time() - sim.run(TIME_DELAY) - POV.follow(POVWaypoints) - - while True: - egoCurrentState = ego.state - if egoCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: - raise evaluator.TestException("Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_EGO_SPEED + SPEED_VARIANCE)) - - POVCurrentState = POV.state - if POVCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: - raise evaluator.TestException("POV1 speed exceeded limit, {} > {} m/s".format(POVCurrentState.speed, MAX_POV_SPEED + SPEED_VARIANCE)) - - sim.run(0.5) - - if time.time() - t0 > TIME_LIMIT: - break -except evaluator.TestException as e: - print("FAILED: " + repr(e)) - exit() - -print("PASSED") diff --git a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py deleted file mode 100755 index 77ee5bb..0000000 --- a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (c) 2019-2020 LG Electronics, Inc. -# -# This software contains code licensed as described in LICENSE. -# - -# See EOV_C_25_20.py for a commented script - -import os -import lgsvl -import time -import evaluator - -MAX_EGO_SPEED = 20 # (72 km/h, 45 mph) -MAX_POV_SPEED = 17.778 # (64 km/h, 40 mph) -INITIAL_HEADWAY = 150 # spec says >68m -SPEED_VARIANCE = 4 -TIME_LIMIT = 30 -TIME_DELAY = 4 - -print("EOV_S_45_40 - ", end='') - -sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1"), 8181) -if sim.current_scene == "SingleLaneRoad": - sim.reset() -else: - sim.load("SingleLaneRoad") - -# spawn EGO in the 2nd to right lane -egoState = lgsvl.AgentState() -# A point close to the desired lane was found in Editor. This method returns the position and orientation of the closest lane to the point. -egoState.transform = sim.get_spawn()[0] -ego = sim.add_agent("Jaguar2015XE (Apollo 5.0)", lgsvl.AgentType.EGO, egoState) - -ego.connect_bridge(os.environ.get("BRIDGE_HOST", "127.0.0.1"), 9090) - -finalPOVWaypointPosition = lgsvl.Vector(0, 0, -125) - -POVState = lgsvl.AgentState() -POVState.transform.position = lgsvl.Vector(finalPOVWaypointPosition.x, finalPOVWaypointPosition.y, finalPOVWaypointPosition.z + 4.5 + INITIAL_HEADWAY) -POVState.transform.rotation = lgsvl.Vector(0, 180, 0) -POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) - -POVWaypoints = [] -POVWaypoints.append(lgsvl.DriveWaypoint(finalPOVWaypointPosition, MAX_POV_SPEED)) - - -def on_collision(agent1, agent2, contact): - raise evaluator.TestException("Ego collided with {}".format(agent2)) - - -ego.on_collision(on_collision) -POV.on_collision(on_collision) - -try: - t0 = time.time() - sim.run(TIME_DELAY) - POV.follow(POVWaypoints) - - while True: - egoCurrentState = ego.state - if egoCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: - raise evaluator.TestException("Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_EGO_SPEED + SPEED_VARIANCE)) - - POVCurrentState = POV.state - if POVCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: - raise evaluator.TestException("POV1 speed exceeded limit, {} > {} m/s".format(POVCurrentState.speed, MAX_POV_SPEED + SPEED_VARIANCE)) - - sim.run(0.5) - - if time.time() - t0 > TIME_LIMIT: - break -except evaluator.TestException as e: - print("FAILED: " + repr(e)) - exit() - -print("PASSED") diff --git a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py deleted file mode 100755 index a508585..0000000 --- a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (c) 2019-2020 LG Electronics, Inc. -# -# This software contains code licensed as described in LICENSE. -# - -# See EOV_C_25_20.py for a commented script - -import os -import lgsvl -import time -import evaluator - -MAX_EGO_SPEED = 29.167 # (105 km/h, 65 mph) -MAX_POV_SPEED = 26.667 # (96 km/h, 60 mph) -INITIAL_HEADWAY = 200 # spec says >105m -SPEED_VARIANCE = 4 -TIME_LIMIT = 30 -TIME_DELAY = 5 - -print("EOV_S_65_60 - ", end='') - -sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1"), 8181) -if sim.current_scene == "SingleLaneRoad": - sim.reset() -else: - sim.load("SingleLaneRoad") - -# spawn EGO in the 2nd to right lane -egoState = lgsvl.AgentState() -# A point close to the desired lane was found in Editor. This method returns the position and orientation of the closest lane to the point. -egoState.transform = sim.get_spawn()[0] -ego = sim.add_agent("Jaguar2015XE (Apollo 5.0)", lgsvl.AgentType.EGO, egoState) - -ego.connect_bridge(os.environ.get("BRIDGE_HOST", "127.0.0.1"), 9090) - -finalPOVWaypointPosition = lgsvl.Vector(0, 0, -125) - -POVState = lgsvl.AgentState() -POVState.transform.position = lgsvl.Vector(finalPOVWaypointPosition.x, finalPOVWaypointPosition.y, finalPOVWaypointPosition.z + 4.5 + INITIAL_HEADWAY) -POVState.transform.rotation = lgsvl.Vector(0, 180, 0) -POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) - -POVWaypoints = [] -POVWaypoints.append(lgsvl.DriveWaypoint(finalPOVWaypointPosition, MAX_POV_SPEED)) - - -def on_collision(agent1, agent2, contact): - raise evaluator.TestException("Ego collided with {}".format(agent2)) - - -ego.on_collision(on_collision) -POV.on_collision(on_collision) - -try: - t0 = time.time() - sim.run(TIME_DELAY) - POV.follow(POVWaypoints) - - while True: - egoCurrentState = ego.state - if egoCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: - raise evaluator.TestException("Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_EGO_SPEED + SPEED_VARIANCE)) - - POVCurrentState = POV.state - if POVCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: - raise evaluator.TestException("POV1 speed exceeded limit, {} > {} m/s".format(POVCurrentState.speed, MAX_POV_SPEED + SPEED_VARIANCE)) - - sim.run(0.5) - - if time.time() - t0 > TIME_LIMIT: - break -except evaluator.TestException as e: - print("FAILED: " + repr(e)) - exit() - -print("PASSED") diff --git a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/evaluator/__init__.py b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/evaluator/__init__.py deleted file mode 100644 index ba0e7b1..0000000 --- a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/evaluator/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -# -# Copyright (c) 2019 LG Electronics, Inc. -# -# This software contains code licensed as described in LICENSE. -# - -from .utils import TestException, separation \ No newline at end of file diff --git a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/evaluator/utils.py b/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/evaluator/utils.py deleted file mode 100644 index e60df8d..0000000 --- a/examples/NHTSA-sample-tests/Encroaching-Oncoming-Vehicles/evaluator/utils.py +++ /dev/null @@ -1,18 +0,0 @@ -# -# Copyright (c) 2019-2020 LG Electronics, Inc. -# -# This software contains code licensed as described in LICENSE. -# - -import math - - -class TestException(Exception): - pass - - -def separation(V1, V2): - xdiff = V1.x - V2.x - ydiff = V1.y - V2.y - zdiff = V1.z - V2.z - return math.sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff) diff --git a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_25_Slow.py b/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_25_Slow.py deleted file mode 100755 index ad07090..0000000 --- a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_25_Slow.py +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (c) 2019-2020 LG Electronics, Inc. -# -# This software contains code licensed as described in LICENSE. -# - -# See VF_C_25_Slow for a commented script - -import os -import lgsvl -import time -import evaluator - -MAX_EGO_SPEED = 11.18 # (40 km/h, 25 mph) -SPEED_VARIANCE = 10 # Simple Physics does not return an accurate value -MAX_POV_SPEED = 8.94 # (32 km/h, 20 mph) -MAX_POV_ROTATION = 5 # deg/s -TIME_LIMIT = 30 # seconds -TIME_DELAY = 3 -MAX_FOLLOWING_DISTANCE = 50 # Apollo 3.5 is very cautious - -print("VF_S_25_Slow - ", end='') - -sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1"), 8181) -if sim.current_scene == "SingleLaneRoad": - sim.reset() -else: - sim.load("SingleLaneRoad") - -sim.set_time_of_day(12) -# spawn EGO in the 2nd to right lane -egoState = lgsvl.AgentState() -egoState.transform = sim.get_spawn()[0] -ego = sim.add_agent("Jaguar2015XE (Apollo 5.0)", lgsvl.AgentType.EGO, egoState) -egoX = ego.state.position.x -egoY = ego.state.position.y -egoZ = ego.state.position.z - -ego.connect_bridge(os.environ.get("BRIDGE_HOST", "127.0.0.1"), 9090) - -POVState = lgsvl.AgentState() -POVState.transform = sim.map_point_on_lane(lgsvl.Vector(egoX, egoY, egoZ + 30)) -POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) - - -def on_collision(agent1, agent2, contact): - raise evaluator.TestException("Ego collided with {}".format(agent2)) - - -ego.on_collision(on_collision) -POV.on_collision(on_collision) - -try: - t0 = time.time() - sim.run(TIME_DELAY) # The EGO should start moving first - POV.follow_closest_lane(True, MAX_POV_SPEED, False) - - while True: - sim.run(0.5) - - egoCurrentState = ego.state - if egoCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: - raise evaluator.TestException("Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_EGO_SPEED + SPEED_VARIANCE)) - - POVCurrentState = POV.state - if POVCurrentState.speed > MAX_POV_SPEED + SPEED_VARIANCE: - raise evaluator.TestException("POV speed exceeded limit, {} > {} m/s".format(POVCurrentState.speed, MAX_POV_SPEED + SPEED_VARIANCE)) - if POVCurrentState.angular_velocity.y > MAX_POV_ROTATION: - raise evaluator.TestException("POV angular rotation exceeded limit, {} > {} deg/s".format(POVCurrentState.angular_velocity, MAX_POV_ROTATION)) - - if evaluator.separation(POVCurrentState.position, lgsvl.Vector(1.8, 0, 125)) < 5: - break - - if time.time() - t0 > TIME_LIMIT: - break -except evaluator.TestException as e: - print("FAILED: " + repr(e)) - exit() - -separation = evaluator.separation(egoCurrentState.position, POVCurrentState.position) -if separation > MAX_FOLLOWING_DISTANCE: - print("FAILED: EGO following distance was not maintained, {} > {}".format(separation, MAX_FOLLOWING_DISTANCE)) -else: - print("PASSED") diff --git a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_45_Slow.py b/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_45_Slow.py deleted file mode 100755 index 08f7bfa..0000000 --- a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_45_Slow.py +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (c) 2019-2020 LG Electronics, Inc. -# -# This software contains code licensed as described in LICENSE. -# - -# See VF_C_25_Slow for a commented script - -import os -import lgsvl -import time -import evaluator - -MAX_EGO_SPEED = 20.12 # (72 km/h, 45 mph) -SPEED_VARIANCE = 10 # Simple Physics does not return an accurate value -MAX_POV_SPEED = 17.88 # (64 km/h, 40 mph) -MAX_POV_ROTATION = 5 # deg/s -TIME_LIMIT = 25 # seconds -TIME_DELAY = 7 -MAX_FOLLOWING_DISTANCE = 100 # Apollo 3.5 is very cautious - -print("VF_S_45_Slow - ", end='') - -sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1"), 8181) -if sim.current_scene == "SingleLaneRoad": - sim.reset() -else: - sim.load("SingleLaneRoad") - -# spawn EGO in the 2nd to right lane -egoState = lgsvl.AgentState() -egoState.transform = sim.get_spawn()[0] -ego = sim.add_agent("Jaguar2015XE (Apollo 5.0)", lgsvl.AgentType.EGO, egoState) -egoX = ego.state.position.x -egoY = ego.state.position.y -egoZ = ego.state.position.z - -ego.connect_bridge(os.environ.get("BRIDGE_HOST", "127.0.0.1"), 9090) - -POVState = lgsvl.AgentState() -POVState.transform = sim.map_point_on_lane(lgsvl.Vector(egoX, egoY, egoZ + 68)) -POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) - - -def on_collision(agent1, agent2, contact): - raise evaluator.TestException("Ego collided with {}".format(agent2)) - - -ego.on_collision(on_collision) -POV.on_collision(on_collision) - -try: - t0 = time.time() - sim.run(TIME_DELAY) # The EGO should start moving first - POV.follow_closest_lane(True, MAX_POV_SPEED, False) - - while True: - sim.run(0.5) - - egoCurrentState = ego.state - if egoCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: - raise evaluator.TestException("Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_EGO_SPEED + SPEED_VARIANCE)) - - POVCurrentState = POV.state - if POVCurrentState.speed > MAX_POV_SPEED + SPEED_VARIANCE: - raise evaluator.TestException("POV speed exceeded limit, {} > {} m/s".format(POVCurrentState.speed, MAX_POV_SPEED + SPEED_VARIANCE)) - if POVCurrentState.angular_velocity.y > MAX_POV_ROTATION: - raise evaluator.TestException("POV angular rotation exceeded limit, {} > {} deg/s".format(POVCurrentState.angular_velocity, MAX_POV_ROTATION)) - - if evaluator.separation(POVCurrentState.position, lgsvl.Vector(1.8, 0, 125)) < 5: - break - - if time.time() - t0 > TIME_LIMIT: - break -except evaluator.TestException as e: - print("FAILED: " + repr(e)) - exit() - -separation = evaluator.separation(egoCurrentState.position, POVCurrentState.position) -if separation > MAX_FOLLOWING_DISTANCE: - print("FAILED: EGO following distance was not maintained, {} > {}".format(separation, MAX_FOLLOWING_DISTANCE)) -else: - print("PASSED") diff --git a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_65_Slow.py b/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_65_Slow.py deleted file mode 100755 index 5a54098..0000000 --- a/examples/NHTSA-sample-tests/Vehicle-Following/VF_S_65_Slow.py +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (c) 2019-2020 LG Electronics, Inc. -# -# This software contains code licensed as described in LICENSE. -# - -# See VF_C_25_Slow for a commented script - -import os -import lgsvl -import time -import evaluator - -MAX_EGO_SPEED = 29.06 # (105 km/h, 65 mph) -SPEED_VARIANCE = 10 # Simple Physics does not return an accurate value -MAX_POV_SPEED = 26.82 # (96 km/h, 60 mph) -MAX_POV_ROTATION = 5 # deg/s -TIME_LIMIT = 45 # seconds -TIME_DELAY = 5 -MAX_FOLLOWING_DISTANCE = 100 # Apollo 3.5 is very cautious - -print("VF_S_65_Slow - ", end='') - -sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1"), 8181) -if sim.current_scene == "SingleLaneRoad": - sim.reset() -else: - sim.load("SingleLaneRoad") - -# spawn EGO in the 2nd to right lane -egoState = lgsvl.AgentState() -egoState.transform = sim.get_spawn()[0] -ego = sim.add_agent("Jaguar2015XE (Apollo 5.0)", lgsvl.AgentType.EGO, egoState) -egoX = ego.state.position.x -egoY = ego.state.position.y -egoZ = ego.state.position.z - -ego.connect_bridge(os.environ.get("BRIDGE_HOST", "127.0.0.1"), 9090) - -POVState = lgsvl.AgentState() -POVState.transform = sim.map_point_on_lane(lgsvl.Vector(egoX - 104.74, egoY, egoZ - 7.34)) -POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) - - -def on_collision(agent1, agent2, contact): - raise evaluator.TestException("Ego collided with {}".format(agent2)) - - -ego.on_collision(on_collision) -POV.on_collision(on_collision) - -try: - t0 = time.time() - sim.run(TIME_DELAY) # The EGO should start moving first - POV.follow_closest_lane(True, MAX_POV_SPEED, False) - - while True: - sim.run(0.5) - - egoCurrentState = ego.state - if egoCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: - raise evaluator.TestException("Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_EGO_SPEED + SPEED_VARIANCE)) - - POVCurrentState = POV.state - if POVCurrentState.speed > MAX_POV_SPEED + SPEED_VARIANCE: - raise evaluator.TestException("POV speed exceeded limit, {} > {} m/s".format(POVCurrentState.speed, MAX_POV_SPEED + SPEED_VARIANCE)) - if POVCurrentState.angular_velocity.y > MAX_POV_ROTATION: - raise evaluator.TestException("POV angular rotation exceeded limit, {} > {} deg/s".format(POVCurrentState.angular_velocity, MAX_POV_ROTATION)) - - if evaluator.separation(POVCurrentState.position, lgsvl.Vector(1.8, 0, 125)) < 5: - break - - if time.time() - t0 > TIME_LIMIT: - break -except evaluator.TestException as e: - print("FAILED: " + repr(e)) - exit() - -separation = evaluator.separation(egoCurrentState.position, POVCurrentState.position) -if separation > MAX_FOLLOWING_DISTANCE: - print("FAILED: EGO following distance was not maintained, {} > {}".format(separation, MAX_FOLLOWING_DISTANCE)) -else: - print("PASSED") diff --git a/examples/NHTSA-sample-tests/Vehicle-Following/VF_test_runner.sh b/examples/NHTSA-sample-tests/Vehicle-Following/VF_test_runner.sh deleted file mode 100755 index 18da927..0000000 --- a/examples/NHTSA-sample-tests/Vehicle-Following/VF_test_runner.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -set -eu - -python3 VF_S_25_Slow.py -python3 VF_S_45_Slow.py -python3 VF_S_65_Slow.py -python3 VF_C_25_Slow.py -python3 VF_C_45_Slow.py -python3 VF_C_65_Slow.py diff --git a/examples/NHTSA-sample-tests/Vehicle-Following/evaluator/__init__.py b/examples/NHTSA-sample-tests/Vehicle-Following/evaluator/__init__.py deleted file mode 100644 index ba0e7b1..0000000 --- a/examples/NHTSA-sample-tests/Vehicle-Following/evaluator/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -# -# Copyright (c) 2019 LG Electronics, Inc. -# -# This software contains code licensed as described in LICENSE. -# - -from .utils import TestException, separation \ No newline at end of file diff --git a/examples/NHTSA-sample-tests/Vehicle-Following/evaluator/utils.py b/examples/NHTSA-sample-tests/Vehicle-Following/evaluator/utils.py deleted file mode 100644 index e60df8d..0000000 --- a/examples/NHTSA-sample-tests/Vehicle-Following/evaluator/utils.py +++ /dev/null @@ -1,18 +0,0 @@ -# -# Copyright (c) 2019-2020 LG Electronics, Inc. -# -# This software contains code licensed as described in LICENSE. -# - -import math - - -class TestException(Exception): - pass - - -def separation(V1, V2): - xdiff = V1.x - V2.x - ydiff = V1.y - V2.y - zdiff = V1.z - V2.z - return math.sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff) From 5b256223764e35e695d782cc3ec066d0bdcf0c52 Mon Sep 17 00:00:00 2001 From: Lokesh Kumar Goel Date: Mon, 8 Mar 2021 20:49:29 -0800 Subject: [PATCH 067/115] Add new version of Sample Tests Change-Id: Ib3273f94da28b08dff0c3a77e525a57c5b65ffc0 --- .../EOV_S_25_20.py | 130 +++++++++++++ .../EOV_S_45_40.py | 130 +++++++++++++ .../EOV_S_65_60.py | 129 +++++++++++++ .../EOV_test_runner.sh | 7 + .../Move-Out-of-Travel-Lane/MOTL_Comp_15.py | 155 +++++++++++++++ .../Move-Out-of-Travel-Lane/MOTL_Comp_25.py | 155 +++++++++++++++ .../Move-Out-of-Travel-Lane/MOTL_Neg_15.py | 155 +++++++++++++++ .../Move-Out-of-Travel-Lane/MOTL_Neg_25.py | 155 +++++++++++++++ .../Move-Out-of-Travel-Lane/MOTL_Simp_15.py | 150 +++++++++++++++ .../Move-Out-of-Travel-Lane/MOTL_Simp_25.py | 138 ++++++++++++++ .../NHTSA/Perform-Lane-Change/PLC_B_15.py | 114 +++++++++++ .../NHTSA/Perform-Lane-Change/PLC_B_25.py | 114 +++++++++++ .../NHTSA/Perform-Lane-Change/PLC_B_35.py | 114 +++++++++++ .../NHTSA/Perform-Lane-Change/PLC_CP_15.py | 147 +++++++++++++++ .../NHTSA/Perform-Lane-Change/PLC_CP_25.py | 149 +++++++++++++++ .../NHTSA/Perform-Lane-Change/PLC_CP_35.py | 150 +++++++++++++++ .../NHTSA/Perform-Lane-Change/PLC_SN_15.py | 177 ++++++++++++++++++ .../NHTSA/Perform-Lane-Change/PLC_SN_25.py | 156 +++++++++++++++ .../NHTSA/Perform-Lane-Change/PLC_SN_35.py | 158 ++++++++++++++++ .../NHTSA/Perform-Lane-Change/PLC_SP_15.py | 130 +++++++++++++ .../NHTSA/Perform-Lane-Change/PLC_SP_25.py | 130 +++++++++++++ .../NHTSA/Perform-Lane-Change/PLC_SP_35.py | 130 +++++++++++++ .../Perform-Lane-Change/PLC_test_runner.sh | 16 ++ .../NHTSA/Vehicle-Following/VF_S_25_Slow.py | 141 ++++++++++++++ .../NHTSA/Vehicle-Following/VF_S_45_Slow.py | 140 ++++++++++++++ .../NHTSA/Vehicle-Following/VF_S_65_Slow.py | 140 ++++++++++++++ .../NHTSA/Vehicle-Following/VF_test_runner.sh | 10 + examples/SampleTestCases/cut-in.py | 114 +++++++++++ examples/SampleTestCases/ped-crossing.py | 88 +++++++++ .../SampleTestCases/random-traffic-local.py | 106 +++++++++++ examples/SampleTestCases/random-traffic.py | 123 ++++++++++++ examples/SampleTestCases/red-light-runner.py | 96 ++++++++++ examples/SampleTestCases/sudden-braking.py | 100 ++++++++++ 33 files changed, 4047 insertions(+) create mode 100755 examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py create mode 100755 examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py create mode 100755 examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py create mode 100755 examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_test_runner.sh create mode 100755 examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py create mode 100755 examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py create mode 100755 examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py create mode 100755 examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py create mode 100755 examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py create mode 100755 examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py create mode 100755 examples/NHTSA/Perform-Lane-Change/PLC_B_15.py create mode 100755 examples/NHTSA/Perform-Lane-Change/PLC_B_25.py create mode 100755 examples/NHTSA/Perform-Lane-Change/PLC_B_35.py create mode 100755 examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py create mode 100755 examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py create mode 100755 examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py create mode 100755 examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py create mode 100755 examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py create mode 100755 examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py create mode 100755 examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py create mode 100755 examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py create mode 100755 examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py create mode 100755 examples/NHTSA/Perform-Lane-Change/PLC_test_runner.sh create mode 100755 examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py create mode 100755 examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py create mode 100755 examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py create mode 100755 examples/NHTSA/Vehicle-Following/VF_test_runner.sh create mode 100755 examples/SampleTestCases/cut-in.py create mode 100755 examples/SampleTestCases/ped-crossing.py create mode 100755 examples/SampleTestCases/random-traffic-local.py create mode 100755 examples/SampleTestCases/random-traffic.py create mode 100755 examples/SampleTestCases/red-light-runner.py create mode 100755 examples/SampleTestCases/sudden-braking.py diff --git a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py new file mode 100755 index 0000000..b5adc2a --- /dev/null +++ b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See EOV_C_25_20.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_EGO_SPEED = 11.111 # (40 km/h, 25 mph) +MAX_POV_SPEED = 8.889 # (32 km/h, 20 mph) +INITIAL_HEADWAY = 130 # spec says >30m +SPEED_VARIANCE = 4 +TIME_LIMIT = 30 +TIME_DELAY = 3 + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("EOV_S_25_20 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneOpposing": + sim.reset() +else: + sim.load("Straight2LaneOpposing") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(-1.6, 0, -65)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneOpposing')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) + +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +destination = egoState.position + 135 * forward +dv.setup_apollo(destination.x, destination.z, modules) + +finalPOVWaypointPosition = egoState.position - 2.15 * right + +POVState = lgsvl.AgentState() +POVState.transform.position = egoState.position + (4.5 + INITIAL_HEADWAY) * forward - 2.15 * right +POVState.transform.rotation = lgsvl.Vector(0, -180, 0) +POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) + +POVWaypoints = [] +POVWaypoints.append(lgsvl.DriveWaypoint(POVState.transform.position, MAX_POV_SPEED, POVState.transform.rotation)) +POVWaypoints.append(lgsvl.DriveWaypoint(finalPOVWaypointPosition, 0, POVState.transform.rotation)) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("Ego collided with {}".format(agent2)) + + +ego.on_collision(on_collision) +POV.on_collision(on_collision) + +try: + t0 = time.time() + sim.run(TIME_DELAY) + POV.follow(POVWaypoints) + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_EGO_SPEED + SPEED_VARIANCE) + ) + POVCurrentState = POV.state + if POVCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 speed exceeded limit, {} > {} m/s".format(POVCurrentState.speed, MAX_POV_SPEED + SPEED_VARIANCE) + ) + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +print("PASSED") diff --git a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py new file mode 100755 index 0000000..2e927bb --- /dev/null +++ b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See EOV_C_25_20.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_EGO_SPEED = 20 # (72 km/h, 45 mph) +MAX_POV_SPEED = 17.778 # (64 km/h, 40 mph) +INITIAL_HEADWAY = 130 # spec says >68m +SPEED_VARIANCE = 4 +TIME_LIMIT = 30 +TIME_DELAY = 4 + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("EOV_S_45_40 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneOpposing": + sim.reset() +else: + sim.load("Straight2LaneOpposing") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(-1.6, 0, -65)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneOpposing')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) + +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +destination = egoState.position + 135 * forward +dv.setup_apollo(destination.x, destination.z, modules) + +finalPOVWaypointPosition = egoState.position - 2.15 * right + +POVState = lgsvl.AgentState() +POVState.transform.position = egoState.position + (4.5 + INITIAL_HEADWAY) * forward - 2.15 * right +POVState.transform.rotation = lgsvl.Vector(0, -180, 0) +POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) + +POVWaypoints = [] +POVWaypoints.append(lgsvl.DriveWaypoint(POVState.transform.position, MAX_POV_SPEED, POVState.transform.rotation)) +POVWaypoints.append(lgsvl.DriveWaypoint(finalPOVWaypointPosition, 0, POVState.transform.rotation)) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("Ego collided with {}".format(agent2)) + + +ego.on_collision(on_collision) +POV.on_collision(on_collision) + +try: + t0 = time.time() + sim.run(TIME_DELAY) + POV.follow(POVWaypoints) + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_EGO_SPEED + SPEED_VARIANCE) + ) + POVCurrentState = POV.state + if POVCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 speed exceeded limit, {} > {} m/s".format(POVCurrentState.speed, MAX_POV_SPEED + SPEED_VARIANCE) + ) + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +print("PASSED") diff --git a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py new file mode 100755 index 0000000..60a71b2 --- /dev/null +++ b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py @@ -0,0 +1,129 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See EOV_C_25_20.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_EGO_SPEED = 29.167 # (105 km/h, 65 mph) +MAX_POV_SPEED = 26.667 # (96 km/h, 60 mph) +INITIAL_HEADWAY = 130 # spec says >105m +SPEED_VARIANCE = 4 +TIME_LIMIT = 30 +TIME_DELAY = 5 + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("EOV_S_65_60 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneOpposing": + sim.reset() +else: + sim.load("Straight2LaneOpposing") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(-1.6, 0, -65)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneOpposing')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +destination = egoState.position + 135 * forward +dv.setup_apollo(destination.x, destination.z, modules) + +finalPOVWaypointPosition = egoState.position - 2.15 * right + +POVState = lgsvl.AgentState() +POVState.transform.position = egoState.position + (4.5 + INITIAL_HEADWAY) * forward - 2.15 * right +POVState.transform.rotation = lgsvl.Vector(0, -180, 0) +POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) + +POVWaypoints = [] +POVWaypoints.append(lgsvl.DriveWaypoint(POVState.transform.position, MAX_POV_SPEED, POVState.transform.rotation)) +POVWaypoints.append(lgsvl.DriveWaypoint(finalPOVWaypointPosition, 0, POVState.transform.rotation)) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("Ego collided with {}".format(agent2)) + + +ego.on_collision(on_collision) +POV.on_collision(on_collision) + +try: + t0 = time.time() + sim.run(TIME_DELAY) + POV.follow(POVWaypoints) + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_EGO_SPEED + SPEED_VARIANCE) + ) + POVCurrentState = POV.state + if POVCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 speed exceeded limit, {} > {} m/s".format(POVCurrentState.speed, MAX_POV_SPEED + SPEED_VARIANCE) + ) + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +print("PASSED") diff --git a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_test_runner.sh b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_test_runner.sh new file mode 100755 index 0000000..fd96036 --- /dev/null +++ b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_test_runner.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -eu + +python3 EOV_S_25_20.py +python3 EOV_S_45_40.py +python3 EOV_S_65_60.py \ No newline at end of file diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py new file mode 100755 index 0000000..25ec862 --- /dev/null +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py @@ -0,0 +1,155 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See MOTL_Simp_15.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 6.667 # (24 km/h, 15 mph) +SPEED_VARIANCE = 4 +TIME_LIMIT = 30 # seconds +PARKING_ZONE_LENGTH = 24 # meters + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("MOTL_Comp_15 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSameCurbRightIntersection": + sim.reset() +else: + sim.load("Straight2LaneSameCurbRightIntersection") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSameCurbRightIntersection')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +# Destination in the middle of the parking zone +destination = egoState.position + (2.75 + 4.6 + 11 + PARKING_ZONE_LENGTH / 2) * forward + 3.6 * right +dv.setup_apollo(destination.x, destination.z, modules) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("{} collided with {}".format(agent1, agent2)) + + +ego.on_collision(on_collision) + +POVList = [] + +POV1State = lgsvl.AgentState() +POV1State.transform = sim.map_point_on_lane(egoState.position + (4.55 + 11) * forward + 3.6 * right) +POV1 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV1State) +POV1.on_collision(on_collision) +POVList.append(POV1) + +POV2State = lgsvl.AgentState() +POV2State.transform = sim.map_point_on_lane(POV1State.position + (PARKING_ZONE_LENGTH + 4.6) * forward) +POV2 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV2State) +POV2.on_collision(on_collision) +POVList.append(POV2) + +for i in range(2,5): + POVState = lgsvl.AgentState() + POVState.transform = sim.map_point_on_lane(POVList[i-1].state.position + 5.5 * forward) + POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) + POV.on_collision(on_collision) + POVList.append(POV) + +try: + t0 = time.time() + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + for i in range(len(POVList)): + POVCurrentState = POVList[i].state + if POVCurrentState.speed > 0 + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV{} speed exceeded limit, {} > {} m/s".format(i, POVCurrentState.speed, 0 + SPEED_VARIANCE) + ) + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +parkingZoneBeginning = sim.map_point_on_lane(egoState.position + (2.75 + 4.6 + 11) * forward + 3.6 * right) +parkingZoneEnd = sim.map_point_on_lane(parkingZoneBeginning.position + PARKING_ZONE_LENGTH * forward) + +finalEgoState = ego.state + +try: + if not lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + raise lgsvl.evaluator.TestException("Ego did not change lanes") + elif not lgsvl.evaluator.in_parking_zone( + parkingZoneBeginning.position, + parkingZoneEnd.position, + finalEgoState.transform + ): + raise lgsvl.evaluator.TestException("Ego did not stop in parking zone") + elif finalEgoState.speed > 0.2: + raise lgsvl.evaluator.TestException("Ego did not park") + else: + print("PASSED") +except ValueError as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py new file mode 100755 index 0000000..5b9323d --- /dev/null +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py @@ -0,0 +1,155 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See MOTL_Simp_15.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 11.111 # (40 km/h, 25 mph) +SPEED_VARIANCE = 4 +TIME_LIMIT = 30 # seconds +PARKING_ZONE_LENGTH = 24 # meters + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("MOTL_Comp_25 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSameCurbRightIntersection": + sim.reset() +else: + sim.load("Straight2LaneSameCurbRightIntersection") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSameCurbRightIntersection')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +# Destination in the middle of the parking zone +destination = egoState.position + (2.75 + 4.6 + 11 + PARKING_ZONE_LENGTH / 2) * forward + 3.6 * right +dv.setup_apollo(destination.x, destination.z, modules) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("{} collided with {}".format(agent1, agent2)) + + +ego.on_collision(on_collision) + +POVList = [] + +POV1State = lgsvl.AgentState() +POV1State.transform = sim.map_point_on_lane(egoState.position + (4.55 + 11) * forward + 3.6 * right) +POV1 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV1State) +POV1.on_collision(on_collision) +POVList.append(POV1) + +POV2State = lgsvl.AgentState() +POV2State.transform = sim.map_point_on_lane(POV1State.position + (PARKING_ZONE_LENGTH + 4.6) * forward) +POV2 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV2State) +POV2.on_collision(on_collision) +POVList.append(POV2) + +for i in range(2,5): + POVState = lgsvl.AgentState() + POVState.transform = sim.map_point_on_lane(POVList[i-1].state.position + 5.5 * forward) + POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) + POV.on_collision(on_collision) + POVList.append(POV) + +try: + t0 = time.time() + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + for i in range(len(POVList)): + POVCurrentState = POVList[i].state + if POVCurrentState.speed > 0 + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV{} speed exceeded limit, {} > {} m/s".format(i, POVCurrentState.speed, 0 + SPEED_VARIANCE) + ) + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +parkingZoneBeginning = sim.map_point_on_lane(egoState.position + (2.75 + 4.6 + 11) * forward + 3.6 * right) +parkingZoneEnd = sim.map_point_on_lane(parkingZoneBeginning.position + PARKING_ZONE_LENGTH * forward) + +finalEgoState = ego.state + +try: + if not lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + raise lgsvl.evaluator.TestException("Ego did not change lanes") + elif not lgsvl.evaluator.in_parking_zone( + parkingZoneBeginning.position, + parkingZoneEnd.position, + finalEgoState.transform + ): + raise lgsvl.evaluator.TestException("Ego did not stop in parking zone") + elif finalEgoState.speed > 0.2: + raise lgsvl.evaluator.TestException("Ego did not park") + else: + print("PASSED") +except ValueError as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py new file mode 100755 index 0000000..2644291 --- /dev/null +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py @@ -0,0 +1,155 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See MOTL_Simp_15.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 6.667 # (24 km/h, 15 mph) +SPEED_VARIANCE = 4 +TIME_LIMIT = 30 # seconds +PARKING_ZONE_LENGTH = 3 # meters + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("MOTL_Neg_15 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSameCurbRightIntersection": + sim.reset() +else: + sim.load("Straight2LaneSameCurbRightIntersection") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSameCurbRightIntersection')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +# Destination in the middle of the parking zone +destination = egoState.position + (2.75 + 4.6 + 6 + PARKING_ZONE_LENGTH / 2) * forward + 3.6 * right +dv.setup_apollo(destination.x, destination.z, modules) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("{} collided with {}".format(agent1, agent2)) + + +ego.on_collision(on_collision) + +POVList = [] + +POV1State = lgsvl.AgentState() +POV1State.transform = sim.map_point_on_lane(egoState.position + (4.55 + 6) * forward + 3.6 * right) +POV1 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV1State) +POV1.on_collision(on_collision) +POVList.append(POV1) + +POV2State = lgsvl.AgentState() +POV2State.transform = sim.map_point_on_lane(POV1State.position + (PARKING_ZONE_LENGTH + 4.6) * forward) +POV2 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV2State) +POV2.on_collision(on_collision) +POVList.append(POV2) + +for i in range(2,11): + POVState = lgsvl.AgentState() + POVState.transform = sim.map_point_on_lane(POVList[i-1].state.position + 5.5 * forward) + POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) + POV.on_collision(on_collision) + POVList.append(POV) + +try: + t0 = time.time() + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + for i in range(len(POVList)): + POVCurrentState = POVList[i].state + if POVCurrentState.speed > 0 + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV{} speed exceeded limit, {} > {} m/s".format(i, POVCurrentState.speed, 0 + SPEED_VARIANCE) + ) + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +parkingZoneBeginning = sim.map_point_on_lane(egoState.position + (2.75 + 4.6 + 6) * forward + 3.6 * right) +parkingZoneEnd = sim.map_point_on_lane(parkingZoneBeginning.position + PARKING_ZONE_LENGTH * forward) + +finalEgoState = ego.state + +try: + if not lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + raise lgsvl.evaluator.TestException("Ego did not change lanes") + elif not lgsvl.evaluator.in_parking_zone( + parkingZoneBeginning.position, + parkingZoneEnd.position, + finalEgoState.transform + ): + raise lgsvl.evaluator.TestException("Ego did not stop in parking zone") + elif finalEgoState.speed > 0.2: + raise lgsvl.evaluator.TestException("Ego did not park") + else: + print("PASSED") +except ValueError as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py new file mode 100755 index 0000000..30b2eb7 --- /dev/null +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py @@ -0,0 +1,155 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See MOTL_Simp_15.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 11.111 # (40 km/h, 25 mph) +SPEED_VARIANCE = 4 +TIME_LIMIT = 30 # seconds +PARKING_ZONE_LENGTH = 3 # meters + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("MOTL_Neg_25 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSameCurbRightIntersection": + sim.reset() +else: + sim.load("Straight2LaneSameCurbRightIntersection") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSameCurbRightIntersection')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +# Destination in the middle of the parking zone +destination = egoState.position + (2.75 + 4.6 + 6 + PARKING_ZONE_LENGTH / 2) * forward + 3.6 * right +dv.setup_apollo(destination.x, destination.z, modules) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("{} collided with {}".format(agent1, agent2)) + + +ego.on_collision(on_collision) + +POVList = [] + +POV1State = lgsvl.AgentState() +POV1State.transform = sim.map_point_on_lane(egoState.position + (4.55 + 6) * forward + 3.6 * right) +POV1 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV1State) +POV1.on_collision(on_collision) +POVList.append(POV1) + +POV2State = lgsvl.AgentState() +POV2State.transform = sim.map_point_on_lane(POV1State.position + (PARKING_ZONE_LENGTH + 4.6) * forward) +POV2 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV2State) +POV2.on_collision(on_collision) +POVList.append(POV2) + +for i in range(2,11): + POVState = lgsvl.AgentState() + POVState.transform = sim.map_point_on_lane(POVList[i-1].state.position + 5.5 * forward) + POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) + POV.on_collision(on_collision) + POVList.append(POV) + +try: + t0 = time.time() + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + for i in range(len(POVList)): + POVCurrentState = POVList[i].state + if POVCurrentState.speed > 0 + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV{} speed exceeded limit, {} > {} m/s".format(i, POVCurrentState.speed, 0 + SPEED_VARIANCE) + ) + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +parkingZoneBeginning = sim.map_point_on_lane(egoState.position + (2.75 + 4.6 + 6) * forward + 3.6 * right) +parkingZoneEnd = sim.map_point_on_lane(parkingZoneBeginning.position + PARKING_ZONE_LENGTH * forward) + +finalEgoState = ego.state + +try: + if not lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + raise lgsvl.evaluator.TestException("Ego did not change lanes") + elif not lgsvl.evaluator.in_parking_zone( + parkingZoneBeginning.position, + parkingZoneEnd.position, + finalEgoState.transform + ): + raise lgsvl.evaluator.TestException("Ego did not stop in parking zone") + elif finalEgoState.speed > 0.2: + raise lgsvl.evaluator.TestException("Ego did not park") + else: + print("PASSED") +except ValueError as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py new file mode 100755 index 0000000..f395809 --- /dev/null +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py @@ -0,0 +1,150 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# The speed limit of the scenario may require the HD map or Apollo's planning configuration to be editted which is out of the scope of this script. + +# LGSVL__SIMULATOR_HOST and LGSVL__AUTOPILOT_0_HOST environment variables need to be set. The default for both is 127.0.0.1 (localhost). +# The scenario assumes that the EGO's destination is ahead in the right lane. + +# POV = Principal Other Vehicle (NPC) + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 6.667 # (24 km/h, 15 mph) +SPEED_VARIANCE = 4 # Without real physics, the calculation for a rigidbody's velocity is very imprecise +TIME_LIMIT = 30 # seconds +PARKING_ZONE_LENGTH = 24 # meters + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("MOTL_Simp_15 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSameCurbRightIntersection": + sim.reset() +else: + sim.load("Straight2LaneSameCurbRightIntersection") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSameCurbRightIntersection')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +# Ego position is the center of the model. +# Destination is half EGO length + NPC length + EGO-NPC bumper distance + half parking zone length ahead of EGO +destination = egoState.position + (2.75 + 4.6 + 12 + PARKING_ZONE_LENGTH / 2) * forward + 3.6 * right +dv.setup_apollo(destination.x, destination.z, modules) + +# The POV is created in the right lane 12 m ahead of the EGO +POVState = lgsvl.AgentState() +POVState.transform = sim.map_point_on_lane(egoState.position + (4.55 + 12) * forward + 3.6 * right) +# The EGO is 4.5m long and the Sedan is 4.6m long. 4.55 is half the length of an EGO and Sedan +POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("{} collided with {}".format(agent1, agent2)) + + +ego.on_collision(on_collision) +POV.on_collision(on_collision) + +try: + t0 = time.time() + while True: + # The EGO should stay at or below the speed limit + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + # The POV should not move + POVCurrentState = POV.state + if POVCurrentState.speed > 0 + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV speed exceeded limit, {} > {} m/s".format(POVCurrentState.speed, 0 + SPEED_VARIANCE) + ) + # The above checks are made every 0.5 seconds + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +# These 2 positions are the beginning and end of the parking zone +parkingZoneBeginning = sim.map_point_on_lane(egoState.position + (2.75 + 4.6 + 12) * forward + 3.6 * right) +parkingZoneEnd = sim.map_point_on_lane(parkingZoneBeginning.position + PARKING_ZONE_LENGTH * forward) + +finalEgoState = ego.state + +try: + if not lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + raise lgsvl.evaluator.TestException("Ego did not change lanes") + elif not lgsvl.evaluator.in_parking_zone( + parkingZoneBeginning.position, + parkingZoneEnd.position, + finalEgoState.transform + ): + raise lgsvl.evaluator.TestException("Ego did not stop in parking zone") + elif finalEgoState.speed > 0.2: + raise lgsvl.evaluator.TestException("Ego did not park") + else: + print("PASSED") +except ValueError as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py new file mode 100755 index 0000000..dac7e59 --- /dev/null +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See MOTL_Simp_15.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 11.111 # (40 km/h, 25 mph) +SPEED_VARIANCE = 4 +TIME_LIMIT = 30 # seconds +PARKING_ZONE_LENGTH = 24 # meters + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("MOTL_Simp_25 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSameCurbRightIntersection": + sim.reset() +else: + sim.load("Straight2LaneSameCurbRightIntersection") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSameCurbRightIntersection')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +# Destination in the middle of the parking zone +destination = egoState.position + (2.75 + 4.6 + 12 + PARKING_ZONE_LENGTH / 2) * forward + 3.6 * right +dv.setup_apollo(destination.x, destination.z, modules) + +POVState = lgsvl.AgentState() +POVState.transform = sim.map_point_on_lane(egoState.position + (4.55 + 12) * forward + 3.6 * right) +POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("{} collided with {}".format(agent1, agent2)) + + +ego.on_collision(on_collision) +POV.on_collision(on_collision) + +try: + t0 = time.time() + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + POVCurrentState = POV.state + if POVCurrentState.speed > 0 + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 speed exceeded limit, {} > {} m/s".format(POVCurrentState.speed, 0 + SPEED_VARIANCE) + ) + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +parkingZoneBeginning = sim.map_point_on_lane(egoState.position + (2.75 + 4.6 + 12) * forward + 3.6 * right) +parkingZoneEnd = sim.map_point_on_lane(parkingZoneBeginning.position + PARKING_ZONE_LENGTH * forward) + +finalEgoState = ego.state + +try: + if not lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + raise lgsvl.evaluator.TestException("Ego did not change lanes") + elif not lgsvl.evaluator.in_parking_zone( + parkingZoneBeginning.position, + parkingZoneEnd.position, + finalEgoState.transform + ): + raise lgsvl.evaluator.TestException("Ego did not stop in parking zone") + elif finalEgoState.speed > 0.2: + raise lgsvl.evaluator.TestException("Ego did not park") + else: + print("PASSED") +except ValueError as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py new file mode 100755 index 0000000..0e143c9 --- /dev/null +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py @@ -0,0 +1,114 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See PLC_SN_15.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 6.667 # (24 km/h, 15mph) +SPEED_VARIANCE = 4 +TIME_LIMIT = 15 # seconds + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("PLC_B_15 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSame": + sim.reset() +else: + sim.load("Straight2LaneSame") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSame')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +destination = egoState.position + 120 * forward + 3.6 * right +dv.setup_apollo(destination.x, destination.z, modules) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("Ego collided with {}".format(agent2)) + + +ego.on_collision(on_collision) + +try: + t0 = time.time() + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +finalEgoState = ego.state +try: + if lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + print("PASSED") + else: + raise lgsvl.evaluator.TestException("Ego did not change lanes") +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py new file mode 100755 index 0000000..77e4756 --- /dev/null +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py @@ -0,0 +1,114 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See PLC_SN_15.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 11.111 # (40 km/h, 25mph) +SPEED_VARIANCE = 4 +TIME_LIMIT = 15 # seconds + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("PLC_B_25 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSame": + sim.reset() +else: + sim.load("Straight2LaneSame") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSame')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +destination = egoState.position + 120 * forward + 3.6 * right +dv.setup_apollo(destination.x, destination.z, modules) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("Ego collided with {}".format(agent2)) + + +ego.on_collision(on_collision) + +try: + t0 = time.time() + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +finalEgoState = ego.state +try: + if lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + print("PASSED") + else: + raise lgsvl.evaluator.TestException("Ego did not change lanes") +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py new file mode 100755 index 0000000..2489f74 --- /dev/null +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py @@ -0,0 +1,114 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See PLC_SN_15.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 15.556 # (56 km/h, 35mph) +SPEED_VARIANCE = 4 +TIME_LIMIT = 15 # seconds + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("PLC_B_35 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSame": + sim.reset() +else: + sim.load("Straight2LaneSame") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSame')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +destination = egoState.position + 120 * forward + 3.6 * right +dv.setup_apollo(destination.x, destination.z, modules) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("Ego collided with {}".format(agent2)) + + +ego.on_collision(on_collision) + +try: + t0 = time.time() + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +finalEgoState = ego.state +try: + if lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + print("PASSED") + else: + raise lgsvl.evaluator.TestException("Ego did not change lanes") +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py new file mode 100755 index 0000000..4c62106 --- /dev/null +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py @@ -0,0 +1,147 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See PLC_SN_15.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 6.667 # (24 km/h, 15mph) +SPEED_VARIANCE = 4 +MAX_POV_SEPARATION = 27 +SEPARATION_VARIANCE = 2 +TIME_LIMIT = 30 # seconds + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("PLC_CP_15 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSame": + sim.reset() +else: + sim.load("Straight2LaneSame") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSame')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +destination = egoState.position + 120 * forward + 3.6 * right +dv.setup_apollo(destination.x, destination.z, modules) + +POV1State = lgsvl.AgentState() +POV1State.transform = sim.map_point_on_lane(egoState.position + 13 * forward + 3.6 * right) +POV1 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV1State) +POV1.follow_closest_lane(True, MAX_SPEED, False) + +POV2State = lgsvl.AgentState() +POV2State.transform = sim.map_point_on_lane(egoState.position - 13 * forward + 3.6 * right) +POV2 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV2State) +POV2.follow_closest_lane(True, MAX_SPEED, False) + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("{} collided with {}".format(agent1, agent2)) + +ego.on_collision(on_collision) +POV1.on_collision(on_collision) +POV2.on_collision(on_collision) + +endOfRoad = egoState.position + 120 * forward + 3.6 * right + +try: + t0 = time.time() + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed ,MAX_SPEED + SPEED_VARIANCE) + ) + POV1CurrentState = POV1.state + POV2CurrentState = POV2.state + POVSeparation = lgsvl.evaluator.separation(POV1CurrentState.position, POV2CurrentState.position) + if POVSeparation > MAX_POV_SEPARATION + SEPARATION_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 and POV2 are too far apart: {} > {}".format( + POVSeparation, MAX_POV_SEPARATION + SEPARATION_VARIANCE + ) + ) + if POV1CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 speed exceeded limit, {} > {} m/s".format(POV1CurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + if POV2CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV2 speed exceeded limit, {} > {} m/s".format(POV2CurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + if lgsvl.evaluator.separation(POV1CurrentState.position, endOfRoad) < 5: + break + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +finalEgoState = ego.state +try: + if lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + print("PASSED") + else: + raise lgsvl.evaluator.TestException("Ego did not change lanes") +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py new file mode 100755 index 0000000..31df3b4 --- /dev/null +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py @@ -0,0 +1,149 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See PLC_SN_15.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 11.111 # (40 km/h, 25 mph) +SPEED_VARIANCE = 4 +MAX_POV_SEPARATION = 27 +SEPARATION_VARIANCE = 2 +TIME_LIMIT = 30 # seconds + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("PLC_CP_25 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSame": + sim.reset() +else: + sim.load("Straight2LaneSame") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSame')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +destination = egoState.position + 120 * forward + 3.6 * right +dv.setup_apollo(destination.x, destination.z, modules) + +POV1State = lgsvl.AgentState() +POV1State.transform = sim.map_point_on_lane(egoState.position + 13 * forward + 3.6 * right) +POV1 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV1State) +POV1.follow_closest_lane(True, MAX_SPEED, False) + +POV2State = lgsvl.AgentState() +POV2State.transform = sim.map_point_on_lane(egoState.position - 13 * forward + 3.6 * right) +POV2 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV2State) +POV2.follow_closest_lane(True, MAX_SPEED, False) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("{} collided with {}".format(agent1, agent2)) + + +ego.on_collision(on_collision) +POV1.on_collision(on_collision) +POV2.on_collision(on_collision) + +endOfRoad = egoState.position + 120 * forward + 3.6 * right + +try: + t0 = time.time() + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed ,MAX_SPEED + SPEED_VARIANCE) + ) + POV1CurrentState = POV1.state + POV2CurrentState = POV2.state + POVSeparation = lgsvl.evaluator.separation(POV1CurrentState.position, POV2CurrentState.position) + if POVSeparation > MAX_POV_SEPARATION + SEPARATION_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 and POV2 are too far apart: {} > {}".format( + POVSeparation, MAX_POV_SEPARATION + SEPARATION_VARIANCE + ) + ) + if POV1CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 speed exceeded limit, {} > {} m/s".format(POV1CurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + if POV2CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV2 speed exceeded limit, {} > {} m/s".format(POV2CurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + if lgsvl.evaluator.separation(POV1CurrentState.position, endOfRoad) < 5: + break + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +finalEgoState = ego.state +try: + if lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + print("PASSED") + else: + raise lgsvl.evaluator.TestException("Ego did not change lanes") +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py new file mode 100755 index 0000000..17d4d29 --- /dev/null +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py @@ -0,0 +1,150 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See PLC_SN_15.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 15.556 # (56 km/h, 35 mph) +SPEED_VARIANCE = 4 +MAX_POV_SEPARATION = 27 +SEPARATION_VARIANCE = 2 +TIME_LIMIT = 30 # seconds + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("PLC_CP_35 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSame": + sim.reset() +else: + sim.load("Straight2LaneSame") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSame')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +destination = egoState.position + 120 * forward + 3.6 * right +dv.setup_apollo(destination.x, destination.z, modules) + +POV1State = lgsvl.AgentState() +POV1State.transform = sim.map_point_on_lane(egoState.position + 13 * forward + 3.6 * right) +POV1 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV1State) +POV1.follow_closest_lane(True, MAX_SPEED, False) + +POV2State = lgsvl.AgentState() +POV2State.transform = sim.map_point_on_lane(egoState.position - 13 * forward + 3.6 * right) +POV2 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV2State) +POV2.follow_closest_lane(True, MAX_SPEED, False) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("{} collided with {}".format(agent1, agent2)) + + +ego.on_collision(on_collision) +POV1.on_collision(on_collision) +POV2.on_collision(on_collision) + +endOfRoad = egoState.position + 120 * forward + 3.6 * right + +try: + t0 = time.time() + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed ,MAX_SPEED + SPEED_VARIANCE) + ) + POV1CurrentState = POV1.state + POV2CurrentState = POV2.state + POVSeparation = lgsvl.evaluator.separation(POV1CurrentState.position, POV2CurrentState.position) + if POVSeparation > MAX_POV_SEPARATION + SEPARATION_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 and POV2 are too far apart: {} > {}".format( + POVSeparation, MAX_POV_SEPARATION + SEPARATION_VARIANCE + ) + ) + if POV1CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 speed exceeded limit, {} > {} m/s".format(POV1CurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + if POV2CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV2 speed exceeded limit, {} > {} m/s".format(POV2CurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + if lgsvl.evaluator.separation(POV1CurrentState.position, endOfRoad) < 5: + break + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +finalEgoState = ego.state +try: + if lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + print("PASSED") + else: + raise lgsvl.evaluator.TestException("Ego did not change lanes") +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py new file mode 100755 index 0000000..0124896 --- /dev/null +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py @@ -0,0 +1,177 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# This scenario simulates a situation where the EGO needs to change lanes in the presence of other traffic +# The speed limit of the scenario may require the HD map or Apollo's planning configuration to be editted which is out of the scope of this script. + +# LGSVL__SIMULATOR_HOST and LGSVL__AUTOPILOT_0_HOST environment variables need to be set. The default for both is 127.0.0.1 (localhost). +# The scenario assumes that the EGO's destination is ahead in the right lane. + +# POV = Principal Other Vehicle (NPC) + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 6.667 # (24 km/h, 15 mph) Max speed of EGO and POVs +SPEED_VARIANCE = 4 # Without real physics, the calculation for a rigidbody's velocity is very imprecise +MAX_POV_SEPARATION = 13 # The POVs in the right lane should keep a constant distance between them +SEPARATION_VARIANCE = 2 # The allowable variance in the POV separation +TIME_LIMIT = 15 # seconds + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("PLC_SN_15 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSame": + sim.reset() +else: + sim.load("Straight2LaneSame") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) # Create the websocket connection to Dreamview +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSame')) # Set the HD map in Dreamview +# Set the Vehicle configuration in Dreamview +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) + +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] # The list of modules to be enabled + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +# This is an lgsvl.Vector with the coordinates of the destination in the Unity coordinate system +destination = egoState.position + 120 * forward + 3.6 * right +# Will enable all the modules and then wait for Apollo to be ready before continuing +dv.setup_apollo(destination.x, destination.z, modules) + +# The first POV is positioned such that its rear bumper is 5m in front of the EGO's front bumper in the right lane +POV1State = lgsvl.AgentState() +# 5m ahead of EGO, +5m because the transforms are the centers of the models +POV1State.transform = sim.map_point_on_lane(egoState.position + 10 * forward + 3.6 * right) +POV1 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV1State) +POV1.follow_closest_lane(True, MAX_SPEED, False) + +# The second POV is positioned such that its front bumper is even with the EGO's front bumper in the right lane +POV2State = lgsvl.AgentState() +POV2State.transform = sim.map_point_on_lane(egoState.position + 3.6 * right) +POV2 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV2State) +POV2.follow_closest_lane(True, MAX_SPEED, False) + +# The third POV is positioned such that its front bumper is 8m behind the EGO's rear bumper in the same lane as the EGO +POV3State = lgsvl.AgentState() +POV3State.transform = sim.map_point_on_lane(egoState.position - 13 * forward + 3.6 * right) +POV3 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV3State) +POV3.follow_closest_lane(True, MAX_SPEED, False) + + +# Any collision results in a failed test +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("{} collided with {}".format(agent1, agent2)) + + +ego.on_collision(on_collision) +POV1.on_collision(on_collision) +POV2.on_collision(on_collision) +POV3.on_collision(on_collision) + +endOfRoad = egoState.position + 120 * forward + 3.6 * right + +try: + t0 = time.time() + while True: + # The EGO should not exceed the max specified speed + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + POV1CurrentState = POV1.state + POV2CurrentState = POV2.state + POV3CurrentState = POV3.state + # The POVs in the right lane should maintain their starting separation + POVSeparation = lgsvl.evaluator.separation(POV1CurrentState.position, POV2CurrentState.position) + if POVSeparation > MAX_POV_SEPARATION + SEPARATION_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 and POV2 are too far apart: {} > {}".format(POVSeparation, MAX_POV_SEPARATION + SEPARATION_VARIANCE) + ) + # The POVs should not exceed the speed limit + if POV1CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 speed exceeded limit, {} > {} m/s".format(POV1CurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + if POV2CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV2 speed exceeded limit, {} > {} m/s".format(POV2CurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + if POV3CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException("POV3 speed exceeded limit, {} > {} m/s".format(POV3CurrentState.speed, MAX_SPEED + SPEED_VARIANCE)) + # Stops the test when the first POV reaches the end of the road + if lgsvl.evaluator.separation(POV1CurrentState.position, endOfRoad) < 5: + break + # The above checks are made every 0.5 seconds. + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +# This checks that the EGO actually changed lanes +finalEgoState = ego.state +try: + if lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + print("PASSED") + else: + raise lgsvl.evaluator.TestException("Ego did not change lanes") +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py new file mode 100755 index 0000000..521b01b --- /dev/null +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py @@ -0,0 +1,156 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See PLC_SN_15.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 11.111 # (40 km/h, 25 mph) +SPEED_VARIANCE = 4 +MAX_POV_SEPARATION = 17 +SEPARATION_VARIANCE = 2 +TIME_LIMIT = 30 # seconds + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("PLC_SN_25 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSame": + sim.reset() +else: + sim.load("Straight2LaneSame") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSame')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +destination = egoState.position + 120 * forward + 3.6 * right +dv.setup_apollo(destination.x, destination.z, modules) + +POV1State = lgsvl.AgentState() +POV1State.transform = sim.map_point_on_lane(egoState.position + 11 * forward + 3.6 * right) +POV1 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV1State) +POV1.follow_closest_lane(True, MAX_SPEED, False) + +POV2State = lgsvl.AgentState() +POV2State.transform = sim.map_point_on_lane(egoState.position + 3.6 * right) +POV2 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV2State) +POV2.follow_closest_lane(True, MAX_SPEED, False) + +POV3State = lgsvl.AgentState() +POV3State.transform = sim.map_point_on_lane(egoState.position - 11 * forward + 3.6 * right) +POV3 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV3State) +POV3.follow_closest_lane(True, MAX_SPEED, False) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("{} collided with {}".format(agent1, agent2)) + + +ego.on_collision(on_collision) +POV1.on_collision(on_collision) +POV2.on_collision(on_collision) +POV3.on_collision(on_collision) + +endOfRoad = egoState.position + 120 * forward + 3.6 * right + +try: + t0 = time.time() + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + POV1CurrentState = POV1.state + POV2CurrentState = POV2.state + POV3CurrentState = POV3.state + POVSeparation = lgsvl.evaluator.separation(POV1CurrentState.position, POV2CurrentState.position) + if POVSeparation > MAX_POV_SEPARATION + SEPARATION_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 and POV2 are too far apart: {} > {}".format(POVSeparation, MAX_POV_SEPARATION + SEPARATION_VARIANCE) + ) + if POV1CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 speed exceeded limit, {} > {} m/s".format(POV1CurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + if POV2CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV2 speed exceeded limit, {} > {} m/s".format(POV2CurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + if POV3CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException("POV3 speed exceeded limit, {} > {} m/s".format(POV3CurrentState.speed, MAX_SPEED + SPEED_VARIANCE)) + if lgsvl.evaluator.separation(POV1CurrentState.position, endOfRoad) < 5: + break + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +finalEgoState = ego.state +try: + if lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + print("PASSED") + else: + raise lgsvl.evaluator.TestException("Ego did not change lanes") +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py new file mode 100755 index 0000000..610043f --- /dev/null +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py @@ -0,0 +1,158 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See PLC_SN_15.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 15.556 # (56 km/h, 35mph) +SPEED_VARIANCE = 4 +MAX_POV_SEPARATION = 19 +SEPARATION_VARIANCE = 2 +TIME_LIMIT = 30 # seconds + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("PLC_SN_35 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSame": + sim.reset() +else: + sim.load("Straight2LaneSame") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSame')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +destination = egoState.position + 120 * forward + 3.6 * right +dv.setup_apollo(destination.x, destination.z, modules) + +POV1State = lgsvl.AgentState() +POV1State.transform = sim.map_point_on_lane(egoState.position + 13 * forward + 3.6 * right) +POV1 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV1State) +POV1.follow_closest_lane(True, MAX_SPEED, False) + +POV2State = lgsvl.AgentState() +POV2State.transform = sim.map_point_on_lane(egoState.position + 3.6 * right) +POV2 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV2State) +POV2.follow_closest_lane(True, MAX_SPEED, False) + +POV3State = lgsvl.AgentState() +POV3State.transform = sim.map_point_on_lane(egoState.position - 13 * forward + 3.6 * right) +POV3 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV3State) +POV3.follow_closest_lane(True, MAX_SPEED, False) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("{} collided with {}".format(agent1, agent2)) + + +ego.on_collision(on_collision) +POV1.on_collision(on_collision) +POV2.on_collision(on_collision) +POV3.on_collision(on_collision) + +endOfRoad = egoState.position + 120 * forward + 3.6 * right + +try: + t0 = time.time() + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + POV1CurrentState = POV1.state + POV2CurrentState = POV2.state + POV3CurrentState = POV3.state + POVSeparation = lgsvl.evaluator.separation(POV1CurrentState.position, POV2CurrentState.position) + if POVSeparation > MAX_POV_SEPARATION + SEPARATION_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 and POV2 are too far apart: {} > {}".format(POVSeparation, MAX_POV_SEPARATION + SEPARATION_VARIANCE) + ) + if POV1CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 speed exceeded limit, {} > {} m/s".format(POV1CurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + if POV2CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV2 speed exceeded limit, {} > {} m/s".format(POV2CurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + if POV3CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV3 speed exceeded limit, {} > {} m/s".format(POV3CurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + if lgsvl.evaluator.separation(POV1CurrentState.position, endOfRoad) < 5: + break + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +finalEgoState = ego.state +try: + if lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + print("PASSED") + else: + raise lgsvl.evaluator.TestException("Ego did not change lanes") +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py new file mode 100755 index 0000000..96ab341 --- /dev/null +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See PLC_SN_15.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 6.667 # (24 km/h, 15 mph) +SPEED_VARIANCE = 4 +TIME_LIMIT = 15 # seconds + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("PLC_SP_15 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSame": + sim.reset() +else: + sim.load("Straight2LaneSame") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSame')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +destination = egoState.position + 120 * forward + 3.6 * right +dv.setup_apollo(destination.x, destination.z, modules) + +POV1State = lgsvl.AgentState() +POV1State.transform = sim.map_point_on_lane(egoState.position + 11 * forward + 3.6 * right) +POV1 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV1State) + +POV1.follow_closest_lane(True, MAX_SPEED, False) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("{} collided with {}".format(agent1, agent2)) + + +ego.on_collision(on_collision) +POV1.on_collision(on_collision) + +endOfRoad = egoState.position + 120 * forward + 3.6 * right + +try: + t0 = time.time() + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + POV1CurrentState = POV1.state + if POV1CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 speed exceeded limit, {} > {} m/s".format(POV1CurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + if lgsvl.evaluator.separation(POV1CurrentState.position, endOfRoad) < 5: + break + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +finalEgoState = ego.state +try: + if lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + print("PASSED") + else: + raise lgsvl.evaluator.TestException("Ego did not change lanes") +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py new file mode 100755 index 0000000..026adbd --- /dev/null +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See PLC_SN_15.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 11.111 # (40 km/h, 25 mph) +SPEED_VARIANCE = 4 +TIME_LIMIT = 15 # seconds + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("PLC_SP_25 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSame": + sim.reset() +else: + sim.load("Straight2LaneSame") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSame')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +destination = egoState.position + 120 * forward + 3.6 * right +dv.setup_apollo(destination.x, destination.z, modules) + +POV1State = lgsvl.AgentState() +POV1State.transform = sim.map_point_on_lane(egoState.position + 5 * forward + 3.6 * right) +POV1 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV1State) + +POV1.follow_closest_lane(True, MAX_SPEED, False) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("{} collided with {}".format(agent1, agent2)) + + +ego.on_collision(on_collision) +POV1.on_collision(on_collision) + +endOfRoad = egoState.position + 120 * forward + 3.6 * right + +try: + t0 = time.time() + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + POV1CurrentState = POV1.state + if POV1CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 speed exceeded limit, {} > {} m/s".format(POV1CurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + if lgsvl.evaluator.separation(POV1CurrentState.position, endOfRoad) < 5: + break + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +finalEgoState = ego.state +try: + if lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + print("PASSED") + else: + raise lgsvl.evaluator.TestException("Ego did not change lanes") +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py new file mode 100755 index 0000000..1b8afc0 --- /dev/null +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See PLC_SN_15.py for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_SPEED = 15.556 # (56 km/h, 35 mph) +SPEED_VARIANCE = 4 +TIME_LIMIT = 15 # seconds + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("PLC_SP_35 - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight2LaneSame": + sim.reset() +else: + sim.load("Straight2LaneSame") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +# A point close to the desired lane was found in Editor. +# This method returns the position and orientation of the closest lane to the point. +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight2LaneSame')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +destination = egoState.position + 120 * forward + 3.6 * right +dv.setup_apollo(destination.x, destination.z, modules) + +POV1State = lgsvl.AgentState() +POV1State.transform = sim.map_point_on_lane(egoState.position + 5 * forward + 3.6 * right) +POV1 = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POV1State) + +POV1.follow_closest_lane(True, MAX_SPEED, False) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("{} collided with {}".format(agent1, agent2)) + + +ego.on_collision(on_collision) +POV1.on_collision(on_collision) + +endOfRoad = egoState.position + 120 * forward + 3.6 * right + +try: + t0 = time.time() + while True: + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + POV1CurrentState = POV1.state + if POV1CurrentState.speed > MAX_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV1 speed exceeded limit, {} > {} m/s".format(POV1CurrentState.speed, MAX_SPEED + SPEED_VARIANCE) + ) + if lgsvl.evaluator.separation(POV1CurrentState.position, endOfRoad) < 5: + break + sim.run(0.5) + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +finalEgoState = ego.state +try: + if lgsvl.evaluator.right_lane_check(sim, finalEgoState.transform): + print("PASSED") + else: + raise lgsvl.evaluator.TestException("Ego did not change lanes") +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_test_runner.sh b/examples/NHTSA/Perform-Lane-Change/PLC_test_runner.sh new file mode 100755 index 0000000..fe677b3 --- /dev/null +++ b/examples/NHTSA/Perform-Lane-Change/PLC_test_runner.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -eu + +python3 PLC_B_15.py +python3 PLC_B_25.py +python3 PLC_B_35.py +python3 PLC_CP_15.py +python3 PLC_CP_25.py +python3 PLC_CP_35.py +python3 PLC_SN_15.py +python3 PLC_SN_25.py +python3 PLC_SN_35.py +python3 PLC_SP_15.py +python3 PLC_SP_25.py +python3 PLC_SP_35.py \ No newline at end of file diff --git a/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py b/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py new file mode 100755 index 0000000..6e440ed --- /dev/null +++ b/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py @@ -0,0 +1,141 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See VF_C_25_Slow for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_EGO_SPEED = 11.18 # (40 km/h, 25 mph) +SPEED_VARIANCE = 10 # Simple Physics does not return an accurate value +MAX_POV_SPEED = 8.94 # (32 km/h, 20 mph) +MAX_POV_ROTATION = 5 # deg/s +TIME_LIMIT = 30 # seconds +TIME_DELAY = 3 +MAX_FOLLOWING_DISTANCE = 50 # Apollo 3.5 is very cautious + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("VF_S_25_Slow - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight1LaneSame": + sim.reset() +else: + sim.load("Straight1LaneSame") + +sim.set_time_of_day(12) +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(1, 0, 65)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight1LaneSame')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +destination = egoState.position + 135 * forward +dv.setup_apollo(destination.x, destination.z, modules) + +POVState = lgsvl.AgentState() +POVState.transform = sim.map_point_on_lane(egoState.position + 35 * forward) +POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("Ego collided with {}".format(agent2)) + + +ego.on_collision(on_collision) +POV.on_collision(on_collision) + +endOfRoad = egoState.position + 135 * forward + +try: + t0 = time.time() + sim.run(TIME_DELAY) # The EGO should start moving first + POV.follow_closest_lane(True, MAX_POV_SPEED, False) + while True: + sim.run(0.5) + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_EGO_SPEED + SPEED_VARIANCE) + ) + POVCurrentState = POV.state + if POVCurrentState.speed > MAX_POV_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV speed exceeded limit, {} > {} m/s".format(POVCurrentState.speed, MAX_POV_SPEED + SPEED_VARIANCE) + ) + if POVCurrentState.angular_velocity.y > MAX_POV_ROTATION: + raise lgsvl.evaluator.TestException( + "POV angular rotation exceeded limit, {} > {} deg/s".format( + POVCurrentState.angular_velocity, MAX_POV_ROTATION + ) + ) + if lgsvl.evaluator.separation(POVCurrentState.position, endOfRoad) < 5: + break + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +separation = lgsvl.evaluator.separation(egoCurrentState.position, POVCurrentState.position) +try: + if separation > MAX_FOLLOWING_DISTANCE: + raise lgsvl.evaluator.TestException( + "FAILED: EGO following distance was not maintained, {} > {}".format(separation, MAX_FOLLOWING_DISTANCE) + ) + else: + print("PASSED") +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py b/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py new file mode 100755 index 0000000..8f01fed --- /dev/null +++ b/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py @@ -0,0 +1,140 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See VF_C_25_Slow for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_EGO_SPEED = 20.12 # (72 km/h, 45 mph) +SPEED_VARIANCE = 10 # Simple Physics does not return an accurate value +MAX_POV_SPEED = 17.88 # (64 km/h, 40 mph) +MAX_POV_ROTATION = 5 # deg/s +TIME_LIMIT = 30 # seconds +TIME_DELAY = 7 +MAX_FOLLOWING_DISTANCE = 100 # Apollo 3.5 is very cautious + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("VF_S_45_Slow - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight1LaneSame": + sim.reset() +else: + sim.load("Straight1LaneSame") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(1, 0, 65)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight1LaneSame')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +destination = egoState.position + 135 * forward +dv.setup_apollo(destination.x, destination.z, modules) + +POVState = lgsvl.AgentState() +POVState.transform = sim.map_point_on_lane(egoState.position + 68 * forward) +POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("Ego collided with {}".format(agent2)) + + +ego.on_collision(on_collision) +POV.on_collision(on_collision) + +endOfRoad = egoState.position + 135 * forward + +try: + t0 = time.time() + sim.run(TIME_DELAY) # The EGO should start moving first + POV.follow_closest_lane(True, MAX_POV_SPEED, False) + while True: + sim.run(0.5) + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_EGO_SPEED + SPEED_VARIANCE) + ) + POVCurrentState = POV.state + if POVCurrentState.speed > MAX_POV_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV speed exceeded limit, {} > {} m/s".format(POVCurrentState.speed, MAX_POV_SPEED + SPEED_VARIANCE) + ) + if POVCurrentState.angular_velocity.y > MAX_POV_ROTATION: + raise lgsvl.evaluator.TestException( + "POV angular rotation exceeded limit, {} > {} deg/s".format( + POVCurrentState.angular_velocity, MAX_POV_ROTATION + ) + ) + if lgsvl.evaluator.separation(POVCurrentState.position, endOfRoad) < 5: + break + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +separation = lgsvl.evaluator.separation(egoCurrentState.position, POVCurrentState.position) +try: + if separation > MAX_FOLLOWING_DISTANCE: + raise lgsvl.evaluator.TestException( + "FAILED: EGO following distance was not maintained, {} > {}".format(separation, MAX_FOLLOWING_DISTANCE) + ) + else: + print("PASSED") +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py b/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py new file mode 100755 index 0000000..efab028 --- /dev/null +++ b/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py @@ -0,0 +1,140 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019-2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# See VF_C_25_Slow for a commented script + +import time +import logging +from environs import Env +import lgsvl +FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" +logging.basicConfig(level=logging.WARNING, format=FORMAT) +log = logging.getLogger(__name__) + +env = Env() + +MAX_EGO_SPEED = 29.06 # (105 km/h, 65 mph) +SPEED_VARIANCE = 10 # Simple Physics does not return an accurate value +MAX_POV_SPEED = 26.82 # (96 km/h, 60 mph) +MAX_POV_ROTATION = 5 # deg/s +TIME_LIMIT = 30 # seconds +TIME_DELAY = 5 +MAX_FOLLOWING_DISTANCE = 100 # Apollo 3.5 is very cautious + +LGSVL__SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +LGSVL__SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +LGSVL__AUTOPILOT_0_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +LGSVL__AUTOPILOT_0_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +print("VF_S_65_Slow - ", end='') + +sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) +if sim.current_scene == "Straight1LaneSame": + sim.reset() +else: + sim.load("Straight1LaneSame") + +# spawn EGO in the 2nd to right lane +egoState = lgsvl.AgentState() +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(1, 0, 65)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +forward = lgsvl.utils.transform_to_forward(egoState.transform) +right = lgsvl.utils.transform_to_right(egoState.transform) + +ego.connect_bridge(LGSVL__AUTOPILOT_0_HOST, LGSVL__AUTOPILOT_0_PORT) + +dv = lgsvl.dreamview.Connection(sim, ego, LGSVL__AUTOPILOT_0_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", 'Straight1LaneSame')) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is empty, using default list: {0}".format(modules)) + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] +except Exception: + modules = [ + 'Recorder', + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control' + ] + log.warning("LGSVL__AUTOPILOT_0_VEHICLE_MODULES is not set, using default list: {0}".format(modules)) + +destination = destination = egoState.position + 135 * forward +dv.setup_apollo(destination.x, destination.z, modules) + +POVState = lgsvl.AgentState() +POVState.transform = sim.map_point_on_lane(egoState.position + 105 * forward) +POV = sim.add_agent("Sedan", lgsvl.AgentType.NPC, POVState) + + +def on_collision(agent1, agent2, contact): + raise lgsvl.evaluator.TestException("Ego collided with {}".format(agent2)) + + +ego.on_collision(on_collision) +POV.on_collision(on_collision) + +endOfRoad = egoState.position + 135 * forward + +try: + t0 = time.time() + sim.run(TIME_DELAY) # The EGO should start moving first + POV.follow_closest_lane(True, MAX_POV_SPEED, False) + while True: + sim.run(0.5) + egoCurrentState = ego.state + if egoCurrentState.speed > MAX_EGO_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "Ego speed exceeded limit, {} > {} m/s".format(egoCurrentState.speed, MAX_EGO_SPEED + SPEED_VARIANCE) + ) + POVCurrentState = POV.state + if POVCurrentState.speed > MAX_POV_SPEED + SPEED_VARIANCE: + raise lgsvl.evaluator.TestException( + "POV speed exceeded limit, {} > {} m/s".format(POVCurrentState.speed, MAX_POV_SPEED + SPEED_VARIANCE) + ) + if POVCurrentState.angular_velocity.y > MAX_POV_ROTATION: + raise lgsvl.evaluator.TestException( + "POV angular rotation exceeded limit, {} > {} deg/s".format( + POVCurrentState.angular_velocity, MAX_POV_ROTATION + ) + ) + if lgsvl.evaluator.separation(POVCurrentState.position, endOfRoad) < 5: + break + if time.time() - t0 > TIME_LIMIT: + break +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) + +separation = lgsvl.evaluator.separation(egoCurrentState.position, POVCurrentState.position) +try: + if separation > MAX_FOLLOWING_DISTANCE: + raise lgsvl.evaluator.TestException( + "FAILED: EGO following distance was not maintained, {} > {}".format(separation, MAX_FOLLOWING_DISTANCE) + ) + else: + print("PASSED") +except lgsvl.evaluator.TestException as e: + exit("FAILED: {}".format(e)) diff --git a/examples/NHTSA/Vehicle-Following/VF_test_runner.sh b/examples/NHTSA/Vehicle-Following/VF_test_runner.sh new file mode 100755 index 0000000..339f1f8 --- /dev/null +++ b/examples/NHTSA/Vehicle-Following/VF_test_runner.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +set -eu + +python3 VF_S_25_Slow.py +python3 VF_S_45_Slow.py +python3 VF_S_65_Slow.py +# python3 VF_C_25_Slow.py +# python3 VF_C_45_Slow.py +# python3 VF_C_65_Slow.py diff --git a/examples/SampleTestCases/cut-in.py b/examples/SampleTestCases/cut-in.py new file mode 100755 index 0000000..1325011 --- /dev/null +++ b/examples/SampleTestCases/cut-in.py @@ -0,0 +1,114 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# LGSVL__SIMULATOR_HOST and LGSVL__AUTOPILOT_0_HOST are environment variables +# They can be set for the terminal instance with `export LGSVL__SIMULATOR_HOST=###` +# which will use the set value for all future commands in that terminal. +# To set the variable for only a particular execution, run the script in this way +# `LGSVL__SIMULATOR_HOST=### LGSVL__AUTOPILOT_0_HOST=### python3 cut-in.py` + +# LGSVL__SIMULATOR_HOST is the IP of the computer running the simulator +# LGSVL__AUTOPILOT_0_HOST is the IP of the computer running the bridge (from the perspective of the Simulator) +# If the simulator and bridge are running on the same computer, then the default values will work. +# Otherwise the variables must be set for in order to connect to the simulator and the bridge to receive data. +# LGSVL__SIMULATOR_PORT and LGSVL__AUTOPILOT_0_HOST need to be set if non-default ports will be used + +import os +import lgsvl +import time +import sys + +SIMULATOR_HOST = os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1") +SIMULATOR_PORT = int(os.environ.get("LGSVL__SIMULATOR_PORT", 8181)) +BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090)) + +sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) +if sim.current_scene == "SanFrancisco": + sim.reset() +else: + sim.load("SanFrancisco", seed=0) + +# spawn EGO +egoState = lgsvl.AgentState() +# Spawn point found in Unity Editor +egoState.transform = sim.map_point_on_lane(lgsvl.Vector(773.29, 10.24, -10.79)) +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT) + +right = lgsvl.utils.transform_to_right(egoState.transform) # Unit vector in the right direction of the EGO +forward = lgsvl.utils.transform_to_forward(egoState.transform) # Unit vector in the forward direction of the EGO + +# spawn NPC +npcState = lgsvl.AgentState() +npcState.transform = egoState.transform +npcState.transform.position = egoState.position - 3.6 * right # NPC is 3.6m to the left of the EGO +npc = sim.add_agent("Jeep", lgsvl.AgentType.NPC, npcState) + +# This function will be called if a collision occurs +def on_collision(agent1, agent2, contact): + raise Exception("{} collided with {}".format(agent1, agent2)) + +ego.on_collision(on_collision) +npc.on_collision(on_collision) + +controlReceived = False + +# This function will be called when the Simulator receives the first message on the topic defined in the CheckControlSensor configuration +def on_control_received(agent, kind, context): + global controlReceived + # There can be multiple custom callbacks defined, this checks for the appropriate kind + if kind == "checkControl": + # Stops the Simulator running, this will only interrupt the first sim.run(30) call + sim.stop() + controlReceived = True + +ego.on_custom(on_control_received) + +# Run Simulator for at most 30 seconds for the AD stack to to initialize +sim.run(30) + +# If a Control message was not received, then the AD stack is not ready and the scenario should not continue +if not controlReceived: + raise Exception("AD stack is not ready after 30 seconds") + sys.exit() + +# NPC will follow the HD map at a max speed of 15 m/s (33 mph) and will not change lanes automatically +# The speed limit of the road is 20m/s so the EGO should drive faster than the NPC +npc.follow_closest_lane(follow=True, max_speed=8, isLaneChange=False) + +# t0 is the time when the Simulation started +t0 = time.time() + +# This will keep track of if the NPC has already changed lanes +npcChangedLanes = False + +# Run Simulation for 4 seconds before checking cut-in or end conditions +sim.run(4) + +# The Simulation will pause every 0.5 seconds to check 2 conditions +while True: + sim.run(0.5) + + # If the NPC has not already changed lanes then the distance between the NPC and EGO is calculated + if not npcChangedLanes: + egoCurrentState = ego.state + npcCurrentState = npc.state + + separationDistance = (egoCurrentState.position - npcCurrentState.position).magnitude() + + # If the EGO and NPC are within 15m, then NPC will change lanes to the right (in front of the EGO) + if separationDistance <= 15: + npc.change_lane(False) + npcChangedLanes = True + + # Simulation will be limited to running for 30 seconds total + if time.time() - t0 > 26: + break diff --git a/examples/SampleTestCases/ped-crossing.py b/examples/SampleTestCases/ped-crossing.py new file mode 100755 index 0000000..aa18600 --- /dev/null +++ b/examples/SampleTestCases/ped-crossing.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# LGSVL__SIMULATOR_HOST and LGSVL__AUTOPILOT_0_HOST are environment variables +# They can be set for the terminal instance with `export LGSVL__SIMULATOR_HOST=###` +# which will use the set value for all future commands in that terminal. +# To set the variable for only a particular execution, run the script in this way +# `LGSVL__SIMULATOR_HOST=### LGSVL__AUTOPILOT_0_HOST=### python3 cut-in.py` + +# LGSVL__SIMULATOR_HOST is the IP of the computer running the simulator +# LGSVL__AUTOPILOT_0_HOST is the IP of the computer running the bridge (from the perspective of the Simulator) +# If the simulator and bridge are running on the same computer, then the default values will work. +# Otherwise the variables must be set for in order to connect to the simulator and the bridge to receive data. +# LGSVL__SIMULATOR_PORT and LGSVL__AUTOPILOT_0_HOST need to be set if non-default ports will be used + +import os +import lgsvl +import sys + +SIMULATOR_HOST = os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1") +SIMULATOR_PORT = int(os.environ.get("LGSVL__SIMULATOR_PORT", 8181)) +BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090)) + +sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) +if sim.current_scene == "Straight1LanePedestrianCrosswalk": + sim.reset() +else: + sim.load("Straight1LanePedestrianCrosswalk") + +# spawn EGO +egoState = lgsvl.AgentState() +egoState.transform = sim.get_spawn()[0] +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT) + +# spawn PED +pedState = lgsvl.AgentState() +pedState.transform.position = lgsvl.Vector(-7.67, 0.2, 6.299) +ped = sim.add_agent("Bob", lgsvl.AgentType.PEDESTRIAN, pedState) + +# This function will be called if a collision occurs +def on_collision(agent1, agent2, contact): + raise Exception("{} collided with {}".format(agent1, agent2)) + +ego.on_collision(on_collision) +ped.on_collision(on_collision) + +controlReceived = False + +# This function will be called when the Simulator receives the first message on the topic defined in the CheckControlSensor configuration +def on_control_received(agent, kind, context): + global controlReceived + # There can be multiple custom callbacks defined, this checks for the appropriate kind + if kind == "checkControl": + # Stops the Simulator running, this will only interrupt the first sim.run(30) call + sim.stop() + controlReceived = True + +ego.on_custom(on_control_received) + +# Run Simulator for at most 30 seconds for the AD stack to to initialize +sim.run(30) + +# If a Control message was not received, then the AD stack is not ready and the scenario should not continue +if not controlReceived: + raise Exception("AD stack is not ready") + sys.exit() + +# Create the list of waypoints for the pedestrian to follow +waypoints = [] +# Fist waypoint is the same position that the PED is spawned. The PED will wait here until the EGO is within 50m +waypoints.append(lgsvl.WalkWaypoint(position=pedState.position, idle=0, trigger_distance=50)) +# Second waypoint is across the crosswalk +waypoints.append(lgsvl.WalkWaypoint(position=lgsvl.Vector(8.88, 0.2, 6.299), idle=0)) + +# List of waypoints is given to the pedestrian +ped.follow(waypoints) + +# Simulation will run for 30 seconds +sim.run(30) diff --git a/examples/SampleTestCases/random-traffic-local.py b/examples/SampleTestCases/random-traffic-local.py new file mode 100755 index 0000000..2e32945 --- /dev/null +++ b/examples/SampleTestCases/random-traffic-local.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2020 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +from datetime import datetime +from environs import Env +import random +import lgsvl + +''' +LGSVL__AUTOPILOT_0_HOST IP address of the computer running the bridge to connect to +LGSVL__AUTOPILOT_0_PORT Port that the bridge listens on for messages +LGSVL__AUTOPILOT_0_VEHICLE_CONFIG Vehicle configuration to be loaded in Dreamview (Capitalization and spacing must match the dropdown in Dreamview) +LGSVL__AUTOPILOT_HD_MAP HD map to be loaded in Dreamview (Capitalization and spacing must match the dropdown in Dreamview) +LGSVL__MAP ID of map to be loaded in Simulator +LGSVL__RANDOM_SEED Simulation random seed +LGSVL__SIMULATION_DURATION_SECS How long to run the simulation for +LGSVL__SIMULATOR_HOST IP address of computer running simulator (Master node if a cluster) +LGSVL__SIMULATOR_PORT Port that the simulator allows websocket connections over +LGSVL__VEHICLE_0 ID of EGO vehicle to be loaded in Simulator +''' + +env = Env() + +SIMULATOR_HOST = env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1") +SIMULATOR_PORT = env.int("LGSVL__SIMULATOR_PORT", 8181) +BRIDGE_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +BRIDGE_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) + +# Map name is passed to WISE instead ID by default. +LGSVL__MAP = env.str("LGSVL__MAP", "san_francisco") +# Here we intentionally make a typo in envrionment variable name and +# use LGSVL__VEHICLE_1 instead of LGSVL__VEHICLE_0 because +# otherwise it will receive proper vehicle ID and simulator will fail, +# since IDs are not supported yet. So for now it will fail to read +# environment variable and use vehicle name as backup option +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 (modular testing) +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/5c7fb3b0-1fd4-4943-8347-f73a05749718 +DEFAULT_VEHICLE_CONFIG = "5c7fb3b0-1fd4-4943-8347-f73a05749718" +LGSVL__VEHICLE_0 = env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG) +LGSVL__AUTOPILOT_HD_MAP = env.str("LGSVL__AUTOPILOT_HD_MAP", "SanFrancisco") +LGSVL__AUTOPILOT_0_VEHICLE_CONFIG = env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ') +LGSVL__SIMULATION_DURATION_SECS = 120.0 +LGSVL__RANDOM_SEED = env.int("LGSVL__RANDOM_SEED", 51472) + +sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) +try: + print("Loading map {}...".format(SIMULATOR_MAP)) + sim.load(SIMULATOR_MAP, LGSVL__RANDOM_SEED) # laod map with random seed +except Exception: + if sim.current_scene == SIMULATOR_MAP: + sim.reset() + else: + sim.load(SIMULATOR_MAP) + + +# reset time of the day +sim.set_date_time(datetime(2020, 7, 1, 15, 0, 0, 0), True) + +spawns = sim.get_spawn() +# select spawn deterministically depending on the seed +spawn_index = LGSVL__RANDOM_SEED % len(spawns) + +state = lgsvl.AgentState() +state.transform = spawns[spawn_index] # TODO some sort of Env Variable so that user/wise can select from list +print("Loading vehicle {}...".format(LGSVL__VEHICLE_0)) +ego = sim.add_agent(LGSVL__VEHICLE_0, lgsvl.AgentType.EGO, state) + +print("Connecting to bridge...") +# The EGO is now looking for a bridge at the specified IP and port +ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT) + +def on_collision(agent1, agent2, contact): + raise Exception("{} collided with {}".format(agent1, agent2)) + sys.exit() + +ego.on_collision(on_collision) + +dv = lgsvl.dreamview.Connection(sim, ego, BRIDGE_HOST) +dv.set_hd_map(LGSVL__AUTOPILOT_HD_MAP) +dv.set_vehicle(LGSVL__AUTOPILOT_0_VEHICLE_CONFIG) + +destination_index = LGSVL__RANDOM_SEED % len(spawns[spawn_index].destinations) +destination = spawns[spawn_index].destinations[destination_index] # TODO some sort of Env Variable so that user/wise can select from list + +default_modules = [ + 'Localization', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Control', + 'Recorder' +] + +dv.disable_apollo() +dv.setup_apollo(destination.position.x, destination.position.z, default_modules) + +print("adding npcs") +sim.add_random_agents(lgsvl.AgentType.NPC) +sim.add_random_agents(lgsvl.AgentType.PEDESTRIAN) + +sim.run(LGSVL__SIMULATION_DURATION_SECS) diff --git a/examples/SampleTestCases/random-traffic.py b/examples/SampleTestCases/random-traffic.py new file mode 100755 index 0000000..8a90e64 --- /dev/null +++ b/examples/SampleTestCases/random-traffic.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +from datetime import datetime +import random +from environs import Env + +import lgsvl + +''' +LGSVL__AUTOPILOT_0_HOST IP address of the computer running the bridge to connect to +LGSVL__AUTOPILOT_0_PORT Port that the bridge listens on for messages +LGSVL__AUTOPILOT_0_VEHICLE_CONFIG Vehicle configuration to be loaded in Dreamview (Capitalization and spacing must match the dropdown in Dreamview) +LGSVL__AUTOPILOT_HD_MAP HD map to be loaded in Dreamview (Capitalization and spacing must match the dropdown in Dreamview) +LGSVL__AUTOPILOT_0_VEHICLE_MODULES List of modules to be enabled in Dreamview (Capitalization and space must match the sliders in Dreamview) +LGSVL__DATE_TIME Date and time to start simulation at, format 'YYYY-mm-ddTHH:MM:SS' +LGSVL__ENVIRONMENT_CLOUDINESS Value of clouds weather effect, clamped to [0, 1] +LGSVL__ENVIRONMENT_DAMAGE Value of road damage effect, clamped to [0, 1] +LGSVL__ENVIRONMENT_FOG Value of fog weather effect, clamped to [0, 1] +LGSVL__ENVIRONMENT_RAIN Value of rain weather effect, clamped to [0, 1] +LGSVL__ENVIRONMENT_WETNESS Value of wetness weather effect, clamped to [0, 1] +LGSVL__MAP Name of map to be loaded in Simulator +LGSVL__RANDOM_SEED Seed used to determine random factors (e.g. NPC type, color, behaviour) +LGSVL__SIMULATION_DURATION_SECS How long to run the simulation for +LGSVL__SIMULATOR_HOST IP address of computer running simulator (Master node if a cluster) +LGSVL__SIMULATOR_PORT Port that the simulator allows websocket connections over +LGSVL__SPAWN_BICYCLES Wether or not to spawn bicycles +LGSVL__SPAWN_PEDESTRIANS Whether or not to spawn pedestrians +LGSVL__SPAWN_TRAFFIC Whether or not to spawn NPC vehicles +LGSVL__TIME_OF_DAY If LGSVL__DATE_TIME is not set, today's date is used and this sets the time of day to start simulation at, clamped to [0, 24] +LGSVL__TIME_STATIC Whether or not time should remain static (True = time is static, False = time moves forward) +LGSVL__VEHICLE_0 Name of EGO vehicle to be loaded in Simulator +''' + +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) +scene_name = env.str("LGSVL__MAP", "BorregasAve") +try: + sim.load(scene_name, env.int("LGSVL__RANDOM_SEED")) +except Exception: + if sim.current_scene == scene_name: + sim.reset() + else: + sim.load(scene_name) + + +def clamp(val, min_v, max_v): + return min(max(val, min_v), max_v) + + +try: + date_time = env.str("LGSVL__DATE_TIME") +except Exception: + date_time = "1970-01-01T00:00:00" +else: + static_time = env.bool("LGSVL__TIME_STATIC", True) + if date_time == "1970-01-01T00:00:00": + time_of_day = clamp(env.float("LGSVL__TIME_OF_DAY", 12), 0, 24) + sim.set_time_of_day(time_of_day, static_time) + else: + sim.set_date_time(datetime.strptime(date_time[:19], '%Y-%m-%dT%H:%M:%S'), static_time) + + +rain = clamp(env.float("LGSVL__ENVIRONMENT_RAIN", 0), 0, 1) +fog = clamp(env.float("LGSVL__ENVIRONMENT_FOG", 0), 0, 1) +wetness = clamp(env.float("LGSVL__ENVIRONMENT_WETNESS", 0), 0, 1) +cloudiness = clamp(env.float("LGSVL__ENVIRONMENT_CLOUDINESS", 0), 0, 1) +damage = clamp(env.float("LGSVL__ENVIRONMENT_DAMAGE", 0), 0, 1) + +sim.weather = lgsvl.WeatherState(rain, fog, wetness, cloudiness, damage) + +spawns = sim.get_spawn() +spawn_index = random.randrange(len(spawns)) + +state = lgsvl.AgentState() +state.transform = spawns[spawn_index] # TODO some sort of Env Variable so that user/wise can select from list +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, state) + +# The EGO is now looking for a bridge at the specified IP and port +BRIDGE_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +ego.connect_bridge(BRIDGE_HOST, env.int("LGSVL__AUTOPILOT_0_PORT", 9090)) + +dv = lgsvl.dreamview.Connection(sim, ego, BRIDGE_HOST) +dv.set_hd_map(env.str("LGSVL__AUTOPILOT_HD_MAP", "Borregas Ave")) +dv.set_vehicle(env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ')) +default_modules = [ + 'Localization', + 'Perception', + 'Transform', + 'Routing', + 'Prediction', + 'Planning', + 'Traffic Light', + 'Control', + 'Recorder' +] + +try: + modules = env.list("LGSVL__AUTOPILOT_0_VEHICLE_MODULES", subcast=str) + if len(modules) == 0: + modules = default_modules +except Exception: + modules = default_modules + +destination_index = random.randrange(len(spawns[spawn_index].destinations)) +destination = spawns[spawn_index].destinations[destination_index] # TODO some sort of Env Variable so that user/wise can select from list +dv.setup_apollo(destination.position.x, destination.position.z, modules) + +if env.bool("LGSVL__SPAWN_TRAFFIC", True): + sim.add_random_agents(lgsvl.AgentType.NPC) + +if env.bool("LGSVL__SPAWN_PEDESTRIANS", True): + sim.add_random_agents(lgsvl.AgentType.PEDESTRIAN) + +sim.run(env.float("LGSVL__SIMULATION_DURATION_SECS", 0)) diff --git a/examples/SampleTestCases/red-light-runner.py b/examples/SampleTestCases/red-light-runner.py new file mode 100755 index 0000000..e2bd78e --- /dev/null +++ b/examples/SampleTestCases/red-light-runner.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# LGSVL__SIMULATOR_HOST and LGSVL__AUTOPILOT_0_HOST are environment variables +# They can be set for the terminal instance with `export LGSVL__SIMULATOR_HOST=###` +# which will use the set value for all future commands in that terminal. +# To set the variable for only a particular execution, run the script in this way +# `LGSVL__SIMULATOR_HOST=### LGSVL__AUTOPILOT_0_HOST=### python3 cut-in.py` + +# LGSVL__SIMULATOR_HOST is the IP of the computer running the simulator +# LGSVL__AUTOPILOT_0_HOST is the IP of the computer running the bridge (from the perspective of the Simulator) +# If the simulator and bridge are running on the same computer, then the default values will work. +# Otherwise the variables must be set for in order to connect to the simulator and the bridge to receive data. +# LGSVL__SIMULATOR_PORT and LGSVL__AUTOPILOT_0_HOST need to be set if non-default ports will be used + +import os +import lgsvl +import sys + +SIMULATOR_HOST = os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1") +SIMULATOR_PORT = int(os.environ.get("LGSVL__SIMULATOR_PORT", 8181)) +BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090)) + +sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) +if sim.current_scene == "BorregasAve": + sim.reset() +else: + sim.load("BorregasAve", seed=0) + +# spawn EGO +egoState = lgsvl.AgentState() +egoState.transform = sim.get_spawn()[0] +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT) + +forward = lgsvl.utils.transform_to_forward(egoState.transform) # Unit vector in the forward direction of the EGO +right = lgsvl.utils.transform_to_right(egoState.transform) # Unit vector in the right direction of the EGO + +# spawn NPC +npcState = lgsvl.AgentState() +npcState.transform = sim.map_point_on_lane(egoState.position + 51.1 * forward + 29 * right) # NPC is 20m ahead of the EGO +npc = sim.add_agent("SUV", lgsvl.AgentType.NPC, npcState) + +# This function will be called if a collision occurs +def on_collision(agent1, agent2, contact): + raise Exception("{} collided with {}".format(agent1, agent2)) + +ego.on_collision(on_collision) +npc.on_collision(on_collision) + +controlReceived = False + +# This function will be called when the Simulator receives the first message on the topic defined in the CheckControlSensor configuration +def on_control_received(agent, kind, context): + global controlReceived + # There can be multiple custom callbacks defined, this checks for the appropriate kind + if kind == "checkControl": + # Stops the Simulator running, this will only interrupt the first sim.run(30) call + sim.stop() + controlReceived = True + +ego.on_custom(on_control_received) + +# Run Simulator for at most 30 seconds for the AD stack to to initialize +sim.run(30) + +# If a Control message was not received, then the AD stack is not ready and the scenario should not continue +if not controlReceived: + raise Exception("AD stack is not ready") + sys.exit() + +# Create the list of waypoints for the npc to follow +waypoints = [] +# First waypoint is the same position that the npc is spawned. The npc will wait here until the EGO is within 50m +waypoints.append(lgsvl.DriveWaypoint(position=npcState.position, speed=20.1168, angle=npcState.rotation, idle=0, deactivate=False, trigger_distance=35)) +# Second waypoint is across the intersection +endPoint = sim.map_point_on_lane(egoState.position + 51.1 * forward - 63.4 * right) +waypoints.append(lgsvl.DriveWaypoint(position=endPoint.position, speed=0, angle=endPoint.rotation)) +npc.follow(waypoints) + +# Set all the traffic lights to green. +# It is possible to set only the lights visible by the EGO to green, but positions of the lights must be known +signals = sim.get_controllables("signal") +for signal in signals: + signal.control("green=3") + +# Run the simulation for 30 seconds +sim.run(30) diff --git a/examples/SampleTestCases/sudden-braking.py b/examples/SampleTestCases/sudden-braking.py new file mode 100755 index 0000000..c571db8 --- /dev/null +++ b/examples/SampleTestCases/sudden-braking.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +# LGSVL__SIMULATOR_HOST and LGSVL__AUTOPILOT_0_HOST are environment variables +# They can be set for the terminal instance with `export LGSVL__SIMULATOR_HOST=###` +# which will use the set value for all future commands in that terminal. +# To set the variable for only a particular execution, run the script in this way +# `LGSVL__SIMULATOR_HOST=### LGSVL__AUTOPILOT_0_HOST=### python3 cut-in.py` + +# LGSVL__SIMULATOR_HOST is the IP of the computer running the simulator +# LGSVL__AUTOPILOT_0_HOST is the IP of the computer running the bridge (from the perspective of the Simulator) +# If the simulator and bridge are running on the same computer, then the default values will work. +# Otherwise the variables must be set for in order to connect to the simulator and the bridge to receive data. +# LGSVL__SIMULATOR_PORT and LGSVL__AUTOPILOT_0_HOST need to be set if non-default ports will be used + +import os +import lgsvl +import sys + +SIMULATOR_HOST = os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1") +SIMULATOR_PORT = int(os.environ.get("LGSVL__SIMULATOR_PORT", 8181)) +BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") +BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090)) + +sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) +if sim.current_scene == "SingleLaneRoad": + sim.reset() +else: + sim.load("SingleLaneRoad", seed=0) + +# spawn EGO +egoState = lgsvl.AgentState() +egoState.transform = sim.get_spawn()[0] +# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 +# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 +DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" +ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT) + +forward = lgsvl.utils.transform_to_forward(egoState.transform) # Unit vector in the forward direction of the EGO + +# spawn NPC +npcState = lgsvl.AgentState() +npcState.transform = egoState.transform +npcState.transform.position = egoState.position + 20 * forward # NPC is 20m ahead of the EGO +npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, npcState) + +# This function will be called if a collision occurs +def on_collision(agent1, agent2, contact): + raise Exception("{} collided with {}".format(agent1, agent2)) + +ego.on_collision(on_collision) +npc.on_collision(on_collision) + +controlReceived = False + +# This function will be called when the Simulator receives the first message on the topic defined in the CheckControlSensor configuration +def on_control_received(agent, kind, context): + global controlReceived + # There can be multiple custom callbacks defined, this checks for the appropriate kind + if kind == "checkControl": + # Stops the Simulator running, this will only interrupt the first sim.run(30) call + sim.stop() + controlReceived = True + +ego.on_custom(on_control_received) + +# Run Simulator for at most 30 seconds for the AD stack to to initialize +sim.run(30) + +# If a Control message was not received, then the AD stack is not ready and the scenario should not continue +if not controlReceived: + raise Exception("AD stack is not ready") + sys.exit() + +# NPC will follow the HD map at a max speed of 11.176 m/s (25 mph) +npc.follow_closest_lane(follow=True, max_speed=11.176) + +# Run Simulation for 10 seconds +sim.run(10) + +# Force the NPC to come to a stop +control = lgsvl.NPCControl() +control.e_stop = True + +npc.apply_control(control) + +# Simulation will run for 10 seconds +# NPC will be stopped for this time +sim.run(10) + +# NPC told to resume following the HD map +npc.follow_closest_lane(True, 11.176) + +# Simulation runs for another 10 seconds +sim.run(10) From 81a451fd3bd49c60ef7df35da381b022b64668c4 Mon Sep 17 00:00:00 2001 From: Lokesh Kumar Goel Date: Tue, 9 Mar 2021 13:50:44 -0800 Subject: [PATCH 068/115] NHTSA: use default vehicle config from settings Change-Id: Ic4e2de72e75cc196359b691136de1f743252ce77 --- examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py | 5 +++-- examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py | 5 +++-- examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py | 5 +++-- examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py | 5 +++-- examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py | 5 +++-- examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py | 5 +++-- examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py | 5 +++-- examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py | 5 +++-- examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_B_15.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_B_25.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_B_35.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py | 5 +++-- examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py | 5 +++-- examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py | 5 +++-- examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py | 5 +++-- settings.py | 4 ++++ 25 files changed, 76 insertions(+), 48 deletions(-) diff --git a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py index b5adc2a..99d65db 100755 --- a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py +++ b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -44,8 +46,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(-1.6, 0, -65)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py index 2e927bb..87351c5 100755 --- a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py +++ b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -44,8 +46,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(-1.6, 0, -65)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py index 60a71b2..66453c2 100755 --- a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py +++ b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -44,8 +46,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(-1.6, 0, -65)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py index 25ec862..97f0347 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -42,8 +44,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py index 5b9323d..f8c53ff 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -42,8 +44,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py index 2644291..60c5e02 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -42,8 +44,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py index 30b2eb7..e56066c 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -42,8 +44,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py index f395809..5445581 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py @@ -16,6 +16,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -47,8 +49,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py index dac7e59..be7ec81 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -42,8 +44,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py index 0e143c9..1db0a08 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -41,8 +43,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py index 77e4756..fecc934 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -41,8 +43,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py index 2489f74..9707217 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -41,8 +43,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py index 4c62106..b47ffe6 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -43,8 +45,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py index 31df3b4..771d664 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -43,8 +45,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py index 17d4d29..0f55ee8 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -43,8 +45,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py index 0124896..cc60cd4 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py @@ -17,6 +17,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -49,8 +51,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py index 521b01b..40b0ac3 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -43,8 +45,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py index 610043f..7fc3261 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -43,8 +45,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py index 96ab341..b9473d4 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -41,8 +43,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py index 026adbd..ab7846c 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -41,8 +43,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py index 1b8afc0..ed7e155 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -41,8 +43,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py b/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py index 6e440ed..6ec383c 100755 --- a/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py +++ b/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -44,8 +46,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(1, 0, 65)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py b/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py index 8f01fed..3c4b2ec 100755 --- a/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py +++ b/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -43,8 +45,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(1, 0, 65)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py b/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py index efab028..b3dcfcb 100755 --- a/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py +++ b/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py @@ -11,6 +11,8 @@ import logging from environs import Env import lgsvl +from settings import SimulatorSettings + FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) log = logging.getLogger(__name__) @@ -43,8 +45,7 @@ egoState.transform = sim.map_point_on_lane(lgsvl.Vector(1, 0, 65)) # Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/settings.py b/settings.py index d71bead..7cc0d71 100644 --- a/settings.py +++ b/settings.py @@ -35,3 +35,7 @@ class SimulatorSettings: # Ego vehicle that is loaded in quickstart/tests scripts. Default value is "Jaguar2015XE - AutowareAI". # https://wise.svlsimulator.com/vehicles/profile/3f4211dc-e5d7-42dc-94c5-c4832b1331bb/edit/configuration/05cbb194-d095-4a0e-ae66-ff56c331ca83 ego_jaguae2015xe_autowareai = "05cbb194-d095-4a0e-ae66-ff56c331ca83" + + # Ego vehicle that is loaded in most of the NHTSA example scripts. Default value is "Lincoln2017MKZ - Full Analysis". This includes bunch of sensors that help analyze test results efficiently. + # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/22656c7b-104b-4e6a-9c70-9955b6582220 + ego_lincoln2017mkz_apollo5_full_analysis = "22656c7b-104b-4e6a-9c70-9955b6582220" From 00dc4d5d07c1ba7ac054dc3c4476628cfba5b107 Mon Sep 17 00:00:00 2001 From: Lokesh Kumar Goel Date: Tue, 9 Mar 2021 15:10:07 -0800 Subject: [PATCH 069/115] SampleTestCases: use default vehicle config from settings Change-Id: I35eccace850dc686b37acb28af8695f90dbb3b9c --- examples/SampleTestCases/cut-in.py | 7 +++---- examples/SampleTestCases/ped-crossing.py | 7 +++---- examples/SampleTestCases/random-traffic-local.py | 7 +++---- examples/SampleTestCases/random-traffic.py | 7 +++---- examples/SampleTestCases/red-light-runner.py | 7 +++---- examples/SampleTestCases/sudden-braking.py | 7 +++---- settings.py | 4 ++++ 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/examples/SampleTestCases/cut-in.py b/examples/SampleTestCases/cut-in.py index 1325011..c0a19c9 100755 --- a/examples/SampleTestCases/cut-in.py +++ b/examples/SampleTestCases/cut-in.py @@ -19,6 +19,8 @@ import os import lgsvl +from settings import SimulatorSettings + import time import sys @@ -37,10 +39,7 @@ egoState = lgsvl.AgentState() # Spawn point found in Unity Editor egoState.transform = sim.map_point_on_lane(lgsvl.Vector(773.29, 10.24, -10.79)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT) right = lgsvl.utils.transform_to_right(egoState.transform) # Unit vector in the right direction of the EGO diff --git a/examples/SampleTestCases/ped-crossing.py b/examples/SampleTestCases/ped-crossing.py index aa18600..cd57e48 100755 --- a/examples/SampleTestCases/ped-crossing.py +++ b/examples/SampleTestCases/ped-crossing.py @@ -19,6 +19,8 @@ import os import lgsvl +from settings import SimulatorSettings + import sys SIMULATOR_HOST = os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1") @@ -35,10 +37,7 @@ # spawn EGO egoState = lgsvl.AgentState() egoState.transform = sim.get_spawn()[0] -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT) # spawn PED diff --git a/examples/SampleTestCases/random-traffic-local.py b/examples/SampleTestCases/random-traffic-local.py index 2e32945..ba3d44e 100755 --- a/examples/SampleTestCases/random-traffic-local.py +++ b/examples/SampleTestCases/random-traffic-local.py @@ -9,6 +9,8 @@ from environs import Env import random import lgsvl +from settings import SimulatorSettings + ''' LGSVL__AUTOPILOT_0_HOST IP address of the computer running the bridge to connect to @@ -37,10 +39,7 @@ # otherwise it will receive proper vehicle ID and simulator will fail, # since IDs are not supported yet. So for now it will fail to read # environment variable and use vehicle name as backup option -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 (modular testing) -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/5c7fb3b0-1fd4-4943-8347-f73a05749718 -DEFAULT_VEHICLE_CONFIG = "5c7fb3b0-1fd4-4943-8347-f73a05749718" -LGSVL__VEHICLE_0 = env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG) +LGSVL__VEHICLE_0 = env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_modular) LGSVL__AUTOPILOT_HD_MAP = env.str("LGSVL__AUTOPILOT_HD_MAP", "SanFrancisco") LGSVL__AUTOPILOT_0_VEHICLE_CONFIG = env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ') LGSVL__SIMULATION_DURATION_SECS = 120.0 diff --git a/examples/SampleTestCases/random-traffic.py b/examples/SampleTestCases/random-traffic.py index 8a90e64..db5bf6b 100755 --- a/examples/SampleTestCases/random-traffic.py +++ b/examples/SampleTestCases/random-traffic.py @@ -10,6 +10,8 @@ from environs import Env import lgsvl +from settings import SimulatorSettings + ''' LGSVL__AUTOPILOT_0_HOST IP address of the computer running the bridge to connect to @@ -79,10 +81,7 @@ def clamp(val, min_v, max_v): state = lgsvl.AgentState() state.transform = spawns[spawn_index] # TODO some sort of Env Variable so that user/wise can select from list -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, state) # The EGO is now looking for a bridge at the specified IP and port BRIDGE_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") diff --git a/examples/SampleTestCases/red-light-runner.py b/examples/SampleTestCases/red-light-runner.py index e2bd78e..b70b68b 100755 --- a/examples/SampleTestCases/red-light-runner.py +++ b/examples/SampleTestCases/red-light-runner.py @@ -19,6 +19,8 @@ import os import lgsvl +from settings import SimulatorSettings + import sys SIMULATOR_HOST = os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1") @@ -35,10 +37,7 @@ # spawn EGO egoState = lgsvl.AgentState() egoState.transform = sim.get_spawn()[0] -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT) forward = lgsvl.utils.transform_to_forward(egoState.transform) # Unit vector in the forward direction of the EGO diff --git a/examples/SampleTestCases/sudden-braking.py b/examples/SampleTestCases/sudden-braking.py index c571db8..fb0e167 100755 --- a/examples/SampleTestCases/sudden-braking.py +++ b/examples/SampleTestCases/sudden-braking.py @@ -19,6 +19,8 @@ import os import lgsvl +from settings import SimulatorSettings + import sys SIMULATOR_HOST = os.environ.get("LGSVL__SIMULATOR_HOST", "127.0.0.1") @@ -35,10 +37,7 @@ # spawn EGO egoState = lgsvl.AgentState() egoState.transform = sim.get_spawn()[0] -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 -DEFAULT_VEHICLE_CONFIG = "47b529db-0593-4908-b3e7-4b24a32a0f70" -ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", DEFAULT_VEHICLE_CONFIG), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT) forward = lgsvl.utils.transform_to_forward(egoState.transform) # Unit vector in the forward direction of the EGO diff --git a/settings.py b/settings.py index 7cc0d71..4f35d77 100644 --- a/settings.py +++ b/settings.py @@ -39,3 +39,7 @@ class SimulatorSettings: # Ego vehicle that is loaded in most of the NHTSA example scripts. Default value is "Lincoln2017MKZ - Full Analysis". This includes bunch of sensors that help analyze test results efficiently. # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/22656c7b-104b-4e6a-9c70-9955b6582220 ego_lincoln2017mkz_apollo5_full_analysis = "22656c7b-104b-4e6a-9c70-9955b6582220" + + # Ego vehicle that is loaded in most of the NHTSA example scripts. Default value is "Lincoln2017MKZ - Apollo 5 modular". This has sensors for modular testing. + # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/5c7fb3b0-1fd4-4943-8347-f73a05749718 + ego_lincoln2017mkz_apollo5_modular = "5c7fb3b0-1fd4-4943-8347-f73a05749718" From adad8a8349a02634f93df19a1caaa3f2954d0249 Mon Sep 17 00:00:00 2001 From: Lokesh Kumar Goel Date: Tue, 9 Mar 2021 16:13:38 -0800 Subject: [PATCH 070/115] SampleTestCases: Update map to uuid from settings Change-Id: I7c312c520ab1ae6ec4fd3561a6076c005cddf0b5 --- examples/SampleTestCases/cut-in.py | 6 +++-- examples/SampleTestCases/ped-crossing.py | 5 +++-- .../SampleTestCases/random-traffic-local.py | 22 +++++++------------ examples/SampleTestCases/random-traffic.py | 2 +- examples/SampleTestCases/red-light-runner.py | 5 +++-- examples/SampleTestCases/sudden-braking.py | 5 +++-- settings.py | 12 ++++++++++ 7 files changed, 34 insertions(+), 23 deletions(-) diff --git a/examples/SampleTestCases/cut-in.py b/examples/SampleTestCases/cut-in.py index c0a19c9..46408bd 100755 --- a/examples/SampleTestCases/cut-in.py +++ b/examples/SampleTestCases/cut-in.py @@ -29,11 +29,13 @@ BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090)) +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_sanfrancisco) + sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) -if sim.current_scene == "SanFrancisco": +if sim.current_scene == scene_name: sim.reset() else: - sim.load("SanFrancisco", seed=0) + sim.load(scene_name, seed=0) # spawn EGO egoState = lgsvl.AgentState() diff --git a/examples/SampleTestCases/ped-crossing.py b/examples/SampleTestCases/ped-crossing.py index cd57e48..7840200 100755 --- a/examples/SampleTestCases/ped-crossing.py +++ b/examples/SampleTestCases/ped-crossing.py @@ -28,11 +28,12 @@ BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090)) +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanepedestriancrosswalk) sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) -if sim.current_scene == "Straight1LanePedestrianCrosswalk": +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight1LanePedestrianCrosswalk") + sim.load(scene_name) # spawn EGO egoState = lgsvl.AgentState() diff --git a/examples/SampleTestCases/random-traffic-local.py b/examples/SampleTestCases/random-traffic-local.py index ba3d44e..dcb1763 100755 --- a/examples/SampleTestCases/random-traffic-local.py +++ b/examples/SampleTestCases/random-traffic-local.py @@ -32,28 +32,22 @@ BRIDGE_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") BRIDGE_PORT = env.int("LGSVL__AUTOPILOT_0_PORT", 9090) -# Map name is passed to WISE instead ID by default. -LGSVL__MAP = env.str("LGSVL__MAP", "san_francisco") -# Here we intentionally make a typo in envrionment variable name and -# use LGSVL__VEHICLE_1 instead of LGSVL__VEHICLE_0 because -# otherwise it will receive proper vehicle ID and simulator will fail, -# since IDs are not supported yet. So for now it will fail to read -# environment variable and use vehicle name as backup option -LGSVL__VEHICLE_0 = env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_modular) LGSVL__AUTOPILOT_HD_MAP = env.str("LGSVL__AUTOPILOT_HD_MAP", "SanFrancisco") LGSVL__AUTOPILOT_0_VEHICLE_CONFIG = env.str("LGSVL__AUTOPILOT_0_VEHICLE_CONFIG", 'Lincoln2017MKZ') LGSVL__SIMULATION_DURATION_SECS = 120.0 LGSVL__RANDOM_SEED = env.int("LGSVL__RANDOM_SEED", 51472) +vehicle_conf = env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_modular) +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_sanfrancisco) sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) try: - print("Loading map {}...".format(SIMULATOR_MAP)) - sim.load(SIMULATOR_MAP, LGSVL__RANDOM_SEED) # laod map with random seed + print("Loading map {}...".format(scene_name)) + sim.load(scene_name, LGSVL__RANDOM_SEED) # laod map with random seed except Exception: - if sim.current_scene == SIMULATOR_MAP: + if sim.current_scene == scene_name: sim.reset() else: - sim.load(SIMULATOR_MAP) + sim.load(scene_name) # reset time of the day @@ -65,8 +59,8 @@ state = lgsvl.AgentState() state.transform = spawns[spawn_index] # TODO some sort of Env Variable so that user/wise can select from list -print("Loading vehicle {}...".format(LGSVL__VEHICLE_0)) -ego = sim.add_agent(LGSVL__VEHICLE_0, lgsvl.AgentType.EGO, state) +print("Loading vehicle {}...".format(vehicle_conf)) +ego = sim.add_agent(vehicle_conf, lgsvl.AgentType.EGO, state) print("Connecting to bridge...") # The EGO is now looking for a bridge at the specified IP and port diff --git a/examples/SampleTestCases/random-traffic.py b/examples/SampleTestCases/random-traffic.py index db5bf6b..75e61e7 100755 --- a/examples/SampleTestCases/random-traffic.py +++ b/examples/SampleTestCases/random-traffic.py @@ -41,7 +41,7 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -scene_name = env.str("LGSVL__MAP", "BorregasAve") +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_borregasave) try: sim.load(scene_name, env.int("LGSVL__RANDOM_SEED")) except Exception: diff --git a/examples/SampleTestCases/red-light-runner.py b/examples/SampleTestCases/red-light-runner.py index b70b68b..dc4a360 100755 --- a/examples/SampleTestCases/red-light-runner.py +++ b/examples/SampleTestCases/red-light-runner.py @@ -28,11 +28,12 @@ BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090)) +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_borregasave) sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) -if sim.current_scene == "BorregasAve": +if sim.current_scene == scene_name: sim.reset() else: - sim.load("BorregasAve", seed=0) + sim.load(scene_name, seed=0) # spawn EGO egoState = lgsvl.AgentState() diff --git a/examples/SampleTestCases/sudden-braking.py b/examples/SampleTestCases/sudden-braking.py index fb0e167..18131a9 100755 --- a/examples/SampleTestCases/sudden-braking.py +++ b/examples/SampleTestCases/sudden-braking.py @@ -28,11 +28,12 @@ BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090)) +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_singlelaneroad) sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) -if sim.current_scene == "SingleLaneRoad": +if sim.current_scene == scene_name: sim.reset() else: - sim.load("SingleLaneRoad", seed=0) + sim.load(scene_name, seed=0) # spawn EGO egoState = lgsvl.AgentState() diff --git a/settings.py b/settings.py index 4f35d77..ae2378b 100644 --- a/settings.py +++ b/settings.py @@ -24,6 +24,18 @@ class SimulatorSettings: # https://wise.svlsimulator.com/maps/profile/aae03d2a-b7ca-4a88-9e41-9035287a12cc map_borregasave = "aae03d2a-b7ca-4a88-9e41-9035287a12cc" + # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "SanFrancisco" + # https://wise.svlsimulator.com/maps/profile/5d272540-f689-4355-83c7-03bf11b6865f + map_sanfrancisco = "5d272540-f689-4355-83c7-03bf11b6865f" + + # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "Straight1LanePedestrianCrosswalk" + # https://wise.svlsimulator.com/maps/profile/a3a818b5-c66b-488a-a780-979bd5692db1 + map_straight1lanepedestriancrosswalk = "a3a818b5-c66b-488a-a780-979bd5692db1" + + # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "SingleLaneRoad" + # https://wise.svlsimulator.com/maps/profile/dac1a8fc-054d-4f32-9f64-d24efe6c0fc9 + map_singlelaneroad = "dac1a8fc-054d-4f32-9f64-d24efe6c0fc9" + # Ego vehicle that is loaded in most of the quickstart scripts. Default value is "Lincoln2017MKZ". This includes a bridge connection if needed and also bunch of sensors including LIDAR. # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego_lincoln2017mkz_apollo5 = "47b529db-0593-4908-b3e7-4b24a32a0f70" From 53d0aea700fa675a68c5498ee340e01848213e49 Mon Sep 17 00:00:00 2001 From: Lokesh Kumar Goel Date: Tue, 9 Mar 2021 16:28:03 -0800 Subject: [PATCH 071/115] NHTSA: Use uuid for map from settings Change-Id: Icd95c2b929c3474477fafdf6eacdcaa01ae92d6b --- .../Encroaching-Oncoming-Vehicles/EOV_S_25_20.py | 5 +++-- .../Encroaching-Oncoming-Vehicles/EOV_S_45_40.py | 5 +++-- .../Encroaching-Oncoming-Vehicles/EOV_S_65_60.py | 5 +++-- .../NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py | 5 +++-- .../NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py | 5 +++-- .../NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py | 5 +++-- .../NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py | 5 +++-- .../NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py | 5 +++-- .../NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_B_15.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_B_25.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_B_35.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py | 5 +++-- examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py | 5 +++-- examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py | 5 +++-- examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py | 5 +++-- examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py | 5 +++-- settings.py | 12 ++++++++++++ 25 files changed, 84 insertions(+), 48 deletions(-) diff --git a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py index 99d65db..3b95f9a 100755 --- a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py +++ b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py @@ -34,10 +34,11 @@ print("EOV_S_25_20 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneOpposing": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2laneopposing) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneOpposing") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py index 87351c5..4b1d1ab 100755 --- a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py +++ b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py @@ -34,10 +34,11 @@ print("EOV_S_45_40 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneOpposing": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2laneopposing) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneOpposing") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py index 66453c2..7874dfa 100755 --- a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py +++ b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py @@ -34,10 +34,11 @@ print("EOV_S_65_60 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneOpposing": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2laneopposing) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneOpposing") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py index 97f0347..1080a26 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py @@ -32,10 +32,11 @@ print("MOTL_Comp_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSameCurbRightIntersection": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2lanesamecurbrightintersection) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSameCurbRightIntersection") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py index f8c53ff..6eeaccd 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py @@ -32,10 +32,11 @@ print("MOTL_Comp_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSameCurbRightIntersection": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2lanesamecurbrightintersection) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSameCurbRightIntersection") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py index 60c5e02..a838838 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py @@ -32,10 +32,11 @@ print("MOTL_Neg_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSameCurbRightIntersection": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2lanesamecurbrightintersection) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSameCurbRightIntersection") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py index e56066c..42a2ad6 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py @@ -32,10 +32,11 @@ print("MOTL_Neg_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSameCurbRightIntersection": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2lanesamecurbrightintersection) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSameCurbRightIntersection") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py index 5445581..dc4820b 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py @@ -37,10 +37,11 @@ print("MOTL_Simp_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSameCurbRightIntersection": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2lanesamecurbrightintersection) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSameCurbRightIntersection") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py index be7ec81..09c6016 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py @@ -32,10 +32,11 @@ print("MOTL_Simp_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSameCurbRightIntersection": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2lanesamecurbrightintersection) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSameCurbRightIntersection") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py index 1db0a08..565c03c 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py @@ -31,10 +31,11 @@ print("PLC_B_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSame": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSame") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py index fecc934..edc3350 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py @@ -31,10 +31,11 @@ print("PLC_B_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSame": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSame") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py index 9707217..10f992f 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py @@ -31,10 +31,11 @@ print("PLC_B_35 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSame": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSame") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py index b47ffe6..3caa1fe 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py @@ -33,10 +33,11 @@ print("PLC_CP_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSame": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSame") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py index 771d664..93c3aa4 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py @@ -33,10 +33,11 @@ print("PLC_CP_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSame": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSame") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py index 0f55ee8..69a4576 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py @@ -33,10 +33,11 @@ print("PLC_CP_35 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSame": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSame") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py index cc60cd4..2f8fedf 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py @@ -39,10 +39,11 @@ print("PLC_SN_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSame": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSame") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py index 40b0ac3..00e8a65 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py @@ -33,10 +33,11 @@ print("PLC_SN_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSame": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSame") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py index 7fc3261..188892e 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py @@ -33,10 +33,11 @@ print("PLC_SN_35 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSame": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSame") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py index b9473d4..6d793d6 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py @@ -31,10 +31,11 @@ print("PLC_SP_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSame": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSame") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py index ab7846c..d50b0b2 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py @@ -31,10 +31,11 @@ print("PLC_SP_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSame": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSame") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py index ed7e155..9f8db42 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py @@ -31,10 +31,11 @@ print("PLC_SP_35 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight2LaneSame": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight2LaneSame") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py b/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py index 6ec383c..abfb412 100755 --- a/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py +++ b/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py @@ -35,10 +35,11 @@ print("VF_S_25_Slow - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight1LaneSame": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight1LaneSame") + sim.load(scene_name) sim.set_time_of_day(12) # spawn EGO in the 2nd to right lane diff --git a/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py b/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py index 3c4b2ec..d1a91cf 100755 --- a/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py +++ b/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py @@ -35,10 +35,11 @@ print("VF_S_45_Slow - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight1LaneSame": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight1LaneSame") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py b/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py index b3dcfcb..3b904ac 100755 --- a/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py +++ b/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py @@ -35,10 +35,11 @@ print("VF_S_65_Slow - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -if sim.current_scene == "Straight1LaneSame": +scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +if sim.current_scene == scene_name: sim.reset() else: - sim.load("Straight1LaneSame") + sim.load(scene_name) # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() diff --git a/settings.py b/settings.py index ae2378b..38c2036 100644 --- a/settings.py +++ b/settings.py @@ -36,6 +36,18 @@ class SimulatorSettings: # https://wise.svlsimulator.com/maps/profile/dac1a8fc-054d-4f32-9f64-d24efe6c0fc9 map_singlelaneroad = "dac1a8fc-054d-4f32-9f64-d24efe6c0fc9" + # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "Straight1LaneSame" + # https://wise.svlsimulator.com/maps/profile/1e2287cf-c590-4804-bcb1-18b2fd3752d1 + map_straight1lanesame = "1e2287cf-c590-4804-bcb1-18b2fd3752d1" + + # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "Straight2LaneSameCurbRightIntersection" + # https://wise.svlsimulator.com/maps/profile/378edc3f-8fce-4596-87dc-7d12fc2ad743 + map_straight2lanesamecurbrightintersection = "378edc3f-8fce-4596-87dc-7d12fc2ad743" + + # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "Straight2LaneOpposing" + # https://wise.svlsimulator.com/maps/profile/671868be-44f9-44a1-913c-cb0f29d12634 + map_straight2laneopposing = "671868be-44f9-44a1-913c-cb0f29d12634" + # Ego vehicle that is loaded in most of the quickstart scripts. Default value is "Lincoln2017MKZ". This includes a bridge connection if needed and also bunch of sensors including LIDAR. # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego_lincoln2017mkz_apollo5 = "47b529db-0593-4908-b3e7-4b24a32a0f70" From 4c355ee5554875f4397f4fce4e5fe588313c0577 Mon Sep 17 00:00:00 2001 From: Eugene Agafonov Date: Tue, 9 Mar 2021 19:06:06 -0800 Subject: [PATCH 072/115] .flake8: add .git into exclude list explicitly --- .flake8 | 1 + 1 file changed, 1 insertion(+) diff --git a/.flake8 b/.flake8 index 9ea05cb..6672bb6 100644 --- a/.flake8 +++ b/.flake8 @@ -4,6 +4,7 @@ max-complexity = 23 ignore = E701, E501, W503 exclude = + .git tests/* examples/* From 1089f6b6d3798fe0207ccb985ff5f662f9744b0d Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Tue, 9 Mar 2021 18:13:19 -0800 Subject: [PATCH 073/115] settings.py: Fix incorrect UUID for "SingleLaneRoad" --- settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/settings.py b/settings.py index 38c2036..6cd79df 100644 --- a/settings.py +++ b/settings.py @@ -33,8 +33,8 @@ class SimulatorSettings: map_straight1lanepedestriancrosswalk = "a3a818b5-c66b-488a-a780-979bd5692db1" # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "SingleLaneRoad" - # https://wise.svlsimulator.com/maps/profile/dac1a8fc-054d-4f32-9f64-d24efe6c0fc9 - map_singlelaneroad = "dac1a8fc-054d-4f32-9f64-d24efe6c0fc9" + # https://wise.svlsimulator.com/maps/profile/a6e2d149-6a18-4b83-9029-4411d7b2e69a + map_singlelaneroad = "a6e2d149-6a18-4b83-9029-4411d7b2e69a" # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "Straight1LaneSame" # https://wise.svlsimulator.com/maps/profile/1e2287cf-c590-4804-bcb1-18b2fd3752d1 From d6b7ccae4122065de42661254adad3faac1841d3 Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Tue, 9 Mar 2021 15:09:13 -0800 Subject: [PATCH 074/115] settings.py: Update comments with final assets names --- settings.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/settings.py b/settings.py index 6cd79df..25265a4 100644 --- a/settings.py +++ b/settings.py @@ -6,7 +6,7 @@ # -# Settings class with common variables used in the quickstart scripts +# Settings class with common variables used in the quickstart and example scripts. class SimulatorSettings: # IP address of the endpoint running the Simulator. Default value is "127.0.0.1" simulator_host = "127.0.0.1" @@ -20,50 +20,53 @@ class SimulatorSettings: # Port used by the Simulator for the bridge connection. Default value is 9090 bridge_port = 9090 - # Map loaded in the quickstart scripts. Changing the map may lead to unexpected behaviour in the quickstart scripts. Default value is "BorregasAve" + # Map loaded in the quickstart scripts. Changing the map may lead to unexpected behaviour in the quickstart scripts. Default value is "BorregasAve". # https://wise.svlsimulator.com/maps/profile/aae03d2a-b7ca-4a88-9e41-9035287a12cc map_borregasave = "aae03d2a-b7ca-4a88-9e41-9035287a12cc" - # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "SanFrancisco" + # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "SanFrancisco". # https://wise.svlsimulator.com/maps/profile/5d272540-f689-4355-83c7-03bf11b6865f map_sanfrancisco = "5d272540-f689-4355-83c7-03bf11b6865f" - # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "Straight1LanePedestrianCrosswalk" + # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "Straight1LanePedestrianCrosswalk". # https://wise.svlsimulator.com/maps/profile/a3a818b5-c66b-488a-a780-979bd5692db1 map_straight1lanepedestriancrosswalk = "a3a818b5-c66b-488a-a780-979bd5692db1" - # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "SingleLaneRoad" + # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "SingleLaneRoad". # https://wise.svlsimulator.com/maps/profile/a6e2d149-6a18-4b83-9029-4411d7b2e69a map_singlelaneroad = "a6e2d149-6a18-4b83-9029-4411d7b2e69a" - # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "Straight1LaneSame" + # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "Straight1LaneSame". # https://wise.svlsimulator.com/maps/profile/1e2287cf-c590-4804-bcb1-18b2fd3752d1 map_straight1lanesame = "1e2287cf-c590-4804-bcb1-18b2fd3752d1" - # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "Straight2LaneSameCurbRightIntersection" + # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "Straight2LaneSameCurbRightIntersection". # https://wise.svlsimulator.com/maps/profile/378edc3f-8fce-4596-87dc-7d12fc2ad743 map_straight2lanesamecurbrightintersection = "378edc3f-8fce-4596-87dc-7d12fc2ad743" - # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "Straight2LaneOpposing" + # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "Straight2LaneOpposing". # https://wise.svlsimulator.com/maps/profile/671868be-44f9-44a1-913c-cb0f29d12634 map_straight2laneopposing = "671868be-44f9-44a1-913c-cb0f29d12634" - # Ego vehicle that is loaded in most of the quickstart scripts. Default value is "Lincoln2017MKZ". This includes a bridge connection if needed and also bunch of sensors including LIDAR. + # Ego vehicle that is loaded in most of the quickstart scripts. Default value is "Lincoln2017MKZ" using the "Apollo 5.0" sensor configuration. + # This includes a bridge connection if needed and also bunch of sensors including LIDAR. # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego_lincoln2017mkz_apollo5 = "47b529db-0593-4908-b3e7-4b24a32a0f70" - # Ego vehicle that is loaded in quickstart/tests scripts. Default value is "Jaguar2015XE - Apollo 5". + # Ego vehicle that is loaded in quickstart/tests scripts. Default value is "Jaguar2015XE" using the "Apollo 5.0" sensor configuration. # https://wise.svlsimulator.com/vehicles/profile/3f4211dc-e5d7-42dc-94c5-c4832b1331bb/edit/configuration/c06d4932-5928-4730-8a91-ba64ac5f1813 ego_jaguar2015xe_apollo5 = "c06d4932-5928-4730-8a91-ba64ac5f1813" - # Ego vehicle that is loaded in quickstart/tests scripts. Default value is "Jaguar2015XE - AutowareAI". + # Ego vehicle that is loaded in quickstart/tests scripts. Default value is "Jaguar2015XE" using the "Autoware AI" sensor configuration. # https://wise.svlsimulator.com/vehicles/profile/3f4211dc-e5d7-42dc-94c5-c4832b1331bb/edit/configuration/05cbb194-d095-4a0e-ae66-ff56c331ca83 ego_jaguae2015xe_autowareai = "05cbb194-d095-4a0e-ae66-ff56c331ca83" - # Ego vehicle that is loaded in most of the NHTSA example scripts. Default value is "Lincoln2017MKZ - Full Analysis". This includes bunch of sensors that help analyze test results efficiently. + # Ego vehicle that is loaded in most of the NHTSA example scripts. Default value is "Lincoln2017MKZ" using the "Apollo 5.0 (Full Analysis)" sensor configuration. + # This includes bunch of sensors that help analyze test results efficiently. # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/22656c7b-104b-4e6a-9c70-9955b6582220 ego_lincoln2017mkz_apollo5_full_analysis = "22656c7b-104b-4e6a-9c70-9955b6582220" - # Ego vehicle that is loaded in most of the NHTSA example scripts. Default value is "Lincoln2017MKZ - Apollo 5 modular". This has sensors for modular testing. + # Ego vehicle that is loaded in most of the NHTSA example scripts. Default value is "Lincoln2017MKZ" using the "Apollo 5.0 (modular testing)" sensor configuration. + # This has sensors for modular testing. # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/5c7fb3b0-1fd4-4943-8347-f73a05749718 ego_lincoln2017mkz_apollo5_modular = "5c7fb3b0-1fd4-4943-8347-f73a05749718" From 972af87c2b332e04bd2d7b4cfac67001b749d0c1 Mon Sep 17 00:00:00 2001 From: David Uhm Date: Tue, 9 Mar 2021 19:07:51 -0800 Subject: [PATCH 075/115] Fix incorrect var name for bridge port --- quickstart/22-connecting-bridge.py | 2 +- quickstart/33-ego-drive-stepped.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/quickstart/22-connecting-bridge.py b/quickstart/22-connecting-bridge.py index ca4024b..1e03ef6 100755 --- a/quickstart/22-connecting-bridge.py +++ b/quickstart/22-connecting-bridge.py @@ -29,7 +29,7 @@ print("Bridge connected:", ego.bridge_connected) # The EGO is now looking for a bridge at the specified IP and port -ego.connect_bridge(env.str("LGSVL__AUTOPILOT_0_HOST", SimulatorSettings.bridge_host), env.int("LGSVL__AUTOPILOT_0_PORT", SimulatorSettings.bridgePort)) +ego.connect_bridge(env.str("LGSVL__AUTOPILOT_0_HOST", SimulatorSettings.bridge_host), env.int("LGSVL__AUTOPILOT_0_PORT", SimulatorSettings.bridge_port)) print("Waiting for connection...") diff --git a/quickstart/33-ego-drive-stepped.py b/quickstart/33-ego-drive-stepped.py index 8df387a..eff2c89 100755 --- a/quickstart/33-ego-drive-stepped.py +++ b/quickstart/33-ego-drive-stepped.py @@ -39,7 +39,7 @@ print("Bridge connected:", ego.bridge_connected) # The EGO looks for a (Cyber) bridge at the specified IP and port -ego.connect_bridge(SimulatorSettings.bridge_host, SimulatorSettings.bridgePort) +ego.connect_bridge(SimulatorSettings.bridge_host, SimulatorSettings.bridge_port) # uncomment to wait for bridge connection; script will drive ego if bridge not found # print("Waiting for connection...") # while not ego.bridge_connected: From 1e9e523c0b822b31864c47e24e5622dd04622eda Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Mon, 8 Mar 2021 14:36:52 -0800 Subject: [PATCH 076/115] AUTO-6386: README.md: Update for WISE 2021.1; make other miscellaneous improvements --- README.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 289447d..98f98c4 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,17 @@ -# Python API for SVL Simulator +# lgsvl - A Python API for SVL Simulator -This folder contains the Python API for the SVL Simulator. +This folder contains **lgsvl**, a Python API for SVL Simulator. # Usage -Look into `quickstart` folder for simple usages. -To run these examples first start the simulator and leave it in main menu. -By default examples connect to Simulator on `localhost` address. -To change it, adjust first argument of `Simulator` constructor, or set up -`LGSVL__SIMULATOR_HOST` environment variable with hostname. +Look into `quickstart` and `examples` folders for simple usages. To run these +examples, first add the maps and vehicles they use into your Library, and then +launch a simulation on a local cluster selecting the **API Only** template. + +By default, the examples expect to be able to connect to SVL Simulator using the +`localhost` address. To change it, set the `LGSVL__SIMULATOR_HOST` environment +variable to the hostname or IP address of the network interface of the machine +running SVL Simulator to which the examples should connect. # Documentation @@ -27,6 +30,10 @@ Documentation is available on our website: https://www.svlsimulator.com/docs/pyt # Running unit tests +To run the unit tests, first add the maps and vehicles they use into your +Library, then launch a simulation on a local cluster selecting the **API Only** +template. + # run all unittests python3 -m unittest discover -v -c From f724a34ad3f923e25f6b75762ca45f26db4a0906 Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Tue, 9 Mar 2021 15:58:14 -0800 Subject: [PATCH 077/115] AUTO-6386: README.md: Specify assets needed to run examples --- README.md | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 98f98c4..615bbcb 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,34 @@ This folder contains **lgsvl**, a Python API for SVL Simulator. # Usage Look into `quickstart` and `examples` folders for simple usages. To run these -examples, first add the maps and vehicles they use into your Library, and then -launch a simulation on a local cluster selecting the **API Only** template. +examples, first make sure that these assets have been added to your Library: + +| Type | Name | URL | +| ------- | -------------- | --- | +| Map | BorregasAve | https://wise.svlsimulator.com/maps/profile/aae03d2a-b7ca-4a88-9e41-9035287a12cc | +| Map | SanFrancisco | https://wise.svlsimulator.com/maps/profile/5d272540-f689-4355-83c7-03bf11b6865f | +| Map | SingleLaneRoad | https://wise.svlsimulator.com/maps/profile/a6e2d149-6a18-4b83-9029-4411d7b2e69a | +| Map | Straight1LanePedestrianCrosswalk | https://wise.svlsimulator.com/maps/profile/a3a818b5-c66b-488a-a780-979bd5692db1 | +| Map | Straight1LaneSame | https://wise.svlsimulator.com/maps/profile/1e2287cf-c590-4804-bcb1-18b2fd3752d1 | +| Map | Straight2LaneOpposing | https://wise.svlsimulator.com/maps/profile/671868be-44f9-44a1-913c-cb0f29d12634 | +| Map | Straight2LaneSame | https://wise.svlsimulator.com/maps/profile/b39d3ef9-21d7-409d-851b-4c90dad80a25 | +| Map | Straight2LaneSameCurbRightIntersection | https://wise.svlsimulator.com/maps/profile/378edc3f-8fce-4596-87dc-7d12fc2ad743 | +| Vehicle | Jaguar2015XE | https://wise.svlsimulator.com/vehicles/profile/3f4211dc-e5d7-42dc-94c5-c4832b1331bb | +| Vehicle | Lincoln2017MKZ | https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e | + +
+and that the plugins required by these vehicle sensor configurations have been added to your Library: + +| Vehicle | Sensor Configuration | URL | +| ------------ | -------------------- | --- | +Jaguar2015XE | Apollo 5.0 | https://wise.svlsimulator.com/vehicles/profile/3f4211dc-e5d7-42dc-94c5-c4832b1331bb/edit/configuration/c06d4932-5928-4730-8a91-ba64ac5f1813 | +Jaguar2015XE | Autoware AI | https://wise.svlsimulator.com/vehicles/profile/3f4211dc-e5d7-42dc-94c5-c4832b1331bb/edit/configuration/05cbb194-d095-4a0e-ae66-ff56c331ca83 | +Lincoln2017MKZ | Apollo 5.0 | https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 | +Lincoln2017MKZ | Apollo 5.0 (Full Analysis) | https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/22656c7b-104b-4e6a-9c70-9955b6582220 | +Lincoln2017MKZ | Apollo 5.0 (modular testing) | https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/5c7fb3b0-1fd4-4943-8347-f73a05749718 | +
+ +Then launch a simulation on a local cluster selecting the **API Only** template. By default, the examples expect to be able to connect to SVL Simulator using the `localhost` address. To change it, set the `LGSVL__SIMULATOR_HOST` environment From f40c3bce2bfb4ba5ea511ed2c5bff9b52376f627 Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Tue, 9 Mar 2021 15:07:32 -0800 Subject: [PATCH 078/115] AUTO-6386: README.md: Specify assets needed to run unit tests --- README.md | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 615bbcb..7669ccc 100644 --- a/README.md +++ b/README.md @@ -56,9 +56,26 @@ Documentation is available on our website: https://www.svlsimulator.com/docs/pyt # Running unit tests -To run the unit tests, first add the maps and vehicles they use into your -Library, then launch a simulation on a local cluster selecting the **API Only** -template. +To run the unit tests, first make sure that these assets have been added to your Library: + +| Type | Name | URL | +| ------- | -------------- | --- | +| Map | BorregasAve | https://wise.svlsimulator.com/maps/profile/aae03d2a-b7ca-4a88-9e41-9035287a12cc | +| Map | CubeTown | https://wise.svlsimulator.com/maps/profile/06773677-1ce3-492f-9fe2-b3147e126e27 | +| Vehicle | Jaguar2015XE | https://wise.svlsimulator.com/vehicles/profile/3f4211dc-e5d7-42dc-94c5-c4832b1331bb | +| Vehicle | Lincoln2017MKZ | https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e | + +
+and that the plugins required by these vehicle sensor configurations have been added to your Library: + +| Vehicle | Sensor Configuration | URL | +| ------------ | -------------------- | --- | +Jaguar2015XE | Apollo 5.0 | https://wise.svlsimulator.com/vehicles/profile/3f4211dc-e5d7-42dc-94c5-c4832b1331bb/edit/configuration/c06d4932-5928-4730-8a91-ba64ac5f1813 | +Jaguar2015XE | Autoware AI | https://wise.svlsimulator.com/vehicles/profile/3f4211dc-e5d7-42dc-94c5-c4832b1331bb/edit/configuration/05cbb194-d095-4a0e-ae66-ff56c331ca83 | +Lincoln2017MKZ | Apollo 5.0 | https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 | + +
+Then launch an **API Only** simulation before running the unit tests. # run all unittests python3 -m unittest discover -v -c From ccd943c9f24058cde643d233a7348114ff17956f Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Tue, 9 Mar 2021 16:04:06 -0800 Subject: [PATCH 079/115] AUTO-6386: README.md: Rename "Usage" to "Examples" and move to be after "Installing" --- README.md | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 7669ccc..dc13e4e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,22 @@ This folder contains **lgsvl**, a Python API for SVL Simulator. -# Usage +# Documentation + +Documentation is available on our website: https://www.svlsimulator.com/docs/python-api/ + +# Requirements + +* Python 3.6 or higher + +# Installing + + pip3 install --user . + + # install in development mode + pip3 install --user -e . + +# Examples Look into `quickstart` and `examples` folders for simple usages. To run these examples, first make sure that these assets have been added to your Library: @@ -39,20 +54,6 @@ By default, the examples expect to be able to connect to SVL Simulator using the variable to the hostname or IP address of the network interface of the machine running SVL Simulator to which the examples should connect. -# Documentation - -Documentation is available on our website: https://www.svlsimulator.com/docs/python-api/ - -# Requirements - -* Python 3.6 or higher - -# Installing - - pip3 install --user . - - # install in development mode - pip3 install --user -e . # Running unit tests From 165ae6a9c8ef3240b73884e1f9fa05f253b2d1ae Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Tue, 9 Mar 2021 22:31:45 -0800 Subject: [PATCH 080/115] AUTO-6386: README.md: Set PYTHONPATH when running examples and unit tests --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index dc13e4e..7cf71f7 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,9 @@ Documentation is available on our website: https://www.svlsimulator.com/docs/pyt # install in development mode pip3 install --user -e . + # only required when running the examples and unit tests + export PYTHONPATH=$PWD + # Examples Look into `quickstart` and `examples` folders for simple usages. To run these @@ -78,6 +81,9 @@ Lincoln2017MKZ | Apollo 5.0 | https://wise.svlsimulator.com/vehicles/p
Then launch an **API Only** simulation before running the unit tests. + # required to run the unittests + export PYTHONPATH=$PWD + # run all unittests python3 -m unittest discover -v -c From 98dc258b07caaa9aafdf1cb008a0c37a20d6fed6 Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Tue, 9 Mar 2021 23:11:47 -0800 Subject: [PATCH 081/115] 98-npc-behaviour.py: Use UUID of CubeTown; add it to settings.py --- README.md | 1 + quickstart/98-npc-behaviour.py | 9 ++++----- settings.py | 4 ++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7cf71f7..3bbdf5b 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ examples, first make sure that these assets have been added to your Library: | Type | Name | URL | | ------- | -------------- | --- | | Map | BorregasAve | https://wise.svlsimulator.com/maps/profile/aae03d2a-b7ca-4a88-9e41-9035287a12cc | +| Map | CubeTown | https://wise.svlsimulator.com/maps/profile/06773677-1ce3-492f-9fe2-b3147e126e27 | | Map | SanFrancisco | https://wise.svlsimulator.com/maps/profile/5d272540-f689-4355-83c7-03bf11b6865f | | Map | SingleLaneRoad | https://wise.svlsimulator.com/maps/profile/a6e2d149-6a18-4b83-9029-4411d7b2e69a | | Map | Straight1LanePedestrianCrosswalk | https://wise.svlsimulator.com/maps/profile/a3a818b5-c66b-488a-a780-979bd5692db1 | diff --git a/quickstart/98-npc-behaviour.py b/quickstart/98-npc-behaviour.py index f4e8b98..32c965b 100755 --- a/quickstart/98-npc-behaviour.py +++ b/quickstart/98-npc-behaviour.py @@ -18,15 +18,14 @@ drunkDriverAvailable = False trailerAvailable = 0 -map = "CubeTown" print("Current Scene = {}".format(sim.current_scene)) -# Loads the named map in the connected simulator. The available maps can be set up in web interface -if sim.current_scene == map: +# Loads the named map in the connected simulator. +if sim.current_scene == SimulatorSettings.map_cubetown: sim.reset() else: - print("Loading Scene = {}".format(map)) - sim.load(map) + print("Loading Scene = {}".format(SimulatorSettings.map_cubetown)) + sim.load(SimulatorSettings.map_cubetown) agents = sim.available_agents print("agents:") diff --git a/settings.py b/settings.py index 25265a4..50cee4a 100644 --- a/settings.py +++ b/settings.py @@ -24,6 +24,10 @@ class SimulatorSettings: # https://wise.svlsimulator.com/maps/profile/aae03d2a-b7ca-4a88-9e41-9035287a12cc map_borregasave = "aae03d2a-b7ca-4a88-9e41-9035287a12cc" + # Map loaded in the quickstart scripts. Changing the map may lead to unexpected behaviour in the quickstart scripts. Default value is "CubeTown". + # https://wise.svlsimulator.com/maps/profile/06773677-1ce3-492f-9fe2-b3147e126e27 + map_cubetown = "06773677-1ce3-492f-9fe2-b3147e126e27" + # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "SanFrancisco". # https://wise.svlsimulator.com/maps/profile/5d272540-f689-4355-83c7-03bf11b6865f map_sanfrancisco = "5d272540-f689-4355-83c7-03bf11b6865f" From f11a15b300453d59545fda6f2ec06e6b810a73dd Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Mon, 8 Mar 2021 17:01:25 -0800 Subject: [PATCH 082/115] tests/*.py: Update copyright year This should have been done in commit 45dcda4d4582f4c9bc2d429e251bead387d37608. --- tests/common.py | 2 +- tests/test_EGO.py | 2 +- tests/test_NPC.py | 2 +- tests/test_collisions.py | 2 +- tests/test_manual_features.py | 2 +- tests/test_peds.py | 2 +- tests/test_sensors.py | 2 +- tests/test_simulator.py | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/common.py b/tests/common.py index 707de20..35d24e7 100644 --- a/tests/common.py +++ b/tests/common.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # diff --git a/tests/test_EGO.py b/tests/test_EGO.py index 133b540..3b8821b 100644 --- a/tests/test_EGO.py +++ b/tests/test_EGO.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # diff --git a/tests/test_NPC.py b/tests/test_NPC.py index 5f78ea2..d78cc7e 100644 --- a/tests/test_NPC.py +++ b/tests/test_NPC.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # diff --git a/tests/test_collisions.py b/tests/test_collisions.py index 2da0f8a..d690245 100644 --- a/tests/test_collisions.py +++ b/tests/test_collisions.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # diff --git a/tests/test_manual_features.py b/tests/test_manual_features.py index 597d03c..f6c9b68 100644 --- a/tests/test_manual_features.py +++ b/tests/test_manual_features.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # diff --git a/tests/test_peds.py b/tests/test_peds.py index f9e3b82..5fdcc5c 100644 --- a/tests/test_peds.py +++ b/tests/test_peds.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # diff --git a/tests/test_sensors.py b/tests/test_sensors.py index b0cb37f..fada233 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # diff --git a/tests/test_simulator.py b/tests/test_simulator.py index 38f08ab..6fced91 100644 --- a/tests/test_simulator.py +++ b/tests/test_simulator.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # From 2a212a9d347b03d5159cd21991f07325fd918ccf Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Mon, 8 Mar 2021 14:17:13 -0800 Subject: [PATCH 083/115] tests/common.py: Use SimulatorSettings value for map --- tests/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/common.py b/tests/common.py index 35d24e7..5cb327b 100644 --- a/tests/common.py +++ b/tests/common.py @@ -7,7 +7,7 @@ import signal import lgsvl import os - +from settings import SimulatorSettings class TestTimeout(Exception): pass @@ -18,7 +18,7 @@ class TestException(Exception): class SimConnection: - def __init__(self, seconds=30, scene="BorregasAve", error_message=None, load_scene=True): + def __init__(self, seconds=30, scene=SimulatorSettings.map_borregasave, error_message=None, load_scene=True): if error_message is None: error_message = 'test timed out after {}s.'.format(seconds) self.seconds = seconds From 979f5d4fb9c90109b919e62cb5b03a06e2430aaf Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Wed, 10 Mar 2021 14:32:45 -0800 Subject: [PATCH 084/115] examples/NHTSA/**.py: Drop the "default vehicle" comments --- examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py | 2 -- examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py | 2 -- examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py | 2 -- examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py | 2 -- examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py | 2 -- examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py | 2 -- examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py | 2 -- examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py | 2 -- examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py | 2 -- examples/NHTSA/Perform-Lane-Change/PLC_B_15.py | 2 -- examples/NHTSA/Perform-Lane-Change/PLC_B_25.py | 2 -- examples/NHTSA/Perform-Lane-Change/PLC_B_35.py | 2 -- examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py | 2 -- examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py | 2 -- examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py | 2 -- examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py | 2 -- examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py | 2 -- examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py | 2 -- examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py | 2 -- examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py | 2 -- examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py | 2 -- examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py | 2 -- examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py | 2 -- examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py | 2 -- 24 files changed, 48 deletions(-) diff --git a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py index 3b95f9a..61f99d0 100755 --- a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py +++ b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py @@ -45,8 +45,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(-1.6, 0, -65)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py index 4b1d1ab..51793fb 100755 --- a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py +++ b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py @@ -45,8 +45,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(-1.6, 0, -65)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py index 7874dfa..2247377 100755 --- a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py +++ b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py @@ -45,8 +45,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(-1.6, 0, -65)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py index 1080a26..30c06cf 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py @@ -43,8 +43,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py index 6eeaccd..0583f44 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py @@ -43,8 +43,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py index a838838..01e0451 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py @@ -43,8 +43,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py index 42a2ad6..613d8b3 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py @@ -43,8 +43,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py index dc4820b..202d434 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py @@ -48,8 +48,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py index 09c6016..420a2e7 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py @@ -43,8 +43,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py index 565c03c..25b5044 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py @@ -42,8 +42,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py index edc3350..8a0f366 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py @@ -42,8 +42,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py index 10f992f..8bc3126 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py @@ -42,8 +42,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py index 3caa1fe..84426e8 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py @@ -44,8 +44,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py index 93c3aa4..11ae80f 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py @@ -44,8 +44,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py index 69a4576..1164189 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py @@ -44,8 +44,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py index 2f8fedf..f4095d3 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py @@ -50,8 +50,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py index 00e8a65..897805c 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py @@ -44,8 +44,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py index 188892e..6e3f1c3 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py @@ -44,8 +44,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py index 6d793d6..fdf8b23 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py @@ -42,8 +42,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py index d50b0b2..dbd61de 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py @@ -42,8 +42,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py index 9f8db42..c686025 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py @@ -42,8 +42,6 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py b/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py index abfb412..b8afdf4 100755 --- a/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py +++ b/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py @@ -45,8 +45,6 @@ # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() egoState.transform = sim.map_point_on_lane(lgsvl.Vector(1, 0, 65)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py b/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py index d1a91cf..c008516 100755 --- a/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py +++ b/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py @@ -44,8 +44,6 @@ # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() egoState.transform = sim.map_point_on_lane(lgsvl.Vector(1, 0, 65)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py b/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py index 3b904ac..36dd64b 100755 --- a/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py +++ b/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py @@ -44,8 +44,6 @@ # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() egoState.transform = sim.map_point_on_lane(lgsvl.Vector(1, 0, 65)) -# Default vehicle for this test case is Lincoln2017MKZ - Apollo 5.0 -# https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) From 54dd3a5e5368dcd88fd87c20300f5135b7dcfcb7 Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Wed, 10 Mar 2021 13:24:26 -0800 Subject: [PATCH 085/115] AUTO-6393: Move SimulationSettings into lgsvl.wise Move the SimulationSettings class into a new lsgvl.wise subpackage. Split off the variables for assets into a separate DefaultAssets class. Update the references as follows: SimulatorSettings.bridge_* -> lgsvl.wise.SimulatorSettings.bridge_* SimulatorSettings.simulator_* -> lgsvl.wise.SimulatorSettings.simulator_* SimulatorSettings.ego_* -> lgsvl.wise.DefaultAssets.ego_* SimulatorSettings.map_* -> lgsvl.wise.DefaultAssets.map_* --- .flake8 | 1 + .../EOV_S_25_20.py | 5 +- .../EOV_S_45_40.py | 5 +- .../EOV_S_65_60.py | 5 +- .../Move-Out-of-Travel-Lane/MOTL_Comp_15.py | 5 +- .../Move-Out-of-Travel-Lane/MOTL_Comp_25.py | 5 +- .../Move-Out-of-Travel-Lane/MOTL_Neg_15.py | 5 +- .../Move-Out-of-Travel-Lane/MOTL_Neg_25.py | 5 +- .../Move-Out-of-Travel-Lane/MOTL_Simp_15.py | 5 +- .../Move-Out-of-Travel-Lane/MOTL_Simp_25.py | 5 +- .../NHTSA/Perform-Lane-Change/PLC_B_15.py | 5 +- .../NHTSA/Perform-Lane-Change/PLC_B_25.py | 5 +- .../NHTSA/Perform-Lane-Change/PLC_B_35.py | 5 +- .../NHTSA/Perform-Lane-Change/PLC_CP_15.py | 5 +- .../NHTSA/Perform-Lane-Change/PLC_CP_25.py | 5 +- .../NHTSA/Perform-Lane-Change/PLC_CP_35.py | 5 +- .../NHTSA/Perform-Lane-Change/PLC_SN_15.py | 5 +- .../NHTSA/Perform-Lane-Change/PLC_SN_25.py | 5 +- .../NHTSA/Perform-Lane-Change/PLC_SN_35.py | 5 +- .../NHTSA/Perform-Lane-Change/PLC_SP_15.py | 5 +- .../NHTSA/Perform-Lane-Change/PLC_SP_25.py | 5 +- .../NHTSA/Perform-Lane-Change/PLC_SP_35.py | 5 +- .../NHTSA/Vehicle-Following/VF_S_25_Slow.py | 5 +- .../NHTSA/Vehicle-Following/VF_S_45_Slow.py | 5 +- .../NHTSA/Vehicle-Following/VF_S_65_Slow.py | 5 +- examples/SampleTestCases/cut-in.py | 7 +-- examples/SampleTestCases/ped-crossing.py | 5 +- .../SampleTestCases/random-traffic-local.py | 5 +- examples/SampleTestCases/random-traffic.py | 5 +- examples/SampleTestCases/red-light-runner.py | 7 +-- examples/SampleTestCases/sudden-braking.py | 7 +-- lgsvl/__init__.py | 3 +- lgsvl/wise/__init__.py | 7 +++ settings.py => lgsvl/wise/wise.py | 5 +- quickstart/01-connecting-to-simulator.py | 3 +- quickstart/02-loading-scene-show-spawns.py | 7 +-- quickstart/03-raycast.py | 9 ++- quickstart/04-ego-drive-straight.py | 9 ++- quickstart/05-ego-drive-in-circle.py | 9 ++- quickstart/06-save-camera-image.py | 9 ++- quickstart/07-save-lidar-point-cloud.py | 9 ++- quickstart/08-create-npc.py | 9 ++- quickstart/09-reset-scene.py | 9 ++- quickstart/10-npc-follow-the-lane.py | 9 ++- quickstart/11-collision-callbacks.py | 9 ++- quickstart/12-create-npc-on-lane.py | 9 ++- quickstart/13-npc-follow-waypoints.py | 9 ++- quickstart/14-create-pedestrians.py | 9 ++- quickstart/15-pedestrian-walk-randomly.py | 9 ++- quickstart/16-pedestrian-follow-waypoints.py | 9 ++- quickstart/17-many-pedestrians-walking.py | 9 ++- quickstart/18-weather-effects.py | 9 ++- quickstart/19-time-of-day.py | 9 ++- quickstart/20-enable-sensors.py | 9 ++- quickstart/21-map-coordinates.py | 7 +-- quickstart/22-connecting-bridge.py | 11 ++-- quickstart/23-npc-callbacks.py | 9 ++- .../24-ego-drive-straight-non-realtime.py | 9 ++- quickstart/25-waypoint-flying-npc.py | 9 ++- quickstart/26-npc-trigger-waypoints.py | 9 ++- quickstart/27-control-traffic-lights.py | 11 ++-- quickstart/28-control-traffic-cone.py | 9 ++- quickstart/29-add-random-agents.py | 9 ++- quickstart/30-time-to-collision-trigger.py | 9 ++- quickstart/31-wait-for-distance-trigger.py | 9 ++- quickstart/32-pedestrian-time-to-collision.py | 9 ++- quickstart/33-ego-drive-stepped.py | 11 ++-- quickstart/34-simulator-cam-set.py | 9 ++- quickstart/98-npc-behaviour.py | 11 ++-- setup.py | 2 +- tests/common.py | 3 +- tests/test_EGO.py | 55 +++++++++---------- tests/test_NPC.py | 41 +++++++------- tests/test_collisions.py | 19 +++---- tests/test_manual_features.py | 15 +++-- tests/test_peds.py | 9 ++- tests/test_sensors.py | 21 ++++--- tests/test_simulator.py | 5 +- 78 files changed, 296 insertions(+), 359 deletions(-) create mode 100644 lgsvl/wise/__init__.py rename settings.py => lgsvl/wise/wise.py (97%) diff --git a/.flake8 b/.flake8 index 6672bb6..126637d 100644 --- a/.flake8 +++ b/.flake8 @@ -12,3 +12,4 @@ per-file-ignores = lgsvl/__init__.py:F401 lgsvl/dreamview/__init__.py:F401 lgsvl/evaluator/__init__.py:F401 + lgsvl/wise/__init__.py:F401 diff --git a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py index 61f99d0..833c743 100755 --- a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py +++ b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_25_20.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -34,7 +33,7 @@ print("EOV_S_25_20 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2laneopposing) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2laneopposing) if sim.current_scene == scene_name: sim.reset() else: @@ -45,7 +44,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(-1.6, 0, -65)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py index 51793fb..54fe9cc 100755 --- a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py +++ b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_45_40.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -34,7 +33,7 @@ print("EOV_S_45_40 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2laneopposing) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2laneopposing) if sim.current_scene == scene_name: sim.reset() else: @@ -45,7 +44,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(-1.6, 0, -65)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py index 2247377..d53a662 100755 --- a/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py +++ b/examples/NHTSA/Encroaching-Oncoming-Vehicles/EOV_S_65_60.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -34,7 +33,7 @@ print("EOV_S_65_60 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2laneopposing) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2laneopposing) if sim.current_scene == scene_name: sim.reset() else: @@ -45,7 +44,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(-1.6, 0, -65)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py index 30c06cf..807ff17 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_15.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -32,7 +31,7 @@ print("MOTL_Comp_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2lanesamecurbrightintersection) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesamecurbrightintersection) if sim.current_scene == scene_name: sim.reset() else: @@ -43,7 +42,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py index 0583f44..eb0a96a 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Comp_25.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -32,7 +31,7 @@ print("MOTL_Comp_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2lanesamecurbrightintersection) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesamecurbrightintersection) if sim.current_scene == scene_name: sim.reset() else: @@ -43,7 +42,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py index 01e0451..f79648c 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_15.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -32,7 +31,7 @@ print("MOTL_Neg_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2lanesamecurbrightintersection) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesamecurbrightintersection) if sim.current_scene == scene_name: sim.reset() else: @@ -43,7 +42,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py index 613d8b3..d8fdc10 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Neg_25.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -32,7 +31,7 @@ print("MOTL_Neg_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2lanesamecurbrightintersection) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesamecurbrightintersection) if sim.current_scene == scene_name: sim.reset() else: @@ -43,7 +42,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py index 202d434..5e66f95 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_15.py @@ -16,7 +16,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -37,7 +36,7 @@ print("MOTL_Simp_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2lanesamecurbrightintersection) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesamecurbrightintersection) if sim.current_scene == scene_name: sim.reset() else: @@ -48,7 +47,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py index 420a2e7..c3ce79b 100755 --- a/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py +++ b/examples/NHTSA/Move-Out-of-Travel-Lane/MOTL_Simp_25.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -32,7 +31,7 @@ print("MOTL_Simp_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight2lanesamecurbrightintersection) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesamecurbrightintersection) if sim.current_scene == scene_name: sim.reset() else: @@ -43,7 +42,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(2.6, 0, 30)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py index 25b5044..61cb14e 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -31,7 +30,7 @@ print("PLC_B_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) if sim.current_scene == scene_name: sim.reset() else: @@ -42,7 +41,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py index 8a0f366..45fca89 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -31,7 +30,7 @@ print("PLC_B_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) if sim.current_scene == scene_name: sim.reset() else: @@ -42,7 +41,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py index 8bc3126..4806d08 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -31,7 +30,7 @@ print("PLC_B_35 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) if sim.current_scene == scene_name: sim.reset() else: @@ -42,7 +41,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py index 84426e8..4f11021 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -33,7 +32,7 @@ print("PLC_CP_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) if sim.current_scene == scene_name: sim.reset() else: @@ -44,7 +43,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py index 11ae80f..abf1d08 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -33,7 +32,7 @@ print("PLC_CP_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) if sim.current_scene == scene_name: sim.reset() else: @@ -44,7 +43,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py index 1164189..795e375 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -33,7 +32,7 @@ print("PLC_CP_35 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) if sim.current_scene == scene_name: sim.reset() else: @@ -44,7 +43,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py index f4095d3..02839b4 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py @@ -17,7 +17,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -39,7 +38,7 @@ print("PLC_SN_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) if sim.current_scene == scene_name: sim.reset() else: @@ -50,7 +49,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py index 897805c..c5ef739 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -33,7 +32,7 @@ print("PLC_SN_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) if sim.current_scene == scene_name: sim.reset() else: @@ -44,7 +43,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py index 6e3f1c3..61e38d4 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -33,7 +32,7 @@ print("PLC_SN_35 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) if sim.current_scene == scene_name: sim.reset() else: @@ -44,7 +43,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py index fdf8b23..ab97900 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -31,7 +30,7 @@ print("PLC_SP_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) if sim.current_scene == scene_name: sim.reset() else: @@ -42,7 +41,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py index dbd61de..889c821 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -31,7 +30,7 @@ print("PLC_SP_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) if sim.current_scene == scene_name: sim.reset() else: @@ -42,7 +41,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py index c686025..875457b 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -31,7 +30,7 @@ print("PLC_SP_35 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) if sim.current_scene == scene_name: sim.reset() else: @@ -42,7 +41,7 @@ # A point close to the desired lane was found in Editor. # This method returns the position and orientation of the closest lane to the point. egoState.transform = sim.map_point_on_lane(lgsvl.Vector(3.68, 0, -50)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py b/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py index b8afdf4..5affb8e 100755 --- a/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py +++ b/examples/NHTSA/Vehicle-Following/VF_S_25_Slow.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -35,7 +34,7 @@ print("VF_S_25_Slow - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) if sim.current_scene == scene_name: sim.reset() else: @@ -45,7 +44,7 @@ # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() egoState.transform = sim.map_point_on_lane(lgsvl.Vector(1, 0, 65)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py b/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py index c008516..4eed8c9 100755 --- a/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py +++ b/examples/NHTSA/Vehicle-Following/VF_S_45_Slow.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -35,7 +34,7 @@ print("VF_S_45_Slow - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) if sim.current_scene == scene_name: sim.reset() else: @@ -44,7 +43,7 @@ # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() egoState.transform = sim.map_point_on_lane(lgsvl.Vector(1, 0, 65)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py b/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py index 36dd64b..774a731 100755 --- a/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py +++ b/examples/NHTSA/Vehicle-Following/VF_S_65_Slow.py @@ -11,7 +11,6 @@ import logging from environs import Env import lgsvl -from settings import SimulatorSettings FORMAT = "[%(levelname)6s] [%(name)s] %(message)s" logging.basicConfig(level=logging.WARNING, format=FORMAT) @@ -35,7 +34,7 @@ print("VF_S_65_Slow - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) if sim.current_scene == scene_name: sim.reset() else: @@ -44,7 +43,7 @@ # spawn EGO in the 2nd to right lane egoState = lgsvl.AgentState() egoState.transform = sim.map_point_on_lane(lgsvl.Vector(1, 0, 65)) -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) forward = lgsvl.utils.transform_to_forward(egoState.transform) right = lgsvl.utils.transform_to_right(egoState.transform) diff --git a/examples/SampleTestCases/cut-in.py b/examples/SampleTestCases/cut-in.py index 46408bd..1447b7c 100755 --- a/examples/SampleTestCases/cut-in.py +++ b/examples/SampleTestCases/cut-in.py @@ -19,7 +19,6 @@ import os import lgsvl -from settings import SimulatorSettings import time import sys @@ -29,7 +28,7 @@ BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090)) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_sanfrancisco) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_sanfrancisco) sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) if sim.current_scene == scene_name: @@ -41,13 +40,13 @@ egoState = lgsvl.AgentState() # Spawn point found in Unity Editor egoState.transform = sim.map_point_on_lane(lgsvl.Vector(773.29, 10.24, -10.79)) -ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT) right = lgsvl.utils.transform_to_right(egoState.transform) # Unit vector in the right direction of the EGO forward = lgsvl.utils.transform_to_forward(egoState.transform) # Unit vector in the forward direction of the EGO -# spawn NPC +# spawn NPC npcState = lgsvl.AgentState() npcState.transform = egoState.transform npcState.transform.position = egoState.position - 3.6 * right # NPC is 3.6m to the left of the EGO diff --git a/examples/SampleTestCases/ped-crossing.py b/examples/SampleTestCases/ped-crossing.py index 7840200..703f94f 100755 --- a/examples/SampleTestCases/ped-crossing.py +++ b/examples/SampleTestCases/ped-crossing.py @@ -19,7 +19,6 @@ import os import lgsvl -from settings import SimulatorSettings import sys @@ -28,7 +27,7 @@ BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090)) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_straight1lanepedestriancrosswalk) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanepedestriancrosswalk) sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) if sim.current_scene == scene_name: sim.reset() @@ -38,7 +37,7 @@ # spawn EGO egoState = lgsvl.AgentState() egoState.transform = sim.get_spawn()[0] -ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT) # spawn PED diff --git a/examples/SampleTestCases/random-traffic-local.py b/examples/SampleTestCases/random-traffic-local.py index dcb1763..27939fe 100755 --- a/examples/SampleTestCases/random-traffic-local.py +++ b/examples/SampleTestCases/random-traffic-local.py @@ -9,7 +9,6 @@ from environs import Env import random import lgsvl -from settings import SimulatorSettings ''' @@ -37,8 +36,8 @@ LGSVL__SIMULATION_DURATION_SECS = 120.0 LGSVL__RANDOM_SEED = env.int("LGSVL__RANDOM_SEED", 51472) -vehicle_conf = env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_modular) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_sanfrancisco) +vehicle_conf = env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_modular) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_sanfrancisco) sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) try: print("Loading map {}...".format(scene_name)) diff --git a/examples/SampleTestCases/random-traffic.py b/examples/SampleTestCases/random-traffic.py index 75e61e7..7060531 100755 --- a/examples/SampleTestCases/random-traffic.py +++ b/examples/SampleTestCases/random-traffic.py @@ -10,7 +10,6 @@ from environs import Env import lgsvl -from settings import SimulatorSettings ''' @@ -41,7 +40,7 @@ env = Env() sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", "127.0.0.1"), env.int("LGSVL__SIMULATOR_PORT", 8181)) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_borregasave) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_borregasave) try: sim.load(scene_name, env.int("LGSVL__RANDOM_SEED")) except Exception: @@ -81,7 +80,7 @@ def clamp(val, min_v, max_v): state = lgsvl.AgentState() state.transform = spawns[spawn_index] # TODO some sort of Env Variable so that user/wise can select from list -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, state) # The EGO is now looking for a bridge at the specified IP and port BRIDGE_HOST = env.str("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") diff --git a/examples/SampleTestCases/red-light-runner.py b/examples/SampleTestCases/red-light-runner.py index dc4a360..45118fd 100755 --- a/examples/SampleTestCases/red-light-runner.py +++ b/examples/SampleTestCases/red-light-runner.py @@ -19,7 +19,6 @@ import os import lgsvl -from settings import SimulatorSettings import sys @@ -28,7 +27,7 @@ BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090)) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_borregasave) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_borregasave) sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) if sim.current_scene == scene_name: sim.reset() @@ -38,13 +37,13 @@ # spawn EGO egoState = lgsvl.AgentState() egoState.transform = sim.get_spawn()[0] -ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT) forward = lgsvl.utils.transform_to_forward(egoState.transform) # Unit vector in the forward direction of the EGO right = lgsvl.utils.transform_to_right(egoState.transform) # Unit vector in the right direction of the EGO -# spawn NPC +# spawn NPC npcState = lgsvl.AgentState() npcState.transform = sim.map_point_on_lane(egoState.position + 51.1 * forward + 29 * right) # NPC is 20m ahead of the EGO npc = sim.add_agent("SUV", lgsvl.AgentType.NPC, npcState) diff --git a/examples/SampleTestCases/sudden-braking.py b/examples/SampleTestCases/sudden-braking.py index 18131a9..8931d6e 100755 --- a/examples/SampleTestCases/sudden-braking.py +++ b/examples/SampleTestCases/sudden-braking.py @@ -19,7 +19,6 @@ import os import lgsvl -from settings import SimulatorSettings import sys @@ -28,7 +27,7 @@ BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090)) -scene_name = env.str("LGSVL__MAP", SimulatorSettings.map_singlelaneroad) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_singlelaneroad) sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) if sim.current_scene == scene_name: sim.reset() @@ -38,12 +37,12 @@ # spawn EGO egoState = lgsvl.AgentState() egoState.transform = sim.get_spawn()[0] -ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) +ego = sim.add_agent(os.environ.get("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5_full_analysis), lgsvl.AgentType.EGO, egoState) ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT) forward = lgsvl.utils.transform_to_forward(egoState.transform) # Unit vector in the forward direction of the EGO -# spawn NPC +# spawn NPC npcState = lgsvl.AgentState() npcState.transform = egoState.transform npcState.transform.position = egoState.position + 20 * forward # NPC is 20m ahead of the EGO diff --git a/lgsvl/__init__.py b/lgsvl/__init__.py index bea00ef..8d0d31e 100644 --- a/lgsvl/__init__.py +++ b/lgsvl/__init__.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2020 LG Electronics, Inc. +# Copyright (c) 2019-2021 LG Electronics, Inc. # # This software contains code licensed as described in LICENSE. # @@ -27,3 +27,4 @@ # Subpackages import lgsvl.dreamview import lgsvl.evaluator +import lgsvl.wise diff --git a/lgsvl/wise/__init__.py b/lgsvl/wise/__init__.py new file mode 100644 index 0000000..4266453 --- /dev/null +++ b/lgsvl/wise/__init__.py @@ -0,0 +1,7 @@ +# +# Copyright (c) 2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +from .wise import DefaultAssets, SimulatorSettings diff --git a/settings.py b/lgsvl/wise/wise.py similarity index 97% rename from settings.py rename to lgsvl/wise/wise.py index 50cee4a..f179f61 100644 --- a/settings.py +++ b/lgsvl/wise/wise.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 # # Copyright (c) 2021 LG Electronics, Inc. # @@ -6,7 +5,7 @@ # -# Settings class with common variables used in the quickstart and example scripts. +# Settings classes with common variables used in the quickstart and example scripts. class SimulatorSettings: # IP address of the endpoint running the Simulator. Default value is "127.0.0.1" simulator_host = "127.0.0.1" @@ -20,6 +19,8 @@ class SimulatorSettings: # Port used by the Simulator for the bridge connection. Default value is 9090 bridge_port = 9090 + +class DefaultAssets: # Map loaded in the quickstart scripts. Changing the map may lead to unexpected behaviour in the quickstart scripts. Default value is "BorregasAve". # https://wise.svlsimulator.com/maps/profile/aae03d2a-b7ca-4a88-9e41-9035287a12cc map_borregasave = "aae03d2a-b7ca-4a88-9e41-9035287a12cc" diff --git a/quickstart/01-connecting-to-simulator.py b/quickstart/01-connecting-to-simulator.py index c9ca2c8..01ab56e 100755 --- a/quickstart/01-connecting-to-simulator.py +++ b/quickstart/01-connecting-to-simulator.py @@ -7,7 +7,6 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #1: Connecting to the Simulator") env = Env() @@ -15,7 +14,7 @@ # Connects to the simulator instance at the ip defined by LGSVL__SIMULATOR_HOST, default is localhost or 127.0.0.1 # env.str() is equivalent to os.environ.get() # env.int() is equivalent to int(os.environ.get()) -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) print("Version =", sim.version) print("Current Time =", sim.current_time) diff --git a/quickstart/02-loading-scene-show-spawns.py b/quickstart/02-loading-scene-show-spawns.py index d0329c6..c9a56f5 100755 --- a/quickstart/02-loading-scene-show-spawns.py +++ b/quickstart/02-loading-scene-show-spawns.py @@ -7,20 +7,19 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #2: Loading the scene spawn points") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) print("Current Scene = {}".format(sim.current_scene)) # Loads the named map in the connected simulator. The available maps can be set up in web interface -if sim.current_scene == SimulatorSettings.map_borregasave: +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) print("Current Scene = {}".format(sim.current_scene)) print("Current Scene ID = {}".format(sim.current_scene_id)) diff --git a/quickstart/03-raycast.py b/quickstart/03-raycast.py index 11cdac7..ae254b0 100755 --- a/quickstart/03-raycast.py +++ b/quickstart/03-raycast.py @@ -7,16 +7,15 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #3: Using raycasts in the Simulator") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) # The next few lines spawns an EGO vehicle in the map spawns = sim.get_spawn() @@ -26,7 +25,7 @@ forward = lgsvl.utils.transform_to_forward(state.transform) right = lgsvl.utils.transform_to_right(state.transform) up = lgsvl.utils.transform_to_up(state.transform) -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # This is the point from which the rays will originate from. It is raised 1m from the ground p = spawns[0].position diff --git a/quickstart/04-ego-drive-straight.py b/quickstart/04-ego-drive-straight.py index 70bddbb..656b900 100755 --- a/quickstart/04-ego-drive-straight.py +++ b/quickstart/04-ego-drive-straight.py @@ -7,16 +7,15 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #4: Ego vehicle driving straight") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() @@ -27,7 +26,7 @@ # Agents can be spawned with a velocity. Default is to spawn with 0 velocity state.velocity = 20 * forward -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # The bounding box of an agent are 2 points (min and max) such that the box formed from those 2 points completely encases the agent print("Vehicle bounding box =", ego.bounding_box) diff --git a/quickstart/05-ego-drive-in-circle.py b/quickstart/05-ego-drive-in-circle.py index e23d8b7..b32385c 100755 --- a/quickstart/05-ego-drive-in-circle.py +++ b/quickstart/05-ego-drive-in-circle.py @@ -7,16 +7,15 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #5: Ego vehicle driving in circle") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() @@ -24,7 +23,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) state.transform.position += 5 * forward # 5m forwards -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) print("Current time = ", sim.current_time) print("Current frame = ", sim.current_frame) diff --git a/quickstart/06-save-camera-image.py b/quickstart/06-save-camera-image.py index babdbc3..4e90274 100755 --- a/quickstart/06-save-camera-image.py +++ b/quickstart/06-save-camera-image.py @@ -7,22 +7,21 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #6: Saving an image from the Main Camera sensor") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # get_sensors returns a list of sensors on the EGO vehicle sensors = ego.get_sensors() diff --git a/quickstart/07-save-lidar-point-cloud.py b/quickstart/07-save-lidar-point-cloud.py index 6adb26a..2842c86 100755 --- a/quickstart/07-save-lidar-point-cloud.py +++ b/quickstart/07-save-lidar-point-cloud.py @@ -7,22 +7,21 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #7: Saving a point cloud from the Lidar sensor") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) sensors = ego.get_sensors() for s in sensors: diff --git a/quickstart/08-create-npc.py b/quickstart/08-create-npc.py index 23e161b..475bc51 100755 --- a/quickstart/08-create-npc.py +++ b/quickstart/08-create-npc.py @@ -7,22 +7,21 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #8: Creating various NPCs") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) diff --git a/quickstart/09-reset-scene.py b/quickstart/09-reset-scene.py index 6bb11c8..9c60fc0 100755 --- a/quickstart/09-reset-scene.py +++ b/quickstart/09-reset-scene.py @@ -8,24 +8,23 @@ import random from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #9: Resetting the scene to it's initial state") env = Env() random.seed(0) -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) diff --git a/quickstart/10-npc-follow-the-lane.py b/quickstart/10-npc-follow-the-lane.py index deaecfc..1b6a4af 100755 --- a/quickstart/10-npc-follow-the-lane.py +++ b/quickstart/10-npc-follow-the-lane.py @@ -7,22 +7,21 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #10: NPC following the lane") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) state = lgsvl.AgentState() diff --git a/quickstart/11-collision-callbacks.py b/quickstart/11-collision-callbacks.py index 59edb26..3357f4e 100755 --- a/quickstart/11-collision-callbacks.py +++ b/quickstart/11-collision-callbacks.py @@ -7,16 +7,15 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #11: Handling the collision callbacks") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -26,7 +25,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] state.velocity = 6 * forward -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # school bus, 20m ahead, perpendicular to road, stopped state = lgsvl.AgentState() diff --git a/quickstart/12-create-npc-on-lane.py b/quickstart/12-create-npc-on-lane.py index 84b0625..27a89ad 100755 --- a/quickstart/12-create-npc-on-lane.py +++ b/quickstart/12-create-npc-on-lane.py @@ -9,22 +9,21 @@ import random from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #12: Creating NPCs on lanes") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) sx = spawns[0].position.x sy = spawns[0].position.y diff --git a/quickstart/13-npc-follow-waypoints.py b/quickstart/13-npc-follow-waypoints.py index ad3a643..d2ef498 100755 --- a/quickstart/13-npc-follow-waypoints.py +++ b/quickstart/13-npc-follow-waypoints.py @@ -8,16 +8,15 @@ import copy from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #13: NPC following waypoints") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -30,7 +29,7 @@ # Ego ego_state = copy.deepcopy(state) ego_state.transform.position += 50 * forward -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # NPC npc_state = copy.deepcopy(state) diff --git a/quickstart/14-create-pedestrians.py b/quickstart/14-create-pedestrians.py index 0e49ef7..c58084b 100755 --- a/quickstart/14-create-pedestrians.py +++ b/quickstart/14-create-pedestrians.py @@ -9,16 +9,15 @@ import time from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #14: Creating pedestrians on the map") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() @@ -26,7 +25,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) input("Press Enter to create 100 pedestrians") diff --git a/quickstart/15-pedestrian-walk-randomly.py b/quickstart/15-pedestrian-walk-randomly.py index 0bac766..0d9691d 100755 --- a/quickstart/15-pedestrian-walk-randomly.py +++ b/quickstart/15-pedestrian-walk-randomly.py @@ -7,16 +7,15 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #15: Pedestrian walking randomly") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -26,7 +25,7 @@ state.transform.position = spawns[0].position + 40 * forward state.transform.rotation = spawns[0].rotation -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) state = lgsvl.AgentState() # Spawn the pedestrian in front of car diff --git a/quickstart/16-pedestrian-follow-waypoints.py b/quickstart/16-pedestrian-follow-waypoints.py index 45a058f..7327891 100755 --- a/quickstart/16-pedestrian-follow-waypoints.py +++ b/quickstart/16-pedestrian-follow-waypoints.py @@ -8,16 +8,15 @@ import math from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #16: Pedestrian following waypoints") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[1]) @@ -25,7 +24,7 @@ state = lgsvl.AgentState() state.transform = spawns[1] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # This will create waypoints in a circle for the pedestrian to follow radius = 4 diff --git a/quickstart/17-many-pedestrians-walking.py b/quickstart/17-many-pedestrians-walking.py index c0083e9..55af15e 100755 --- a/quickstart/17-many-pedestrians-walking.py +++ b/quickstart/17-many-pedestrians-walking.py @@ -8,16 +8,15 @@ import random from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #17: Many pedestrians walking simultaneously") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() @@ -25,7 +24,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) right = lgsvl.utils.transform_to_right(spawns[0]) -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) names = [ "Bob", diff --git a/quickstart/18-weather-effects.py b/quickstart/18-weather-effects.py index 7ba2c8f..c62f281 100755 --- a/quickstart/18-weather-effects.py +++ b/quickstart/18-weather-effects.py @@ -7,22 +7,21 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #18: Changing the weather effects") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) print(sim.weather) diff --git a/quickstart/19-time-of-day.py b/quickstart/19-time-of-day.py index 4aeee9a..70f230d 100755 --- a/quickstart/19-time-of-day.py +++ b/quickstart/19-time-of-day.py @@ -8,22 +8,21 @@ from environs import Env import lgsvl from datetime import datetime -from settings import SimulatorSettings print("Python API Quickstart #19: Changing the time of day") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) print("Current time:", sim.time_of_day) diff --git a/quickstart/20-enable-sensors.py b/quickstart/20-enable-sensors.py index 4c79cff..d764147 100755 --- a/quickstart/20-enable-sensors.py +++ b/quickstart/20-enable-sensors.py @@ -7,22 +7,21 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #20: Enabling and disabling sensors") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[1] -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) sensors = ego.get_sensors() diff --git a/quickstart/21-map-coordinates.py b/quickstart/21-map-coordinates.py index 9106230..e446266 100755 --- a/quickstart/21-map-coordinates.py +++ b/quickstart/21-map-coordinates.py @@ -7,16 +7,15 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #21: Converting the map coordinates") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() diff --git a/quickstart/22-connecting-bridge.py b/quickstart/22-connecting-bridge.py index 1e03ef6..0cdc2ef 100755 --- a/quickstart/22-connecting-bridge.py +++ b/quickstart/22-connecting-bridge.py @@ -8,28 +8,27 @@ import time from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #22: Connecting to a bridge") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() state = lgsvl.AgentState() state.transform = spawns[0] -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # An EGO will not connect to a bridge unless commanded to print("Bridge connected:", ego.bridge_connected) # The EGO is now looking for a bridge at the specified IP and port -ego.connect_bridge(env.str("LGSVL__AUTOPILOT_0_HOST", SimulatorSettings.bridge_host), env.int("LGSVL__AUTOPILOT_0_PORT", SimulatorSettings.bridge_port)) +ego.connect_bridge(env.str("LGSVL__AUTOPILOT_0_HOST", lgsvl.wise.SimulatorSettings.bridge_host), env.int("LGSVL__AUTOPILOT_0_PORT", lgsvl.wise.SimulatorSettings.bridge_port)) print("Waiting for connection...") diff --git a/quickstart/23-npc-callbacks.py b/quickstart/23-npc-callbacks.py index 4570a02..7b8ffaa 100755 --- a/quickstart/23-npc-callbacks.py +++ b/quickstart/23-npc-callbacks.py @@ -9,16 +9,15 @@ import random from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #23: Handling NPCs callbacks") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -26,7 +25,7 @@ state = lgsvl.AgentState() state.transform = sim.map_point_on_lane(spawns[0].position + 200 * forward) -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) mindist = 10.0 maxdist = 40.0 diff --git a/quickstart/24-ego-drive-straight-non-realtime.py b/quickstart/24-ego-drive-straight-non-realtime.py index e000813..175a143 100755 --- a/quickstart/24-ego-drive-straight-non-realtime.py +++ b/quickstart/24-ego-drive-straight-non-realtime.py @@ -8,16 +8,15 @@ import time from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #24: Changing the Simulator timescale") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() @@ -26,7 +25,7 @@ forward = lgsvl.utils.transform_to_forward(spawns[0]) # Agents can be spawned with a velocity. Default is to spawn with 0 velocity state.velocity = 20 * forward -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) print("Real time elapsed =", 0) print("Simulation time =", sim.current_time) diff --git a/quickstart/25-waypoint-flying-npc.py b/quickstart/25-waypoint-flying-npc.py index 9cae166..903feef 100755 --- a/quickstart/25-waypoint-flying-npc.py +++ b/quickstart/25-waypoint-flying-npc.py @@ -7,16 +7,15 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #25: NPC flying to waypoints") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() @@ -26,7 +25,7 @@ right = lgsvl.utils.transform_to_right(spawns[0]) up = lgsvl.utils.transform_to_up(spawns[0]) state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() diff --git a/quickstart/26-npc-trigger-waypoints.py b/quickstart/26-npc-trigger-waypoints.py index 65110ef..4dff68f 100755 --- a/quickstart/26-npc-trigger-waypoints.py +++ b/quickstart/26-npc-trigger-waypoints.py @@ -7,16 +7,15 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #26: NPC triggering the waypoints callbacks") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() @@ -26,7 +25,7 @@ right = lgsvl.utils.transform_to_right(spawns[0]) state.transform = spawns[0] state.velocity = 12 * forward -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() diff --git a/quickstart/27-control-traffic-lights.py b/quickstart/27-control-traffic-lights.py index 926178d..20814be 100755 --- a/quickstart/27-control-traffic-lights.py +++ b/quickstart/27-control-traffic-lights.py @@ -7,16 +7,15 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #27: How to Control Traffic Light") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave, 42) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave, 42) spawns = sim.get_spawn() @@ -24,11 +23,11 @@ forward = lgsvl.utils.transform_to_forward(spawns[0]) state.transform = spawns[0] state.transform.position = spawns[0].position + 20 * forward -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # # Get a list of controllable objects controllables = sim.get_controllables("signal") -print("\n# List of controllable objects in {} scene:".format(SimulatorSettings.map_borregasave)) +print("\n# List of controllable objects in {} scene:".format(lgsvl.wise.DefaultAssets.map_borregasave)) for c in controllables: print(c) diff --git a/quickstart/28-control-traffic-cone.py b/quickstart/28-control-traffic-cone.py index 2b65ab9..c0e2572 100755 --- a/quickstart/28-control-traffic-cone.py +++ b/quickstart/28-control-traffic-cone.py @@ -7,16 +7,15 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #28: How to Add/Control Traffic Cone") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave, 42) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave, 42) spawns = sim.get_spawn() @@ -26,7 +25,7 @@ up = lgsvl.utils.transform_to_up(spawns[0]) state.transform = spawns[0] -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) for i in range(10 * 3): # Create controllables in a block diff --git a/quickstart/29-add-random-agents.py b/quickstart/29-add-random-agents.py index 6324c9f..8fbf6df 100755 --- a/quickstart/29-add-random-agents.py +++ b/quickstart/29-add-random-agents.py @@ -7,16 +7,15 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #29: Adding random agents to a simulation") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) spawns = sim.get_spawn() forward = lgsvl.utils.transform_to_forward(spawns[0]) @@ -26,7 +25,7 @@ state.transform.position = spawns[0].position + 40 * forward state.transform.rotation = spawns[0].rotation -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) sim.add_random_agents(lgsvl.AgentType.NPC) sim.add_random_agents(lgsvl.AgentType.PEDESTRIAN) diff --git a/quickstart/30-time-to-collision-trigger.py b/quickstart/30-time-to-collision-trigger.py index 594c67f..69e256f 100755 --- a/quickstart/30-time-to-collision-trigger.py +++ b/quickstart/30-time-to-collision-trigger.py @@ -7,16 +7,15 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #30: Using the time to collision trigger") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave, 42) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave, 42) spawns = sim.get_spawn() layer_mask = 0 @@ -33,7 +32,7 @@ spawn_state.position = hit.point state.transform = spawn_state state.velocity = forward * 2 -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() diff --git a/quickstart/31-wait-for-distance-trigger.py b/quickstart/31-wait-for-distance-trigger.py index effac06..89b3b40 100755 --- a/quickstart/31-wait-for-distance-trigger.py +++ b/quickstart/31-wait-for-distance-trigger.py @@ -7,16 +7,15 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #31: Using the wait for distance trigger") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave, 42) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave, 42) spawns = sim.get_spawn() layer_mask = 0 @@ -33,7 +32,7 @@ spawn_state.position = hit.point state.transform = spawn_state state.velocity = forward * 2 -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # NPC state = lgsvl.AgentState() diff --git a/quickstart/32-pedestrian-time-to-collision.py b/quickstart/32-pedestrian-time-to-collision.py index 1702b4a..ac89a07 100755 --- a/quickstart/32-pedestrian-time-to-collision.py +++ b/quickstart/32-pedestrian-time-to-collision.py @@ -7,16 +7,15 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #1: Using the time to collision trigger with a pedestrian") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave, 42) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave, 42) spawns = sim.get_spawn() layer_mask = 0 @@ -30,7 +29,7 @@ state.transform.rotation = lgsvl.Vector(0.0, 15.0, 0.0) forward = lgsvl.Vector(0.2, 0.0, 0.8) state.velocity = forward * 15 -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # Pedestrian state = lgsvl.AgentState() diff --git a/quickstart/33-ego-drive-stepped.py b/quickstart/33-ego-drive-stepped.py index eff2c89..22b130d 100755 --- a/quickstart/33-ego-drive-stepped.py +++ b/quickstart/33-ego-drive-stepped.py @@ -8,14 +8,13 @@ import os import lgsvl import time -from settings import SimulatorSettings print("Python API Quickstart #33: Stepping a simulation") -sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), SimulatorSettings.simulator_port) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(os.environ.get("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), lgsvl.wise.SimulatorSettings.simulator_port) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() # Re-load scene and set random seed -sim.load(SimulatorSettings.map_borregasave, seed=123) +sim.load(lgsvl.wise.DefaultAssets.map_borregasave, seed=123) spawns = sim.get_spawn() @@ -33,13 +32,13 @@ # We can test Apollo with standard MKZ or MKZ with ground truth sensors # Refer to https://www.svlsimulator.com/docs/modular-testing/ -ego = sim.add_agent(SimulatorSettings.ego_lincoln2017mkz_apollo5, lgsvl.AgentType.EGO, state) +ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5, lgsvl.AgentType.EGO, state) # An EGO will not connect to a bridge unless commanded to print("Bridge connected:", ego.bridge_connected) # The EGO looks for a (Cyber) bridge at the specified IP and port -ego.connect_bridge(SimulatorSettings.bridge_host, SimulatorSettings.bridge_port) +ego.connect_bridge(lgsvl.wise.SimulatorSettings.bridge_host, lgsvl.wise.SimulatorSettings.bridge_port) # uncomment to wait for bridge connection; script will drive ego if bridge not found # print("Waiting for connection...") # while not ego.bridge_connected: diff --git a/quickstart/34-simulator-cam-set.py b/quickstart/34-simulator-cam-set.py index aa2eff7..8f84e95 100755 --- a/quickstart/34-simulator-cam-set.py +++ b/quickstart/34-simulator-cam-set.py @@ -7,16 +7,15 @@ from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #34: Setting the fixed camera position") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) -if sim.current_scene == SimulatorSettings.map_borregasave: +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave: sim.reset() else: - sim.load(SimulatorSettings.map_borregasave) + sim.load(lgsvl.wise.DefaultAssets.map_borregasave) # This creates a transform in Unity world coordinates tr = lgsvl.Transform(lgsvl.Vector(10, 50, 0), lgsvl.Vector(90, 0, 0)) @@ -27,7 +26,7 @@ state.transform = spawns[0] forward = lgsvl.utils.transform_to_forward(spawns[0]) state.velocity = 20 * forward -ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) # This function sets the camera to free state and applies the transform to the camera rig sim.set_sim_camera(tr) diff --git a/quickstart/98-npc-behaviour.py b/quickstart/98-npc-behaviour.py index 32c965b..24a846a 100755 --- a/quickstart/98-npc-behaviour.py +++ b/quickstart/98-npc-behaviour.py @@ -9,23 +9,22 @@ import random from environs import Env import lgsvl -from settings import SimulatorSettings print("Python API Quickstart #98: Simulating different NPCs behaviours") env = Env() -sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", SimulatorSettings.simulator_port)) +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) drunkDriverAvailable = False trailerAvailable = 0 print("Current Scene = {}".format(sim.current_scene)) # Loads the named map in the connected simulator. -if sim.current_scene == SimulatorSettings.map_cubetown: +if sim.current_scene == lgsvl.wise.DefaultAssets.map_cubetown: sim.reset() else: - print("Loading Scene = {}".format(SimulatorSettings.map_cubetown)) - sim.load(SimulatorSettings.map_cubetown) + print("Loading Scene = {}".format(lgsvl.wise.DefaultAssets.map_cubetown)) + sim.load(lgsvl.wise.DefaultAssets.map_cubetown) agents = sim.available_agents print("agents:") @@ -60,7 +59,7 @@ state = lgsvl.AgentState() state.transform = spawns[0] -sim.add_agent(env.str("LGSVL__VEHICLE_0", SimulatorSettings.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) +sim.add_agent(env.str("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state) mindist = 10.0 maxdist = 40.0 diff --git a/setup.py b/setup.py index 4c46208..39589cf 100755 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ author_email="contact@svlsimulator.com", python_requires=">=3.6.0", url="https://github.com/lgsvl/PythonAPI", - packages=["lgsvl", "lgsvl.dreamview", "lgsvl.evaluator"], + packages=["lgsvl", "lgsvl.dreamview", "lgsvl.evaluator", "lgsvl.wise"], install_requires=[ "websockets==7.0", "websocket-client==0.57.0", diff --git a/tests/common.py b/tests/common.py index 5cb327b..bc38f4d 100644 --- a/tests/common.py +++ b/tests/common.py @@ -7,7 +7,6 @@ import signal import lgsvl import os -from settings import SimulatorSettings class TestTimeout(Exception): pass @@ -18,7 +17,7 @@ class TestException(Exception): class SimConnection: - def __init__(self, seconds=30, scene=SimulatorSettings.map_borregasave, error_message=None, load_scene=True): + def __init__(self, seconds=30, scene=lgsvl.wise.DefaultAssets.map_borregasave, error_message=None, load_scene=True): if error_message is None: error_message = 'test timed out after {}s.'.format(seconds) self.seconds = seconds diff --git a/tests/test_EGO.py b/tests/test_EGO.py index 3b8821b..775951e 100644 --- a/tests/test_EGO.py +++ b/tests/test_EGO.py @@ -10,7 +10,6 @@ import lgsvl from .common import SimConnection, spawnState, cmEqual -from settings import SimulatorSettings # TODO add tests for bridge connection @@ -20,7 +19,7 @@ def test_agent_name(self): # Check if EGO Apollo is created with SimConnection() as sim: agent = self.create_EGO(sim) - self.assertEqual(agent.name, SimulatorSettings.ego_jaguar2015xe_apollo5) + self.assertEqual(agent.name, lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5) def test_different_spawns(self): # Check if EGO is spawned in the spawn positions with SimConnection() as sim: @@ -31,7 +30,7 @@ def test_different_spawns(self): # Check if EGO is spawned in the spawn positio state = spawnState(sim) state.transform = spawns[1] - agent2 = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + agent2 = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) cmEqual(self, agent2.state.position, spawns[1].position, "Spawn Position 1") cmEqual(self, agent2.state.rotation, spawns[1].rotation, "Spawn Rotation 1") @@ -45,7 +44,7 @@ def test_agent_velocity(self): # Check EGO velocity sim.reset() right = lgsvl.utils.transform_to_right(state.transform) state.velocity = -50 * right - agent = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + agent = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) cmEqual(self, agent.state.velocity, state.velocity, "50 Velocity") @@ -57,21 +56,21 @@ def test_ego_different_directions(self): # Check that the xyz velocities equate right = lgsvl.utils.transform_to_right(state.transform) state.velocity = -10 * right - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) sim.run(.5) target = state.position - 3 * right self.assertLess((ego.state.position - target).magnitude(), 1) sim.remove_agent(ego) state.velocity = 10 * up - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) sim.run(.5) target = state.position + 3 * up self.assertLess((ego.state.position - target).magnitude(), 1) sim.remove_agent(ego) state.velocity = 10 * forward - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) sim.run(.5) target = state.position + 4 * forward self.assertLess((ego.state.position - target).magnitude(), 1) @@ -83,7 +82,7 @@ def test_speed(self): # check that speed returns a reasonable number up = lgsvl.utils.transform_to_up(state.transform) right = lgsvl.utils.transform_to_right(state.transform) state.velocity = -10 * right + 10 * up + 10 * forward - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) self.assertAlmostEqual(ego.state.speed, math.sqrt(300), places=3) @unittest.skip("No highway in currents maps") @@ -91,14 +90,14 @@ def test_rotation_on_highway_ramp(self): # Check that vehicle is rotated when s with SimConnection() as sim: state = spawnState(sim) state.transform.position = lgsvl.Vector(469.6401, 15.67488, 100.4229) - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) self.assertAlmostEqual(ego.state.rotation.z, state.rotation.z) sim.run(0.5) self.assertAlmostEqual(ego.state.rotation.z, 356, delta=0.5) 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(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.throttle = 0.3 control.steering = -1.0 @@ -110,7 +109,7 @@ def test_ego_steering(self): # Check that a steering command can be given to an 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(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.throttle = 0.5 ego.apply_control(control, True) @@ -122,7 +121,7 @@ def test_ego_throttle(self): # Check that a throttle command can be given to an 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(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + 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) @@ -133,7 +132,7 @@ def test_ego_braking(self): # Check that a brake command can be given to an EGO noBrakeDistance = (ego.state.position - state.position).magnitude() sim.reset() - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + 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) @@ -148,7 +147,7 @@ def test_ego_braking(self): # Check that a brake command can be given to an EGO 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(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + 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) @@ -159,7 +158,7 @@ def test_ego_handbrake(self): # Check that the handbrake can be enable on an EG noBrakeDistance = (ego.state.position - state.position).magnitude() sim.reset() - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + 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) @@ -174,7 +173,7 @@ def test_ego_handbrake(self): # Check that the handbrake can be enable on an EG 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(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) control = lgsvl.VehicleControl() control.throttle = 0.5 control.reverse = True @@ -188,7 +187,7 @@ def test_ego_reverse(self): # Check that the gear can be changed in an EGO vehi 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(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + 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) @@ -196,7 +195,7 @@ def test_not_sticky_control(self): # Check that the a non sticky control is rem stickySpeed = ego.state.speed sim.reset() - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + 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) @@ -208,7 +207,7 @@ def test_not_sticky_control(self): # Check that the a non sticky control is rem def test_vary_throttle(self): # Check that different throttle values accelerate differently with SimConnection(40) as sim: - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.throttle = 0.5 ego.apply_control(control, True) @@ -216,7 +215,7 @@ def test_vary_throttle(self): # Check that different throttle values accelerate initialSpeed = ego.state.speed sim.reset() - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.throttle = 0.1 ego.apply_control(control, True) @@ -225,7 +224,7 @@ def test_vary_throttle(self): # Check that different throttle values accelerate def test_vary_steering(self): # Check that different steering values turn the car differently with SimConnection(40) as sim: - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.throttle = 0.5 control.steering = -0.8 @@ -234,7 +233,7 @@ def test_vary_steering(self): # Check that different steering values turn the c initialAngle = ego.state.rotation.y sim.reset() - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.throttle = 0.5 control.steering = -0.3 @@ -244,7 +243,7 @@ def test_vary_steering(self): # Check that different steering values turn the c def test_bounding_box_size(self): # Check that the bounding box is calculated properly and is reasonable with SimConnection() as sim: - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) bBox = ego.bounding_box self.assertAlmostEqual(bBox.size.x, abs(bBox.max.x-bBox.min.x)) self.assertAlmostEqual(bBox.size.y, abs(bBox.max.y-bBox.min.y)) @@ -255,7 +254,7 @@ def test_bounding_box_size(self): # Check that the bounding box is calculated p def test_bounding_box_center(self): # Check that the bounding box center is calcualted properly with SimConnection() as sim: - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) bBox = ego.bounding_box self.assertAlmostEqual(bBox.center.x, (bBox.max.x+bBox.min.x)/2) self.assertAlmostEqual(bBox.center.y, (bBox.max.y+bBox.min.y)/2) @@ -263,22 +262,22 @@ def test_bounding_box_center(self): # Check that the bounding box center is cal def test_equality(self): # Check that agent == operation works with SimConnection() as sim: - ego1 = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) - ego2 = sim.add_agent(SimulatorSettings.ego_jaguae2015xe_autowareai, lgsvl.AgentType.EGO, spawnState(sim)) + ego1 = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + ego2 = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguae2015xe_autowareai, lgsvl.AgentType.EGO, spawnState(sim)) self.assertTrue(ego1 == ego1) self.assertFalse(ego1 == ego2) @unittest.skip("Cruise Control not implemented yet") def test_set_fixed_speed(self): with SimConnection(60) as sim: - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) ego.set_fixed_speed(True, 15.0) self.assertAlmostEqual(ego.state.speed, 0, delta=0.001) sim.run(5) self.assertAlmostEqual(ego.state.speed, 15, delta=1) def create_EGO(self, sim): # Only create an EGO is none are already spawned - return sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + return sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) # def test_large_throttle(self): # with SimConnection(60) as sim: diff --git a/tests/test_NPC.py b/tests/test_NPC.py index d78cc7e..dcd693c 100644 --- a/tests/test_NPC.py +++ b/tests/test_NPC.py @@ -8,7 +8,6 @@ import time import lgsvl from .common import SimConnection, spawnState, cmEqual, mEqual, TestException -from settings import SimulatorSettings PROBLEM = "Object reference not set to an instance of an object" @@ -31,7 +30,7 @@ def test_NPC_creation(self): # Check if the different types of NPCs can be crea state = spawnState(sim) right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position + 10 * right - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) spawns = sim.get_spawn() for name in ["Sedan", "SUV", "Jeep", "Hatchback", "SchoolBus", "BoxTruck"]: agent = self.create_NPC(sim, name) @@ -44,17 +43,17 @@ def test_get_agents(self): state = spawnState(sim) right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position + 10 * right - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) for name in ["Sedan", "SUV", "Jeep", "Hatchback", "SchoolBus", "BoxTruck"]: self.create_NPC(sim, name) agentCount += 1 agents = sim.get_agents() self.assertEqual(len(agents), agentCount) - agentCounter = {SimulatorSettings.ego_jaguar2015xe_apollo5:0, "Sedan":0, "SUV":0, "Jeep":0, "Hatchback":0, "SchoolBus":0, "BoxTruck":0} + agentCounter = {lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5:0, "Sedan":0, "SUV":0, "Jeep":0, "Hatchback":0, "SchoolBus":0, "BoxTruck":0} for a in agents: agentCounter[a.name] += 1 - expectedAgents = [SimulatorSettings.ego_jaguar2015xe_apollo5, "Sedan", "SUV", "Jeep", "Hatchback", "SchoolBus", "BoxTruck"] + expectedAgents = [lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, "Sedan", "SUV", "Jeep", "Hatchback", "SchoolBus", "BoxTruck"] for a in expectedAgents: with self.subTest(a): self.assertEqual(agentCounter[a], 1) @@ -64,7 +63,7 @@ def test_NPC_follow_lane(self): # Check if NPC can follow lane state = spawnState(sim) right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position - 5 * right - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) agent = self.create_NPC(sim, "Sedan") agent.follow_closest_lane(True, 5.6) sim.run(2.0) @@ -78,7 +77,7 @@ def test_rotate_NPC(self): # Check if NPC can be rotated state = spawnState(sim) right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position - 5 * right - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) agent = self.create_NPC(sim, "SUV") self.assertAlmostEqual(agent.state.transform.rotation.y, 104.823394, places=3) x = agent.state @@ -112,7 +111,7 @@ def test_upsidedown_NPC(self): # Check that an upside-down NPC keeps falling state = spawnState(sim) right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position + 10 * right - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) state = spawnState(sim) state.rotation.z += 180 agent = sim.add_agent("Hatchback", lgsvl.AgentType.NPC, state) @@ -127,7 +126,7 @@ def test_flying_NPC(self): # Check if an NPC created above the map falls forward = lgsvl.utils.transform_to_forward(state.transform) up = lgsvl.utils.transform_to_up(state.transform) state.transform.position = state.position - 10 * forward + 200 * up - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) state = spawnState(sim) state.transform.position = state.position + 200 * up agent = sim.add_agent("Hatchback", lgsvl.AgentType.NPC, state) @@ -163,7 +162,7 @@ def test_follow_waypoints(self): # Check that the NPC can follow waypoints forward = lgsvl.utils.transform_to_forward(state.transform) right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position - 5 * right - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) spawns = sim.get_spawn() agent = self.create_NPC(sim, "Sedan") @@ -203,7 +202,7 @@ def test_high_waypoint(self): # Check that a NPC will drive to under a high way right = lgsvl.utils.transform_to_right(state.transform) up = lgsvl.utils.transform_to_up(state.transform) state.transform.position = state.position - 5 * right - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) spawns = sim.get_spawn() agent = self.create_NPC(sim, "Sedan") @@ -231,7 +230,7 @@ def test_npc_different_directions(self): # Check that specified velocities matc right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position - 5 * right - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) state = spawnState(sim) state.velocity = -10 * right npc = sim.add_agent("SUV", lgsvl.AgentType.NPC, state) @@ -268,7 +267,7 @@ def on_stop_line(agent): right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position - 5 * right - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) sim.run(60) self.assertIn("Waypoint reached", repr(e.exception)) @@ -291,7 +290,7 @@ def on_stop_line(agent): def test_spawn_speed(self): # Checks that a spawned agent keeps the correct speed when spawned with SimConnection() as sim: - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim, 1)) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim, 1)) npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, spawnState(sim)) self.assertEqual(npc.state.speed,0) @@ -305,7 +304,7 @@ def test_lane_change_right(self): npc = sim.add_agent("SUV", lgsvl.AgentType.NPC, state) state.transform = sim.map_point_on_lane(lgsvl.Vector(0.63, -1.57, 42.73)) - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(state.transform) target = state.position + 31 * forward @@ -333,7 +332,7 @@ def test_lane_change_right_missing_lane(self): target = state.position + 42.75 * forward state.transform = sim.map_point_on_lane(lgsvl.Vector(4.49, -1.57, 40.85)) - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) npc.follow_closest_lane(True, 10) @@ -357,7 +356,7 @@ def test_lane_change_left(self): npc = sim.add_agent("SUV", lgsvl.AgentType.NPC, state) state.transform = sim.map_point_on_lane(lgsvl.Vector(9.82, -1.79, 42.02)) - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(state.transform) target = state.position + 31 * forward @@ -385,7 +384,7 @@ def test_lane_change_left_opposing_traffic(self): target = state.position + 42.75 * forward state.transform.position = state.position - 10 * forward - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) npc.follow_closest_lane(True, 10) @@ -408,7 +407,7 @@ def test_multiple_lane_changes(self): state = lgsvl.AgentState() state.transform.position = lgsvl.Vector(-180,10,239) state.transform.rotation = lgsvl.Vector(0,90,0) - sim.add_agent(SimulatorSettings.ego_jaguae2015xe_autowareai, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguae2015xe_autowareai, lgsvl.AgentType.EGO, state) state = lgsvl.AgentState() state.transform.position = lgsvl.Vector(-175, 10, 234.5) @@ -465,7 +464,7 @@ def test_e_stop(self): with SimConnection(60) as sim: state = lgsvl.AgentState() state.transform = sim.map_point_on_lane(lgsvl.Vector(78.962, -3.363, -40.292)) - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(state.transform) state.transform.position = state.position + 10 * forward npc = sim.add_agent("Jeep", lgsvl.AgentType.NPC, state) @@ -486,7 +485,7 @@ def test_waypoint_speed(self): with SimConnection(60) as sim: state = lgsvl.AgentState() state.transform = sim.map_point_on_lane(lgsvl.Vector(78.962, -3.363, -40.292)) - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) forward = lgsvl.utils.transform_to_forward(state.transform) up = lgsvl.utils.transform_to_up(state.transform) state.transform.position = state.position + 10 * forward diff --git a/tests/test_collisions.py b/tests/test_collisions.py index d690245..c24ae6c 100644 --- a/tests/test_collisions.py +++ b/tests/test_collisions.py @@ -8,7 +8,6 @@ import lgsvl from .common import SimConnection, spawnState -from settings import SimulatorSettings # TODO add tests for collisions between NPCs, EGO & obstacles @@ -16,7 +15,7 @@ class TestCollisions(unittest.TestCase): def test_ego_collision(self): # Check that a collision between Ego and NPC is reported with SimConnection() as sim: - mover, bus = self.setup_collision(sim, SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, "SchoolBus", lgsvl.AgentType.NPC) + mover, bus = self.setup_collision(sim, lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, "SchoolBus", lgsvl.AgentType.NPC) collisions = [] def on_collision(agent1, agent2, contact): @@ -31,12 +30,12 @@ def on_collision(agent1, agent2, contact): self.assertGreater(len(collisions), 0) self.assertInBetween(collisions[0][2], collisions[0][0].state.position, collisions[0][1].state.position, "Ego Collision") - self.assertTrue(collisions[0][0].name == SimulatorSettings.ego_jaguar2015xe_apollo5 or collisions[0][1].name == SimulatorSettings.ego_jaguar2015xe_apollo5) + self.assertTrue(collisions[0][0].name == lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5 or collisions[0][1].name == lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5) self.assertTrue(True) def test_sim_stop(self): # Check that sim.stop works properly with SimConnection() as sim: - mover, bus = self.setup_collision(sim, SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, "SchoolBus", lgsvl.AgentType.NPC) + mover, bus = self.setup_collision(sim, lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, "SchoolBus", lgsvl.AgentType.NPC) collisions = [] def on_collision(agent1, agent2, contact): @@ -52,7 +51,7 @@ def on_collision(agent1, agent2, contact): def test_ped_collision(self): # Check if a collision between EGO and pedestrian is reported with SimConnection() as sim: - ego, ped = self.setup_collision(sim, SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, "Howard", lgsvl.AgentType.PEDESTRIAN) + ego, ped = self.setup_collision(sim, lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, "Howard", lgsvl.AgentType.PEDESTRIAN) self.assertTrue(isinstance(ego, lgsvl.EgoVehicle)) self.assertTrue(isinstance(ped, lgsvl.Pedestrian)) collisions = [] @@ -66,7 +65,7 @@ def on_collision(agent1, agent2, contact): sim.run(15) self.assertGreater(len(collisions), 0) self.assertInBetween(collisions[0][2], collisions[0][0].state.position, collisions[0][1].state.position, "Ped Collision") - self.assertTrue(collisions[0][0].name == SimulatorSettings.ego_jaguar2015xe_apollo5 or collisions[0][1].name == SimulatorSettings.ego_jaguar2015xe_apollo5) + self.assertTrue(collisions[0][0].name == lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5 or collisions[0][1].name == lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5) @unittest.skip("NPCs ignore collisions with Pedestrians, activate this when NPCs use real physics") def test_ped_npc_collisions(self): # Check that collision between NPC and Pedestrian is reported @@ -94,7 +93,7 @@ def test_npc_collision(self): # Check that collision between NPC and NPC is rep with SimConnection() as sim: state = spawnState(sim) state.position.x += 10 - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) jeep, bus = self.setup_collision(sim, "Jeep", lgsvl.AgentType.NPC, "SchoolBus", lgsvl.AgentType.NPC) collisions = [] @@ -120,7 +119,7 @@ def test_wall_collision(self): # Check that an EGO collision with a wall is rep right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position + 30 * right - 1 * up + 140 * forward state.velocity = 50 * forward - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) collisions = [] def on_collision(agent1, agent2, contact): @@ -133,9 +132,9 @@ def on_collision(agent1, agent2, contact): self.assertGreater(len(collisions), 0) if collisions[0][0] is None: - self.assertTrue(collisions[0][1].name == SimulatorSettings.ego_jaguar2015xe_apollo5) + self.assertTrue(collisions[0][1].name == lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5) elif collisions[0][1] is None: - self.assertTrue(collisions[0][0].name == SimulatorSettings.ego_jaguar2015xe_apollo5) + self.assertTrue(collisions[0][0].name == lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5) else: self.fail("Collision not with object") diff --git a/tests/test_manual_features.py b/tests/test_manual_features.py index f6c9b68..c9be960 100644 --- a/tests/test_manual_features.py +++ b/tests/test_manual_features.py @@ -10,14 +10,13 @@ import lgsvl from .common import SimConnection, spawnState, TestTimeout -from settings import SimulatorSettings class TestManual(unittest.TestCase): @unittest.skip("Windshield wipers no longer supported") def test_wipers(self): try: with SimConnection() as sim: - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(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) @@ -41,7 +40,7 @@ def test_wipers(self): def test_headlights(self): try: with SimConnection() as sim: - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.headlights = 1 ego.apply_control(control, True) @@ -59,7 +58,7 @@ def test_headlights(self): def test_blinkers(self): try: with SimConnection() as sim: - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.turn_signal_left = True ego.apply_control(control, True) @@ -78,7 +77,7 @@ def test_blinkers(self): def test_wiper_large_value(self): try: with SimConnection() as sim: - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.windshield_wipers = 4 ego.apply_control(control, True) @@ -91,7 +90,7 @@ def test_wiper_large_value(self): def test_wiper_str(self): try: with SimConnection() as sim: - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + ego = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) control = lgsvl.VehicleControl() control.windshield_wipers = "on" ego.apply_control(control, True) @@ -103,7 +102,7 @@ def test_wiper_str(self): def test_headlights_large_value(self): try: with SimConnection() as sim: - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(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) @@ -115,7 +114,7 @@ def test_headlights_large_value(self): def test_headlights_str(self): try: with SimConnection() as sim: - ego = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(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) diff --git a/tests/test_peds.py b/tests/test_peds.py index 5fdcc5c..d49fb5d 100644 --- a/tests/test_peds.py +++ b/tests/test_peds.py @@ -9,7 +9,6 @@ import lgsvl from .common import SimConnection, cmEqual, mEqual, spawnState -from settings import SimulatorSettings class TestPeds(unittest.TestCase): @@ -18,7 +17,7 @@ def test_ped_creation(self): # Check if the different types of Peds can be crea state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) state.transform.position = state.position - 4 * forward - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) for name in ["Bob", "EntrepreneurFemale", "Howard", "Johny", \ "Pamela", "Presley", "Robin", "Stephen", "Zoe"]: agent = self.create_ped(sim, name, spawnState(sim)) @@ -30,7 +29,7 @@ def test_ped_random_walk(self): # Check if pedestrians can walk randomly state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) state.transform.position = state.position - 4 * forward - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) state = spawnState(sim) spawnPoint = state.transform.position @@ -54,7 +53,7 @@ def test_ped_circle_waypoints(self): # Check if pedestrians can follow waypoint forward = lgsvl.utils.transform_to_forward(state.transform) right = lgsvl.utils.transform_to_right(state.transform) state.transform.position = state.position - 4 * forward - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) state = spawnState(sim) state.transform.position = state.position + 10 * forward radius = 5 @@ -85,7 +84,7 @@ def on_waypoint(agent,index): def test_waypoint_idle_time(self): with SimConnection(60) as sim: - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) state = spawnState(sim) forward = lgsvl.utils.transform_to_forward(state.transform) right = lgsvl.utils.transform_to_right(state.transform) diff --git a/tests/test_sensors.py b/tests/test_sensors.py index fada233..e890b7d 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -8,7 +8,6 @@ import os import lgsvl from .common import SimConnection, spawnState, notAlmostEqual -from settings import SimulatorSettings # TODO add tests for bridge to check if enabled sensor actually sends data @@ -16,7 +15,7 @@ class TestSensors(unittest.TestCase): def test_apollo_5_sensors(self): # Check that Apollo 3.5 sensors are created and are positioned reasonably with SimConnection(60) as sim: - agent = self.create_EGO(sim, SimulatorSettings.ego_lincoln2017mkz_apollo5) + agent = self.create_EGO(sim, lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5) expectedSensors = ['Lidar', 'GPS', 'Telephoto Camera', \ 'Main Camera', 'IMU', 'CAN Bus', 'Radar'] sensors = agent.get_sensors() @@ -34,7 +33,7 @@ def test_apollo_5_sensors(self): # Check that Apollo 3.5 sensors are created an @unittest.skip("No SF vehicle") def test_santafe_sensors(self): # Check that Apollo Santa Fe sensors are created and are positioned reasonably with SimConnection() as sim: - agent = self.create_EGO(sim, SimulatorSettings.ego_lincoln2017mkz_apollo5) + agent = self.create_EGO(sim, lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5) expectedSensors = ['velodyne', 'GPS', 'Telephoto Camera', 'Main Camera', \ 'IMU', 'RADAR', 'CANBUS', 'Segmentation Camera', 'Left Camera', 'Right Camera'] sensors = agent.get_sensors() @@ -52,7 +51,7 @@ def test_santafe_sensors(self): # Check that Apollo Santa Fe sensors are create @unittest.skip("No LGSVL Vehicle") def test_lgsvl_sensors(self): # Check that LGSVL sensors are created and are positioned reasonably with SimConnection() as sim: - agent = self.create_EGO(sim, SimulatorSettings.ego_lincoln2017mkz_apollo5) + agent = self.create_EGO(sim, lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5) expectedSensors = ['velodyne', 'GPS', 'Telephoto Camera', 'Main Camera', \ 'IMU', 'RADAR', 'CANBUS', 'Segmentation Camera', 'Left Camera', 'Right Camera'] sensors = agent.get_sensors() @@ -87,7 +86,7 @@ def test_ep_sensors(self): # Check that Apollo EP sensors are created and are p def test_apollo_sensors(self): # Check that all the Apollo sensors are there with SimConnection() as sim: - agent = self.create_EGO(sim, SimulatorSettings.ego_jaguar2015xe_apollo5) + agent = self.create_EGO(sim, lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5) expectedSensors = ["Lidar", "GPS", "Telephoto Camera", "Main Camera", "IMU", \ "CAN Bus", "Radar"] @@ -105,7 +104,7 @@ def test_apollo_sensors(self): # Check that all the Apollo sensors are there def test_autoware_sensors(self): # Check that all Autoware sensors are there with SimConnection() as sim: - agent = self.create_EGO(sim, SimulatorSettings.ego_jaguae2015xe_autowareai) + agent = self.create_EGO(sim, lgsvl.wise.DefaultAssets.ego_jaguae2015xe_autowareai) expectedSensors = ["Lidar", "GPS", "Main Camera", "IMU"] sensors = agent.get_sensors() @@ -131,7 +130,7 @@ def test_save_sensor(self): # Check that sensor results can be saved if os.path.isfile(path): os.remove(path) - agent = self.create_EGO(sim, SimulatorSettings.ego_jaguar2015xe_apollo5) + agent = self.create_EGO(sim, lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5) sensors = agent.get_sensors() savedSuccess = False @@ -158,7 +157,7 @@ def test_save_lidar(self): # Check that LIDAR sensor results can be saved if os.path.isfile(path): os.remove(path) - agent = self.create_EGO(sim, SimulatorSettings.ego_jaguar2015xe_apollo5) + agent = self.create_EGO(sim, lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5) sensors = agent.get_sensors() savedSuccess = False @@ -180,7 +179,7 @@ def test_GPS(self): # Check that the GPS sensor works state.transform = sim.get_spawn()[0] right = lgsvl.utils.transform_to_right(state.transform) state.velocity = -50 * right - agent = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + agent = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) sensors = agent.get_sensors() initialGPSData = None gps = None @@ -206,7 +205,7 @@ def test_GPS(self): # Check that the GPS sensor works def test_sensor_disabling(self): # Check if sensors can be enabled with SimConnection() as sim: - agent = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + agent = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) for s in agent.get_sensors(): if s.name == "Lidar": s.enabled = False @@ -220,7 +219,7 @@ def test_sensor_disabling(self): # Check if sensors can be enabled def test_sensor_equality(self): # Check that sensor == operator works with SimConnection() as sim: - agent = sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + agent = sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) prevSensor = None for s in agent.get_sensors(): self.assertTrue(s == s) diff --git a/tests/test_simulator.py b/tests/test_simulator.py index 6fced91..ca46998 100644 --- a/tests/test_simulator.py +++ b/tests/test_simulator.py @@ -9,7 +9,6 @@ import lgsvl from .common import SimConnection, spawnState -from settings import SimulatorSettings PROBLEM = "Object reference not set to an instance of an object" @@ -33,7 +32,7 @@ def test_spawns(self): # Check if there is at least 1 spawn point for Ego Vehic def test_run_time(self): # Check if the simulator runs 2 seconds with SimConnection() as sim: - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, spawnState(sim)) time = 2.0 initial_time = sim.current_time @@ -64,7 +63,7 @@ def test_raycast(self): # Check if raycasting works forward = lgsvl.utils.transform_to_forward(state.transform) right = lgsvl.utils.transform_to_right(state.transform) up = lgsvl.utils.transform_to_up(state.transform) - sim.add_agent(SimulatorSettings.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) + sim.add_agent(lgsvl.wise.DefaultAssets.ego_jaguar2015xe_apollo5, lgsvl.AgentType.EGO, state) p = spawns[0].position p.y += 1 From c3cc39b8945711bbb32f8985dfbb7de88bd1980d Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Wed, 10 Mar 2021 11:26:41 -0800 Subject: [PATCH 086/115] AUTO-6393: Revert "AUTO-6386: README.md: Set PYTHONPATH when running examples and unit tests" This reverts commit 165ae6a9c8ef3240b73884e1f9fa05f253b2d1ae. --- README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/README.md b/README.md index 3bbdf5b..61745f2 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,6 @@ Documentation is available on our website: https://www.svlsimulator.com/docs/pyt # install in development mode pip3 install --user -e . - # only required when running the examples and unit tests - export PYTHONPATH=$PWD - # Examples Look into `quickstart` and `examples` folders for simple usages. To run these @@ -82,9 +79,6 @@ Lincoln2017MKZ | Apollo 5.0 | https://wise.svlsimulator.com/vehicles/p
Then launch an **API Only** simulation before running the unit tests. - # required to run the unittests - export PYTHONPATH=$PWD - # run all unittests python3 -m unittest discover -v -c From 13c92096e7b0ba3c4ac9ad3ea5fee95b56efd234 Mon Sep 17 00:00:00 2001 From: David Uhm Date: Thu, 11 Mar 2021 18:31:35 -0800 Subject: [PATCH 087/115] AUTO-6408: Fix incorrect map name to match with hd map --- examples/NHTSA/Perform-Lane-Change/PLC_B_15.py | 2 +- examples/NHTSA/Perform-Lane-Change/PLC_B_25.py | 2 +- examples/NHTSA/Perform-Lane-Change/PLC_B_35.py | 2 +- examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py | 2 +- examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py | 2 +- examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py | 2 +- examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py | 2 +- examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py | 2 +- examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py | 2 +- examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py | 2 +- examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py | 2 +- examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py | 2 +- lgsvl/wise/wise.py | 4 ++++ 13 files changed, 16 insertions(+), 12 deletions(-) diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py index 61cb14e..8802dba 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_15.py @@ -30,7 +30,7 @@ print("PLC_B_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesame) if sim.current_scene == scene_name: sim.reset() else: diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py index 45fca89..ec48ef9 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_25.py @@ -30,7 +30,7 @@ print("PLC_B_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesame) if sim.current_scene == scene_name: sim.reset() else: diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py index 4806d08..d89dc52 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_B_35.py @@ -30,7 +30,7 @@ print("PLC_B_35 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesame) if sim.current_scene == scene_name: sim.reset() else: diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py index 4f11021..ff7d087 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_15.py @@ -32,7 +32,7 @@ print("PLC_CP_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesame) if sim.current_scene == scene_name: sim.reset() else: diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py index abf1d08..c8f3b75 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_25.py @@ -32,7 +32,7 @@ print("PLC_CP_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesame) if sim.current_scene == scene_name: sim.reset() else: diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py index 795e375..cc469bf 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_CP_35.py @@ -32,7 +32,7 @@ print("PLC_CP_35 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesame) if sim.current_scene == scene_name: sim.reset() else: diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py index 02839b4..c1f6fcb 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_15.py @@ -38,7 +38,7 @@ print("PLC_SN_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesame) if sim.current_scene == scene_name: sim.reset() else: diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py index c5ef739..4c1e9e5 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_25.py @@ -32,7 +32,7 @@ print("PLC_SN_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesame) if sim.current_scene == scene_name: sim.reset() else: diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py index 61e38d4..184d1b1 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SN_35.py @@ -32,7 +32,7 @@ print("PLC_SN_35 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesame) if sim.current_scene == scene_name: sim.reset() else: diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py index ab97900..218d91a 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_15.py @@ -30,7 +30,7 @@ print("PLC_SP_15 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesame) if sim.current_scene == scene_name: sim.reset() else: diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py index 889c821..40233c4 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_25.py @@ -30,7 +30,7 @@ print("PLC_SP_25 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesame) if sim.current_scene == scene_name: sim.reset() else: diff --git a/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py b/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py index 875457b..faf8a39 100755 --- a/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py +++ b/examples/NHTSA/Perform-Lane-Change/PLC_SP_35.py @@ -30,7 +30,7 @@ print("PLC_SP_35 - ", end='') sim = lgsvl.Simulator(LGSVL__SIMULATOR_HOST, LGSVL__SIMULATOR_PORT) -scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanesame) +scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight2lanesame) if sim.current_scene == scene_name: sim.reset() else: diff --git a/lgsvl/wise/wise.py b/lgsvl/wise/wise.py index f179f61..db7daa3 100644 --- a/lgsvl/wise/wise.py +++ b/lgsvl/wise/wise.py @@ -45,6 +45,10 @@ class DefaultAssets: # https://wise.svlsimulator.com/maps/profile/1e2287cf-c590-4804-bcb1-18b2fd3752d1 map_straight1lanesame = "1e2287cf-c590-4804-bcb1-18b2fd3752d1" + # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "Straight2LaneSame". + # https://wise.svlsimulator.com/maps/profile/b39d3ef9-21d7-409d-851b-4c90dad80a25 + map_straight2lanesame = "b39d3ef9-21d7-409d-851b-4c90dad80a25" + # Map loaded in some of the examples. Changing the map may lead to unexpected behaviour in the example scripts. Default value is "Straight2LaneSameCurbRightIntersection". # https://wise.svlsimulator.com/maps/profile/378edc3f-8fce-4596-87dc-7d12fc2ad743 map_straight2lanesamecurbrightintersection = "378edc3f-8fce-4596-87dc-7d12fc2ad743" From 949ff0d06ea02ca860e2eb4a3933edce14d770f7 Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Wed, 31 Mar 2021 21:05:36 -0700 Subject: [PATCH 088/115] README.md: Add instructions for users of Simulator release 2020.06 --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 61745f2..adea632 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,14 @@ Documentation is available on our website: https://www.svlsimulator.com/docs/pyt # install in development mode pip3 install --user -e . +**NOTE:** If you are using release 2020.06 of SVL Simulator, you must switch to +the `release-2020.06` branch of this repository prior to installing: + + git checkout -b release-2020.06 + +We encourage you to migrate to release 2021.1 of SVL Simulator soon as it is +feasible/practical to do so. + # Examples Look into `quickstart` and `examples` folders for simple usages. To run these From 84ebef249ae9b8da8bc151c7c4ce3708e18e95cf Mon Sep 17 00:00:00 2001 From: Hadi Tabatabaee Date: Fri, 16 Apr 2021 15:41:52 -0700 Subject: [PATCH 089/115] Add coordinate system type as argument anywhere that coordinates are provided --- lgsvl/dreamview/dreamview.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lgsvl/dreamview/dreamview.py b/lgsvl/dreamview/dreamview.py index e02f0a2..61a5ed1 100644 --- a/lgsvl/dreamview/dreamview.py +++ b/lgsvl/dreamview/dreamview.py @@ -261,7 +261,7 @@ def reconnect(self): self.ws = create_connection(self.url) return - def enable_apollo(self, dest_x, dest_z, modules): + def enable_apollo(self, dest_x, dest_z, modules, coord_type=CoordType.Unity): """ Enables a list of modules and then sets the destination """ @@ -269,7 +269,7 @@ def enable_apollo(self, dest_x, dest_z, modules): log.info("Starting {} module...".format(mod)) self.enable_module(mod) - self.set_destination(dest_x, dest_z) + self.set_destination(dest_x, dest_z, coord_type=coord_type) def disable_apollo(self): """ @@ -290,7 +290,7 @@ def check_module_status(self, modules): "Warning: Apollo module {} is not running!!!".format(module) ) - def setup_apollo(self, dest_x, dest_z, modules, default_timeout=60.0): + def setup_apollo(self, dest_x, dest_z, modules, default_timeout=60.0, coord_type=CoordType.Unity): """ Starts a list of Apollo modules and sets the destination. Will wait for Control module to send a message before returning. Control sending a message indicates that all modules are working and Apollo is ready to continue. @@ -302,7 +302,7 @@ def setup_apollo(self, dest_x, dest_z, modules, default_timeout=60.0): if not all(mod_status[mod] for mod in modules): self.disable_apollo() - self.enable_apollo(dest_x, dest_z, modules) + self.enable_apollo(dest_x, dest_z, modules, coord_type=coord_type) self.ego.is_control_received = False def on_control_received(agent, kind, context): From 7ab8e8ccb86d4114b33061c8581dd6d05ca912e4 Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Wed, 21 Apr 2021 22:47:09 -0700 Subject: [PATCH 090/115] AUTO-2688: setup.py: Use "git describe" to set the package version --- README.md | 15 ++++++++-- pyproject.toml | 3 ++ setup.py | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 pyproject.toml diff --git a/README.md b/README.md index adea632..bd3eae7 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,16 @@ Documentation is available on our website: https://www.svlsimulator.com/docs/pyt # Requirements * Python 3.6 or higher +* Pip 21.0 or higher (install using `python3 -m pip install 'pip>=21.0'`) # Installing - pip3 install --user . + python3 -m pip install --user . # install in development mode - pip3 install --user -e . + python3 -m pip install --user -e . + +Do not use the legacy `python3 setup.py install` nor `pip3 install`. **NOTE:** If you are using release 2020.06 of SVL Simulator, you must switch to the `release-2020.06` branch of this repository prior to installing: @@ -110,6 +113,14 @@ Then launch an **API Only** simulation before running the unit tests. # output is in htmlcov/index.html +# Tagging releases + +The final change for a new release must be to set the argument of the +`get_version('')` call in `setup.py` to the new version. +Then commit this change and tag it with the new version: + + git tag -a -m + # Copyright and License Copyright (c) 2018-2021 LG Electronics, Inc. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..0986ac6 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +# get_version() in setup.py requires GitPython. +requires = ["setuptools", "wheel", "GitPython"] diff --git a/setup.py b/setup.py index 39589cf..c1f3450 100755 --- a/setup.py +++ b/setup.py @@ -2,8 +2,83 @@ from setuptools import setup +# Without enabling the user site, "python3 -m pip install --user -e ." fails +# with: +# +# WARNING: The user site-packages directory is disabled. +# error: can't create or remove files in install directory +# ... +# [Errno 13] Permission denied: '/usr/local/lib/python3.6/dist-packages/' +# +# Taken from https://github.com/pypa/pip/issues/7953#issuecomment-645133255. +import site +import sys +site.ENABLE_USER_SITE = "--user" in sys.argv[1:] + + +def get_version(git_tag): + """ + Returns a PEP 440 version identifier + + [+] + + derived from its parameter and the output from: + + git describe --match --tags + + which has the format: + + [--g] + + The public version identifier is formed from . PEP 440 versioning + allows only digits without leading zeros in the release segments of public + version identifiers, so they are dropped along with any "P"-s found in + . And PEP 440 does not allow hyphens in pre-release segments, so + any "-rc"-s are replaced with "rc". Fortunately, this mapping doesn't + introduce any ambiguities when used for the tags that currently exist. + + The optional local version label is formed from the portion of the + "git describe" output which follows with all hyphens converted to + periods (except the first, which is dropped). This segment will be empty if: + - Git is not available, or + - the working tree is not a Git repository, or + - the tag is not present or not on the currrent branch, or + - the HEAD of the current branch is coincident with the tag . + + NB. - Not using https://pypi.org/project/setuptools-git-version/ because it + passes "--long" to "git describe". + - Not using https://pypi.org/project/setuptools-scm/ because it's way + more complicated to configure it to do what is wanted. + """ + + # ASSERT( has no more than one leading "0", no more than one "-rc", + # and no more than one "P", which is expected to be at the end -- but + # this is not checked) + public_version_identifier = git_tag.replace(".0", ".", 1) \ + .replace("P", "", 1) \ + .replace("-rc", "rc", 1) + from os import getenv + try: + from git import Repo + # PWD is the directory from where we invoked "pip install", which is + # the root of the Git repository; when setup() is + # called, pip has changed the current directory to be under /tmp. + repo = Repo(path=getenv('PWD')) + val = repo.git.describe('--match', git_tag, '--tags') + except Exception: + val = "" + + # Remove and convert the first hyphen to a "+": + local_version_label_with_plus = val.replace(git_tag, '', 1) \ + .replace('-', '+', 1) \ + .replace('-', '.') + + return public_version_identifier + local_version_label_with_plus + + setup( name="lgsvl", + version=get_version('2021.1'), description="Python API for SVL Simulator", author="LGSVL", author_email="contact@svlsimulator.com", @@ -16,6 +91,9 @@ "numpy", "environs" ], + setup_requires=[ + "GitPython" + ], license="Other", classifiers=[ "License :: Other/Proprietary License", From e95cc2b38d5f455c96f0d1bd6893ff99cf35a0ac Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Mon, 1 Mar 2021 13:54:27 -0800 Subject: [PATCH 091/115] AUTO-6118: Upgrade Python image used for CI to v3.6.13 Note that this image version supplies a version of pip that satisfies the requirement of >=21.0 . --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bc1053a..5851197 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: "python:3.6.9" +image: "python:3.6.13" before_script: - pip install -r requirements.txt From 6e9d06f4926f067ed2570a5283f14db350eec792 Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Mon, 3 May 2021 11:09:23 -0700 Subject: [PATCH 092/115] AUTO-6930: README.md: Specify pip >= 21.1.1 Prevent use of the warning-spewing v21.1 of pip by specifying >=21.1.1 . --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bd3eae7..4d99d01 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Documentation is available on our website: https://www.svlsimulator.com/docs/pyt # Requirements * Python 3.6 or higher -* Pip 21.0 or higher (install using `python3 -m pip install 'pip>=21.0'`) +* Pip 21.1.1 or higher (install using `python3 -m pip install 'pip>=21.1.1'`) # Installing From dfd866ca681e731a39ef2b4ff2a3c4186c4c211d Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Tue, 2 Mar 2021 23:01:06 -0800 Subject: [PATCH 093/115] AUTO-6119: Pin GitPython build dependency to v3.1.14 --- pyproject.toml | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0986ac6..020a6ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,3 @@ [build-system] # get_version() in setup.py requires GitPython. -requires = ["setuptools", "wheel", "GitPython"] +requires = ["setuptools", "wheel", "GitPython==3.1.14"] diff --git a/setup.py b/setup.py index c1f3450..54edb1a 100755 --- a/setup.py +++ b/setup.py @@ -92,7 +92,7 @@ def get_version(git_tag): "environs" ], setup_requires=[ - "GitPython" + "GitPython==3.1.14" ], license="Other", classifiers=[ From 42a24c1d51e619db63d93d70e413c9b7c20fbbf3 Mon Sep 17 00:00:00 2001 From: David Uhm Date: Mon, 24 May 2021 03:43:14 -0700 Subject: [PATCH 094/115] Add apollo6 modular sensor config --- lgsvl/wise/wise.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lgsvl/wise/wise.py b/lgsvl/wise/wise.py index db7daa3..8d21906 100644 --- a/lgsvl/wise/wise.py +++ b/lgsvl/wise/wise.py @@ -79,3 +79,8 @@ class DefaultAssets: # This has sensors for modular testing. # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/5c7fb3b0-1fd4-4943-8347-f73a05749718 ego_lincoln2017mkz_apollo5_modular = "5c7fb3b0-1fd4-4943-8347-f73a05749718" + + # Ego vehicle that is loaded in most of the Apollo 6.0 scripts. Default value is "Lincoln2017MKZ" using the "Apollo 6.0 (modular testing)" sensor configuration. + # This has sensors for modular testing. + # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/2e9095fa-c9b9-4f3f-8d7d-65fa2bb03921 + ego_lincoln2017mkz_apollo6_modular = "2e9095fa-c9b9-4f3f-8d7d-65fa2bb03921" From a298503281c50907757183db0fffaf45620e7972 Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Thu, 13 May 2021 16:13:36 -0700 Subject: [PATCH 095/115] README.md: Mention that the unit tests recognize LGSVL__SIMULATOR_HOST --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 4d99d01..f872f86 100644 --- a/README.md +++ b/README.md @@ -88,8 +88,14 @@ Jaguar2015XE | Autoware AI | https://wise.svlsimulator.com/vehicles/p Lincoln2017MKZ | Apollo 5.0 | https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 |
+ Then launch an **API Only** simulation before running the unit tests. +By default, the unit tests expect to be able to connect to SVL Simulator using +the `localhost` address. To change it, set the `LGSVL__SIMULATOR_HOST` +environment variable to the hostname or IP address of the network interface of +the machine running SVL Simulator to which the unit tests should connect. + # run all unittests python3 -m unittest discover -v -c From b55c0ecf40e1555150c052f47cc95b2ba832432f Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Mon, 22 Feb 2021 13:23:30 -0800 Subject: [PATCH 096/115] AUTO-6263: Place CI dependencies in "extras_require" dict --- .gitlab-ci.yml | 2 +- requirements.txt | 1 - setup.py | 5 +++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5851197..07c1e3f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ image: "python:3.6.13" before_script: - - pip install -r requirements.txt + - python3 -m pip install -r requirements.txt .\[ci\] stages: - Style Guide Enforcement diff --git a/requirements.txt b/requirements.txt index 040786e..4d2458e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ websockets>=7.0 websocket-client==0.57.0 # for dreamview -flake8>=3.7.0 numpy # for evaluator environs diff --git a/setup.py b/setup.py index 54edb1a..4094ee6 100755 --- a/setup.py +++ b/setup.py @@ -94,6 +94,11 @@ def get_version(git_tag): setup_requires=[ "GitPython==3.1.14" ], + extras_require={ + "ci": [ + "flake8>=3.7.0" + ], + }, license="Other", classifiers=[ "License :: Other/Proprietary License", From 689a1d57c636728e6becd01a5393f94fc9fb28c3 Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Mon, 22 Feb 2021 09:30:39 -0800 Subject: [PATCH 097/115] AUTO-6263: requirements.txt: Add dependency version constraints based on Python version Drop the version constraints from the dependencies listed in the install_requires[] keyword argument to setup(). Instead, require that "-r requirements.txt" be supplied to "pip install" and populate the file with rules conditional on the version of Python being used. Determine the rules for a dependency by examining the Python versions shown as Requires and Classifiers on the documentation for its versions on PyPi. Also, rearrange the list of dependencies in install_requires[] to be in alphabetical order and indicate for which submodule the dependency is for. --- requirements.txt | 19 +++++++++++++++---- setup.py | 8 ++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index 4d2458e..ec2d6d4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,15 @@ -websockets>=7.0 -websocket-client==0.57.0 # for dreamview -numpy # for evaluator -environs + +# - PACKAGE >= PKG_VERSION ; python_version >= PYTHON_VERSION +# PKG_VERSION is the first version of PACKAGE that supports PYTHON_VERSION +# - PACKAGE < PKG_VERSION ; python_version < PYTHON_VERSION +# PKG_VERSION is the first version of PACKAGE that no longer supports +# PYTHON_VERSION; add entries for PYTHON_VERSION > "python_requires" of +# lgsvl in setup.py +# - Keep in alphabetical order. +environs >= 8.1.0 ; python_version >= '3.9' +numpy < 1.20 ; python_version < '3.7' +numpy >= 1.20 ; python_version >= '3.7' +websocket-client >= 0.58.0 ; python_version >= '3.8' +websockets < 8.1 ; python_version < '3.6.1' +websockets >= 8.1 ; python_version >= '3.8' +websockets >= 9.0.1 ; python_version >= '3.9' diff --git a/setup.py b/setup.py index 4094ee6..16c29f2 100755 --- a/setup.py +++ b/setup.py @@ -86,10 +86,10 @@ def get_version(git_tag): url="https://github.com/lgsvl/PythonAPI", packages=["lgsvl", "lgsvl.dreamview", "lgsvl.evaluator", "lgsvl.wise"], install_requires=[ - "websockets==7.0", - "websocket-client==0.57.0", - "numpy", - "environs" + "environs", + "numpy", # for evaluator + "websocket-client", # for dreamview + "websockets" ], setup_requires=[ "GitPython==3.1.14" From fec82f5201499e8217d3790450299f87ad8d3ede Mon Sep 17 00:00:00 2001 From: Herb Kuta Date: Mon, 22 Feb 2021 13:39:29 -0800 Subject: [PATCH 098/115] AUTO-6263: README.md: Update installation instructions to use requirements.txt --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f872f86..a1421d9 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,10 @@ Documentation is available on our website: https://www.svlsimulator.com/docs/pyt # Installing - python3 -m pip install --user . + python3 -m pip install -r requirements.txt --user . # install in development mode - python3 -m pip install --user -e . + python3 -m pip install -r requirements.txt --user -e . Do not use the legacy `python3 setup.py install` nor `pip3 install`. From 3056953eda77284fd4891dcaaf0409122b7eb39c Mon Sep 17 00:00:00 2001 From: David Uhm Date: Fri, 11 Jun 2021 11:15:00 -0700 Subject: [PATCH 099/115] Catch ConnectionRefusedError earlier --- lgsvl/dreamview/dreamview.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lgsvl/dreamview/dreamview.py b/lgsvl/dreamview/dreamview.py index 61a5ed1..5115a94 100644 --- a/lgsvl/dreamview/dreamview.py +++ b/lgsvl/dreamview/dreamview.py @@ -237,7 +237,13 @@ def get_current_map(self): """ Returns the current HD Map loaded in Dreamview """ - self.reconnect() + try: + self.reconnect() + except ConnectionRefusedError as e: + log.error("Not able to get the current HD map loaded in Dreamview.") + log.error("Original exception: " + str(e)) + return None + data = json.loads(self.ws.recv()) while data["type"] != "HMIStatus": data = json.loads(self.ws.recv()) @@ -247,7 +253,13 @@ def get_current_vehicle(self): """ Returns the current Vehicle configuration loaded in Dreamview """ - self.reconnect() + try: + self.reconnect() + except ConnectionRefusedError as e: + log.error("Not able to get the current vehicle configuration loaded in Dreamview.") + log.error("Original exception: " + str(e)) + return None + data = json.loads(self.ws.recv()) while data["type"] != "HMIStatus": data = json.loads(self.ws.recv()) From cd4c850eac0b49ccfb39193197b3205b240b344d Mon Sep 17 00:00:00 2001 From: "eric.boise" Date: Fri, 25 Jun 2021 17:04:37 -0700 Subject: [PATCH 100/115] add command to set sim camera state --- lgsvl/simulator.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index 35b389b..9343fae 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -11,6 +11,7 @@ from .utils import accepts, ObjectState from .controllable import Controllable +from enum import Enum from collections import namedtuple from environs import Env from datetime import datetime @@ -26,6 +27,12 @@ class Simulator: + class SimulatorCameraState(Enum): + FREE = 0 + FOLLOW = 1 + CINEMATIC = 2 + DRIVER = 3 + @accepts(str, int) def __init__(self, address=env.str("LGSVL__SIMULATOR_HOST", "localhost"), port=env.int("LGSVL__SIMULATOR_PORT", 8181)): if port <= 0 or port > 65535: @@ -80,6 +87,10 @@ def available_npc_behaviours(self): def set_sim_camera(self, transform): self.remote.command("simulator/camera/set", {"transform": transform.to_json()}) + @accepts(SimulatorCameraState) + def set_sim_camera_state(self, state): + self.remote.command("simulator/camera/state/set", {"state": state.value}) + def agents_traversed_waypoints(self, fn): self._add_callback(None, "agents_traversed_waypoints", fn) From a1d1524f684d48b3633d60e9d5e9b325932b84b0 Mon Sep 17 00:00:00 2001 From: "karol.byczkowski" Date: Mon, 28 Jun 2021 18:49:58 -0700 Subject: [PATCH 101/115] Added new parameter path type to the follow waypoints command. --- lgsvl/agent.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lgsvl/agent.py b/lgsvl/agent.py index 346eeb9..6c8e578 100644 --- a/lgsvl/agent.py +++ b/lgsvl/agent.py @@ -216,8 +216,8 @@ class NpcVehicle(Vehicle): def __init__(self, uid, simulator): super().__init__(uid, simulator) - @accepts(Iterable, bool) - def follow(self, waypoints, loop=False): + @accepts(Iterable, bool, str) + def follow(self, waypoints, loop=False, waypoints_path_type="Linear"): """Tells the NPC to follow the waypoints When an NPC reaches a waypoint, it will: @@ -258,6 +258,9 @@ def follow(self, waypoints, loop=False): loop : bool whether the NPC should loop through the waypoints after reaching the final one + + waypoints_path_type : string + how the waypoints path should be interpreted, default path type is "Linear" """ self.remote.command( "vehicle/follow_waypoints", @@ -278,6 +281,7 @@ def follow(self, waypoints, loop=False): } for wp in waypoints ], + "waypoints_path_type": waypoints_path_type, "loop": loop, }, ) @@ -346,8 +350,8 @@ def walk_randomly(self, enable): "pedestrian/walk_randomly", {"uid": self.uid, "enable": enable} ) - @accepts(Iterable, bool) - def follow(self, waypoints, loop=False): + @accepts(Iterable, bool, str) + def follow(self, waypoints, loop=False, waypoints_path_type="Linear"): """Tells the Pedestrian to follow the waypoints When a pedestrian reaches a waypoint, it will: @@ -391,6 +395,7 @@ def follow(self, waypoints, loop=False): } for wp in waypoints ], + "waypoints_path_type": waypoints_path_type, "loop": loop, }, ) From 9aaad18d0e37b78d6cc58f0e2f9140c9229e71cd Mon Sep 17 00:00:00 2001 From: Joshua Whitley Date: Sat, 1 May 2021 11:32:10 -0500 Subject: [PATCH 102/115] Add files required to make a ROS package --- package.xml | 18 ++++++++++++++++++ resource/lgsvl | 0 setup.cfg | 4 ++++ setup.py | 19 +++++++++++++++---- 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 package.xml create mode 100644 resource/lgsvl create mode 100644 setup.cfg diff --git a/package.xml b/package.xml new file mode 100644 index 0000000..20ed2e2 --- /dev/null +++ b/package.xml @@ -0,0 +1,18 @@ + + + + lgsvl + 2021.1.0 + A Python API for SVL Simulator + Hadi Tabatabaee + Other + + python3-environs-pip + python3-numpy + python3-websocket + python3-websockets + + + ament_python + + diff --git a/resource/lgsvl b/resource/lgsvl new file mode 100644 index 0000000..e69de29 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..34a94f7 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,4 @@ +[develop] +script_dir=$base/lib/lgsvl +[install] +install_scripts=$base/lib/lgsvl diff --git a/setup.py b/setup.py index 16c29f2..3719c6b 100755 --- a/setup.py +++ b/setup.py @@ -76,9 +76,16 @@ def get_version(git_tag): return public_version_identifier + local_version_label_with_plus +package_name = 'lgsvl' + setup( - name="lgsvl", + name=package_name, version=get_version('2021.1'), + data_files=[ + ('share/ament_index/resource_index/packages', + ['resource/' + package_name]), + ('share/' + package_name, ['package.xml']), + ], description="Python API for SVL Simulator", author="LGSVL", author_email="contact@svlsimulator.com", @@ -87,8 +94,9 @@ def get_version(git_tag): packages=["lgsvl", "lgsvl.dreamview", "lgsvl.evaluator", "lgsvl.wise"], install_requires=[ "environs", - "numpy", # for evaluator - "websocket-client", # for dreamview + "numpy", + "setuptools", + "websocket-client", "websockets" ], setup_requires=[ @@ -99,7 +107,10 @@ def get_version(git_tag): "flake8>=3.7.0" ], }, - license="Other", + zip_safe=True, + maintainer='Hadi Tabatabaee', + maintainer_email='hadi.tabatabaee@lge.com', + license='Other', classifiers=[ "License :: Other/Proprietary License", "Programming Language :: Python :: 3", From dfc93b7597a02411eeadbf3004946dd0ad3ef706 Mon Sep 17 00:00:00 2001 From: Hadi Tabatabaee Date: Thu, 12 Aug 2021 22:20:07 -0700 Subject: [PATCH 103/115] Invoke flake8 unambiguously --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 07c1e3f..65833ea 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,4 +9,4 @@ stages: flake8: stage: Style Guide Enforcement script: - - flake8 + - python3 -m flake8 From 04f3df82a73d5fb3224a7e2d20e611f625ab7f4c Mon Sep 17 00:00:00 2001 From: "karol.byczkowski" Date: Thu, 19 Aug 2021 13:56:24 -0700 Subject: [PATCH 104/115] [VSE] [AUTO-7412] Added acceleration parameter to drive and walk waypoints. --- lgsvl/agent.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lgsvl/agent.py b/lgsvl/agent.py index 6c8e578..b4b1c56 100644 --- a/lgsvl/agent.py +++ b/lgsvl/agent.py @@ -18,6 +18,7 @@ def __init__( self, position, speed, + acceleration=0, angle=Vector(0, 0, 0), idle=0, deactivate=False, @@ -27,6 +28,7 @@ def __init__( ): self.position = position self.speed = speed + self.acceleration = acceleration self.angle = angle self.idle = idle self.deactivate = deactivate @@ -36,9 +38,10 @@ def __init__( class WalkWaypoint: - def __init__(self, position, idle, trigger_distance=0, speed=1, trigger=None): + def __init__(self, position, idle, trigger_distance=0, speed=1, acceleration=0, trigger=None): self.position = position self.speed = speed + self.acceleration = acceleration self.idle = idle self.trigger_distance = trigger_distance self.trigger = trigger @@ -228,7 +231,7 @@ def follow(self, waypoints, loop=False, waypoints_path_type="Linear"): Parameters ---------- waypoints : list of DriveWaypoints - DriveWaypoint : Class (position, speed, angle, idle, trigger_distance) + DriveWaypoint : Class (position, speed, acceleration, angle, idle, trigger_distance) position : lgsvl.Vector() Unity coordinates of waypoint @@ -236,6 +239,9 @@ def follow(self, waypoints, loop=False, waypoints_path_type="Linear"): speed : float how fast the NPC should drive to the waypoint + acceleration : float + how fast the NPC will increase the speed + angle : lgsvl.Vector() Unity rotation of the NPC at the waypoint @@ -270,6 +276,7 @@ def follow(self, waypoints, loop=False, waypoints_path_type="Linear"): { "position": wp.position.to_json(), "speed": wp.speed, + "acceleration": wp.acceleration, "angle": wp.angle.to_json(), "idle": wp.idle, "deactivate": wp.deactivate, @@ -362,7 +369,7 @@ def follow(self, waypoints, loop=False, waypoints_path_type="Linear"): Parameters ---------- waypoints : list of WalkWaypoints - WalkWaypoint : Class (position, idle, trigger_distance, speed) + WalkWaypoint : Class (position, idle, trigger_distance, speed, acceleration) position : lgsvl.Vector() Unity coordinates of waypoint @@ -376,6 +383,9 @@ def follow(self, waypoints, loop=False, waypoints_path_type="Linear"): speed : float how fast the pedestrian should drive to the waypoint (default value 1) + acceleration : float + how fast the pedestrian will increase the speed + loop : bool whether the pedestrian should loop through the waypoints after reaching the final one """ @@ -389,6 +399,7 @@ def follow(self, waypoints, loop=False, waypoints_path_type="Linear"): "idle": wp.idle, "trigger_distance": wp.trigger_distance, "speed": wp.speed, + "acceleration": wp.acceleration, "trigger": ( None if wp.trigger is None else wp.trigger.to_json() ), From 469151941ef767d34782fa9c91e59cfb4963cff9 Mon Sep 17 00:00:00 2001 From: David Uhm Date: Fri, 20 Aug 2021 03:07:20 -0700 Subject: [PATCH 105/115] [AUTO-7425] Add an API call for canceling destination --- lgsvl/agent.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lgsvl/agent.py b/lgsvl/agent.py index b4b1c56..064d65a 100644 --- a/lgsvl/agent.py +++ b/lgsvl/agent.py @@ -214,6 +214,14 @@ def apply_control(self, control, sticky=False): def on_custom(self, fn): self.simulator._add_callback(self, "custom", fn) + def cancel_destination(self): + self.remote.command( + "vehicle/cancel_destination", + { + "uid": self.uid, + } + ) + class NpcVehicle(Vehicle): def __init__(self, uid, simulator): From 9132959c220a16e098af31d9690cb7691b191587 Mon Sep 17 00:00:00 2001 From: Hadi Tabatabaee Date: Sun, 29 Aug 2021 00:27:19 -0700 Subject: [PATCH 106/115] Fix env var getting erros in SampleTestCases --- examples/SampleTestCases/cut-in.py | 2 +- examples/SampleTestCases/ped-crossing.py | 2 +- examples/SampleTestCases/red-light-runner.py | 2 +- examples/SampleTestCases/sudden-braking.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/SampleTestCases/cut-in.py b/examples/SampleTestCases/cut-in.py index 1447b7c..9a9006c 100755 --- a/examples/SampleTestCases/cut-in.py +++ b/examples/SampleTestCases/cut-in.py @@ -28,7 +28,7 @@ BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090)) -scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_sanfrancisco) +scene_name = os.environ.get("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_sanfrancisco) sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) if sim.current_scene == scene_name: diff --git a/examples/SampleTestCases/ped-crossing.py b/examples/SampleTestCases/ped-crossing.py index 703f94f..06bef16 100755 --- a/examples/SampleTestCases/ped-crossing.py +++ b/examples/SampleTestCases/ped-crossing.py @@ -27,7 +27,7 @@ BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090)) -scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanepedestriancrosswalk) +scene_name = os.environ.get("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_straight1lanepedestriancrosswalk) sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) if sim.current_scene == scene_name: sim.reset() diff --git a/examples/SampleTestCases/red-light-runner.py b/examples/SampleTestCases/red-light-runner.py index 45118fd..a974ba1 100755 --- a/examples/SampleTestCases/red-light-runner.py +++ b/examples/SampleTestCases/red-light-runner.py @@ -27,7 +27,7 @@ BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090)) -scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_borregasave) +scene_name = os.environ.get("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_borregasave) sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) if sim.current_scene == scene_name: sim.reset() diff --git a/examples/SampleTestCases/sudden-braking.py b/examples/SampleTestCases/sudden-braking.py index 8931d6e..802747d 100755 --- a/examples/SampleTestCases/sudden-braking.py +++ b/examples/SampleTestCases/sudden-braking.py @@ -27,7 +27,7 @@ BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", "127.0.0.1") BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", 9090)) -scene_name = env.str("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_singlelaneroad) +scene_name = os.environ.get("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_singlelaneroad) sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) if sim.current_scene == scene_name: sim.reset() From a6739c7916a40706db1da1c4eb0c12f4baf005e1 Mon Sep 17 00:00:00 2001 From: "david.uhm" Date: Wed, 8 Sep 2021 13:45:38 -0700 Subject: [PATCH 107/115] [AUTO-7321] Add python API functions to send destination to Nav2 --- lgsvl/__init__.py | 2 +- lgsvl/agent.py | 24 +++++++- lgsvl/geometry.py | 18 ++++++ lgsvl/simulator.py | 15 ++++- quickstart/36-send-destination-to-nav2.py | 70 +++++++++++++++++++++++ 5 files changed, 126 insertions(+), 3 deletions(-) create mode 100755 quickstart/36-send-destination-to-nav2.py diff --git a/lgsvl/__init__.py b/lgsvl/__init__.py index 8d0d31e..be4e2ef 100644 --- a/lgsvl/__init__.py +++ b/lgsvl/__init__.py @@ -4,7 +4,7 @@ # This software contains code licensed as described in LICENSE. # -from .geometry import Vector, BoundingBox, Transform +from .geometry import Vector, BoundingBox, Transform, Quaternion from .simulator import Simulator, RaycastHit, WeatherState from .sensor import Sensor, CameraSensor, LidarSensor, ImuSensor from .agent import ( diff --git a/lgsvl/agent.py b/lgsvl/agent.py index 064d65a..9797b60 100644 --- a/lgsvl/agent.py +++ b/lgsvl/agent.py @@ -4,7 +4,7 @@ # This software contains code licensed as described in LICENSE. # -from .geometry import Vector, BoundingBox +from .geometry import Vector, BoundingBox, Transform from .sensor import Sensor from .utils import accepts, ObjectState as AgentState @@ -222,6 +222,28 @@ def cancel_destination(self): } ) + def set_initial_pose(self): + self.remote.command( + "vehicle/set_initial_pose", + { + "uid": self.uid, + } + ) + + @accepts(Transform) + def set_destination(self, transform): + self.remote.command( + "vehicle/set_destination", + { + "uid": self.uid, + "transform": transform.to_json(), + } + ) + + def on_destination_reached(self, fn): + self.remote.command("agent/on_destination_reached", {"uid": self.uid}) + self.simulator._add_callback(self, "destination_reached", fn) + class NpcVehicle(Vehicle): def __init__(self, uid, simulator): diff --git a/lgsvl/geometry.py b/lgsvl/geometry.py index 9b129ce..d914d50 100644 --- a/lgsvl/geometry.py +++ b/lgsvl/geometry.py @@ -132,3 +132,21 @@ def __repr__(self): return "Spawn(position={}, rotation={}, destinations={})".format( self.position, self.rotation, self.destinations ) + + +class Quaternion: + def __init__(self, x=0.0, y=0.0, z=0.0, w=0.0): + self.x = x + self.y = y + self.z = z + self.w = w + + @staticmethod + def from_json(j): + return Quaternion(j["x"], j["y"], j["z"], j["w"]) + + def to_json(self): + return {"x": self.x, "y": self.y, "z": self.z, "w": self.w} + + def __repr__(self): + return "Quaternion({}, {}, {}, {})".format(self.x, self.y, self.z, self.w) diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index 9343fae..3499b04 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -7,7 +7,7 @@ from .remote import Remote from .agent import Agent, AgentType, AgentState from .sensor import GpsData -from .geometry import Vector, Transform, Spawn +from .geometry import Vector, Transform, Spawn, Quaternion from .utils import accepts, ObjectState from .controllable import Controllable @@ -131,6 +131,8 @@ def _process_events(self, events): fn(agent) elif event_type == "lane_change": fn(agent) + elif event_type == "destination_reached": + fn(agent) elif event_type == "custom": fn(agent, ev["kind"], ev["context"]) if self.stopped: @@ -281,6 +283,17 @@ def map_point_on_lane(self, point): j = self.remote.command("map/point_on_lane", {"point": point.to_json()}) return Transform.from_json(j) + @accepts(Vector, Quaternion) + def map_from_nav(self, position, orientation): + res = self.remote.command( + "map/from_nav", + { + "position": position.to_json(), + "orientation": orientation.to_json() + } + ) + return Transform.from_json(res) + @accepts(Vector, Vector, int, float) def raycast(self, origin, direction, layer_mask=-1, max_distance=float("inf")): hit = self.remote.command("simulator/raycast", [{ diff --git a/quickstart/36-send-destination-to-nav2.py b/quickstart/36-send-destination-to-nav2.py new file mode 100755 index 0000000..6a8681b --- /dev/null +++ b/quickstart/36-send-destination-to-nav2.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +import lgsvl +from environs import Env +from lgsvl import Vector, Quaternion + +print("Python API Quickstart #36: Sending destinations to Navigation2") +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) + +# TODO: Make public assets for LGSeocho with NavOrigin and cloi sensor config +map_seocho = "9b494638-b3e9-4239-9f3f-51b2c68cd292" +ego_cloi = "4717598d-6c67-48a1-9a02-988a89d8660c" + +if sim.current_scene == map_seocho: + sim.reset() +else: + sim.load(map_seocho) + +sim.set_time_of_day(0, fixed=True) +spawns = sim.get_spawn() +state = lgsvl.AgentState() +state.transform = spawns[0] + +ego = sim.add_agent(env.str("LGSVL__VEHICLE_0", ego_cloi), lgsvl.AgentType.EGO, state) +ego.connect_bridge(env.str("LGSVL__AUTOPILOT_0_HOST", lgsvl.wise.SimulatorSettings.bridge_host), env.int("LGSVL__AUTOPILOT_0_PORT", lgsvl.wise.SimulatorSettings.bridge_port)) + +i = 0 + +# List of destinations in Nav2 costmap coordinates +ros_destinations = [ + ((3.118, -0.016, 0), (0, 0, 0.0004, 0.999)), + ((3.126, -10.025, 0), (0, 0, 0.006, 0.999)), + ((11.171, -9.875, 0), (0, 0, 0.707, 0.707)), + ((11.882, -0.057, 0), (0, 0, 0.699, 0.715)), + ((12.351, 11.820, 0), (0, 0, -0.999, 0.0004)), + ((2.965, 11.190, 0), (0, 0, -0.707, 0.707)), + ((2.687, -0.399, 0), (0, 0, -0.0036, 0.999)), +] + +ego.set_initial_pose() +sim.run(5) + +def send_next_destination(agent): + global i + print(f"{i}: {agent.name} reached destination") + i += 1 + if i >= len(ros_destinations): + print("Iterated all destinations successfully. Stopping...") + sim.stop() + return + + ros_dst = ros_destinations[i] + next_dst = sim.map_from_nav(Vector(*ros_dst[0]), Quaternion(*ros_dst[1])) + ego.set_destination(next_dst) + +ros_dst = ros_destinations[0] +first_dst = sim.map_from_nav(Vector(*ros_dst[0]), Quaternion(*ros_dst[1])) +ego.set_destination(first_dst) +ego.on_destination_reached(send_next_destination) + +sim.run() + +print("Done!") From 6a58a3b946417f1a64324cf19387bb536e72467d Mon Sep 17 00:00:00 2001 From: "david.uhm" Date: Wed, 8 Sep 2021 14:14:44 -0700 Subject: [PATCH 108/115] [AUTO-7690] Implement API function to set NavOrigin in scene --- lgsvl/simulator.py | 10 ++++++++++ quickstart/36-send-destination-to-nav2.py | 2 ++ 2 files changed, 12 insertions(+) diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index 3499b04..6e203bf 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -294,6 +294,16 @@ def map_from_nav(self, position, orientation): ) return Transform.from_json(res) + @accepts(Transform, Vector) + def set_nav_origin(self, transform, offset=Vector()): + self.remote.command( + "navigation/set_origin", + { + "transform": transform.to_json(), + "offset": offset.to_json(), + } + ) + @accepts(Vector, Vector, int, float) def raycast(self, origin, direction, layer_mask=-1, max_distance=float("inf")): hit = self.remote.command("simulator/raycast", [{ diff --git a/quickstart/36-send-destination-to-nav2.py b/quickstart/36-send-destination-to-nav2.py index 6a8681b..7589d09 100755 --- a/quickstart/36-send-destination-to-nav2.py +++ b/quickstart/36-send-destination-to-nav2.py @@ -47,6 +47,7 @@ ego.set_initial_pose() sim.run(5) + def send_next_destination(agent): global i print(f"{i}: {agent.name} reached destination") @@ -60,6 +61,7 @@ def send_next_destination(agent): next_dst = sim.map_from_nav(Vector(*ros_dst[0]), Quaternion(*ros_dst[1])) ego.set_destination(next_dst) + ros_dst = ros_destinations[0] first_dst = sim.map_from_nav(Vector(*ros_dst[0]), Quaternion(*ros_dst[1])) ego.set_destination(first_dst) From 1d9ff0b90453e8a71e0d10a61093f8136f516161 Mon Sep 17 00:00:00 2001 From: "david.uhm" Date: Wed, 8 Sep 2021 14:21:10 -0700 Subject: [PATCH 109/115] [AUTO-7691] Add API call to get NavOrigin from scene --- lgsvl/simulator.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lgsvl/simulator.py b/lgsvl/simulator.py index 6e203bf..f486f7a 100644 --- a/lgsvl/simulator.py +++ b/lgsvl/simulator.py @@ -304,6 +304,16 @@ def set_nav_origin(self, transform, offset=Vector()): } ) + def get_nav_origin(self): + res = self.remote.command("navigation/get_origin") + nav_origin = None + if res: + nav_origin = { + "transform": Transform.from_json(res), + "offset": res["offset"] + } + return nav_origin + @accepts(Vector, Vector, int, float) def raycast(self, origin, direction, layer_mask=-1, max_distance=float("inf")): hit = self.remote.command("simulator/raycast", [{ From 0a6dd34fb2639388fda75dc50479f23f7779b5ae Mon Sep 17 00:00:00 2001 From: "karol.byczkowski" Date: Wed, 15 Sep 2021 23:48:11 -0700 Subject: [PATCH 110/115] Quickstart 20-enable-sensors now checks if LiDAR sensor is available + Quickstart 23-npc-callbacks now runs for a fixed time --- quickstart/20-enable-sensors.py | 19 +++++++++++++------ quickstart/23-npc-callbacks.py | 3 ++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/quickstart/20-enable-sensors.py b/quickstart/20-enable-sensors.py index d764147..12dfc64 100755 --- a/quickstart/20-enable-sensors.py +++ b/quickstart/20-enable-sensors.py @@ -28,14 +28,21 @@ # Sensors have an enabled/disabled state that can be set # By default all sensors are enabled # Disabling sensor will prevent it to send or receive messages to ROS or Cyber bridges +lidarAvailable = False for s in sensors: print(type(s), s.enabled) + if isinstance(s, lgsvl.LidarSensor): + lidarAvailable = True -input("Press Enter to disable lidar") +if lidarAvailable: + input("Press Enter to disable LiDAR") -for s in sensors: - if isinstance(s, lgsvl.LidarSensor): - s.enabled = False + for s in sensors: + if isinstance(s, lgsvl.LidarSensor): + s.enabled = False -for s in sensors: - print(type(s), s.enabled) + for s in sensors: + print(type(s), s.enabled) +else: + print("LiDAR sensor is not included in the selected sensor configuration. Please check the \"ego_lincoln2017mkz_apollo5\" sensor configuration in the default assets.") + input("Press Enter to stop the simulation") diff --git a/quickstart/23-npc-callbacks.py b/quickstart/23-npc-callbacks.py index 7b8ffaa..03c362d 100755 --- a/quickstart/23-npc-callbacks.py +++ b/quickstart/23-npc-callbacks.py @@ -61,4 +61,5 @@ def on_lane_change(agent): npc.on_lane_change(on_lane_change) npc.on_stop_line(on_stop_line) -sim.run() +print("Running the simulation for 30 seconds.") +sim.run(30) From 334db7a3118b8b073341234caa558ae9832e0490 Mon Sep 17 00:00:00 2001 From: Hadi Tabatabaee Date: Wed, 15 Sep 2021 23:46:49 -0700 Subject: [PATCH 111/115] Fix waypoints in quickstart 13 --- quickstart/13-npc-follow-waypoints.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickstart/13-npc-follow-waypoints.py b/quickstart/13-npc-follow-waypoints.py index d2ef498..9f47752 100755 --- a/quickstart/13-npc-follow-waypoints.py +++ b/quickstart/13-npc-follow-waypoints.py @@ -73,7 +73,7 @@ def on_collision(agent1, agent2, contact): ) # NPC will wait for 1 second at each waypoint - wp = lgsvl.DriveWaypoint(hit.point, speed, angle, 1) + wp = lgsvl.DriveWaypoint(hit.point, speed, angle=angle, idle=1) waypoints.append(wp) From 5d0db92870842059f98376e374b0377ccec512a6 Mon Sep 17 00:00:00 2001 From: David Uhm Date: Thu, 23 Sep 2021 15:55:10 -0700 Subject: [PATCH 112/115] Revert "[AUTO-7425] Add an API call for canceling destination" This reverts commit 469151941ef767d34782fa9c91e59cfb4963cff9. --- lgsvl/agent.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lgsvl/agent.py b/lgsvl/agent.py index 9797b60..74e0575 100644 --- a/lgsvl/agent.py +++ b/lgsvl/agent.py @@ -214,14 +214,6 @@ def apply_control(self, control, sticky=False): def on_custom(self, fn): self.simulator._add_callback(self, "custom", fn) - def cancel_destination(self): - self.remote.command( - "vehicle/cancel_destination", - { - "uid": self.uid, - } - ) - def set_initial_pose(self): self.remote.command( "vehicle/set_initial_pose", From c6affda4354a19fb8d23c9eb959a8a649b1457bb Mon Sep 17 00:00:00 2001 From: Hadi Tabatabaee Date: Fri, 24 Sep 2021 14:53:20 -0700 Subject: [PATCH 113/115] Add get_bridge_type for ego agents --- lgsvl/agent.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lgsvl/agent.py b/lgsvl/agent.py index 74e0575..f9ca63e 100644 --- a/lgsvl/agent.py +++ b/lgsvl/agent.py @@ -177,6 +177,9 @@ def connect_bridge(self, address, port): {"uid": self.uid, "address": address, "port": port}, ) + def get_bridge_type(self): + return self.remote.command("vehicle/bridge/type", {"uid": self.uid}) + def get_sensors(self): j = self.remote.command("vehicle/sensors/get", {"uid": self.uid}) return [Sensor.create(self.remote, sensor) for sensor in j] From 05f610bd6f3fab37b6523c1775cfcbf361261c0b Mon Sep 17 00:00:00 2001 From: "david.uhm" Date: Mon, 27 Sep 2021 14:54:47 -0700 Subject: [PATCH 114/115] [AUTO-7652] Add example python API script for spawning multi robots --- lgsvl/wise/wise.py | 20 ++++++++++ quickstart/35-spawn-multi-robots.py | 48 +++++++++++++++++++++++ quickstart/36-send-destination-to-nav2.py | 5 +-- 3 files changed, 70 insertions(+), 3 deletions(-) create mode 100755 quickstart/35-spawn-multi-robots.py diff --git a/lgsvl/wise/wise.py b/lgsvl/wise/wise.py index 8d21906..29bf94a 100644 --- a/lgsvl/wise/wise.py +++ b/lgsvl/wise/wise.py @@ -57,6 +57,10 @@ class DefaultAssets: # https://wise.svlsimulator.com/maps/profile/671868be-44f9-44a1-913c-cb0f29d12634 map_straight2laneopposing = "671868be-44f9-44a1-913c-cb0f29d12634" + # Map loaded in the quickstart scripts. Changing the map may lead to unexpected behaviour in the quickstart scripts. Default value is "LGSeocho". + # https://wise.svlsimulator.com/maps/profile/26546191-86e8-4b53-9432-1cecbbd95c87 + map_lgseocho = "26546191-86e8-4b53-9432-1cecbbd95c87" + # Ego vehicle that is loaded in most of the quickstart scripts. Default value is "Lincoln2017MKZ" using the "Apollo 5.0" sensor configuration. # This includes a bridge connection if needed and also bunch of sensors including LIDAR. # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/47b529db-0593-4908-b3e7-4b24a32a0f70 @@ -84,3 +88,19 @@ class DefaultAssets: # This has sensors for modular testing. # https://wise.svlsimulator.com/vehicles/profile/73805704-1e46-4eb6-b5f9-ec2244d5951e/edit/configuration/2e9095fa-c9b9-4f3f-8d7d-65fa2bb03921 ego_lincoln2017mkz_apollo6_modular = "2e9095fa-c9b9-4f3f-8d7d-65fa2bb03921" + + # Cloi robot that is loaded in quickstart/tests scripts. Default value is "LGCloi" using the "Navigation2" sensor configuration. + # https://wise.svlsimulator.com/vehicles/profile/20609b67-6dbd-40ad-9b46-e6bc455278ed/edit/configuration/c2207cd4-c8d0-4a12-b5b7-c79ab748becc + ego_lgcloi_navigation2 = "c2207cd4-c8d0-4a12-b5b7-c79ab748becc" + + # Cloi robot that is loaded in quickstart/tests scripts. Default value is "LGCloi" using the "Nav2_Multi_Robot1" sensor configuration. + # https://wise.svlsimulator.com/vehicles/profile/20609b67-6dbd-40ad-9b46-e6bc455278ed/edit/configuration/eee61d18-c6e3-4292-988d-445802aaee97 + ego_lgcloi_navigation2_multi_robot1 = "eee61d18-c6e3-4292-988d-445802aaee97" + + # Cloi robot that is loaded in quickstart/tests scripts. Default value is "LGCloi" using the "Nav2_Multi_Robot2" sensor configuration. + # https://wise.svlsimulator.com/vehicles/profile/20609b67-6dbd-40ad-9b46-e6bc455278ed/edit/configuration/f9c5ace0-969a-4ade-8208-87d09d1a53f8 + ego_lgcloi_navigation2_multi_robot2 = "f9c5ace0-969a-4ade-8208-87d09d1a53f8" + + # Cloi robot that is loaded in quickstart/tests scripts. Default value is "LGCloi" using the "Nav2_Multi_Robot3" sensor configuration. + # https://wise.svlsimulator.com/vehicles/profile/20609b67-6dbd-40ad-9b46-e6bc455278ed/edit/configuration/cfdb1484-91b7-4f27-b729-e313cc31ed8e + ego_lgcloi_navigation2_multi_robot3 = "cfdb1484-91b7-4f27-b729-e313cc31ed8e" diff --git a/quickstart/35-spawn-multi-robots.py b/quickstart/35-spawn-multi-robots.py new file mode 100755 index 0000000..f4a9727 --- /dev/null +++ b/quickstart/35-spawn-multi-robots.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +import time +from environs import Env +import lgsvl + +print("Python API Quickstart #35: Spawning multi robots with bridge connections") +env = Env() + +sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) + +map_seocho = lgsvl.wise.DefaultAssets.map_lgseocho +robots = [ + lgsvl.wise.DefaultAssets.ego_lgcloi_navigation2_multi_robot1, + lgsvl.wise.DefaultAssets.ego_lgcloi_navigation2_multi_robot2, + lgsvl.wise.DefaultAssets.ego_lgcloi_navigation2_multi_robot3, +] + +if sim.current_scene == map_seocho: + sim.reset() +else: + sim.load(map_seocho) + +spawns = sim.get_spawn() +spawn = spawns[1] +right = lgsvl.utils.transform_to_right(spawn) + +for i, robot in enumerate(robots): + state = lgsvl.AgentState() + state.transform.position = spawn.position + (1.0 * i * right) + state.transform.rotation = spawn.rotation + ego = sim.add_agent(robot, lgsvl.AgentType.EGO, state) + print("Spawned a robot at:", state.transform.position) + + ego.connect_bridge(env.str("LGSVL__AUTOPILOT_0_HOST", lgsvl.wise.SimulatorSettings.bridge_host), env.int("LGSVL__AUTOPILOT_0_PORT", lgsvl.wise.SimulatorSettings.bridge_port)) + print("Waiting for connection...") + while not ego.bridge_connected: + time.sleep(1) + + print("Bridge connected:", ego.bridge_connected) + +print("Running the simulation...") +sim.run() diff --git a/quickstart/36-send-destination-to-nav2.py b/quickstart/36-send-destination-to-nav2.py index 7589d09..7c4362d 100755 --- a/quickstart/36-send-destination-to-nav2.py +++ b/quickstart/36-send-destination-to-nav2.py @@ -14,9 +14,8 @@ sim = lgsvl.Simulator(env.str("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host), env.int("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) -# TODO: Make public assets for LGSeocho with NavOrigin and cloi sensor config -map_seocho = "9b494638-b3e9-4239-9f3f-51b2c68cd292" -ego_cloi = "4717598d-6c67-48a1-9a02-988a89d8660c" +map_seocho = lgsvl.wise.DefaultAssets.map_lgseocho +ego_cloi = lgsvl.wise.DefaultAssets.ego_lgcloi_navigation2 if sim.current_scene == map_seocho: sim.reset() From 9bc29c9aee5e98d4d99e6a410c04b153b8f7feef Mon Sep 17 00:00:00 2001 From: David Uhm Date: Tue, 28 Sep 2021 15:42:10 -0700 Subject: [PATCH 115/115] [AUTO-7654] Add example scripts for Navigation2 stack with Cloi --- examples/Nav2/single-robot-cut-in.py | 81 ++++++++++++++++++++ examples/Nav2/single-robot-freemode.py | 60 +++++++++++++++ examples/Nav2/single-robot-sudden-braking.py | 80 +++++++++++++++++++ examples/Nav2/single-robot-traffic-cones.py | 81 ++++++++++++++++++++ 4 files changed, 302 insertions(+) create mode 100755 examples/Nav2/single-robot-cut-in.py create mode 100755 examples/Nav2/single-robot-freemode.py create mode 100755 examples/Nav2/single-robot-sudden-braking.py create mode 100755 examples/Nav2/single-robot-traffic-cones.py diff --git a/examples/Nav2/single-robot-cut-in.py b/examples/Nav2/single-robot-cut-in.py new file mode 100755 index 0000000..5ab9719 --- /dev/null +++ b/examples/Nav2/single-robot-cut-in.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +import os +import lgsvl + +print("Navigation2 Example: Single Robot Cut In") + +TIME_DELAY = 5 +TIME_LIMIT = 70 +NAV_DST = ((10.9, -0, 0), (0, 0, 0, 1.0)) + +SIMULATOR_HOST = os.environ.get("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host) +SIMULATOR_PORT = int(os.environ.get("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", lgsvl.wise.SimulatorSettings.bridge_host) +BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", lgsvl.wise.SimulatorSettings.bridge_port)) + +SCENE = os.environ.get("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_lgseocho) +ROBOT = os.environ.get("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lgcloi_navigation2) + +sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) +if sim.current_scene == SCENE: + sim.reset() +else: + sim.load(SCENE, seed=0) + +spawns = sim.get_spawn() +egoState = lgsvl.AgentState() +egoState.transform = spawns[0] + +ego = sim.add_agent(ROBOT, lgsvl.AgentType.EGO, egoState) +ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT) +ego.set_initial_pose() +sim.run(TIME_DELAY) +is_reached = False + + +def on_destination_reached(agent): + global is_reached + is_reached = True + print(f"Robot reached destination") + sim.stop() + return + + +sim_dst = sim.map_from_nav(lgsvl.Vector(*NAV_DST[0]), lgsvl.Quaternion(*NAV_DST[1])) +ego.set_destination(sim_dst) +res = ego.on_destination_reached(on_destination_reached) + +right = lgsvl.utils.transform_to_right(egoState.transform) +forward = lgsvl.utils.transform_to_forward(egoState.transform) + +pedState = lgsvl.AgentState() +pedState.transform.position = egoState.transform.position +pedState.transform.position += 5 * right + 5 * forward +ped = sim.add_agent("Robin", lgsvl.AgentType.PEDESTRIAN, pedState) + + +def on_collision(agent1, agent2, contact): + raise Exception("Failed: {} collided with {}".format(agent1, agent2)) + + +ego.on_collision(on_collision) +ped.on_collision(on_collision) +waypoints = [] +waypoints.append(lgsvl.WalkWaypoint(pedState.position, idle=0, trigger_distance=6)) +waypoints.append(lgsvl.WalkWaypoint(pedState.transform.position - 5 * right, idle=15)) +waypoints.append(lgsvl.WalkWaypoint(pedState.transform.position - 10 * right, idle=0)) +ped.follow(waypoints) + +print(f"Running simulation for {TIME_LIMIT} seconds...") +sim.run(TIME_LIMIT) + +if is_reached: + print("PASSED") +else: + exit("FAILED: Ego did not reach the destination") diff --git a/examples/Nav2/single-robot-freemode.py b/examples/Nav2/single-robot-freemode.py new file mode 100755 index 0000000..843c0f2 --- /dev/null +++ b/examples/Nav2/single-robot-freemode.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +import os +import lgsvl + +print("Navigation2 Example: Single Robot Freemode") + +TIME_DELAY = 5 +TIME_LIMIT = 70 +NAV_DST = ((10.9, -0, 0), (0, 0, 0, 1.0)) + +SIMULATOR_HOST = os.environ.get("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host) +SIMULATOR_PORT = int(os.environ.get("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", lgsvl.wise.SimulatorSettings.bridge_host) +BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", lgsvl.wise.SimulatorSettings.bridge_port)) + +SCENE = os.environ.get("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_lgseocho) +ROBOT = os.environ.get("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lgcloi_navigation2) + +sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) +if sim.current_scene == SCENE: + sim.reset() +else: + sim.load(SCENE, seed=0) + +spawns = sim.get_spawn() +state = lgsvl.AgentState() +state.transform = spawns[0] + +ego = sim.add_agent(ROBOT, lgsvl.AgentType.EGO, state) +ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT) +ego.set_initial_pose() +sim.run(TIME_DELAY) +is_reached = False + + +def on_destination_reached(agent): + global is_reached + is_reached = True + print(f"Robot reached destination") + sim.stop() + return + + +sim_dst = sim.map_from_nav(lgsvl.Vector(*NAV_DST[0]), lgsvl.Quaternion(*NAV_DST[1])) +ego.set_destination(sim_dst) +res = ego.on_destination_reached(on_destination_reached) + +print(f"Running simulation for {TIME_LIMIT} seconds...") +sim.run(TIME_LIMIT) + +if is_reached: + print("PASSED") +else: + exit("FAILED: Ego did not reach the destination") diff --git a/examples/Nav2/single-robot-sudden-braking.py b/examples/Nav2/single-robot-sudden-braking.py new file mode 100755 index 0000000..3adda33 --- /dev/null +++ b/examples/Nav2/single-robot-sudden-braking.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +import os +import lgsvl + +print("Navigation2 Example: Single Robot Sudden Braking") + +TIME_DELAY = 5 +TIME_LIMIT = 70 +NAV_DST = ((10.9, -0, 0), (0, 0, 0, 1.0)) + +SIMULATOR_HOST = os.environ.get("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host) +SIMULATOR_PORT = int(os.environ.get("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", lgsvl.wise.SimulatorSettings.bridge_host) +BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", lgsvl.wise.SimulatorSettings.bridge_port)) + +SCENE = os.environ.get("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_lgseocho) +ROBOT = os.environ.get("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lgcloi_navigation2) + +sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) +if sim.current_scene == SCENE: + sim.reset() +else: + sim.load(SCENE, seed=0) + +spawns = sim.get_spawn() +egoState = lgsvl.AgentState() +egoState.transform = spawns[0] + +ego = sim.add_agent(ROBOT, lgsvl.AgentType.EGO, egoState) +ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT) +ego.set_initial_pose() +sim.run(TIME_DELAY) +is_reached = False + + +def on_destination_reached(agent): + global is_reached + is_reached = True + print(f"Robot reached destination") + sim.stop() + return + + +sim_dst = sim.map_from_nav(lgsvl.Vector(*NAV_DST[0]), lgsvl.Quaternion(*NAV_DST[1])) +ego.set_destination(sim_dst) +res = ego.on_destination_reached(on_destination_reached) + +right = lgsvl.utils.transform_to_right(egoState.transform) +forward = lgsvl.utils.transform_to_forward(egoState.transform) + +pedState = lgsvl.AgentState() +pedState.transform = egoState.transform +pedState.transform.position += 2 * forward +ped = sim.add_agent("Robin", lgsvl.AgentType.PEDESTRIAN, pedState) + + +def on_collision(agent1, agent2, contact): + raise Exception("Failed: {} collided with {}".format(agent1.name, agent2.name)) + + +ego.on_collision(on_collision) +ped.on_collision(on_collision) +waypoints = [] +waypoints.append(lgsvl.WalkWaypoint(pedState.position, idle=0, trigger_distance=1.5)) +waypoints.append(lgsvl.WalkWaypoint(pedState.position + 3 * forward, 0, speed=1)) +ped.follow(waypoints) + +print(f"Running simulation for {TIME_LIMIT} seconds...") +sim.run(TIME_LIMIT) + +if is_reached: + print("PASSED") +else: + exit("FAILED: Ego did not reach the destination") diff --git a/examples/Nav2/single-robot-traffic-cones.py b/examples/Nav2/single-robot-traffic-cones.py new file mode 100755 index 0000000..85f7a59 --- /dev/null +++ b/examples/Nav2/single-robot-traffic-cones.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2021 LG Electronics, Inc. +# +# This software contains code licensed as described in LICENSE. +# + +import os +import lgsvl + +print("Navigation2 Example: Single Robot Traffic Cones") + +TIME_DELAY = 5 +TIME_LIMIT = 90 +NAV_DST = ((10.9, -0, 0), (0, 0, 0, 1.0)) + +SIMULATOR_HOST = os.environ.get("LGSVL__SIMULATOR_HOST", lgsvl.wise.SimulatorSettings.simulator_host) +SIMULATOR_PORT = int(os.environ.get("LGSVL__SIMULATOR_PORT", lgsvl.wise.SimulatorSettings.simulator_port)) +BRIDGE_HOST = os.environ.get("LGSVL__AUTOPILOT_0_HOST", lgsvl.wise.SimulatorSettings.bridge_host) +BRIDGE_PORT = int(os.environ.get("LGSVL__AUTOPILOT_0_PORT", lgsvl.wise.SimulatorSettings.bridge_port)) + +SCENE = os.environ.get("LGSVL__MAP", lgsvl.wise.DefaultAssets.map_lgseocho) +ROBOT = os.environ.get("LGSVL__VEHICLE_0", lgsvl.wise.DefaultAssets.ego_lgcloi_navigation2) + +sim = lgsvl.Simulator(SIMULATOR_HOST, SIMULATOR_PORT) +if sim.current_scene == SCENE: + sim.reset() +else: + sim.load(SCENE, seed=0) + +spawns = sim.get_spawn() +state = lgsvl.AgentState() +state.transform = spawns[0] + +ego = sim.add_agent(ROBOT, lgsvl.AgentType.EGO, state) +ego.connect_bridge(BRIDGE_HOST, BRIDGE_PORT) +ego.set_initial_pose() +sim.run(TIME_DELAY) +is_reached = False + + +def on_destination_reached(agent): + global is_reached + is_reached = True + print(f"Robot reached destination") + sim.stop() + return + + +sim_dst = sim.map_from_nav(lgsvl.Vector(*NAV_DST[0]), lgsvl.Quaternion(*NAV_DST[1])) +ego.set_destination(sim_dst) +res = ego.on_destination_reached(on_destination_reached) + +right = lgsvl.utils.transform_to_right(state.transform) +forward = lgsvl.utils.transform_to_forward(state.transform) + +sign = 1 +for j in range(2, 11, 2): + sign *= -1 + for i in range(5): + objState = lgsvl.ObjectState() + objState.transform.position = state.transform.position + offset = sign * 0.5 * i * right + j * forward + objState.transform.position += offset + sim.controllable_add("TrafficCone", objState) + + +def on_collision(agent1, agent2, contact): + name1 = "traffic cone" if agent1 is None else agent1.name + name2 = "traffic cone" if agent2 is None else agent2.name + raise Exception("Failed: {} collided with {}".format(name1, name2)) + + +ego.on_collision(on_collision) +print(f"Running simulation for {TIME_LIMIT} seconds...") +sim.run(TIME_LIMIT) + +if is_reached: + print("PASSED") +else: + exit("FAILED: Ego did not reach the destination")