Skip to content

Commit 5304ad1

Browse files
KarBycEricBoiseLGSVL
authored andcommitted
[FEATURE] AUTO-4016 Added triggers system to the Python API.
1 parent 183ccdc commit 5304ad1

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

lgsvl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
from .geometry import Vector, BoundingBox, Transform
88
from .simulator import Simulator, RaycastHit, WeatherState
99
from .sensor import Sensor, CameraSensor, LidarSensor, ImuSensor
10-
from .agent import AgentType, AgentState, VehicleControl, Vehicle, EgoVehicle, NpcVehicle, Pedestrian, DriveWaypoint, WalkWaypoint, NPCControl
10+
from .agent import AgentType, AgentState, VehicleControl, Vehicle, EgoVehicle, NpcVehicle, Pedestrian, DriveWaypoint, WalkWaypoint, WaypointTrigger, TriggerEffector, NPCControl
1111
from .controllable import Controllable
1212
from .utils import ObjectState

lgsvl/agent.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,58 @@
1111
from enum import Enum
1212
from collections.abc import Iterable, Callable
1313
import math
14+
import json
1415

1516
class DriveWaypoint:
16-
def __init__(self, position, speed, angle = Vector(0,0,0), idle = 0, deactivate = False, trigger_distance = 0, timestamp = -1):
17+
def __init__(self, position, speed, angle = Vector(0,0,0), idle = 0, deactivate = False, trigger_distance = 0, timestamp = -1, trigger = None):
1718
self.position = position
1819
self.speed = speed
1920
self.angle = angle
2021
self.idle = idle
2122
self.deactivate = deactivate
2223
self.trigger_distance = trigger_distance
2324
self.timestamp = timestamp
25+
self.trigger = trigger
2426

2527
class WalkWaypoint:
26-
def __init__(self, position, idle, trigger_distance = 0):
28+
def __init__(self, position, idle, trigger_distance = 0, trigger = None):
2729
self.position = position
2830
self.idle = idle
2931
self.trigger_distance = trigger_distance
32+
self.trigger = trigger
33+
34+
class WaypointTrigger:
35+
def __init__(self, effectors):
36+
self.effectors = effectors
37+
38+
@staticmethod
39+
def from_json(j):
40+
return WaypointTrigger(
41+
json.loads(j["effectors"])
42+
)
43+
44+
def to_json(self):
45+
effectors_json = []
46+
for effector in self.effectors:
47+
effectors_json.append(effector.to_json())
48+
return {
49+
"effectors": effectors_json
50+
}
51+
52+
class TriggerEffector:
53+
def __init__(self, type_name, value):
54+
self.type_name = type_name
55+
self.value = value
56+
57+
@staticmethod
58+
def from_json(j):
59+
return TriggerEffector(j["type_name"], j["value"])
60+
61+
def to_json(self):
62+
return {
63+
"type_name": self.type_name,
64+
"value": self.value
65+
}
3066

3167
class AgentType(Enum):
3268
EGO = 1
@@ -196,6 +232,14 @@ def follow(self, waypoints, loop = False):
196232
trigger_distance : float
197233
how close an EGO must approach for the NPC to continue
198234
235+
trigger : Class (list of Effectors)
236+
trigger data with effectors applied on this waypoint
237+
effectors : Class (type, value)
238+
typeName : string
239+
effector type name
240+
value : float
241+
value of the effector (for example time duration)
242+
199243
loop : bool
200244
whether the NPC should loop through the waypoints after reaching the final one
201245
'''
@@ -208,7 +252,8 @@ def follow(self, waypoints, loop = False):
208252
"idle": wp.idle,
209253
"deactivate": wp.deactivate,
210254
"trigger_distance": wp.trigger_distance,
211-
"timestamp": wp.timestamp
255+
"timestamp": wp.timestamp,
256+
"trigger": (None if wp.trigger is None else wp.trigger.to_json())
212257
} for wp in waypoints],
213258
"loop": loop,
214259
})

0 commit comments

Comments
 (0)