-
Couldn't load subscription status.
- Fork 87
refactor collision sensor #755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a full review yet, but one of my questions could involve some code change if you agree, so let's start with this.
mujoco_warp/_src/types.py
Outdated
| -2 if skipped | ||
| nxn_pairid_filtered: predefined pair id, -1 if not (<= ngeom * (ngeom - 1) // 2,) | ||
| predefined | ||
| nxn_pairid: predefined pair id (<= ngeom * (ngeom - 1) // 2, 3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is starting to get a little tricky to reason about... what if we introduce an enum that's like:
class NxNType(enum.IntEnum):
DEFAULT = 0
SKIP = 1
PAIR = 2
SENSOR = 3Then separately we have an nxn_objid that corresponds to the collision id or sensor id?
If want to keep it as a single array that's fine, but this way it can be a vec2i (type, objid) instead of a vec3i - WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if the proposed enum.IntEnum will work in all cases we need. for example:
- contact pair and distance sensor have the same geoms
- exclude contact and distance sensor have the same geoms
we could enumerate all possibilities, for example adding SKIPSENSOR (this would skip contact but write collision sensor), etc or maybe utilize an enum.IntFlag instead?
i think we probably need three numbers in some form in order to write contacts and write collision sensor data during the narrowphase
- [0]: contact pair id, -1 if no pair id, -2 if contact is excluded/skipped
- [1]: sensor id, -1 if no sensor
[2]: collision sensors have both geom and body semantics. we need some way of organizing geom data by body when we write collision sensor data. the current implementation writes to sensor_collision[worldid, [1], [2]] using the second and third numbers. an alternative approach might be to have a counter and to utilize atomic adds to increment it. another approach might be to have the third number be the body id and then search over sensor_collision for body id matches in the sensor function.
do we think there is an approach that only requires two numbers (ie, type and objid)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we can use IntFlag. Not quite sure why you need to store the bodyid in nxn_pairid - can't you get it fromgeom_bodyid?
|
Can confirm this compiles much much faster and in principle resolves #747. |
|
@erikfrey the pr and pr description are updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK this is lovely and moves the resulting code is easier to understand!
I know you had some concerns that sweeping across all contacts to find just the sensor contacts might be expensive. Did you run any benchmarks?
Assuming you're satisfied with the perf, I think this code looks nice. Just had one nit.
|
benchmarking with adding a distance sensor note: needed to increase to improve performance we can add a kernel launch over contacts that writes to a temporary array. will follow up with new timing results when the updated implementation is ready. |
|
the updated implementation aggregates contact information for collision sensors before writing to
humanoid + distance sensor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, one last nit and let's get it in.
d863769 to
ef9cdc4
Compare
refactor collision sensor to follow @erikfrey's suggestion to utilize the collision driver
augmentsnxn_pairid/nxn_pairid_filtered/collision_pairidwith two new elements [1]: unique collision id corresponding to row in new fieldData.sensor_collision, [2]: unique geom collision id since collision sensors can be specified with body semantics and potentially have multiple geoms that will need to be evaluted and comparedadd fieldsensor_collisiontoData. this field will be computed by the collision driver and_sensor_poswill read from this field and utilize the information to compute values forsensordatanxn_pairid/nxn_pairid_filtered/collision_pairidwith a new element (making the array typewp.vec2i): a unique collision idcorresponding to an element in the new field.Data.collisionadd fieldcollisiontoData. this field is computed by the collision driver and_sensor_poswill read from this field and utilize the information to compute collision sensor values forsensordata. each element in this field is avec7. each element isdistance(1) andfromto(6).ContactTypefor a new bitflag fieldContact.typethat is utilized by constraints and sensors.notes:
sensordata. a TODO has been added for improving performance here by iterating over all contacts once for all of the collision sensorsData.contactandData.naconcan now include and account for contacts that don't contribute to the constraints