Skip to content

hylo.manip.kinematics

Package: hylo-manip · Core contracts

kinematics

Kinematics from a RobotSpec: each arm's model loaded with MuJoCo (MJCF directly, URDF through MuJoCo's importer), forward kinematics of the TCP in the world, geometric Jacobians and damped-least-squares IK with joint limits.

IKResult dataclass

IKResult(q: ndarray, pos_err: float, rot_err: float, ok: bool)

q instance-attribute

q: ndarray

pos_err instance-attribute

pos_err: float

rot_err instance-attribute

rot_err: float

ok instance-attribute

ok: bool

ArmModel

ArmModel(arm: ArmSpec, model: MjModel, data: MjData)

One arm in its MuJoCo model. Arms loaded from the same file share the model and its data.

name instance-attribute

name = arm.name

jids instance-attribute

jids = np.array(jids)

qadr instance-attribute

qadr = model.jnt_qposadr[self.jids]

hinge instance-attribute

hinge = model.jnt_type[self.jids] == int(mujoco.mjtJoint.mjJNT_HINGE)

ee instance-attribute

ee = mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_BODY, arm.ee_frame)

tcp_in_ee instance-attribute

tcp_in_ee = _mat(arm.hand.tcp_in_ee)

base instance-attribute

base = _mat(arm.base_in_world)

home instance-attribute

home = np.array(arm.home, float)

n instance-attribute

n = len(jids)

finger_adr instance-attribute

finger_adr = np.array([model.jnt_qposadr[j] for j in fj if j >= 0], dtype=int)

finger_range instance-attribute

finger_range = np.array([model.jnt_range[j] for j in fj if j >= 0]).reshape(-1, 2)

set_q

set_q(q) -> None

set_hand

set_hand(cmd) -> None

Finger joints at command cmd. A parallel hand's one value (0 closed .. 1 open) maps to the joint range's lower .. upper end; a dexterous hand's command with one value per finger joint is those joint positions.

forward

forward() -> None

ee_model

ee_model() -> np.ndarray

tcp

tcp() -> np.ndarray

TCP pose in the world after forward().

fk

fk(q) -> np.ndarray

TCP pose (4x4, world) at joint positions q.

jacobian

jacobian(T_tcp: ndarray) -> np.ndarray

(6, n) world Jacobian of the TCP (linear; angular) after forward().

solve

solve(target: ndarray, q0, free: str | None = None, pos_tol: float = 0.0005, rot_tol: float = 0.005, iters: int = 150, damping: float = 0.02, w_rot: float = 0.3) -> IKResult

Damped least squares from q0, clipped to the joint limits.

seeds

seeds(q_now, rng: Generator, n_random: int = 12) -> Iterator[np.ndarray]

ik

ik(target: ndarray, q_now=None, free: str | None = None, rng: Generator | None = None, n_random: int = 12, **kw) -> IKResult

First converged solution over the seeds (current q, home, random), else the smallest residual.

ik_solutions

ik_solutions(target: ndarray, q_now=None, free: str | None = None, rng: Generator | None = None, n_random: int = 12, **kw) -> Iterator[IKResult]

Distinct converged solutions, in seed order (current q, home, random).

Kinematics

Kinematics(spec: RobotSpec)

Every arm of a RobotSpec.

spec instance-attribute

spec = spec

arms instance-attribute

arms: dict[str, ArmModel] = {}

resolve_model_path

resolve_model_path(ref: str) -> str

An absolute path, or a "pkg:///" resource of an installed distribution.

load_model

load_model(ref: str) -> mujoco.MjModel