Skip to content

Commit 5cfffdd

Browse files
shalinmehtalgsvlmartins-mozeiko
authored andcommitted
Add Pedestrian Trigger Waypoints
1 parent 030dfba commit 5cfffdd

File tree

1 file changed

+68
-3
lines changed

1 file changed

+68
-3
lines changed

lgsvl/agent.py

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,19 @@
1313
from collections.abc import Iterable, Callable
1414
import math
1515

16-
DriveWaypoint = namedtuple("DriveWaypoint", "position speed angle idle trigger_distance")
17-
WalkWaypoint = namedtuple("WalkWaypoint", "position idle")
16+
class DriveWaypoint:
17+
def __init__(self, position, speed, angle = Vector(0,0,0), idle = 0, trigger_distance = 0):
18+
self.position = position
19+
self.speed = speed
20+
self.angle = angle
21+
self.idle = idle
22+
self.trigger_distance = trigger_distance
23+
24+
class WalkWaypoint:
25+
def __init__(self, position, idle, trigger_distance = 0):
26+
self.position = position
27+
self.idle = idle
28+
self.trigger_distance = trigger_distance
1829

1930
class AgentType(Enum):
2031
EGO = 1
@@ -199,6 +210,36 @@ def __init__(self, uid, simulator):
199210

200211
@accepts(Iterable, bool)
201212
def follow(self, waypoints, loop = False):
213+
'''Tells the NPC to follow the waypoints
214+
215+
When an NPC reaches a waypoint, it will:
216+
1. Wait for an EGO vehicle to approach to within the trigger_distance [meters] (ignored if 0)
217+
2. Wait the idle time (ignored if 0)
218+
3. Drive to the next waypoint (if any)
219+
220+
Parameters
221+
----------
222+
waypoints : list of DriveWaypoints
223+
DriveWaypoint : tuple (position, speed, angle, idle, trigger_distance)
224+
225+
position : lgsvl.Vector()
226+
Unity coordinates of waypoint
227+
228+
speed : float
229+
how fast the NPC should drive to the waypoint
230+
231+
angle : lgsvl.Vector()
232+
Unity rotation of the NPC at the waypoint
233+
234+
idle : float
235+
time for the NPC to wait at the waypoint
236+
237+
trigger_distance : float
238+
how close an EGO must approach for the NPC to continue
239+
240+
loop : bool
241+
whether the NPC should loop through the waypoints after reaching the final one
242+
'''
202243
self.remote.command("vehicle/follow_waypoints", {
203244
"uid": self.uid,
204245
"waypoints": [{"position": wp.position.to_json(), "speed": wp.speed, "angle": wp.angle.to_json(), "idle": wp.idle, "trigger_distance": wp.trigger_distance} for wp in waypoints],
@@ -254,9 +295,33 @@ def walk_randomly(self, enable):
254295

255296
@accepts(Iterable, bool)
256297
def follow(self, waypoints, loop = False):
298+
'''Tells the Pedestrian to follow the waypoints
299+
300+
When a pedestrian reaches a waypoint, it will:
301+
1. Wait for an EGO vehicle to approach to within the trigger_distance [meters] (ignored if 0)
302+
2. Wait the idle time (ignored if 0)
303+
3. Walk to the next waypoint (if any)
304+
305+
Parameters
306+
----------
307+
waypoints : list of WalkWaypoints
308+
WalkWaypoint : tuple (position, idle, trigger_distance)
309+
310+
position : lgsvl.Vector()
311+
Unity coordinates of waypoint
312+
313+
idle : float
314+
time for the pedestrian to wait at the waypoint
315+
316+
trigger_distance : float
317+
how close an EGO must approach for the pedestrian to continue
318+
319+
loop : bool
320+
whether the pedestrian should loop through the waypoints after reaching the final one
321+
'''
257322
self.remote.command("pedestrian/follow_waypoints", {
258323
"uid": self.uid,
259-
"waypoints": [{"position": wp.position.to_json(), "idle": wp.idle} for wp in waypoints],
324+
"waypoints": [{"position": wp.position.to_json(), "idle": wp.idle, "trigger_distance": wp.trigger_distance} for wp in waypoints],
260325
"loop": loop,
261326
})
262327

0 commit comments

Comments
 (0)