def test_abstract_robot() -> None: check_object_type(AbstractRobot) assert AbstractRobot.abstract() assert inspect.signature( AbstractRobot.move_to_joints) == inspect.signature( Robot.move_to_joints)
def test_dobot_m1() -> None: check_object_type(DobotM1) assert not DobotM1.abstract() assert inspect.signature( DobotM1.set_hand_teaching_mode) == inspect.signature( Robot.set_hand_teaching_mode)
def upload_def(type_def: Type[Generic], model: Optional[Models] = None, urdf: Optional[Urdf] = None) -> None: if not issubclass(type_def, GenericWithPose) and model: raise UploadException("Object without pose can't have collision model.") try: check_object_type(type_def) except Arcor2Exception as e: print(e) raise UploadException(f"There is something wrong with source code of '{type_def.__name__}'.") obj_type = ObjectType( id=type_def.__name__, source=get_containing_module_sources(type_def), description=type_def.description() ) if model: obj_type.model = model.metamodel() ps.put_model(model) print(f"Storing '{obj_type.id}'...") ps.update_object_type(obj_type) if urdf: if not os.path.isdir(urdf.path_to_directory): print(f"{urdf.path_to_directory} is not a directory.") return print(f"Storing URDF package for '{obj_type.id}'.") paths: List[str] = [] # full path is in form src/python/arcor2_fit_demo/data/dobot-m1/dobot_m1_description/meshes # so we need to remove the prefix (e.g. src/python/arcor2_fit_demo/data/dobot-m1) # let's find the prefix... for root, _, files in os.walk(urdf.path_to_directory): for filename in files: paths.append(os.path.join(root, filename)) prefix = os.path.commonpath(paths) mem_zip = BytesIO() with zipfile.ZipFile(mem_zip, mode="w", compression=zipfile.ZIP_DEFLATED) as zf: for root, _, files in os.walk(urdf.path_to_directory): for filename in files: path = os.path.join(root, filename) # in the archive, the path will be without the prefix zf.write(path, os.path.relpath(path, prefix)) mem_zip.seek(0) ps.upload_mesh_file(urdf.archive_name, mem_zip.getvalue())
def test_object_type() -> None: check_object_type(GenericWithPose) assert GenericWithPose.abstract()
def test_object_type() -> None: check_object_type(Interaction) assert not Interaction.abstract()
def test_object_type() -> None: check_object_type(Generic) assert Generic.abstract()
def test_object_type() -> None: check_object_type(Ict) assert not Ict.abstract()
def upload_def( type_def: type[Generic], model: Optional[Models] = None, urdf: Optional[Urdf] = None, file_to_upload: Optional[str] = None, ) -> None: """Uploads ObjectType definition to the Project service. :param type_def: Class definition. :param model: Collision model. :param urdf: If the type is robot, path to its URDF can be given here. :param file_to_upload: Path to a file. Used e.g. to upload a mesh together with the ObjectType. :return: """ if not issubclass(type_def, Robot) and urdf: raise UploadException("Parameter 'urdf' set for non-Robot.") try: check_object_type(type_def) except Arcor2Exception as e: raise UploadException( f"{type_def.__name__} is not a valid ObjectType. {str(e)}") obj_type = ObjectType(id=type_def.__name__, source=get_containing_module_sources(type_def), description=type_def.description()) if issubclass(type_def, CollisionObject): if not model: raise UploadException( "Parameter 'model' must be set for CollisionObject.") if model.id != obj_type.id: raise UploadException( "Model id have to be the same as ObjectType id.") obj_type.model = model.metamodel() if isinstance(model, Mesh): if not type_def.mesh_filename: raise UploadException("Mesh filename not set.") if not file_to_upload: raise UploadException( "For mesh collision model, file_to_upload parameter have to be set." ) try: with open(file_to_upload, "rb") as f: ps.upload_file(type_def.mesh_filename, f.read()) except OSError as e: raise UploadException(f"Failed to read mesh file. {str(e)}") ps.put_model(model) else: if model: raise UploadException( "Parameter 'model' set for non-CollisionObject.") print(f"Storing '{obj_type.id}'...") ps.update_object_type(obj_type) if urdf: if not os.path.isdir(urdf.path_to_directory): print(f"{urdf.path_to_directory} is not a directory.") return print(f"Storing URDF package for '{obj_type.id}'.") paths: list[str] = [] # full path is in form src/python/arcor2_fit_demo/data/dobot-m1/dobot_m1_description/meshes # so we need to remove the prefix (e.g. src/python/arcor2_fit_demo/data/dobot-m1) # let's find the prefix... for root, _, files in os.walk(urdf.path_to_directory): for filename in files: paths.append(os.path.join(root, filename)) prefix = os.path.commonpath(paths) mem_zip = BytesIO() with zipfile.ZipFile(mem_zip, mode="w", compression=zipfile.ZIP_DEFLATED) as zf: for root, _, files in os.walk(urdf.path_to_directory): for filename in files: path = os.path.join(root, filename) # in the archive, the path will be without the prefix zf.write(path, os.path.relpath(path, prefix)) mem_zip.seek(0) ps.upload_file(urdf.archive_name, mem_zip.getvalue())
def test_object_type() -> None: check_object_type(Robot) assert Robot.abstract()
def test_object_type() -> None: check_object_type(Statistic) assert not Statistic.abstract()
def test_logic_actions() -> None: check_object_type(LogicActions) assert not LogicActions.abstract()
def test_time_actions() -> None: check_object_type(TimeActions) assert not TimeActions.abstract()
def test_object_type() -> None: check_object_type(Search) assert not Search.abstract()
def test_object_type() -> None: check_object_type(AbstractWithPose) assert AbstractWithPose.abstract()
def test_abstract() -> None: check_object_type(YuMi) assert not YuMi.abstract()
def test_object_type() -> None: check_object_type(Aubo) assert not Aubo.abstract()
def test_abstract_dobot() -> None: check_object_type(AbstractDobot) assert AbstractDobot.abstract()
def test_dobot_magician() -> None: check_object_type(DobotMagician) assert not DobotMagician.abstract()
def test_random_actions() -> None: check_object_type(RandomActions)
def test_abstract_simple() -> None: check_object_type(AbstractSimple) assert AbstractSimple.abstract()
def test_object_type() -> None: check_object_type(Barcode) assert not Barcode.abstract()