Collision detection: CARLA collision sensor + Newtonian 2D collision physics#463
Open
servinar wants to merge 3 commits intoBerkeleyLearnVerify:mainfrom
Open
Collision detection: CARLA collision sensor + Newtonian 2D collision physics#463servinar wants to merge 3 commits intoBerkeleyLearnVerify:mainfrom
servinar wants to merge 3 commits intoBerkeleyLearnVerify:mainfrom
Conversation
Add a CarlaCollisionSensor wrapping CARLA's sensor.other.collision blueprint, exported from the world model as CollisionSensor. It exposes collision_history, has_collision, and the most recent event's intensity and impulse, with reset() to clear state between simulations. Make CarlaSimulation.step() aware of event-based sensors: rather than blocking on sensor.frame != current_frame (which never matches for sensors that only fire on events), bump their frame number via updateFrame() and skip the wait. Sensors with a reset() method are reset on simulation teardown.
Attach a CarlaCollisionSensor to the ego in createObjectInSimulator if the user hasn't declared one explicitly, so scenarios can use terminate when ego.sensors['collision'].has_collision without boilerplate. Add a colored "Collision:" status line to the CARLA HUD via a new (label, value, color) tuple format. Renders green when no collision, red when one is in progress, with the impacted actor and impulse intensity.
Detect pairwise object collisions via shapely polygon intersection on _corners2D, then resolve them with an SAT-derived collision normal: apply an impulse along the normal scaled by mass and restitution, and split the penetration depth between the two objects. Optional crash physics (toggled by enable_crash_physics, default on) marks colliding cars and pedestrians as crashed, applies post-impact dynamics — heavy friction, momentum transfer for car-pedestrian hits, randomized spin for car-car crashes — and freezes their controls in subsequent ticks. Per-object mass defaults to 1500 kg for cars and 70 kg for pedestrians.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds collision detection in two places — a CARLA collision sensor wrapped as a Scenic-usable
CollisionSensor, and pairwise 2D collision physics in the Newtonian simulator.CARLA:
CarlaCollisionSensorwrappingsensor.other.collision, exported from the world model asCollisionSensor. Trackscollision_history,has_collision, and the most recent event's intensity / impulse, withreset()for between-simulation cleanup.CarlaSimulation.step()learns about event-based sensors: rather than blocking onsensor.frame != current_frame(which never matches for sensors that only fire on events), bump the frame number viaupdateFrame()and skip the wait. Sensors with areset()method are reset on simulation teardown.createObjectInSimulatorso users can writeterminate when ego.sensors['collision'].has_collisionwithout boilerplate.(label, value, color)tuple format; green for none, red for hit + intensity.Newtonian:
_corners2D, resolved with an SAT-derived collision normal. Apply impulse along the normal scaled by mass and restitution, and split penetration depth between the two objects.enable_crash_physics(default on) marks colliding cars and pedestrians ascrashedand applies post-impact dynamics: heavy friction, momentum transfer for car-pedestrian hits, randomized spin for car-car crashes. Per-objectmassdefaults to 1500 kg for cars and 70 kg for pedestrians.Issue Link
N/A
Checklist
pytestand/or other meansAdditional Notes
with sensors {...}, drove the ego forward viaSetThrottleAction(1.0), and confirmedterminate when ego.sensors['collision'].has_collisionfires when the ego rear-ends a stopped vehicle. Collision history populates with frame, other actor type, and impulse intensity.step()actually callshud.tick()andhud.render()— that wiring lives in companion PR CARLA usability fixes (HUD, cleanup, substepping) + Ubuntu/2D defaults #462. Until both land, the line is built but not rendered.