MCPcopy Create free account
hub / github.com/Simple-Robotics/Simple / addSystemCollisionPairs

Function addSystemCollisionPairs

tests/python/test_simulator_instance.py:245–281  ·  view source on GitHub ↗

Add the right collision pairs of a model, given qref. qref is here as a `T-pose`. The function uses this pose to determine which objects are in collision in this ref pose. If objects are in collision, they are not added as collision pairs, as they are considered to always be in coll

(model, geom_model, qref)

Source from the content-addressed store, hash-verified

243
244
245def addSystemCollisionPairs(model, geom_model, qref):
246 """
247 Add the right collision pairs of a model, given qref.
248 qref is here as a `T-pose`. The function uses this pose to determine which objects are in collision
249 in this ref pose. If objects are in collision, they are not added as collision pairs, as they are considered
250 to always be in collision.
251 """
252 data = model.createData()
253 geom_data = geom_model.createData()
254 pin.updateGeometryPlacements(model, data, geom_model, geom_data, qref)
255 geom_model.removeAllCollisionPairs()
256 num_col_pairs = 0
257 for i in range(len(geom_model.geometryObjects)):
258 for j in range(i + 1, len(geom_model.geometryObjects)):
259 # Don't add collision pair if same object
260 if i != j:
261 gobj_i: pin.GeometryObject = geom_model.geometryObjects[i]
262 gobj_j: pin.GeometryObject = geom_model.geometryObjects[j]
263 if gobj_i.name == "floor" or gobj_j.name == "floor":
264 num_col_pairs += 1
265 col_pair = pin.CollisionPair(i, j)
266 geom_model.addCollisionPair(col_pair)
267 else:
268 if gobj_i.parentJoint != gobj_j.parentJoint:
269 # Compute collision between the geometries. Only add the collision pair if there is no collision.
270 M1 = geom_data.oMg[i]
271 M2 = geom_data.oMg[j]
272 colreq = CollisionRequest()
273 colreq.security_margin = 1e-2 # 1cm of clearance
274 colres = CollisionResult()
275 collide(
276 gobj_i.geometry, M1, gobj_j.geometry, M2, colreq, colres
277 )
278 if not colres.isCollision():
279 num_col_pairs += 1
280 col_pair = pin.CollisionPair(i, j)
281 geom_model.addCollisionPair(col_pair)
282
283
284def addFloor(geom_model: pin.GeometryModel):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected