skbot.transform¶
Manage n-dimensional coordinate transformations via directed graphs.
skbot.transform
allows you to change the representation of a vector from one
coordinate system to another, i.e., it transforms the basis of the vector.
Contrary to similar libraries, this is not limited to 3D or affine
transformations, but can transform in N dimensions and between different
dimensions, too. Additionally, you can create chains - more precisely directed
graphs - of transformations between different frames, which allows you to
express quite complicated transformations.
If you come from a robotics background, this module is analogous to ROS tf2, but works in (and between) n-dimensions. This means it naturally includes projections, e.g. world space to pixel space, and it allows you to use more esoteric transformations like spherical coordinates, too.
Examples¶
>>> import skbot.transform as tf
>>> import numpy as np
Forward kinematics on a 1 DoF robot arm in 2D
>>> # setup of the arm
>>> link = tf.Translation((1, 0))
>>> joint = tf.Rotation((1, 0), (0, 1))
>>> tool_frame = tf.Frame(2)
>>> joint_frame = link(tool_frame)
>>> world = joint(joint_frame)
>>> joint.angle = 0
>>> # FK of initial position
>>> tool_pos = tool_frame.transform((0, 0), to_frame=world)
>>> assert np.allclose(tool_pos, (1, 0))
>>> # Set new joint angle and compute new FK
>>> joint.angle = np.pi / 2
>>> tool_pos = tool_frame.transform((0, 0), to_frame=world)
>>> assert np.allclose(tool_pos, (0, 1))
Base Elements¶
|
Representation of a coordinate system. |
|
A directional relationship between two Frames |
Available Transformations¶
nD Links
|
Transform to affine space |
|
Translation in N-D. |
|
Planar rotation in N-D. |
|
Perspective projection in N-D. |
3D Links
|
Rotation based on Euler angles in 3D. |
|
Rotation based on Quaternions in 3D. |
|
Rotation based on rotation vector in 3D. |
|
Frustum based intrinsic camera transformation. |
|
Rotation with constraints in 3D. |
|
Translation with constraints in N-D. |
2D Links
|
Rotation in 2D. |
|
Rotation with constraints in 2D. |
|
Conversion to Axial Hexagon Coordininates in 2D |
|
Round Hexagon Axis Coordinates in 2D. |
Other Links
|
A link representing a custom transformation. |
|
A link representing a sequence of other links |
|
Inverse of an existing Link. |
Joints¶
Joints are a special subclass of links. On top of normal links, they are bounded, i.e. they have
an upper_limit
and a lower_limit
, and their value can be accessed by the common name param
.
For example:
import skbot.transform as tf
import numpy as np
joint = tf.AngleJoint()
assert joint.param == joint.angle
assert joint.lower_limit == 0
assert joint.upper_limit == 2 * np.pi
# setting param affects the angle
joint.param = np.pi
assert joint.angle == np.pi
Available Joints
|
Rotation with constraints in 3D. |
|
Translation with constraints in N-D. |
|
Rotation with constraints in 2D. |
Custom Joints
You can create your own joints by inheriting from tf.Link
(to make the class a link) and from tf.Joint
(to
mark the class as a joint):
class CustomJoint(tf.Link, tf.Joint):
...
# Make sure to implement the required properties:
# param, lower_limit, upper_limit
# and to implement a setter for param
Functions¶
|
Simplify a transformation sequence. |