[WIP]Added collision types, at-fault collision percentage#394
[WIP]Added collision types, at-fault collision percentage#394
Conversation
There was a problem hiding this comment.
Pull request overview
Adds collision-type classification to the Ocean Drive environment and surfaces new “at-fault” vs “not-at-fault” collision metrics through the Python logging interface.
Changes:
- Introduces
CollisionTypeand storescurrent_collision_typeon eachAgent. - Adds collision classification helpers and increments new log counters for at-fault / not-at-fault collisions.
- Exposes
at_fault_collision_pctandnot_at_fault_collision_pctviamy_log().
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
pufferlib/ocean/drive/drive.h |
Adds collision classification logic, new log fields, and updates collision metric handling. |
pufferlib/ocean/drive/datatypes.h |
Defines CollisionType enum and adds current_collision_type to Agent. |
pufferlib/ocean/drive/binding.c |
Emits at-fault and not-at-fault collision percentages into the Python log dict. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| float at_fault_collision_pct = | ||
| (log->collisions_per_agent > 0) ? log->at_fault_collision_count / log->collisions_per_agent : 0.0f; | ||
| assign_to_dict(dict, "at_fault_collision_pct", at_fault_collision_pct); | ||
| float not_at_fault_collision_pct = | ||
| (log->collisions_per_agent > 0) ? log->not_at_fault_collision_count / log->collisions_per_agent : 0.0f; |
There was a problem hiding this comment.
The at-fault percentages are computed using log->collisions_per_agent as the denominator. Since you already track at_fault_collision_count and not_at_fault_collision_count, the most direct/consistent denominator is their sum; using collisions_per_agent risks drifting if the two counters ever differ from the collision counter and makes the intent less clear.
| float at_fault_collision_pct = | |
| (log->collisions_per_agent > 0) ? log->at_fault_collision_count / log->collisions_per_agent : 0.0f; | |
| assign_to_dict(dict, "at_fault_collision_pct", at_fault_collision_pct); | |
| float not_at_fault_collision_pct = | |
| (log->collisions_per_agent > 0) ? log->not_at_fault_collision_count / log->collisions_per_agent : 0.0f; | |
| float total_collision_count = log->at_fault_collision_count + log->not_at_fault_collision_count; | |
| float at_fault_collision_pct = | |
| (total_collision_count > 0) ? log->at_fault_collision_count / total_collision_count : 0.0f; | |
| assign_to_dict(dict, "at_fault_collision_pct", at_fault_collision_pct); | |
| float not_at_fault_collision_pct = | |
| (total_collision_count > 0) ? log->not_at_fault_collision_count / total_collision_count : 0.0f; |
| /** | ||
| * @brief Categorizes the type of collision an agent is involved in. | ||
| * | ||
| * - STATIONARY_PARTNER_COLLISION: ego hit a stationary partner agent | ||
| * | ||
| * - STATIONARY_EGO_COLLISION: ego was stationary when hit by another agent | ||
| * | ||
| * - ACTIVE_FRONT_COLLISION: ego collided with something ahead of it | ||
| * | ||
| * - ACTIVE_REAR_COLLISION: ego was hit from behind while moving | ||
| * | ||
| * - ACTIVE_LATERAL_COLLISION: ego was involved in a side collision while moving | ||
| */ | ||
| typedef enum { | ||
| STATIONARY_AGENT_COLLISION, | ||
| STATIONARY_EGO_COLLISION, | ||
| ACTIVE_FRONT_COLLISION, | ||
| ACTIVE_REAR_COLLISION, | ||
| ACTIVE_LATERAL_COLLISION, | ||
| } CollisionType; |
There was a problem hiding this comment.
The enum doc comment references STATIONARY_PARTNER_COLLISION, but the actual enum value is named STATIONARY_AGENT_COLLISION. Please align the documentation and the enum name to avoid confusion for downstream users.
No description provided.