Source code for genericroboticarm.robo_APIs.dummy_robot
"""
An exemplary implementation of a robotic arm.
It can change its simulated location in 3d space and print logging messages.
This serves as a demo on how to implement an interface to a real robotic arm
"""
import logging
import time
from pathlib import Path
from typing import List, Tuple
from .robo_interface import RoboInterface
from ..control.graph_manager import JointState
from datetime import datetime
[docs]
class DummyRobot(RoboInterface):
# load and store the position graph in the in-repo package `graphs` directory
# (genericroboticarm/graphs) so the Dummy graph stays version controlled
graph_dir: Path | None = Path(__file__).resolve().parent.parent / "graphs"
[docs]
@classmethod
def get_used_cli_args(cls) -> dict[str, str]:
return {}
[docs]
@classmethod
def get_name(cls) -> str:
return "Dummy"
def __init__(self):
super().__init__(start_simulating=False)
self.pos = {name: 0 for name in self.joint_names}
self.init_connection()
[docs]
def init_connection(self):
logging.info(f"{datetime.now()}: Initializing connection to hardware")
@property
def joint_names(self) -> list[str]:
return ["x", "y", "z"]
[docs]
def move_relative(self, movements: List[Tuple[str, float]], **kwargs):
for joint, diff in movements:
self.pos[joint] += diff
logging.info(f"{datetime.now()}: Moved to {self.pos}")
[docs]
def grip_close(self):
#logging.info("Closing Gripper")
print(f"{datetime.now()}: Closing Gripper")
[docs]
def grip_open(self):
#logging.info("Opening Gripper")
print(f"{datetime.now()}: Opening Gripper")
[docs]
def move_to_coordinates(self, coords: JointState, **kwargs) -> None:
time.sleep(1)
self.pos = coords
@property
def current_coordinates(self) -> JointState:
return self.pos.copy()