Skip to content

Commit fbe70ef

Browse files
Fix unit tests to use BorregasAve
1 parent 3a1746c commit fbe70ef

File tree

10 files changed

+249
-212
lines changed

10 files changed

+249
-212
lines changed

quickstart/03-raycast.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@
3939

4040
# raycast returns None if the ray doesn't collide with anything
4141
# hit also has the point property which is the Unity position vector of where the ray collided with something
42-
hit = sim.raycast(p, lgsvl.Vector(0,0,1), layer_mask)
42+
hit = sim.raycast(p, lgsvl.Vector(1,0,0), layer_mask)
4343
if hit:
4444
print("Distance right:", hit.distance)
4545

46-
hit = sim.raycast(p, lgsvl.Vector(0,0,-1), layer_mask)
46+
hit = sim.raycast(p, lgsvl.Vector(-1,0,0), layer_mask)
4747
if hit:
4848
print("Distance left:", hit.distance)
4949

50-
hit = sim.raycast(p, lgsvl.Vector(1,0,0), layer_mask)
50+
hit = sim.raycast(p, lgsvl.Vector(0,0,-1), layer_mask)
5151
if hit:
5252
print("Distance back:", hit.distance)
5353

54-
hit = sim.raycast(p, lgsvl.Vector(-1,0,0), layer_mask)
54+
hit = sim.raycast(p, lgsvl.Vector(0,0,1), layer_mask)
5555
if hit:
5656
print("Distance forward:", hit.distance)
5757

quickstart/13-npc-follow-waypoints.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,20 @@
4141
waypoints = []
4242
x_max = 2
4343
z_delta = 12
44+
45+
layer_mask = 0
46+
layer_mask |= 1 << 0 # 0 is the layer for the road (default)
47+
4448
for i in range(20):
4549
speed = 6 if i % 2 == 0 else 12
4650
px = x_max * (-1 if i % 2 == 0 else 1)
4751
pz = (i + 1) * z_delta
4852

49-
wp = lgsvl.DriveWaypoint(lgsvl.Vector(sx + px, sy, sz + pz), speed)
53+
# Raycast the points onto the ground because BorregasAve is not flat
54+
hit = sim.raycast(lgsvl.Vector(sx + px, sy, sz + pz), lgsvl.Vector(0,-1,0), layer_mask)
55+
56+
wp = lgsvl.DriveWaypoint(hit.point, speed)
57+
#wp = lgsvl.DriveWaypoint(lgsvl.Vector(sx + px, sy, sz + pz), speed)
5058
waypoints.append(wp)
5159

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

tests/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TestException(Exception):
1515
pass
1616

1717
class SimConnection:
18-
def __init__(self, seconds=30, scene="SanFrancisco", error_message=None, load_scene=True):
18+
def __init__(self, seconds=30, scene="BorregasAve", error_message=None, load_scene=True):
1919
if error_message is None:
2020
error_message = 'test timed out after {}s.'.format(seconds)
2121
self.seconds = seconds

tests/test_EGO.py

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_agent_name(self): # Check if EGO Apollo is created
1717
with SimConnection() as sim:
1818
agent = self.create_EGO(sim)
1919

20-
self.assertEqual(agent.name, "XE_Rigged-apollo")
20+
self.assertEqual(agent.name, "Jaguar2015XE (Apollo 3.5)")
2121

2222
def test_different_spawns(self): # Check if EGO is spawned in the spawn positions
2323
with SimConnection() as sim:
@@ -28,7 +28,7 @@ def test_different_spawns(self): # Check if EGO is spawned in the spawn position
2828

2929
state = spawnState(sim)
3030
state.transform = spawns[1]
31-
agent2 = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, state)
31+
agent2 = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, state)
3232

3333
cmEqual(self, agent2.state.position, spawns[1].position, "Spawn Position 1")
3434
cmEqual(self, agent2.state.rotation, spawns[1].rotation, "Spawn Rotation 1")
@@ -41,41 +41,42 @@ def test_agent_velocity(self): # Check EGO velocity
4141

4242
sim.reset()
4343
state.velocity = lgsvl.Vector(-50, 0, 0)
44-
agent = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, state)
44+
agent = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, state)
4545

4646
cmEqual(self, agent.state.velocity, state.velocity, "50 Velocity")
4747

4848
def test_ego_different_directions(self): # Check that the xyz velocities equate to xyz changes in position
49-
with SimConnection() as sim:
49+
with SimConnection(40) as sim:
5050
state = spawnState(sim)
5151
state.velocity = lgsvl.Vector(-10,0,0)
52-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, state)
52+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, state)
5353
sim.run(.5)
5454
self.assertNotAlmostEqual(state.position.x, ego.state.position.x, places=1)
5555
self.assertAlmostEqual(state.position.y, ego.state.position.y, places=1)
5656
self.assertAlmostEqual(state.position.z, ego.state.position.z, places=1)
5757
sim.remove_agent(ego)
5858
state.velocity = lgsvl.Vector(0,10,0)
59-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, state)
59+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, state)
6060
sim.run(.5)
6161
self.assertNotAlmostEqual(state.position.y, ego.state.position.y, places=1)
6262
self.assertAlmostEqual(state.position.x, ego.state.position.x, places=1)
6363
self.assertAlmostEqual(state.position.z, ego.state.position.z, places=1)
6464
sim.remove_agent(ego)
65-
state.velocity = lgsvl.Vector(0,0,-10)
66-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, state)
65+
state.velocity = lgsvl.Vector(0,0,10)
66+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, state)
6767
sim.run(.5)
6868
self.assertNotAlmostEqual(state.position.z, ego.state.position.z, places=1)
69-
self.assertAlmostEqual(state.position.y, ego.state.position.y, places=1)
69+
self.assertAlmostEqual(state.position.y, ego.state.position.y, delta=0.15)
7070
self.assertAlmostEqual(state.position.x, ego.state.position.x, places=1)
7171

7272
def test_speed(self): # check that speed returns a reasonable number
7373
with SimConnection() as sim:
7474
state = spawnState(sim)
7575
state.velocity = lgsvl.Vector(-10,10,10)
76-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, state)
76+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, state)
7777
self.assertAlmostEqual(ego.state.speed, math.sqrt(300))
7878

79+
@unittest.skip("No highway in currents maps")
7980
def test_rotation_on_highway_ramp(self): # Check that vehicle is rotated when spawned on the highway ramp
8081
with SimConnection() as sim:
8182
state = spawnState(sim)
@@ -87,7 +88,7 @@ def test_rotation_on_highway_ramp(self): # Check that vehicle is rotated when sp
8788

8889
def test_ego_steering(self): # Check that a steering command can be given to an EGO vehicle, and the car turns
8990
with SimConnection() as sim:
90-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, spawnState(sim))
91+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim))
9192
control = lgsvl.VehicleControl()
9293
control.throttle = 0.3
9394
control.steering = -1.0
@@ -99,7 +100,7 @@ def test_ego_steering(self): # Check that a steering command can be given to an
99100

100101
def test_ego_throttle(self): # Check that a throttle command can be given to an EGO vehicle, and the car accelerates
101102
with SimConnection() as sim:
102-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, spawnState(sim))
103+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim))
103104
control = lgsvl.VehicleControl()
104105
control.throttle = 0.5
105106
ego.apply_control(control, True)
@@ -109,20 +110,20 @@ def test_ego_throttle(self): # Check that a throttle command can be given to an
109110
self.assertGreater(finalSpeed, initialSpeed)
110111

111112
def test_ego_braking(self): # Check that a brake command can be given to an EGO vehicle, and the car stops sooner than without brakes
112-
with SimConnection() as sim:
113+
with SimConnection(60) as sim:
113114
state = spawnState(sim)
114-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, state)
115+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, state)
115116
control = lgsvl.VehicleControl()
116117
control.throttle = 1
117118
ego.apply_control(control, True)
118119
sim.run(1)
119120
control = lgsvl.VehicleControl()
120121
ego.apply_control(control,True)
121122
sim.run(3)
122-
noBrakePosition = ego.state.position.x
123+
noBrakePosition = ego.state.position.z
123124

124125
sim.reset()
125-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, state)
126+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, state)
126127
control = lgsvl.VehicleControl()
127128
control.throttle = 1
128129
ego.apply_control(control, True)
@@ -131,23 +132,23 @@ def test_ego_braking(self): # Check that a brake command can be given to an EGO
131132
control.braking = 1
132133
ego.apply_control(control, True)
133134
sim.run(3)
134-
self.assertGreater(ego.state.position.x, noBrakePosition)
135+
self.assertLess(ego.state.position.z, noBrakePosition)
135136

136137
def test_ego_handbrake(self): # Check that the handbrake can be enable on an EGO vehicle, and the car stops sooner than without brakes
137-
with SimConnection() as sim:
138+
with SimConnection(60) as sim:
138139
state = spawnState(sim)
139-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, state)
140+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, state)
140141
control = lgsvl.VehicleControl()
141142
control.throttle = 1
142143
ego.apply_control(control, True)
143144
sim.run(1)
144145
control = lgsvl.VehicleControl()
145146
ego.apply_control(control,True)
146147
sim.run(3)
147-
noBrakePosition = ego.state.position.x
148+
noBrakePosition = ego.state.position.z
148149

149150
sim.reset()
150-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, state)
151+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, state)
151152
control = lgsvl.VehicleControl()
152153
control.throttle = 1
153154
ego.apply_control(control, True)
@@ -156,44 +157,46 @@ def test_ego_handbrake(self): # Check that the handbrake can be enable on an EGO
156157
control.handbrake = True
157158
ego.apply_control(control, True)
158159
sim.run(3)
159-
self.assertGreater(ego.state.position.x, noBrakePosition)
160+
self.assertLess(ego.state.position.z, noBrakePosition)
160161

161162
def test_ego_reverse(self): # Check that the gear can be changed in an EGO vehicle, and the car moves in reverse
162163
with SimConnection() as sim:
163-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, spawnState(sim))
164+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim))
164165
control = lgsvl.VehicleControl()
165166
control.throttle = 0.5
166167
control.reverse = True
167168
ego.apply_control(control, True)
168169
sim.run(2)
169-
self.assertGreater(ego.state.position.x, sim.get_spawn()[0].position.x)
170+
self.assertLess(ego.state.position.z, sim.get_spawn()[0].position.z)
170171

171172
def test_not_sticky_control(self): # Check that the a non sticky control is removed
172-
with SimConnection() as sim:
173-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, spawnState(sim))
173+
with SimConnection(60) as sim:
174+
state = spawnState(sim)
175+
state.position.z += 20
176+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, state)
174177
control = lgsvl.VehicleControl()
175-
control.throttle = 0.5
178+
control.throttle = 1
176179
ego.apply_control(control, True)
177-
sim.run(1)
178-
initialSpeed = ego.state.speed
180+
sim.run(3)
181+
stickySpeed = ego.state.speed
179182
control = lgsvl.VehicleControl()
180-
control.throttle = 0.5
183+
control.throttle = 1
181184
ego.apply_control(control, False)
182-
sim.run(1)
185+
sim.run(3)
183186
finalSpeed = ego.state.speed
184-
self.assertGreater(initialSpeed, finalSpeed)
187+
self.assertGreater(stickySpeed, finalSpeed)
185188

186189
def test_vary_throttle(self): # Check that different throttle values accelerate differently
187190
with SimConnection() as sim:
188-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, spawnState(sim))
191+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim))
189192
control = lgsvl.VehicleControl()
190193
control.throttle = 0.5
191194
ego.apply_control(control, True)
192195
sim.run(1)
193196
initialSpeed = ego.state.speed
194197

195198
sim.reset()
196-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, spawnState(sim))
199+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim))
197200
control = lgsvl.VehicleControl()
198201
control.throttle = 0.1
199202
ego.apply_control(control, True)
@@ -202,7 +205,7 @@ def test_vary_throttle(self): # Check that different throttle values accelerate
202205

203206
def test_vary_steering(self): # Check that different steering values turn the car differently
204207
with SimConnection() as sim:
205-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, spawnState(sim))
208+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim))
206209
control = lgsvl.VehicleControl()
207210
control.throttle = 0.5
208211
control.steering = -0.8
@@ -211,7 +214,7 @@ def test_vary_steering(self): # Check that different steering values turn the ca
211214
initialAngle = ego.state.rotation.y
212215

213216
sim.reset()
214-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, spawnState(sim))
217+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim))
215218
control = lgsvl.VehicleControl()
216219
control.throttle = 0.5
217220
control.steering = -0.3
@@ -221,7 +224,7 @@ def test_vary_steering(self): # Check that different steering values turn the ca
221224

222225
def test_bounding_box_size(self): # Check that the bounding box is calculated properly and is reasonable
223226
with SimConnection() as sim:
224-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, spawnState(sim))
227+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim))
225228
bBox = ego.bounding_box
226229
self.assertAlmostEqual(bBox.size.x, abs(bBox.max.x-bBox.min.x))
227230
self.assertAlmostEqual(bBox.size.y, abs(bBox.max.y-bBox.min.y))
@@ -232,29 +235,30 @@ def test_bounding_box_size(self): # Check that the bounding box is calculated pr
232235

233236
def test_bounding_box_center(self): # Check that the bounding box center is calcualted properly
234237
with SimConnection() as sim:
235-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, spawnState(sim))
238+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim))
236239
bBox = ego.bounding_box
237240
self.assertAlmostEqual(bBox.center.x, (bBox.max.x+bBox.min.x)/2)
238241
self.assertAlmostEqual(bBox.center.y, (bBox.max.y+bBox.min.y)/2)
239242
self.assertAlmostEqual(bBox.center.z, (bBox.max.z+bBox.min.z)/2)
240243

241244
def test_equality(self): # Check that agent == operation works
242245
with SimConnection() as sim:
243-
ego1 = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, spawnState(sim))
244-
ego2 = sim.add_agent("XE_Rigged-autoware", lgsvl.AgentType.EGO, spawnState(sim))
246+
ego1 = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim))
247+
ego2 = sim.add_agent("Jaguar2015XE (Autoware)", lgsvl.AgentType.EGO, spawnState(sim))
245248
self.assertTrue(ego1 == ego1)
246249
self.assertFalse(ego1 == ego2)
247250

251+
@unittest.skip("Cruise Control not implemented yet")
248252
def test_set_fixed_speed(self):
249253
with SimConnection(60) as sim:
250-
ego = sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, spawnState(sim))
254+
ego = sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim))
251255
ego.set_fixed_speed(True, 15.0)
252256
self.assertAlmostEqual(ego.state.speed, 0, delta=0.001)
253257
sim.run(5)
254258
self.assertAlmostEqual(ego.state.speed, 15, delta=1)
255259

256260
def create_EGO(self, sim): # Only create an EGO is none are already spawned
257-
return sim.add_agent("XE_Rigged-apollo", lgsvl.AgentType.EGO, spawnState(sim))
261+
return sim.add_agent("Jaguar2015XE (Apollo 3.5)", lgsvl.AgentType.EGO, spawnState(sim))
258262

259263
# def test_large_throttle(self):
260264
# with SimConnection(60) as sim:

0 commit comments

Comments
 (0)