35 """Forward, differential, and inverse kinematics."""
48 class RxFK(ctypes.Structure):
49 """Opaque type for fk result pointer"""
52 """Forward Kinematics."""
53 __slots__ = [
'_ptr',
'_q',
'scenegraph']
55 def __init__(self, scenegraph):
57 self.
_ptr_ptr = libamino.aa_rx_fk_malloc(scenegraph._ptr)
58 self.
_q_q =
DVec(scenegraph.config_count)
61 libamino.aa_rx_fk_destroy(self.
_ptr_ptr)
67 key: a frame name/id or pair of frame names/ids.
70 if isinstance(key, tuple):
72 parent = self.
scenegraphscenegraph.ensure_frame_id(parent)
73 child = self.
scenegraphscenegraph.ensure_frame_id(child)
74 libamino.aa_rx_fk_get_rel_qutr(self.
_ptr_ptr, parent, child, E)
76 key = self.
scenegraphscenegraph.ensure_frame_id(key)
77 libamino.aa_rx_fk_get_abs_qutr(self.
_ptr_ptr, key, E)
82 """The current configuration."""
87 self.
scenegraphscenegraph.config_vector(config, self.
_q_q)
88 libamino.aa_rx_fk_all(self.
_ptr_ptr, self.
_q_q)
92 """Number of frames."""
93 return libamino.aa_rx_fk_cnt(self.
_ptr_ptr)
96 """Return pointer to data."""
97 return libamino.aa_rx_fk_data(self.
_ptr_ptr)
100 """Return leading dimension of data."""
101 return libamino.aa_rx_fk_ld(self.
_ptr_ptr)
104 libamino.aa_rx_fk_malloc.argtypes = [ctypes.POINTER(RxSg)]
105 libamino.aa_rx_fk_malloc.restype = ctypes.POINTER(RxFK)
107 libamino.aa_rx_fk_destroy.argtypes = [ctypes.POINTER(RxFK)]
109 libamino.aa_rx_fk_all.argtypes = [ctypes.POINTER(RxFK), ctypes.POINTER(DVec)]
111 libamino.aa_rx_fk_get_abs_qutr.argtypes = [
112 ctypes.POINTER(RxFK), ctypes.c_int,
113 ctypes.POINTER(QuatTrans)
116 libamino.aa_rx_fk_get_rel_qutr.argtypes = [
117 ctypes.POINTER(RxFK), ctypes.c_int, ctypes.c_int,
118 ctypes.POINTER(QuatTrans)
121 libamino.aa_rx_fk_data.argtypes = [ctypes.POINTER(RxFK)]
122 libamino.aa_rx_fk_data.restype = ctypes.POINTER(ctypes.c_double)
124 libamino.aa_rx_fk_ld.argtypes = [ctypes.POINTER(RxFK)]
125 libamino.aa_rx_fk_ld.restype = ctypes.c_size_t
127 libamino.aa_rx_fk_cnt.argtypes = [ctypes.POINTER(RxFK)]
128 libamino.aa_rx_fk_cnt.restype = ctypes.c_size_t
136 """Opaque type for workspace options result pointer"""
139 """Differential Kinematics"""
150 def __init__(self, sub_scenegraph, scene_fk):
151 self.
ssgssg = sub_scenegraph
153 self.
optsopts = libamino.aa_rx_wk_opts_create()
160 libamino.aa_rx_wk_opts_destroy(self.
optsopts)
164 """Reference pose."""
173 """Reference pose velocity."""
184 """Reference configuration."""
188 @ref_config_all.setter
190 """Reference configuration."""
191 sg = self.
ssgssg.scenegraph
192 self.
_config_ref_config_ref = sg.copy_config(value)
195 """Solve for velocity.
198 sub-scenegraph configuration velocity or None if no solution.
201 raise Exception(
"No reference provided.")
204 dq =
DVec(self.
ssgssg.config_count)
216 tf_act = self.
fkfk[self.
ssgssg.end_effector_id]
217 libamino.aa_rx_wk_dx_pos(self.
optsopts, tf_act, self.
_tf_ref_tf_ref, dx)
222 r = libamino.aa_rx_wk_dx2dq(self.
ssgssg._ptr, self.
optsopts, self.
fkfk._ptr, dx,
225 return dq
if r == 0
else None
228 libamino.aa_rx_wk_opts_create.argtypes = []
229 libamino.aa_rx_wk_opts_create.restype = ctypes.POINTER(RxWkOpts)
230 libamino.aa_rx_wk_opts_destroy.argtypes = [ctypes.POINTER(RxWkOpts)]
232 libamino.aa_rx_wk_dx2dq.argtypes = [
233 ctypes.POINTER(RxSgSub),
234 ctypes.POINTER(RxWkOpts),
235 ctypes.POINTER(RxFK),
236 ctypes.POINTER(DVec),
239 libamino.aa_rx_wk_dx2dq.restype = ctypes.c_int
241 libamino.aa_rx_wk_dx_pos.argtypes = [
242 ctypes.POINTER(RxWkOpts),
243 ctypes.POINTER(QuatTrans),
244 ctypes.POINTER(QuatTrans),
253 class RxIK(ctypes.Structure):
254 """Opaque type for inverse kinematics context"""
256 class RxIKParm(ctypes.Structure):
257 """Opaque type for inverse kinematics parameters"""
260 """Inverse Kinematics"""
261 __slots__ = [
"_ptr",
"ik_parm",
"ssg",
"_tf_ref"]
263 def __init__(self, sub_scenegraph):
264 self.
ssgssg = sub_scenegraph
266 self.
ik_parmik_parm = libamino.aa_rx_ik_parm_create()
267 self.
_ptr_ptr = libamino.aa_rx_ik_cx_create(self.
ssgssg._ptr, self.
ik_parmik_parm)
270 libamino.aa_rx_ik_cx_destroy(self.
_ptr_ptr)
271 libamino.aa_rx_ik_parm_destroy(self.
ik_parmik_parm)
275 """Reference transformation"""
280 """Set the reference transformation"""
284 """Sets the optimization seed."""
285 q = self.
ssgssg.config_vector(config_sub)
286 libamino.aa_rx_ik_set_seed(self.
_ptr_ptr, q)
289 """Sets the optimization seed to the joint center position."""
290 libamino.aa_rx_ik_set_seed_center(self.
_ptr_ptr)
293 """Sets the optimization seed to a random position."""
294 libamino.aa_rx_ik_set_seed_rand(self.
_ptr_ptr)
297 """Sets the objective function for optimization."""
298 libamino.aa_rx_ik_parm_set_obj(self.
ik_parmik_parm, fun)
301 """Sets the angle error tolerance"""
302 libamino.aa_rx_ik_parm_set_tol_angle(self.
ik_parmik_parm, angle)
305 """Sets the translational error tolerance"""
306 libamino.aa_rx_ik_parm_set_tol_trans(self.
ik_parmik_parm, trans)
310 """Maximum time limit for IK restarts."""
311 return libamino.aa_rx_ik_get_restart_time(self.
_ptr_ptr)
315 libamino.aa_rx_ik_set_restart_time(self.
_ptr_ptr, t)
319 Solves the IK problem.
322 The sub-scenegraph configuration vector or None if no solution.
324 if self.
_tf_ref_tf_ref
is None:
325 raise Exception(
"No reference provided.")
328 M.col_vec(0).copy_from(self.
_tf_ref_tf_ref)
330 q =
DVec(self.
ssgssg.config_count)
332 r = libamino.aa_rx_ik_solve(self.
_ptr_ptr, M, q)
334 return q
if r == 0
else None
337 libamino.aa_rx_ik_parm_create.argtypes = []
338 libamino.aa_rx_ik_parm_create.restype = ctypes.POINTER(RxIKParm)
339 libamino.aa_rx_ik_parm_destroy.argtypes = [ctypes.POINTER(RxIKParm)]
341 libamino.aa_rx_ik_cx_create.argtypes = [
342 ctypes.POINTER(RxSgSub), ctypes.POINTER(RxIKParm)
344 libamino.aa_rx_ik_cx_create.restype = ctypes.POINTER(RxIK)
345 libamino.aa_rx_ik_cx_destroy.argtypes = [ctypes.POINTER(RxIK)]
347 libamino.aa_rx_ik_solve.argtypes = [
348 ctypes.POINTER(RxIK),
349 ctypes.POINTER(DMat),
352 libamino.aa_rx_ik_solve.restype = ctypes.c_int
354 libamino.aa_rx_ik_set_seed.argtypes = [
355 ctypes.POINTER(RxIK), ctypes.POINTER(DVec)
357 libamino.aa_rx_ik_set_seed_center.argtypes = [ctypes.POINTER(RxIK)]
358 libamino.aa_rx_ik_set_seed_rand.argtypes = [ctypes.POINTER(RxIK)]
360 libamino.aa_rx_ik_set_restart_time.argtypes = [
361 ctypes.POINTER(RxIK), ctypes.c_double
364 libamino.aa_rx_ik_parm_set_tol_angle.argtypes = [ctypes.POINTER(RxIKParm), ctypes.c_double]
365 libamino.aa_rx_ik_parm_set_tol_trans.argtypes = [ctypes.POINTER(RxIKParm), ctypes.c_double]
366 libamino.aa_rx_ik_get_restart_time.argtypes = [ctypes.POINTER(RxIK)]
367 libamino.aa_rx_ik_get_restart_time.restype = ctypes.c_double
Differential Kinematics ##.
def ref_tf(self)
Reference pose.
def solve_vel(self, dq=None)
Solve for velocity.
def ref_config_all(self)
Reference configuration.
def ref_tf_vel(self)
Reference pose velocity.
def __len__(self)
Number of frames.
def config(self)
The current configuration.
def __getitem__(self, key)
Get a transform.
def solve(self)
Solves the IK problem.
def ref_tf(self)
Reference transformation.
def set_obj(self, fun)
Sets the objective function for optimization.
def set_seed_center(self)
Sets the optimization seed to the joint center position.
def restart_time(self)
Maximum time limit for IK restarts.
def set_seed_rand(self)
Sets the optimization seed to a random position.
def set_tol_angle(self, angle)
Sets the angle error tolerance.
def set_seed(self, config_sub)
Sets the optimization seed.
def set_tol_trans(self, trans)
Sets the translational error tolerance.
Class for Quaternion-Translation.