-
Notifications
You must be signed in to change notification settings - Fork 73
/
17-many-pedestrians-walking.py
executable file
·64 lines (53 loc) · 1.78 KB
/
17-many-pedestrians-walking.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
#
# Copyright (c) 2019-2021 LG Electronics, Inc.
#
# This software contains code licensed as described in LICENSE.
#
import random
from environs import Env
import lgsvl
print("Python API Quickstart #17: Many pedestrians walking simultaneously")
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))
if sim.current_scene == lgsvl.wise.DefaultAssets.map_borregasave:
sim.reset()
else:
sim.load(lgsvl.wise.DefaultAssets.map_borregasave)
spawns = sim.get_spawn()
state = lgsvl.AgentState()
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", lgsvl.wise.DefaultAssets.ego_lincoln2017mkz_apollo5), lgsvl.AgentType.EGO, state)
names = [
"Bob",
"EntrepreneurFemale",
"Howard",
"Johny",
"Pamela",
"Presley",
"Robin",
"Stephen",
"Zoe",
]
print("Creating 120 pedestrians")
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 the simulation for 30 seconds")
sim.run(30)