35 """Collision checking"""
43 LIBAMINOCL = ctypes.CDLL(
"libamino-collision.so")
46 class RxClSet(ctypes.Structure):
47 """Opaque type for struct aa_rx_cl_set."""
50 """Set of frame pairs indicating collision between frames."""
52 __slots__ = [
"_ptr",
"scenegraph"]
54 def __init__(self, scenegraph):
56 self.
_ptr_ptr = LIBAMINOCL.aa_rx_cl_set_create(self.
scenegraphscenegraph._ptr)
59 LIBAMINOCL.aa_rx_cl_set_destroy(self.
_ptr_ptr)
62 """Returns the value for the frame pair indicated by key.
65 key: A tuple of two frame names or ids.
68 IndexError: Invalid frame name or ID.
71 i = self.
scenegraphscenegraph.ensure_frame_id_actual(i)
72 j = self.
scenegraphscenegraph.ensure_frame_id_actual(j)
73 v = LIBAMINOCL.aa_rx_cl_set_get(self.
_ptr_ptr, i, j)
77 """Sets the value for the frame pair indicated by key.
80 key: A tuple of two frame names or ids.
84 IndexError: Invalid frame ID.
87 i = self.
scenegraphscenegraph.ensure_frame_id_actual(i)
88 j = self.
scenegraphscenegraph.ensure_frame_id_actual(j)
90 LIBAMINOCL.aa_rx_cl_set_set(self.
_ptr_ptr, i, j, v)
93 """Sets all entries to False."""
94 LIBAMINOCL.aa_rx_cl_set_clear(self.
_ptr_ptr)
97 """Fills self with all true entries in other."""
98 LIBAMINOCL.aa_rx_cl_set_fill(self.
_ptr_ptr, src._ptr)
101 LIBAMINOCL.aa_rx_cl_set_create.argtypes = [ctypes.POINTER(RxSg)]
102 LIBAMINOCL.aa_rx_cl_set_create.restype = ctypes.POINTER(RxClSet)
104 LIBAMINOCL.aa_rx_cl_set_destroy.argtypes = [ctypes.POINTER(RxClSet)]
106 LIBAMINOCL.aa_rx_cl_set_get.argtypes = [
107 ctypes.POINTER(RxClSet), ctypes.c_int, ctypes.c_int
109 LIBAMINOCL.aa_rx_cl_set_get.restypes = ctypes.c_int
111 LIBAMINOCL.aa_rx_cl_set_set.argtypes = [
112 ctypes.POINTER(RxClSet), ctypes.c_int, ctypes.c_int, ctypes.c_int
115 LIBAMINOCL.aa_rx_cl_set_clear.argtypes = [ctypes.POINTER(RxClSet)]
117 LIBAMINOCL.aa_rx_cl_set_fill.argtypes = [
118 ctypes.POINTER(RxClSet), ctypes.POINTER(RxClSet)
122 class RxCl(ctypes.Structure):
123 """Opaque type for struct aa_rx_cl."""
125 class SceneCollision:
126 """Context object for collision detection."""
128 __slots__ = [
"_ptr",
"scenegraph"]
130 def __init__(self, scenegraph):
132 LIBAMINOCL.aa_rx_sg_cl_init(self.
scenegraphscenegraph._ptr)
133 self.
_ptr_ptr = LIBAMINOCL.aa_rx_cl_create(self.
scenegraphscenegraph._ptr)
136 LIBAMINOCL.aa_rx_cl_destroy(self.
_ptr_ptr)
138 def allow(self, i, j):
139 """Allows collisions between frames i and j."""
140 i = self.
scenegraphscenegraph.ensure_frame_id_actual(i)
141 j = self.
scenegraphscenegraph.ensure_frame_id_actual(j)
142 LIBAMINOCL.aa_rx_cl_allow(self.
_ptr_ptr, i, j, 1)
145 """Allows collisions between all frames in the collision set."""
146 LIBAMINOCL.aa_rx_cl_allow_set(self.
_ptr_ptr, collision_set._ptr)
149 """Allows collisions between all frames coliding at config."""
153 self.
checkcheck(fk, cl_set)
156 def check(self, scene_fk, collision_set=None):
157 """Checks for collisions and optionally outputs colliding frames.
160 fk: A SceneFK updated with the configuration to check.
161 collision_set: If not None, a SceneCollisionSet that will
162 be filled with all detected, non-allowed collisions.
165 True if collisions are detected and False otherwise.
170 collision_set.clear()
171 cl_set_ptr = collision_set._ptr
172 r = LIBAMINOCL.aa_rx_cl_check(self.
_ptr_ptr, len(scene_fk),
173 scene_fk._data_ptr(),
174 scene_fk._data_ld(), cl_set_ptr)
178 """Creates a SceneCollisionSet."""
182 """Creates a SceneCollisionDist."""
186 LIBAMINOCL.aa_rx_sg_cl_init.argtypes = [ctypes.POINTER(RxSg)]
189 LIBAMINOCL.aa_rx_cl_create.argtypes = [ctypes.POINTER(RxSg)]
190 LIBAMINOCL.aa_rx_cl_create.restype = ctypes.POINTER(RxCl)
192 LIBAMINOCL.aa_rx_cl_destroy.argtypes = [ctypes.POINTER(RxCl)]
194 LIBAMINOCL.aa_rx_cl_allow.argtypes = [
195 ctypes.POINTER(RxCl), ctypes.c_int, ctypes.c_int, ctypes.c_int
198 LIBAMINOCL.aa_rx_cl_allow_set.argtypes = [
199 ctypes.POINTER(RxCl), ctypes.POINTER(RxClSet)
202 LIBAMINOCL.aa_rx_cl_check.argtypes = [
203 ctypes.POINTER(RxCl), ctypes.c_size_t,
204 ctypes.POINTER(ctypes.c_double), ctypes.c_size_t,
205 ctypes.POINTER(RxClSet)
207 LIBAMINOCL.aa_rx_cl_check.restypes = ctypes.c_int
211 """Opaque type for struct aa_rx_cl_dist."""
214 LIBAMINOCL.aa_rx_cl_dist_create.argtypes = [ctypes.POINTER(RxCl)]
215 LIBAMINOCL.aa_rx_cl_dist_create.restype = ctypes.POINTER(RxClDist)
217 LIBAMINOCL.aa_rx_cl_dist_destroy.argtypes = [ctypes.POINTER(RxClDist)]
219 LIBAMINOCL.aa_rx_cl_dist_check.argtypes = [
220 ctypes.POINTER(RxClDist), ctypes.POINTER(RxFK)
222 LIBAMINOCL.aa_rx_cl_dist_check.restype = ctypes.c_int
224 LIBAMINOCL.aa_rx_cl_dist_get_dist.argtypes = [
225 ctypes.POINTER(RxClDist), ctypes.c_int, ctypes.c_int
227 LIBAMINOCL.aa_rx_cl_dist_get_dist.restype = ctypes.c_double
229 LIBAMINOCL.aa_rx_cl_dist_get_points.argtypes = [
230 ctypes.POINTER(RxClDist), ctypes.c_int, ctypes.c_int,
231 ctypes.POINTER(Vec3),
234 LIBAMINOCL.aa_rx_cl_dist_get_points.restype = ctypes.c_double
237 class SceneCollisionDist:
238 """Context object for separation distances."""
241 """Descriptor for distance access."""
242 __slots__ = [
"_cl_dist"]
244 def __init__(self, cl_dist):
248 """Returns the separation distance for the frames.
251 key: a pair of frame names or ids
254 i = self.
_cl_dist_cl_dist._cl.scenegraph.ensure_frame_id_actual(i)
255 j = self.
_cl_dist_cl_dist._cl.scenegraph.ensure_frame_id_actual(j)
256 return LIBAMINOCL.aa_rx_cl_dist_get_dist(self.
_cl_dist_cl_dist._ptr, i, j)
259 """Descriptor for point access."""
260 __slots__ = [
"_cl_dist"]
262 def __init__(self, cl_dist):
266 """Returns a tuple (distance, point0, point1) for the frames.
269 key: a pair of frame names or ids
272 i = self.
_cl_dist_cl_dist._cl.scenegraph.ensure_frame_id_actual(i)
273 j = self.
_cl_dist_cl_dist._cl.scenegraph.ensure_frame_id_actual(j)
276 dist = LIBAMINOCL.aa_rx_cl_dist_get_points(self.
_cl_dist_cl_dist._ptr, i,
278 return (dist, p_i, p_j)
280 __slots__ = [
"_ptr",
"_cl",
"_dist",
"_points"]
282 def __init__(self, cl):
284 self._ptr = LIBAMINOCL.aa_rx_cl_dist_create(cl._ptr)
285 self._dist = self.DistDesc(self)
286 self._points = self.PointsDesc(self)
289 LIBAMINOCL.aa_rx_cl_dist_destroy(self._ptr)
291 def check(self, scene_fk):
292 """Checks for collision distances from the given forward kinematics."""
293 LIBAMINOCL.aa_rx_cl_dist_check(self.
_ptr_ptr, scene_fk._ptr)
297 """The DistDesc descriptor."""
298 return self.
_dist_dist
302 """The PointsDesc descriptor."""
305 LIBAMINOCL.aa_rx_sg_cl_init.argtypes = [ctypes.POINTER(RxSg)]
Opaque type for struct aa_rx_cl_dist.
Opaque type for struct aa_rx_cl.
Descriptor for distance access.
def __getitem__(self, key)
Returns the separation distance for the frames.
Descriptor for point access.
def __getitem__(self, key)
Returns a tuple (distance, point0, point1) for the frames.
Context object for separation distances.
def check(self, scene_fk)
Checks for collision distances from the given forward kinematics.
def dist(self)
The DistDesc descriptor.
def points(self)
The PointsDesc descriptor.
def __getitem__(self, key)
Returns the value for the frame pair indicated by key.
def clear(self)
Sets all entries to False.
def __setitem__(self, key, item)
Sets the value for the frame pair indicated by key.
def fill(self, src)
Fills self with all true entries in other.
def allow_config(self, config)
Allows collisions between all frames coliding at config.
def collision_dist(self)
Creates a SceneCollisionDist.
def check(self, scene_fk, collision_set=None)
Checks for collisions and optionally outputs colliding frames.
def collision_set(self)
Creates a SceneCollisionSet.
def allow_set(self, collision_set)
Allows collisions between all frames in the collision set.
def allow(self, i, j)
Allows collisions between frames i and j.