MCPcopy Create free account
hub / github.com/OpenDriveLab/DriveAdapter / tick

Method tick

roach/criteria/run_red_light.py:13–54  ·  view source on GitHub ↗
(self, vehicle, timestamp)

Source from the content-addressed store, hash-verified

11 self._distance_light = distance_light
12
13 def tick(self, vehicle, timestamp):
14 ev_tra = vehicle.get_transform()
15 ev_loc = ev_tra.location
16 ev_dir = ev_tra.get_forward_vector()
17 ev_extent = vehicle.bounding_box.extent.x
18
19 tail_close_pt = ev_tra.transform(carla.Location(x=-0.8 * ev_extent))
20 tail_far_pt = ev_tra.transform(carla.Location(x=-ev_extent - 1.0))
21 tail_wp = self._map.get_waypoint(tail_far_pt)
22
23 info = None
24 for idx_tl in range(TrafficLightHandler.num_tl):
25 traffic_light = TrafficLightHandler.list_tl_actor[idx_tl]
26 tl_tv_loc = TrafficLightHandler.list_tv_loc[idx_tl]
27 if tl_tv_loc.distance(ev_loc) > self._distance_light:
28 continue
29 if traffic_light.state != carla.TrafficLightState.Red:
30 continue
31 if self._last_red_light_id and self._last_red_light_id == traffic_light.id:
32 continue
33
34 for idx_wp in range(len(TrafficLightHandler.list_stopline_wps[idx_tl])):
35 wp = TrafficLightHandler.list_stopline_wps[idx_tl][idx_wp]
36 wp_dir = wp.transform.get_forward_vector()
37 dot_ve_wp = ev_dir.x * wp_dir.x + ev_dir.y * wp_dir.y + ev_dir.z * wp_dir.z
38
39 if tail_wp.road_id == wp.road_id and tail_wp.lane_id == wp.lane_id and dot_ve_wp > 0:
40 # This light is red and is affecting our lane
41 stop_left_loc, stop_right_loc = TrafficLightHandler.list_stopline_vtx[idx_tl][idx_wp]
42 # Is the vehicle traversing the stop line?
43 if self._is_vehicle_crossing_line((tail_close_pt, tail_far_pt), (stop_left_loc, stop_right_loc)):
44 tl_loc = traffic_light.get_location()
45 # loc_in_ev = trans_utils.loc_global_to_ref(tl_loc, ev_tra)
46 self._last_red_light_id = traffic_light.id
47 info = {
48 'step': timestamp['step'],
49 'simulation_time': timestamp['relative_simulation_time'],
50 'id': traffic_light.id,
51 'tl_loc': [tl_loc.x, tl_loc.y, tl_loc.z],
52 'ev_loc': [ev_loc.x, ev_loc.y, ev_loc.z]
53 }
54 return info
55
56 @staticmethod
57 def _is_vehicle_crossing_line(seg1, seg2):

Callers

nothing calls this directly

Calls 5

get_transformMethod · 0.80
get_waypointMethod · 0.80
distanceMethod · 0.80
get_locationMethod · 0.80

Tested by

no test coverage detected