Skip to content

Commit 1f9956e

Browse files
shalinmehtalgsvlmartins-mozeiko
authored andcommitted
Fix remaining quickstart scripts
1 parent 362f134 commit 1f9956e

8 files changed

+29
-45
lines changed

lgsvl/geometry.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ def __mul__(self, v):
4343

4444
def __rmul__(self, v):
4545
return self * v
46-
# if isinstance(v, Vector):
47-
# return Vector(self.x * v.x, self.y * v.y, self.z * v.z)
48-
49-
# if isinstance(v, (int, float)):
50-
# return Vector(self.x * v, self.y * v, self.z * v)
5146

5247
class BoundingBox:
5348
def __init__(self, min, max):

quickstart/16-pedestrian-follow-waypoints.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
state.transform = spawns[1]
2626
a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state)
2727

28-
# sx = state.position.x + 8
29-
# sy = state.position.y
30-
# sz = state.position.z
31-
3228
# This will create waypoints in a circle for the pedestrian to follow
3329
radius = 5
3430
count = 8

quickstart/17-many-pedestrians-walking.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
state = lgsvl.AgentState()
2222
state.transform = spawns[0]
23+
forward = lgsvl.utils.transform_to_forward(spawns[0])
24+
right = lgsvl.utils.transform_to_right(spawns[0])
2325
a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state)
2426

2527
sx = state.transform.position.x
@@ -30,18 +32,17 @@
3032

3133
for i in range(20*6):
3234
# Create peds in a block
33-
px = sx - 8 + (1.0 * (i % 6))
34-
pz = sz - 5 + (1.0 * (i//6))
35+
start = spawns[0].position + (5 + (1.0 * (i//6))) * forward - (2 + (1.0 * (i % 6))) * right
36+
end = start + 10 * forward
3537

3638
# Give waypoints for the spawn location and 10m ahead
37-
wp = [ lgsvl.WalkWaypoint(lgsvl.Vector(px, sy, pz), 0),
38-
lgsvl.WalkWaypoint(lgsvl.Vector(px, sy, pz + 10), 0),
39+
wp = [ lgsvl.WalkWaypoint(start, 0),
40+
lgsvl.WalkWaypoint(end, 0),
3941
]
4042

4143
state = lgsvl.AgentState()
42-
state.transform = spawns[0]
43-
state.transform.position.x = px
44-
state.transform.position.z = pz
44+
state.transform.position = start
45+
state.transform.rotation = spawns[0].rotation
4546
name = random.choice(names)
4647

4748
# Send the waypoints and make the pedestrian loop over the waypoints

quickstart/23-npc-callbacks.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
sim.load("BorregasAve")
1818

1919
spawns = sim.get_spawn()
20-
sx = spawns[0].position.x
21-
sy = spawns[0].position.y
22-
sz = spawns[0].position.z + 200.0
20+
forward = lgsvl.utils.transform_to_forward(spawns[0])
21+
right = lgsvl.utils.transform_to_right(spawns[0])
2322

2423
state = lgsvl.AgentState()
25-
state.transform = spawns[0]
26-
state.transform = sim.map_point_on_lane(lgsvl.Vector(sx, sy, sz))
24+
state.transform = sim.map_point_on_lane(spawns[0].position + 200 * forward)
2725
a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state)
2826

2927
mindist = 10.0
@@ -44,7 +42,7 @@ def on_lane_change(agent):
4442
angle = random.uniform(0.0, 2*math.pi)
4543
dist = random.uniform(mindist, maxdist)
4644

47-
point = lgsvl.Vector(sx + dist * math.sin(angle), sy, sz + 25 + dist * math.cos(angle))
45+
point = spawns[0].position + dist * math.sin(angle) * right + (225 + dist * math.cos(angle)) * forward
4846

4947
state = lgsvl.AgentState()
5048
state.transform = sim.map_point_on_lane(point)

quickstart/24-ego-drive-straight-non-realtime.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919

2020
state = lgsvl.AgentState()
2121
state.transform = spawns[0]
22+
forward = lgsvl.utils.transform_to_forward(spawns[0])
2223
# Agents can be spawned with a velocity. Default is to spawn with 0 velocity
23-
state.velocity = lgsvl.Vector(0, 0, 20)
24+
state.velocity = 20 * forward
2425
a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state)
2526

2627
print("Real time elapsed =", 0)

quickstart/25-waypoint-flying-npc.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,16 @@
2020
# EGO
2121

2222
state = lgsvl.AgentState()
23+
forward = lgsvl.utils.transform_to_forward(spawns[0])
24+
right = lgsvl.utils.transform_to_right(spawns[0])
25+
up = lgsvl.utils.transform_to_up(spawns[0])
2326
state.transform = spawns[0]
2427
a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state)
2528

2629
# NPC, 10 meters ahead
27-
28-
sx = spawns[0].position.x
29-
sy = spawns[0].position.y
30-
sz = spawns[0].position.z + 10.0
31-
3230
state = lgsvl.AgentState()
33-
state.transform = spawns[0]
34-
state.transform.position.x = sx
35-
state.transform.position.z = sz
31+
state.transform.position = spawns[0].position + 10 * forward
32+
state.transform.rotation = spawns[0].rotation
3633
npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, state)
3734

3835

@@ -57,9 +54,9 @@
5754
angle = lgsvl.Vector(i, 0, 3*i)
5855

5956
# Raycast the points onto the ground because BorregasAve is not flat
60-
hit = sim.raycast(lgsvl.Vector(sx + px, sy, sz + pz), lgsvl.Vector(0,-1,0), layer_mask)
57+
hit = sim.raycast(spawns[0].position + px * right + pz * forward, lgsvl.Vector(0,-1,0), layer_mask)
6158

62-
wp = lgsvl.DriveWaypoint(lgsvl.Vector(sx + px, sy + py, sz + pz), speed, angle, 0, 0)
59+
wp = lgsvl.DriveWaypoint(spawns[0].position + px * right + py * up + pz * forward, speed, angle, 0, 0)
6360
waypoints.append(wp)
6461

6562
# When the NPC is within 1m of the waypoint, this will be called

quickstart/26-npc-trigger-waypoints.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,15 @@
2020
# EGO
2121

2222
state = lgsvl.AgentState()
23+
forward = lgsvl.utils.transform_to_forward(spawns[0])
24+
right = lgsvl.utils.transform_to_right(spawns[0])
2325
state.transform = spawns[0]
2426
a = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state)
2527

2628
# NPC, 10 meters ahead
27-
28-
sx = spawns[0].position.x
29-
sy = spawns[0].position.y
30-
sz = spawns[0].position.z + 10.0
31-
3229
state = lgsvl.AgentState()
33-
state.transform = spawns[0]
34-
state.transform.position.x = sx
35-
state.transform.position.z = sz
30+
state.transform.position = spawns[0].position + 10 * forward
31+
state.transform.rotation = spawns[0].rotation
3632
npc = sim.add_agent("Sedan", lgsvl.AgentType.NPC, state)
3733

3834
vehicles = {
@@ -63,9 +59,9 @@ def on_collision(agent1, agent2, contact):
6359
px = 0
6460
pz = (i + 1) * z_delta
6561
# Waypoint angles are input as Euler angles (roll, pitch, yaw)
66-
angle = lgsvl.Vector(0, 0, 0)
62+
angle = spawns[0].rotation
6763
# Raycast the points onto the ground because BorregasAve is not flat
68-
hit = sim.raycast(lgsvl.Vector(sx + px, sy, sz + pz), lgsvl.Vector(0,-1,0), layer_mask)
64+
hit = sim.raycast(spawns[0].position + px * right + pz * forward, lgsvl.Vector(0,-1,0), layer_mask)
6965

7066
# Trigger is set to 10 meters for every other waypoint (0 means no trigger)
7167
tr = 0

quickstart/27-control-traffic-lights.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
spawns = sim.get_spawn()
2121

2222
state = lgsvl.AgentState()
23+
forward = lgsvl.utils.transform_to_forward(spawns[0])
2324
state.transform = spawns[0]
24-
state.transform.position.z += 20
25-
# state.velocity = lgsvl.Vector(0, 0, 20)
25+
state.transform.position = spawns[0].position + 20 * forward
2626
ego = sim.add_agent("Lincoln2017MKZ (Apollo 5.0)", lgsvl.AgentType.EGO, state)
2727

2828
print("Python API Quickstart #27: How to Control Traffic Light")

0 commit comments

Comments
 (0)