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"""
[docs] xyz: List
[docs] rpy: List
@dataclasses.dataclass
[docs] class Inertia: """Inertia class"""
[docs] ixx: npt.ArrayLike
[docs] ixy: npt.ArrayLike
[docs] ixz: npt.ArrayLike
[docs] iyy: npt.ArrayLike
[docs] iyz: npt.ArrayLike
[docs] izz: npt.ArrayLike
@dataclasses.dataclass
[docs] class Limits: """Limits class"""
[docs] lower: npt.ArrayLike
[docs] upper: npt.ArrayLike
[docs] effort: npt.ArrayLike
[docs] velocity: npt.ArrayLike
@dataclasses.dataclass
[docs] class Joint(abc.ABC): """Base Joint class. You need to fill at least these fields"""
[docs] math: SpatialMath
[docs] name: str
[docs] parent: str
[docs] child: str
[docs] type: str
[docs] axis: List
[docs] origin: Pose
[docs] limit: Limits
[docs] idx: int
""" Abstract base class for all joints. """ @abc.abstractmethod
[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 """ pass
@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"""
[docs] mass: npt.ArrayLike
[docs] inertia: Inertia
[docs] origin: Pose
@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 @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 """
[docs] math: SpatialMath
[docs] name: str
@abc.abstractmethod @abc.abstractmethod
[docs] def build_joint(self) -> Joint: """build the single joint Returns: Joint """ pass
@abc.abstractmethod @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