Module pipettin-piper.piper.plugins.cameras
Functions
def load_plugin(controller: "'Controller'", **kwargs)-
Expand source code
def load_plugin(controller: "Controller", **kwargs): """Instantiate the plugin, which also registers the tools. Plugins are expected to have a function named 'load_plugin' which will instantiate the plugin's class and returning it to the main Commander class. If they fail to load, they must raise a PluginError exception. """ logging.debug(f"load_plugin: loading {plugin_name} plugin.") try: class_instance = ToolHandler(controller) except Exception as e: msg = f"Failed to load with error: {e}" logging.error(msg) raise PluginError(msg) from e return class_instanceInstantiate the plugin, which also registers the tools. Plugins are expected to have a function named 'load_plugin' which will instantiate the plugin's class and returning it to the main Commander class. If they fail to load, they must raise a PluginError exception.
Classes
class ToolHandler (controller: Controller = None)-
Expand source code
class ToolHandler(Plugin): """Generic tool-loading plugin""" def __init__(self, controller: Controller = None): self.controller: Controller = controller self.builder: GcodeBuilder = self.controller.builder self.gcode: GcodePrimitives = self.builder.gcode self.verbose: bool = self.builder.verbose # Dictionary with python 'tool' objects in its values. self.tools = {} # Register the tool loader function. logging.info("Registering tool loader function.") self.builder.register_tool_loader( tool_type=TOOL_TYPE, loader_function=self.load_tool) # Register a handler in the GcodeBuilder for the new action. self.builder.add_action_handler(self.snapshot_cmd, self.parse_snapshot_cmd) # Register a runner for the new action. self.controller.add_action_runner(name=self.snapshot_cmd, function=self.run_snapshot_cmd) # Set status. self._status = True def load_tool(self, tool_data: dict): """Instantiate and save one Tool from a parameter set. This is a tool loader function for GcodeBuilder. """ tool_name = tool_data["name"] logging.info(f"Loading tool '{tool_name}'.") # Check if the tool is already registered locally. if tool_name in self.tools: msg = f"Tool '{tool_name}' is already in the tool handler's list." logging.error(msg) raise DataError(msg) # Load the tool. try: # Instance the tool and save it internally for reference. tool = Camera(tool_data, self.builder) self.tools[tool_name] = tool except Exception as e: msg = f"Failed to initialize tool '{tool_name}' with error: {e}" logging.error(msg) raise CommanderError(msg) from e # Return the tool instance to the gcode builder class. return tool snapshot_cmd = "SNAP" def parse_snapshot_cmd(self, action, i, operation_time=10.0): """Move over a content""" try: # Move over the target content. self.builder.macroGoToTubeXY(action, i) # Extend the operation time. self.controller.machine.update_exec_opts(action, timeout=operation_time, add_timeout=True) except Exception as e: raise ProtocolError(f"{self.snapshot_cmd} failed.") from e async def run_snapshot_cmd(self, action, i, *args, **kwargs): """Take a picture""" # Run the GCODE first, moving over the content. await self.controller.machine.run_actions_protocol( actions=[action], i=i, wait=True, check=True ) # Take the snapshot. for tool, name in self.tools.items(): logging.info(f"Capturing an image with tool '{name}'.") tool.snap_and_save("snapshot.png")Generic tool-loading plugin
Ancestors
Class variables
var snapshot_cmd
Methods
def load_tool(self, tool_data: dict)-
Expand source code
def load_tool(self, tool_data: dict): """Instantiate and save one Tool from a parameter set. This is a tool loader function for GcodeBuilder. """ tool_name = tool_data["name"] logging.info(f"Loading tool '{tool_name}'.") # Check if the tool is already registered locally. if tool_name in self.tools: msg = f"Tool '{tool_name}' is already in the tool handler's list." logging.error(msg) raise DataError(msg) # Load the tool. try: # Instance the tool and save it internally for reference. tool = Camera(tool_data, self.builder) self.tools[tool_name] = tool except Exception as e: msg = f"Failed to initialize tool '{tool_name}' with error: {e}" logging.error(msg) raise CommanderError(msg) from e # Return the tool instance to the gcode builder class. return toolInstantiate and save one Tool from a parameter set. This is a tool loader function for GcodeBuilder.
def parse_snapshot_cmd(self, action, i, operation_time=10.0)-
Expand source code
def parse_snapshot_cmd(self, action, i, operation_time=10.0): """Move over a content""" try: # Move over the target content. self.builder.macroGoToTubeXY(action, i) # Extend the operation time. self.controller.machine.update_exec_opts(action, timeout=operation_time, add_timeout=True) except Exception as e: raise ProtocolError(f"{self.snapshot_cmd} failed.") from eMove over a content
async def run_snapshot_cmd(self, action, i, *args, **kwargs)-
Expand source code
async def run_snapshot_cmd(self, action, i, *args, **kwargs): """Take a picture""" # Run the GCODE first, moving over the content. await self.controller.machine.run_actions_protocol( actions=[action], i=i, wait=True, check=True ) # Take the snapshot. for tool, name in self.tools.items(): logging.info(f"Capturing an image with tool '{name}'.") tool.snap_and_save("snapshot.png")Take a picture
Inherited members