Kinematics¶
Kinematics backend of Pinker.
This module implements the kinematics functions used by Pinker:
models built from URDF (revolute, continuous, prismatic, planar, floating and fixed joints);
forward kinematics, frame placements, frame and joint Jacobians in world, local and local-world-aligned frames;
Lie-group operations on SE(3) and configuration spaces;
center of mass and its Jacobian.
Heavy computations are delegated to an internal C extension. Functions were implemented based on their homonyms in Pinocchio v4.1.0 as a reference. Their outputs are cross-validated against Pinocchio by the test suite in tests/kinematics.
Model and data¶
Robot model and data.
A Model describes the kinematic tree of a robot: joints, frames,
inertias and limits. A Data holds the buffers written by the
kinematics algorithms (joint and frame placements, Jacobians).
- class pinker.kinematics.model.Data(model=None)¶
Buffers written by the kinematics algorithms.
- J¶
Full model Jacobian (6 x nv), world frame, filled by compute_joint_jacobians.
- Jcom¶
Center-of-mass Jacobian (3 x nv).
- com¶
List whose first element is the robot’s center of mass.
- mass¶
List whose first element is the robot’s total mass.
- copy()¶
Copy of this data with its own buffers.
- Return type:
- Returns:
New data with the same values in freshly allocated buffers.
- property oMf: _SE3View¶
Frame placements in the world frame.
- Returns:
List-like view of the frame placements.
- property oMi: _SE3View¶
Joint placements in the world frame.
- Returns:
List-like view of the joint placements.
- class pinker.kinematics.model.Frame(name, parent_joint, parent_frame, placement, type)¶
Coordinate frame attached to a joint of the kinematic tree.
- name¶
Name of the frame.
- parent_joint¶
Index of the joint supporting the frame.
- parent_frame¶
Index of the previous frame in the tree.
- placement¶
Pose of the frame in the support joint frame.
- type¶
Frame type.
- class pinker.kinematics.model.FrameType(*values)¶
Frame types, with the same values.
- class pinker.kinematics.model.Model¶
Kinematic model of a robot.
Joints are indexed by joint id, the first one being the universe; limits are indexed by configuration or tangent coordinate.
- effort_limit¶
Maximum effort of each tangent coordinate.
- frames¶
Frames of the model, indexed by frame id.
- inertias¶
Inertia of the body attached to each joint, in the frame of that joint.
- joint_placements¶
Placement of each joint in the frame of its parent joint.
- joints¶
Joint models of the kinematic tree.
- lower_position_limit¶
Lower bound of each configuration coordinate.
- name¶
Name of the robot model.
- names¶
Name of each joint.
- nq¶
Dimension of the configuration vector.
- nv¶
Dimension of the tangent vector.
- parents¶
Index of the parent joint of each joint.
- supports¶
Indexes of the joints supporting each joint, from the universe down to that joint.
- upper_position_limit¶
Upper bound of each configuration coordinate.
- velocity_limit¶
Maximum velocity of each tangent coordinate.
- add_body_frame(name, parent_joint, placement=None, previous_frame=-1)¶
Add a BODY type frame to the model.
- Parameters:
name (
str) – Name of the new frame.parent_joint (
int) – Index of the joint supporting the frame.placement (
Optional[SE3]) – Pose of the frame in the support joint frame, defaulting to the identity.previous_frame (
int) – Index of the previous frame in the tree. A negative value denotes the universe frame.
- Return type:
- Returns:
Index of the new frame.
- add_frame(frame)¶
Add a frame to the model.
- add_joint(parent_id, joint_model, placement, name, max_effort=None, max_velocity=None, min_config=None, max_config=None)¶
Add a joint to the kinematic tree.
- Parameters:
parent_id (
int) – Index of the parent joint.joint_model (
JointModel) – Joint model, e.g. fromJointModelRZ().placement (
SE3) – Pose of the joint frame in the parent joint frame.name (
str) – Name of the new joint.max_effort (
Optional[ndarray]) – Maximum joint efforts (default: unbounded).max_velocity (
Optional[ndarray]) – Maximum joint velocities (default: unbounded).min_config (
Optional[ndarray]) – Lower configuration limits (default: unbounded).max_config (
Optional[ndarray]) – Upper configuration limits (default: unbounded).
- Return type:
- Returns:
Index of the new joint.
- add_joint_frame(joint_id, previous_frame=-1)¶
Add a JOINT type frame coinciding with a joint of the model.
- append_body_to_joint(joint_id, inertia, placement=None)¶
Append body inertia to a joint of the model.
- create_data()¶
Create a data buffer matching this model.
- Return type:
- Returns:
New data for this model.
- exist_frame(name)¶
Check whether a frame name exists in the model.
- exist_joint_name(name)¶
Check whether a joint name exists in the model.
- get_frame_id(name)¶
Index of the frame with a given name.
- Parameters:
name (
str) – Name of the frame to look up.- Return type:
- Returns:
Index of the frame.
- Raises:
ValueError – If the model has no frame with this name. Pinocchio returns
nframesin that case; we raise so that all Model getters behave the same way.
- get_joint_id(name)¶
Index of the joint with a given name.
- Parameters:
name (
str) – Name of the joint to look up.- Return type:
- Returns:
Index of the joint.
- Raises:
ValueError – If the model has no joint with this name. Pinocchio returns
njointsin that case; we raise so that all Model getters behave the same way.
- get_joint_tangent_id(name)¶
Index of a joint in the tangent vector.
- Parameters:
name (
str) – Name of the joint to look up.- Return type:
- Returns:
Index of the first tangent coordinate of the joint, so that its coordinates are
v[idx_v:idx_v + joint.nv].- Raises:
ValueError – If the model has no joint with this name.
- get_root_joint_dim()¶
Count configuration and tangent dimensions of the root joint.
- has_configuration_limit()¶
Boolean array flagging configuration coordinates with limits.
- Return type:
- Returns:
One boolean per configuration coordinate, True if that coordinate has a position limit.
- class pinker.kinematics.model.ReferenceFrame(*values)¶
Reference frame for velocities and Jacobians.
Joints¶
Joint models.
Joint type identifiers match the enumeration in the C extension. Quantities per joint type (configuration and tangent dimensions, neutral configuration) follow Pinocchio’s conventions:
Revolute and prismatic joints have one configuration variable.
Unbounded (continuous) revolute joints store (cos, sin) of their angle.
Spherical joints store a unit quaternion (x, y, z, w).
Planar joints store (x, y, cos, sin).
Free-flyer joints store (x, y, z, qx, qy, qz, qw).
Note that quaternions are stored with their vector part coming first.
- class pinker.kinematics.joints.JointModel(jtype, axis=None)¶
Description of a joint, before or after it is added to a model.
Index attributes are set when the joint is added to a model, and are -1 until then.
- axis¶
Joint axis, for revolute and prismatic joints, None otherwise.
- id¶
Index of the joint in the model it belongs to.
- idx_q¶
Index of the joint in the configuration vector, so that its coordinates are
q[idx_q:idx_q + nq].
- idx_v¶
Index of the joint in the tangent vector, so that its coordinates are
v[idx_v:idx_v + nv].
- jtype¶
Joint type identifier.
- property nq: int¶
Number of configuration variables.
- Returns:
Dimension of the configuration segment of the joint.
- pinker.kinematics.joints.JointModelFreeFlyer()¶
Free-flyer joint: full 6-DoF rigid motion.
Its configuration segment is (x, y, z, qx, qy, qz, qw): the position of the joint followed by its unit quaternion, vector part first, so that the neutral configuration of the joint is (0, 0, 0, 0, 0, 0, 1).
- Return type:
- Returns:
Corresponding joint model.
- pinker.kinematics.joints.JointModelPX()¶
Prismatic joint along the x-axis.
- Return type:
- Returns:
Corresponding joint model.
- pinker.kinematics.joints.JointModelPY()¶
Prismatic joint along the y-axis.
- Return type:
- Returns:
Corresponding joint model.
- pinker.kinematics.joints.JointModelPZ()¶
Prismatic joint along the z-axis.
- Return type:
- Returns:
Corresponding joint model.
- pinker.kinematics.joints.JointModelPlanar()¶
Planar joint: translation in the xy-plane, rotation about z.
- Return type:
- Returns:
Corresponding joint model.
- pinker.kinematics.joints.JointModelPrismaticUnaligned(x=1.0, y=0.0, z=0.0)¶
Prismatic joint along an arbitrary axis.
- Parameters:
x – First coordinate of the joint axis.
y – Second coordinate of the joint axis.
z – Third coordinate of the joint axis.
- Return type:
- Returns:
Corresponding joint model.
- pinker.kinematics.joints.JointModelRX()¶
Revolute joint about the x-axis.
- Return type:
- Returns:
Corresponding joint model.
- pinker.kinematics.joints.JointModelRY()¶
Revolute joint about the y-axis.
- Return type:
- Returns:
Corresponding joint model.
- pinker.kinematics.joints.JointModelRZ()¶
Revolute joint about the z-axis.
- Return type:
- Returns:
Corresponding joint model.
- pinker.kinematics.joints.JointModelRevoluteUnaligned(x=1.0, y=0.0, z=0.0)¶
Revolute joint about an arbitrary axis.
- Parameters:
x – First coordinate of the joint axis.
y – Second coordinate of the joint axis.
z – Third coordinate of the joint axis.
- Return type:
- Returns:
Corresponding joint model.
- pinker.kinematics.joints.JointModelSpherical()¶
Ball joint, parameterized by a unit quaternion.
Its configuration segment is the unit quaternion (x, y, z, w), vector part first, so that the neutral configuration of the joint is (0, 0, 0, 1).
- Return type:
- Returns:
Corresponding joint model.
- pinker.kinematics.joints.joint_has_configuration_limit(jtype)¶
Which configuration variables of a joint have position limits.
Algorithms¶
Kinematics algorithms.
Configuration vectors are laid out per joint as described in
pinker.kinematics.joints. Functions take configuration and tangent
vectors as array-likes (which they copy into contiguous float64 arrays) and
return NumPy arrays.
- pinker.kinematics.algorithms.Jlog6(M)¶
Jacobian of the SE3 logarithm at a rigid transform.
- pinker.kinematics.algorithms.center_of_mass(model, data, q=None)¶
Center of mass of the robot, in the world frame.
- Parameters:
- Return type:
- Returns:
Position of the center of mass in the world frame.
- pinker.kinematics.algorithms.compute_joint_jacobians(model, data, q=None)¶
Compute joint placements and the full model Jacobian.
As in Pinocchio, the full Jacobian
data.Jhas one column per tangent coordinate, expressed in the world frame.
- pinker.kinematics.algorithms.custom_configuration(model, **kwargs)¶
Generate a configuration vector where named joints have given values.
- Parameters:
model (
Model) – Robot model.kwargs – Custom values for joint coordinates.
- Return type:
- Returns:
Configuration vector where named joints have the values specified in keyword arguments, and other joints have their neutral value.
- Raises:
ValueError – If a joint value does not have the dimension of the corresponding joint.
- pinker.kinematics.algorithms.d_difference(model, q0, q1, arg=0)¶
Jacobian of the difference with respect to one of its arguments.
- pinker.kinematics.algorithms.difference(model, q0, q1)¶
Tangent-space difference going from q0 to q1.
- pinker.kinematics.algorithms.exp3(w)¶
Exponential map of a rotation vector.
- Parameters:
w (numpy.typing.ArrayLike) – Rotation vector, whose norm is the rotation angle.
- Return type:
- Returns:
Corresponding rotation matrix.
- pinker.kinematics.algorithms.exp6(nu)¶
Exponential map of a twist.
- pinker.kinematics.algorithms.forward_kinematics(model, data, q)¶
Compute joint placements for a configuration.
- pinker.kinematics.algorithms.frames_forward_kinematics(model, data, q)¶
Compute joint and frame placements for a configuration.
- pinker.kinematics.algorithms.get_frame_jacobian(model, data, frame_id, reference_frame=ReferenceFrame.LOCAL)¶
Jacobian of a frame, extracted from the full model Jacobian.
Requires
compute_joint_jacobiansandupdate_frame_placementsto have been called on the data beforehand.- Parameters:
model (
Model) – Robot model.data (
Data) – Data of the model, with up-to-date Jacobian and placements.frame_id (
int) – Index of the frame inmodel.frames.reference_frame (
ReferenceFrame) – Frame in which the Jacobian is expressed.
- Return type:
- Returns:
Jacobian of the frame, of shape (6, nv).
- pinker.kinematics.algorithms.get_joint_jacobian(model, data, joint_id, reference_frame=ReferenceFrame.LOCAL)¶
Jacobian of a joint, extracted from the full model Jacobian.
- Parameters:
model (
Model) – Robot model.data (
Data) – Data of the model, with an up-to-date Jacobian.joint_id (
int) – Index of the joint inmodel.joints.reference_frame (
ReferenceFrame) – Frame in which the Jacobian is expressed.
- Return type:
- Returns:
Jacobian of the joint, of shape (6, nv).
- pinker.kinematics.algorithms.integrate(model, q, v)¶
Integrate a tangent-space displacement from a configuration.
- pinker.kinematics.algorithms.jacobian_center_of_mass(model, data, q=None)¶
Jacobian of the center of mass (3 x nv), in the world frame.
- Parameters:
- Return type:
- Returns:
Center-of-mass Jacobian
data.Jcom, of shape (3, nv).
- pinker.kinematics.algorithms.log3(R)¶
Logarithm map of a rotation matrix.
- Parameters:
R (numpy.typing.ArrayLike) – Rotation matrix.
- Return type:
- Returns:
Rotation vector, whose norm is the rotation angle.
- pinker.kinematics.algorithms.log6(M)¶
Logarithm map of a rigid transform.
- pinker.kinematics.algorithms.neutral(model)¶
Neutral configuration of a model.
Spatial algebra¶
Conversions between representations of rotations.
Quaternions are laid out as (x, y, z, w), vector part first, as in
configuration vectors. The one exception is quaternion_wxyz(),
named after the scalar-first order that Viser expects.
- pinker.kinematics.so3.quaternion_to_matrix(quat)¶
Rotation matrix of a unit quaternion.
- Parameters:
quat (numpy.typing.ArrayLike) – Unit quaternion, as (x, y, z, w) with its vector part first, the way quaternions are laid out in configuration vectors.
- Return type:
- Returns:
Corresponding rotation matrix.
- pinker.kinematics.so3.quaternion_wxyz(R)¶
Quaternion (w, x, y, z) of a rotation matrix, by Shepperd’s method.
- pinker.kinematics.so3.rpy_to_matrix(roll, pitch, yaw)¶
Rotation matrix from roll-pitch-yaw angles (extrinsic x-y-z).
- pinker.kinematics.so3.skew(v)¶
Skew-symmetric matrix of a 3D vector.
- Parameters:
v (numpy.typing.ArrayLike) – Three-dimensional vector.
- Return type:
- Returns:
Matrix such that multiplying it by a vector w yields the cross product of v and w.
Rigid transforms, spatial vectors and inertias.
- class pinker.kinematics.se3.Inertia(mass=0.0, lever=None, inertia=None)¶
Spatial inertia: mass, center of mass and rotational inertia.
- classmethod FromBox(mass, x, y, z)¶
Inertia of a box of a given mass and dimensions.
- classmethod Zero()¶
Zero inertia.
- Return type:
- Returns:
Inertia with zero mass, lever and rotational inertia.
- class pinker.kinematics.se3.Motion(vector)¶
Spatial velocity (linear, angular).
- asarray()¶
Convert to a NumPy array as a 6-dimensional vector.
Note that this is not a copy: the returned array is directly the stored representation of the motion vector, and writing to it updates the motion directly. Copy it (or call
numpy.array()) if that is not what you want.- Return type:
- Returns:
Spatial velocity as a vector of size 6.
- class pinker.kinematics.se3.SE3(rotation=None, translation=None)¶
Rigid transform, represented by a rotation matrix and a translation.
- classmethod Identity()¶
Identity transform.
- Return type:
- Returns:
Transform with identity rotation and zero translation.
- classmethod Interpolate(A, B, alpha)¶
Interpolate between two transforms.
- classmethod Random()¶
Random transform, with translation in the unit cube.
- Return type:
- Returns:
Transform with a random rotation and a random translation.
- act(other)¶
Compose with a transform, or apply to a point.
- act_inv(other)¶
Compose the inverse with a transform, or apply it to a point.
- property action: ndarray¶
Adjoint 6x6 matrix, mapping (linear, angular) twists.
- Returns:
Adjoint matrix of the transform.
- property action_inverse: ndarray¶
Adjoint 6x6 matrix of the inverse transform.
- Returns:
Adjoint matrix of the inverse transform.
- copy()¶
Copy of this transform with its own memory.
- Return type:
- Returns:
New transform with the same value in freshly allocated arrays.
- property homogeneous: ndarray¶
Homogeneous 4x4 matrix of the transform.
- Returns:
Homogeneous matrix of the transform.
- is_approx(other, prec=1e-12)¶
Check if two transforms are approximately equal.
Loading models¶
Build a model from a URDF file.
The conventions (joint ordering, frame ordering, default limits) follow Pinocchio’s URDF parser so that models built by pinker.kinematics match those built by Pinocchio joint by joint and frame by frame:
Joints are added by depth-first traversal of the kinematic tree, with child joints visited in alphabetical order of joint name.
Each movable joint adds a JOINT frame and a BODY frame for its child link. Fixed joints add a FIXED_JOINT frame and a BODY frame attached to the nearest movable ancestor joint, and their child link’s inertia is merged into that joint.
Continuous joints have their (cos, sin) configuration bounded by 1.01, like free-flyer and planar quaternion/cosine-sine coordinates.
- pinker.kinematics.urdf.build_geom_from_urdf(model, filename, package_dirs=None)¶
Parse the visual geometries of a URDF file.
- pinker.kinematics.urdf.build_model_from_urdf(filename, root_joint=None)¶
Build a model from a URDF file.
- Parameters:
filename (
str) – Path to the URDF file.root_joint (
Optional[JointModel]) – Optional joint model connecting the root link to the world.
- Return type:
- Returns:
Robot model.
- pinker.kinematics.urdf.build_model_from_xml(xml_string, root_joint=None)¶
Build a model from a URDF string.
- Parameters:
xml_string (
str) – URDF description of the robot.root_joint (
Optional[JointModel]) – Optional joint model connecting the root link to the world, e.g.JointModelFreeFlyer()for mobile robots.
- Return type:
- Returns:
Robot model.
Convenience wrapper bundling a model with its data.
- class pinker.kinematics.robot_wrapper.RobotWrapper(model, visual_model=None)¶
Robot model with its data and neutral configuration.
- model¶
Robot model.
- data¶
Data buffers for the model.
- q0¶
Neutral configuration.
- visual_model¶
Geometry model with the robot’s visuals, when built from URDF.
- static BuildFromURDF(filename, package_dirs=None, root_joint=None)¶
Build a robot wrapper from a URDF file.
- Parameters:
- Return type:
- Returns:
Robot wrapper.
Geometry¶
Visual geometry attached to a robot model.
Each geometry object carries a primitive shape (box, sphere, cylinder) or a mesh file path, together with its placement in the frame of its parent joint.
- class pinker.kinematics.geometry.GeometryModel¶
Collection of geometry objects attached to a robot model.
- add_geometry_object(geometry_object)¶
Add a geometry object to the model.
- Parameters:
geometry_object (
GeometryObject) – Geometry object to add.- Return type:
- Returns:
Index of the new geometry object in the model.
- class pinker.kinematics.geometry.GeometryObject(name, parent_joint, placement, shape, size=None, mesh_path='', mesh_scale=None, mesh_color=None)¶
One displayable shape, attached to a joint of the model.
- name¶
Name of the geometry object, unique in its geometry model.
- parent_joint¶
Index of the supporting joint.
- placement¶
Pose of the shape in the parent joint frame.
- shape¶
One of “box”, “sphere”, “cylinder” or “mesh”.
- size¶
Shape parameters: full extents (3,) for a box, (radius,) for a sphere, (radius, length) for a cylinder, unused for a mesh.
- mesh_path¶
Path to the mesh file, for mesh shapes.
- mesh_scale¶
Scale applied to the mesh (3,).
- mesh_color¶
RGBA color in [0, 1].