robometric_frame.safety.base
Base class for robotics policy safety metrics.
Provides common functionality for trajectory validation and distance function calling patterns shared across all safety metrics.
Classes
|
Base class for safety metrics with trajectory validation and distance function calling. |
- class robometric_frame.safety.base.BaseSafetyMetric(distance_fn, **kwargs)[source]
Base class for safety metrics with trajectory validation and distance function calling.
This base class provides common functionality for safety metrics that use user-defined distance functions to evaluate trajectories against environments:
Trajectory validation (shape and dimensionality checks)
Safe calling of user-provided distance functions with error handling
Output validation (type, shape, and non-negativity constraints)
Collision detection based on distance thresholds
Standardized signatures for distance functions
All safety metrics use distance functions as the fundamental building block. Collision information can be derived from distances using threshold-based detection via _detect_collisions().
Subclasses should: 1. Implement metric-specific logic in update() and compute() 2. Call _compute_distances() to get validated distance values 3. Use _detect_collisions() for threshold-based collision detection
- Parameters:
distance_fn (
Callable[[Tensor,Any],Tensor]) –User-defined function that computes distances to obstacles. Signature: distance_fn(trajectory: Tensor, environment: Any) -> Tensor - trajectory: Shape (…, L, D) where L is trajectory length, D is spatial dims - environment: User-defined environment representation (optional) - Returns: Tensor of shape (…, L) with distances to nearest obstacle
at each trajectory point (positive values)
**kwargs (
Any) – Additional keyword arguments passed to the base Metric class.
- Raises:
TypeError – If distance_fn is not callable.