Source code for concepts.dm.crowhat.robots.robot_interfaces

#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# File   : robot_interfaces.py
# Author : Jiayuan Mao
# Email  : maojiayuan@gmail.com
# Date   : 03/30/2024
#
# This file is part of Project Concepts.
# Distributed under terms of the MIT license.

from typing import Any, Dict
from concepts.dm.crow.interfaces.controller_interface import CrowControllerExecutionError

__all__ = [
    'RobotControllerExecutionFailed', 'RobotControllerExecutionContext', 'RobotArmJointTrajectory',
    'RobotControllerInterfaceBase',
    'PrimitiveRobotControllerInterface', 'ContactPrimitiveRobotControlInterface'
]


[docs] class RobotControllerExecutionFailed(CrowControllerExecutionError): pass
[docs] class RobotControllerExecutionContext(object):
[docs] def __init__(self, controller_name, *args, **kwargs): self.controller_name = controller_name self.args = args self.kwargs = kwargs
def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): return False
[docs] def monitor(self, rv: bool): if not rv: raise RobotControllerExecutionFailed(f"Execution of {self.controller_name} failed. Args: {self.args}, kwargs: {self.kwargs}")
[docs] class RobotArmJointTrajectory(list): pass
[docs] class RobotControllerInterfaceBase(object):
[docs] def __init__(self): self._default_parameters = dict()
@property def default_parameters(self) -> Dict[str, Dict[str, Any]]: """Get the default parameters for each primitive.""" return self._default_parameters
[docs] def set_default_parameters(self, primitive: str, **kwargs): """Set the default parameters for a specific primitive.""" if primitive not in self._default_parameters: self._default_parameters[primitive] = dict() self._default_parameters[primitive].update(kwargs)
[docs] def get_update_default_parameters(self, primitive: str, kwargs_: Dict[str, Any]) -> None: """Update the default parameters for a specific primitive.""" if primitive not in self._default_parameters: return kwargs_.update(self._default_parameters[primitive])
[docs] class PrimitiveRobotControllerInterface(RobotControllerInterfaceBase): """The most primitive-level robot control interface. For example, typically, it provides interfaces for controlling the robot joints by - joint position control - end-effector impedance control - torque control """
[docs] class ContactPrimitiveRobotControlInterface(RobotControllerInterfaceBase): """The contact-aware primitive-level robot control interface. It abstracts over the primitive joint-level control interfaces and provides additional interfaces for controlling how the robot end-effector makes contact with a single object. - grasping - pushing - placing """