Skip to content

[WIP]Added collision types, at-fault collision percentage#394

Open
mpragnay wants to merge 5 commits into3.0from
pragnay/AtFaultCollision
Open

[WIP]Added collision types, at-fault collision percentage#394
mpragnay wants to merge 5 commits into3.0from
pragnay/AtFaultCollision

Conversation

@mpragnay
Copy link
Copy Markdown

@mpragnay mpragnay commented Apr 9, 2026

No description provided.

Copilot AI review requested due to automatic review settings April 9, 2026 22:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CollisionType and stores current_collision_type on each Agent.
  • Adds collision classification helpers and increments new log counters for at-fault / not-at-fault collisions.
  • Exposes at_fault_collision_pct and not_at_fault_collision_pct via my_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.

Comment thread pufferlib/ocean/drive/drive.h
Comment thread pufferlib/ocean/drive/drive.h
Comment on lines +471 to +475
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;
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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;

Copilot uses AI. Check for mistakes.
Comment on lines +142 to +161
/**
* @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;
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@mpragnay mpragnay changed the title Added collision types, at-fault collision percentage [WIP]Added collision types, at-fault collision percentage Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants