from dataclasses import dataclass
from typing import List, Optional
import numpy as np
from omegaconf import OmegaConf
from mpscenes.obstacles.collision_obstacle import CollisionObstacle, CollisionObstacleConfig, GeometryConfig
from mpscenes.common.errors import NoDistanceFunctionForURDFObstacle, DimensionNotSuitableForEnv
[docs]@dataclass
class UrdfGeometryConfig(GeometryConfig):
pass
[docs]@dataclass
class UrdfObstacleConfig:
"""Configuration dataclass for sphere obstacle.
This configuration class holds information about the position, size
and randomization of a spherical obstacle.
Parameters:
------------
urdf : str : Filename of the urdf
geometry : GeometryConfig : Geometry of the obstacle
low: GeometryConfig : Lower limit for randomization
high: GeometryConfig : Upper limit for randomization
"""
urdf: str
type: str
geometry: UrdfGeometryConfig
scaling: float = 1
movable: bool = False
low: Optional[UrdfGeometryConfig] = None
high: Optional[UrdfGeometryConfig] = None
[docs]class UrdfObstacle(CollisionObstacle):
def __init__(self, **kwargs):
if not 'schema' in kwargs:
schema = OmegaConf.structured(UrdfObstacleConfig)
kwargs['schema'] = schema
super().__init__(**kwargs)
self.check_completeness()
[docs] def size(self):
return []
[docs] def urdf(self):
return self._config.urdf
[docs] def position(self):
return self._config.geometry.position
[docs] def velocity(self):
return np.zeros(3)
[docs] def acceleration(self):
return np.zeros(3)
[docs] def dimension(self):
return len(self._config.geometry.position)
[docs] def distance(self, position: np.ndarray) -> None:
raise NoDistanceFunctionForURDFObstacle("Cannot compute distance for urdf-obstacle.")