Source code for pyrobotiqgripper.exceptions

"""Custom exceptions for pyRobotiqGripper package."""


[docs] class RobotiqGripperError(Exception): """Base exception for all pyRobotiqGripper errors.""" pass
[docs] class GripperConnectionError(RobotiqGripperError): """Raised when connection to gripper fails or is lost.""" pass
[docs] class GripperNotActivatedError(RobotiqGripperError): """Raised when an action is requested but gripper is not activated."""
[docs] def __init__(self): super().__init__( "Gripper must be activated before requesting an action. " "Call activate() or resetActivate() first." )
[docs] class GripperNotCalibratedError(RobotiqGripperError): """Raised when mm-based operations are used without calibration."""
[docs] def __init__(self): super().__init__( "The gripper must be calibrated before using mm-based positioning. " "Call calibrate(closemm, openmm) first." )
[docs] class GripperTimeoutError(RobotiqGripperError): """Raised when gripper operation exceeds timeout."""
[docs] def __init__(self, operation: str = "Operation", timeout: float = 10): super().__init__( f"{operation} did not complete within {timeout} seconds." )
[docs] class GripperPositionError(RobotiqGripperError): """Raised when an invalid position is requested."""
[docs] def __init__(self, position: int, min_val: int = 0, max_val: int = 255): super().__init__( f"Position {position} is out of range [{min_val}, {max_val}]." )
[docs] class GripperCalibrationError(RobotiqGripperError): """Raised when calibration data is invalid.""" pass
[docs] class GripperCommunicationError(RobotiqGripperError): """Raised when Modbus communication fails.""" pass
[docs] class UnsupportedGripperTypeError(RobotiqGripperError): """Raised when an unsupported gripper type is specified."""
[docs] def __init__(self, gripper_type: str): super().__init__( f"Gripper type '{gripper_type}' is not supported." )