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

Method _on_collision

roach/criteria/collision.py:50–112  ·  view source on GitHub ↗
(weakself, event)

Source from the content-addressed store, hash-verified

48
49 @staticmethod
50 def _on_collision(weakself, event):
51 self = weakself()
52 if not self:
53 return
54 # Ignore the current one if it's' the same id as before
55 if self.last_id == event.other_actor.id:
56 return
57 # Ignore if it's too close to a previous collision (avoid micro collisions)
58 ev_loc = event.actor.get_transform().location
59 for collision_location in self.registered_collisions:
60 if ev_loc.distance(collision_location) <= self._min_area_of_collision:
61 return
62 # Ignore if its intensity is smaller than self._intensity_threshold
63 impulse = event.normal_impulse
64 intensity = np.linalg.norm([impulse.x, impulse.y, impulse.z])
65 if intensity < self._intensity_threshold:
66 return
67
68 # collision_type
69 if ('static' in event.other_actor.type_id or 'traffic' in event.other_actor.type_id) \
70 and 'sidewalk' not in event.other_actor.type_id:
71 collision_type = 0 # TrafficEventType.COLLISION_STATIC
72 elif 'vehicle' in event.other_actor.type_id:
73 collision_type = 1 # TrafficEventType.COLLISION_VEHICLE
74 elif 'walker' in event.other_actor.type_id:
75 collision_type = 2 # TrafficEventType.COLLISION_PEDESTRIAN
76 else:
77 collision_type = -1
78
79 # write to info, all quantities in in world coordinate
80 event_loc = event.transform.location
81 event_rot = event.transform.rotation
82 oa_loc = event.other_actor.get_transform().location
83 oa_rot = event.other_actor.get_transform().rotation
84 oa_vel = event.other_actor.get_velocity()
85 ev_rot = event.actor.get_transform().rotation
86 ev_vel = event.actor.get_velocity()
87
88 self._collision_info = {
89 'step': event.frame,
90 'simulation_time': event.timestamp,
91 'collision_type': collision_type,
92 'other_actor_id': event.other_actor.id,
93 'other_actor_type_id': event.other_actor.type_id,
94 'intensity': intensity,
95 'normal_impulse': [impulse.x, impulse.y, impulse.z],
96 'event_loc': [event_loc.x, event_loc.y, event_loc.z],
97 'event_rot': [event_rot.roll, event_rot.pitch, event_rot.yaw],
98 'ev_loc': [ev_loc.x, ev_loc.y, ev_loc.z],
99 'ev_rot': [ev_rot.roll, ev_rot.pitch, ev_rot.yaw],
100 'ev_vel': [ev_vel.x, ev_vel.y, ev_vel.z],
101 'oa_loc': [oa_loc.x, oa_loc.y, oa_loc.z],
102 'oa_rot': [oa_rot.roll, oa_rot.pitch, oa_rot.yaw],
103 'oa_vel': [oa_vel.x, oa_vel.y, oa_vel.z]
104 }
105
106 self.collision_time = event.timestamp
107

Callers 1

__init__Method · 0.95

Calls 3

get_transformMethod · 0.80
distanceMethod · 0.80
get_velocityMethod · 0.80

Tested by

no test coverage detected