Source code for adam.model.std_factories.std_joint

from typing import Union

import numpy.typing as npt
import urdf_parser_py.urdf

from adam.core.spatial_math import SpatialMath
from adam.model import Joint


[docs] class StdJoint(Joint): """Standard Joint class""" def __init__( self, joint: urdf_parser_py.urdf.Joint, math: SpatialMath, idx: Union[int, None] = None, ) -> None:
[docs] self.math = math
[docs] self.name = joint.name
[docs] self.parent = joint.parent
[docs] self.child = joint.child
[docs] self.type = joint.joint_type
[docs] self.axis = joint.axis
[docs] self.origin = joint.origin
[docs] self.limit = joint.limit
[docs] self.idx = idx
[docs] def homogeneous(self, q: npt.ArrayLike) -> npt.ArrayLike: """ Args: q (npt.ArrayLike): joint value Returns: npt.ArrayLike: the homogenous transform of a joint, given q """ if self.type == "fixed": xyz = self.origin.xyz rpy = self.origin.rpy return self.math.H_from_Pos_RPY(xyz, rpy) elif self.type in ["revolute", "continuous"]: return self.math.H_revolute_joint( self.origin.xyz, self.origin.rpy, self.axis, q, ) elif self.type in ["prismatic"]: return self.math.H_prismatic_joint( self.origin.xyz, self.origin.rpy, self.axis, q, )
[docs] def spatial_transform(self, q: npt.ArrayLike) -> npt.ArrayLike: """ Args: q (npt.ArrayLike): joint motion Returns: npt.ArrayLike: spatial transform of the joint given q """ if self.type == "fixed": return self.math.X_fixed_joint(self.origin.xyz, self.origin.rpy) elif self.type in ["revolute", "continuous"]: return self.math.X_revolute_joint( self.origin.xyz, self.origin.rpy, self.axis, q ) elif self.type in ["prismatic"]: return self.math.X_prismatic_joint( self.origin.xyz, self.origin.rpy, self.axis, q, )
[docs] def motion_subspace(self) -> npt.ArrayLike: """ Args: joint (Joint): Joint Returns: npt.ArrayLike: motion subspace of the joint """ if self.type == "fixed": return self.math.vertcat(0, 0, 0, 0, 0, 0) elif self.type in ["revolute", "continuous"]: return self.math.vertcat( 0, 0, 0, self.axis[0], self.axis[1], self.axis[2], ) elif self.type in ["prismatic"]: return self.math.vertcat( self.axis[0], self.axis[1], self.axis[2], 0, 0, 0, )