Source code for adam.model.abc_factories
import abc
import dataclasses
from typing import List
import numpy.typing as npt
from adam.core.spatial_math import SpatialMath
@dataclasses.dataclass
[docs]
class Pose:
"""Pose class"""
@dataclasses.dataclass
[docs]
class Inertia:
"""Inertia class"""
@dataclasses.dataclass
[docs]
class Limits:
"""Limits class"""
[docs]
velocity: npt.ArrayLike
@dataclasses.dataclass
[docs]
class Joint(abc.ABC):
"""Base Joint class. You need to fill at least these fields"""
"""
Abstract base class for all joints.
"""
@abc.abstractmethod
@abc.abstractmethod
[docs]
def motion_subspace(self) -> npt.ArrayLike:
"""
Returns:
npt.ArrayLike: motion subspace of the joint
"""
@abc.abstractmethod
[docs]
def homogeneous(self, q: npt.ArrayLike) -> npt.ArrayLike:
"""
Args:
q (npt.ArrayLike): joint value
Returns:
npt.ArrayLike: homogeneous transform given the joint value
"""
pass
@dataclasses.dataclass
[docs]
class Inertial:
"""Inertial description"""
@staticmethod
[docs]
def zero() -> "Inertial":
"""Returns an Inertial object with zero mass and inertia"""
return Inertial(
mass=0.0,
inertia=Inertia(
ixx=0.0,
ixy=0.0,
ixz=0.0,
iyy=0.0,
iyz=0.0,
izz=0.0,
),
origin=Pose(xyz=[0.0, 0.0, 0.0], rpy=[0.0, 0.0, 0.0]),
)
[docs]
def set_mass(self, mass: npt.ArrayLike) -> "Inertial":
"""Set the mass of the inertial object"""
self.mass = mass
[docs]
def set_inertia(self, inertia: Inertia) -> "Inertial":
"""Set the inertia of the inertial object"""
self.inertia = inertia
[docs]
def set_origin(self, origin: Pose) -> "Inertial":
"""Set the origin of the inertial object"""
self.origin = origin
@dataclasses.dataclass
[docs]
class Link(abc.ABC):
"""Base Link class. You need to fill at least these fields"""
@abc.abstractmethod
[docs]
def spatial_inertia(self) -> npt.ArrayLike:
"""
Returns:
npt.ArrayLike: the 6x6 inertia matrix expressed at
the origin of the link (with rotation)
"""
pass
@abc.abstractmethod
[docs]
def homogeneous(self) -> npt.ArrayLike:
"""
Returns:
npt.ArrayLike: the homogeneous transform of the link
"""
pass
@dataclasses.dataclass
[docs]
class ModelFactory(abc.ABC):
"""The abstract class of the model factory.
The model factory is responsible for creating the model.
You need to implement all the methods in your concrete implementation
"""
@abc.abstractmethod
[docs]
def build_link(self) -> Link:
"""build the single link
Returns:
Link
"""
pass
@abc.abstractmethod
[docs]
def build_joint(self) -> Joint:
"""build the single joint
Returns:
Joint
"""
pass
@abc.abstractmethod
[docs]
def get_links(self) -> List[Link]:
"""
Returns:
List[Link]: the list of the link
"""
pass
@abc.abstractmethod
[docs]
def get_frames(self) -> List[Link]:
"""
Returns:
List[Link]: the list of the frames
"""
pass
@abc.abstractmethod
[docs]
def get_joints(self) -> List[Joint]:
"""
Returns:
List[Joint]: the list of the joints
"""
pass