|
13 | 13 | from collections.abc import Iterable, Callable |
14 | 14 | import math |
15 | 15 |
|
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 |
18 | 29 |
|
19 | 30 | class AgentType(Enum): |
20 | 31 | EGO = 1 |
@@ -199,6 +210,36 @@ def __init__(self, uid, simulator): |
199 | 210 |
|
200 | 211 | @accepts(Iterable, bool) |
201 | 212 | 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 | + ''' |
202 | 243 | self.remote.command("vehicle/follow_waypoints", { |
203 | 244 | "uid": self.uid, |
204 | 245 | "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): |
254 | 295 |
|
255 | 296 | @accepts(Iterable, bool) |
256 | 297 | 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 | + ''' |
257 | 322 | self.remote.command("pedestrian/follow_waypoints", { |
258 | 323 | "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], |
260 | 325 | "loop": loop, |
261 | 326 | }) |
262 | 327 |
|
|
0 commit comments