Utilities
Utility functions for working with EmbodiK. Includes pose error computation, quaternion conversions, and SE3 creation.
Pose Error
compute_pose_error
Compute 6D pose error (goal - current) using native :func:log3.
Optimized to work directly with SE3 objects without wrapping when possible. Extracts rotation/translation once to minimize Python binding overhead.
Source code in python/embodik/utils.py
get_pose_error_vector
Pose-error helper function.
Uses Pinocchio's log3 for rotation error computation.
Supports both PoseData objects and Pinocchio SE3 objects.
Source code in python/embodik/utils.py
Quaternion Conversions (spatialmath-python compatible)
r2q
Convert rotation matrix to quaternion (spatialmath-python compatible).
Uses native embodiK/Pinocchio conversion (no SciPy dependency).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rotation
|
ndarray
|
3x3 rotation matrix |
required |
order
|
str
|
Quaternion order, 'sxyz' (default, [w,x,y,z]) or 'xyzs' ([x,y,z,w]) |
'sxyz'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Quaternion as numpy array: |
ndarray
|
|
ndarray
|
|
Examples:
>>> R = np.eye(3)
>>> q = r2q(R) # Returns [1, 0, 0, 0] (wxyz format)
>>> q = r2q(R, order='xyzs') # Returns [0, 0, 0, 1] (xyzw format)
Source code in python/embodik/utils.py
q2r
Convert quaternion to rotation matrix (spatialmath-python compatible).
Uses native embodiK/Pinocchio conversion (no SciPy dependency).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quaternion
|
ndarray
|
Quaternion as array |
required |
order
|
str
|
Quaternion order, 'sxyz' (default, [w,x,y,z]) or 'xyzs' ([x,y,z,w]) |
'sxyz'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
3x3 rotation matrix |
Examples:
>>> q = np.array([1, 0, 0, 0]) # Identity quaternion (wxyz)
>>> R = q2r(q) # Returns 3x3 identity matrix
>>> q = np.array([0, 0, 0, 1]) # Identity quaternion (xyzw)
>>> R = q2r(q, order='xyzs') # Returns 3x3 identity matrix
Source code in python/embodik/utils.py
SE3 Creation
Rt
Create SE3 transform from rotation matrix and translation (spatialmath-python compatible).
Equivalent to spatialmath-python's SE3.Rt(R, t).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
R
|
Optional[ndarray]
|
3x3 rotation matrix (default: identity) |
None
|
t
|
Optional[ndarray]
|
3D translation vector (default: zero) |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
SE3 transform |
Examples:
>>> R = np.eye(3)
>>> t = np.array([1, 2, 3])
>>> T = Rt(R=R, t=t) # Create SE3 from R and t
>>> T = Rt(t=t) # Create SE3 with identity rotation
>>> T = Rt(R=R) # Create SE3 with zero translation
>>> T = Rt() # Create identity transform
Source code in python/embodik/utils.py
Example
import embodik
import numpy as np
# Compute pose error between two SE3 transforms
pose_current = embodik.Rt(R=np.eye(3), t=[0, 0, 0])
pose_target = embodik.Rt(R=np.eye(3), t=[0.1, 0.2, 0.3])
error = embodik.compute_pose_error(pose_current, pose_target)
# error[:3] = translation error, error[3:] = rotation error (axis-angle)
# Quaternion conversions (native, no SciPy)
R = np.eye(3)
q_wxyz = embodik.r2q(R, order='sxyz') # [1, 0, 0, 0]
q_xyzw = embodik.r2q(R, order='xyzs') # [0, 0, 0, 1]
R_back = embodik.q2r(q_wxyz, order='sxyz')
# Create SE3
T = embodik.Rt(R=np.eye(3), t=[1, 2, 3])