@@ -40,41 +40,48 @@ def test_agent_velocity(self): # Check EGO velocity
4040 cmEqual (self , agent .state .velocity , state .velocity , "0 Velocity" )
4141
4242 sim .reset ()
43- state .velocity = lgsvl .Vector (- 50 , 0 , 0 )
43+ right = lgsvl .utils .transform_to_right (state .transform )
44+ state .velocity = - 50 * right
4445 agent = sim .add_agent ("Jaguar2015XE (Apollo 3.0)" , lgsvl .AgentType .EGO , state )
4546
4647 cmEqual (self , agent .state .velocity , state .velocity , "50 Velocity" )
4748
4849 def test_ego_different_directions (self ): # Check that the xyz velocities equate to xyz changes in position
4950 with SimConnection (40 ) as sim :
5051 state = spawnState (sim )
51- state .velocity = lgsvl .Vector (- 10 ,0 ,0 )
52+ forward = lgsvl .utils .transform_to_forward (state .transform )
53+ up = lgsvl .utils .transform_to_up (state .transform )
54+ right = lgsvl .utils .transform_to_right (state .transform )
55+
56+ state .velocity = - 10 * right
5257 ego = sim .add_agent ("Jaguar2015XE (Apollo 3.0)" , lgsvl .AgentType .EGO , state )
5358 sim .run (.5 )
54- self .assertNotAlmostEqual (state .position .x , ego .state .position .x , places = 1 )
55- self .assertAlmostEqual (state .position .y , ego .state .position .y , places = 1 )
56- self .assertAlmostEqual (state .position .z , ego .state .position .z , places = 1 )
59+ target = state .position - 3 * right
60+ self .assertLess ((ego .state .position - target ).magnitude (), 1 )
5761 sim .remove_agent (ego )
58- state .velocity = lgsvl .Vector (0 ,10 ,0 )
62+
63+ state .velocity = 10 * up
5964 ego = sim .add_agent ("Jaguar2015XE (Apollo 3.0)" , lgsvl .AgentType .EGO , state )
6065 sim .run (.5 )
61- self .assertNotAlmostEqual (state .position .y , ego .state .position .y , places = 1 )
62- self .assertAlmostEqual (state .position .x , ego .state .position .x , places = 1 )
63- self .assertAlmostEqual (state .position .z , ego .state .position .z , places = 1 )
66+ target = state .position + 3 * up
67+ self .assertLess ((ego .state .position - target ).magnitude (), 1 )
6468 sim .remove_agent (ego )
65- state .velocity = lgsvl .Vector (0 ,0 ,10 )
69+
70+ state .velocity = 10 * forward
6671 ego = sim .add_agent ("Jaguar2015XE (Apollo 3.0)" , lgsvl .AgentType .EGO , state )
6772 sim .run (.5 )
68- self .assertNotAlmostEqual (state .position .z , ego .state .position .z , places = 1 )
69- self .assertAlmostEqual (state .position .y , ego .state .position .y , delta = 0.15 )
70- self .assertAlmostEqual (state .position .x , ego .state .position .x , places = 1 )
73+ target = state .position + 4 * forward
74+ self .assertLess ((ego .state .position - target ).magnitude (), 1 )
7175
7276 def test_speed (self ): # check that speed returns a reasonable number
7377 with SimConnection () as sim :
7478 state = spawnState (sim )
75- state .velocity = lgsvl .Vector (- 10 ,10 ,10 )
79+ forward = lgsvl .utils .transform_to_forward (state .transform )
80+ up = lgsvl .utils .transform_to_up (state .transform )
81+ right = lgsvl .utils .transform_to_right (state .transform )
82+ state .velocity = - 10 * right + 10 * up + 10 * forward
7683 ego = sim .add_agent ("Jaguar2015XE (Apollo 3.0)" , lgsvl .AgentType .EGO , state )
77- self .assertAlmostEqual (ego .state .speed , math .sqrt (300 ))
84+ self .assertAlmostEqual (ego .state .speed , math .sqrt (300 ), places = 3 )
7885
7986 @unittest .skip ("No highway in currents maps" )
8087 def test_rotation_on_highway_ramp (self ): # Check that vehicle is rotated when spawned on the highway ramp
@@ -120,7 +127,7 @@ def test_ego_braking(self): # Check that a brake command can be given to an EGO
120127 control = lgsvl .VehicleControl ()
121128 ego .apply_control (control ,True )
122129 sim .run (3 )
123- noBrakePosition = ego .state .position . z
130+ noBrakeDistance = ( ego .state .position - state . position ). magnitude ()
124131
125132 sim .reset ()
126133 ego = sim .add_agent ("Jaguar2015XE (Apollo 3.0)" , lgsvl .AgentType .EGO , state )
@@ -132,7 +139,8 @@ def test_ego_braking(self): # Check that a brake command can be given to an EGO
132139 control .braking = 1
133140 ego .apply_control (control , True )
134141 sim .run (3 )
135- self .assertLess (ego .state .position .z , noBrakePosition )
142+ brakeDistance = (ego .state .position - state .position ).magnitude ()
143+ self .assertLess (brakeDistance , noBrakeDistance )
136144
137145 def test_ego_handbrake (self ): # Check that the handbrake can be enable on an EGO vehicle, and the car stops sooner than without brakes
138146 with SimConnection (60 ) as sim :
@@ -145,7 +153,7 @@ def test_ego_handbrake(self): # Check that the handbrake can be enable on an EGO
145153 control = lgsvl .VehicleControl ()
146154 ego .apply_control (control ,True )
147155 sim .run (3 )
148- noBrakePosition = ego .state .position . z
156+ noBrakeDistance = ( ego .state .position - state . position ). magnitude ()
149157
150158 sim .reset ()
151159 ego = sim .add_agent ("Jaguar2015XE (Apollo 3.0)" , lgsvl .AgentType .EGO , state )
@@ -157,32 +165,41 @@ def test_ego_handbrake(self): # Check that the handbrake can be enable on an EGO
157165 control .handbrake = True
158166 ego .apply_control (control , True )
159167 sim .run (3 )
160- self .assertLess (ego .state .position .z , noBrakePosition )
168+ brakeDistance = (ego .state .position - state .position ).magnitude ()
169+ self .assertLess (brakeDistance , noBrakeDistance )
161170
162171 def test_ego_reverse (self ): # Check that the gear can be changed in an EGO vehicle, and the car moves in reverse
163172 with SimConnection () as sim :
164- ego = sim .add_agent ("Jaguar2015XE (Apollo 3.0)" , lgsvl .AgentType .EGO , spawnState (sim ))
173+ state = spawnState (sim )
174+ ego = sim .add_agent ("Jaguar2015XE (Apollo 3.0)" , lgsvl .AgentType .EGO , state )
165175 control = lgsvl .VehicleControl ()
166176 control .throttle = 0.5
167177 control .reverse = True
168178 ego .apply_control (control , True )
169179 sim .run (2 )
170- self .assertLess (ego .state .position .z , sim .get_spawn ()[0 ].position .z )
180+ forward = lgsvl .utils .transform_to_forward (state .transform )
181+ target = state .position - 3.5 * forward
182+ diff = ego .state .position - target
183+ self .assertLess ((diff ).magnitude (), 1 )
171184
172185 def test_not_sticky_control (self ): # Check that the a non sticky control is removed
173186 with SimConnection (60 ) as sim :
174187 state = spawnState (sim )
175- state .position .z += 20
176188 ego = sim .add_agent ("Jaguar2015XE (Apollo 3.0)" , lgsvl .AgentType .EGO , state )
177189 control = lgsvl .VehicleControl ()
178190 control .throttle = 1
179191 ego .apply_control (control , True )
180192 sim .run (3 )
181193 stickySpeed = ego .state .speed
194+
195+ sim .reset ()
196+ ego = sim .add_agent ("Jaguar2015XE (Apollo 3.0)" , lgsvl .AgentType .EGO , state )
182197 control = lgsvl .VehicleControl ()
183198 control .throttle = 1
184- ego .apply_control (control , False )
185- sim .run (3 )
199+ ego .apply_control (control , True )
200+ sim .run (1 )
201+ ego .apply_control (control ,False )
202+ sim .run (2 )
186203 finalSpeed = ego .state .speed
187204 self .assertGreater (stickySpeed , finalSpeed )
188205
0 commit comments