Source code for mpscenes.goals.sub_goal

from dataclasses import dataclass
from typing import List
from abc import abstractmethod

from mpscenes.common.component import MPComponent
from mpscenes.common.errors import MissmatchDimensionError


[docs]@dataclass class SubGoalConfig: """Configuration dataclass for sub goal. This configuration class holds information about the the weight, accuracy required, type and position in the kinematic chain. Parameters: ------------ m: int: Dimension of the sub goal w: float: Weight of the sub goal type: str: Type of the sub goal indices: list: Indices of a forward map to be considered epsilon: float: Required accuracy of the sub goal prime: bool: Flag for primary goal """ weight: float type: str indices: List[int] epsilon: float is_primary_goal: bool
[docs]class SubGoal(MPComponent):
[docs] def check_dimensionality(self): if isinstance(self.position(), str): return if len(self.indices()) != len(self.position()): raise MissmatchDimensionError( "SubGoal: Dimension mismatch between goal and indices" )
[docs] def is_primary_goal(self): return self._config.is_primary_goal
[docs] def epsilon(self): return self._config.epsilon
[docs] def indices(self): return self._config.indices
[docs] def dimension(self): return len(self.indices())
[docs] def weight(self): return self._config.weight
[docs] def type(self): return self._config.type
[docs] def evaluate(self, **kwargs) -> list: return [ self.position(**kwargs), self.velocity(**kwargs), self.acceleration(**kwargs) ]
[docs] @abstractmethod def position(self, **kwargs): pass
[docs] @abstractmethod def velocity(self, **kwargs): pass
[docs] @abstractmethod def acceleration(self, **kwargs): pass
[docs] @abstractmethod def shuffle(self): pass