From 8876b3d50e0d05baa388727da82ee1ace88d006b Mon Sep 17 00:00:00 2001 From: Kevin Dean <42547789+AdvancedImagingUTSW@users.noreply.github.com> Date: Fri, 21 Jun 2024 14:43:32 -0500 Subject: [PATCH] Formatting. Needs some work. --- ...mous_robotic_sample_handling_controller.py | 221 +++++++++--------- .../view/frames/move_sequence.py | 2 +- docs/source/user_guide/images/startup.rst | 17 ++ 3 files changed, 129 insertions(+), 111 deletions(-) diff --git a/autonomous_robotic_sample_handling/controller/autonomous_robotic_sample_handling_controller.py b/autonomous_robotic_sample_handling/controller/autonomous_robotic_sample_handling_controller.py index 68cef13..f532ee1 100644 --- a/autonomous_robotic_sample_handling/controller/autonomous_robotic_sample_handling_controller.py +++ b/autonomous_robotic_sample_handling/controller/autonomous_robotic_sample_handling_controller.py @@ -1,70 +1,102 @@ + +# Standard Library Imports +import os + +# Third Party Imports + +# Local Application Imports from navigate.tools.file_functions import load_yaml_file from navigate.config.config import get_navigate_path - from autonomous_robotic_sample_handling.controller.sub_controllers.robot_arm_controller import ( RobotArmController ) - from autonomous_robotic_sample_handling.controller.sub_controllers.multiposition_controller import ( MultipositionController ) - from autonomous_robotic_sample_handling.controller.sub_controllers.motor_controller import ( MotorController ) - from autonomous_robotic_sample_handling.controller.sub_controllers.automation_controller import ( AutomationController ) - from autonomous_robotic_sample_handling.controller.sub_controllers.inhouse_tools_controller import ( InHouseToolsPopupController ) - from autonomous_robotic_sample_handling.view.popups.inhouse_tools_popup import InHouseToolsPopup class AutonomousRoboticSampleHandlingController: + """AutonomousRoboticSampleHandlingController""" def __init__(self, view, parent_controller=None): + """ + Initialize the AutonomousRoboticSampleHandlingController + + Parameters + ---------- + view : object + The view object + parent_controller : object + The parent controller object + """ + #: object: The view object self.view = view + + #: object: The parent controller object self.parent_controller = parent_controller + #: dict: The variables from the view self.variables = self.view.get_variables() - self.buttons = self.view.buttons - self.buttons['automation_sequence'].configure(command=self.automated_sample_handling) - self.buttons['process_sample'].configure(command=self.sample_iteration) - self.buttons['offline_program'].configure(command=self.start_offline_program) - self.buttons['in_house'].configure(command=self.launch_inhouse_tools) + #: dict: The buttons from the view + self.buttons = self.view.buttons + # Configure traces + self.buttons['automation_sequence'].configure( + command=self.automated_sample_handling) + self.buttons['process_sample'].configure( + command=self.sample_iteration) + self.buttons['offline_program'].configure( + command=self.start_offline_program) + self.buttons['in_house'].configure( + command=self.launch_inhouse_tools) + + #: dict: The data from the configuration file self.data = self.load_config_data() self.prepare_config_data(self.data) # Initialize sub-controllers + #: RobotArmController: The robot arm controller self.robot_arm_controller = RobotArmController( self.view, self.parent_controller ) + + #: MultipositionController: The multiposition controller self.multiposition_controller = MultipositionController( self.view, self.parent_controller ) + + #: MotorController: The motor controller self.motor_controller = MotorController( self.view, self.parent_controller ) + + #: AutomationController: The automation controller self.automation_controller = AutomationController( self.view.move_sequence, self.parent_controller ) + + #: InHouseToolsPopupController: The in house tools popup controller self.inhouse_tools_popup_controller = None + #: dict: The key positions + self.key_positions = None + def launch_inhouse_tools(self): """Launches inhouse tools popup. - Will only launch when button in GUI is pressed, and will not duplicate. - Pressing button again brings popup to top - - Examples - -------- - >>> self.launch_inhouse_tools() - """ + Will only launch when button in GUI is pressed, and will not duplicate. + Pressing button again brings popup to the front. + """ if hasattr(self, "inhouse_tools_popup_controller"): self.inhouse_tools_popup_controller.showup() @@ -73,13 +105,12 @@ def launch_inhouse_tools(self): self.inhouse_tools_popup_controller = InHouseToolsPopupController(inhouse_tools, self) def load_config_data(self): - """ + """ Load the configuration data Returns ------- """ - import os plugins_config_path = os.path.join( get_navigate_path(), "config", "plugins_config.yml" ) @@ -90,69 +121,67 @@ def load_config_data(self): return data def start_offline_program(self, program_name="Vertical_Oscillation"): - """ + """ Start the offline program Parameters ---------- - program_name - - Returns - ------- - + program_name: str + The name of the program to start """ self.parent_controller.execute( "start_program", program_name ) def get_microscope_position(self, data): - """ + """ Get the microscope position Parameters ---------- - data + data : dict + The data from the configuration Returns ------- - + list + The list of the positions """ x = data["environment"]["microscope"]["x"] y = data["environment"]["microscope"]["y"] z = data["environment"]["microscope"]["z"] - Rx = data["environment"]["microscope"]["R1"] - Ry = data["environment"]["microscope"]["R2"] - Rz = data["environment"]["microscope"]["R3"] - return [x, y, z, Rx, Ry, Rz] + theta_x = data["environment"]["microscope"]["R1"] + theta_y = data["environment"]["microscope"]["R2"] + theta_z = data["environment"]["microscope"]["R3"] + return [x, y, z, theta_x, theta_y, theta_z] def get_loading_zone_position(self, data): - """ + """ Get the loading zone position Parameters ---------- - data + data : dict + The data from the configuration Returns ------- - + list + The list of the positions """ x = data["environment"]["loading_zone"]["pose"]["x"] y = data["environment"]["loading_zone"]["pose"]["y"] z = data["environment"]["loading_zone"]["pose"]["z"] - Rx = data["environment"]["loading_zone"]["pose"]["Rx"] - Ry = data["environment"]["loading_zone"]["pose"]["Ry"] - Rz = data["environment"]["loading_zone"]["pose"]["Rz"] + theta_x = data["environment"]["loading_zone"]["pose"]["Rx"] + theta_y = data["environment"]["loading_zone"]["pose"]["Ry"] + theta_z = data["environment"]["loading_zone"]["pose"]["Rz"] flag = data["environment"]["loading_zone"]["flag"] - return [x, y, z, Rx, Ry, Rz] if flag else None + return [x, y, z, theta_x, theta_y, theta_z] if flag else None def prepare_config_data(self, data): - """ + """ Prepare the configuration data Parameters ---------- - data - - Returns - ------- - + data : dict + The data from the configuration file. """ motor_position = data["environment"]["motor"]["units"] motor_to_robot_mm = motor_position * 25.4 @@ -171,13 +200,17 @@ def prepare_config_data(self, data): "tolerance_up": data["environment"]["components"]["tolerance_up"], "tolerance_forward": data["environment"]["components"]["tolerance_forward"], } - motor_position_x = data_points["robot_base"] + data_points["wrf_to_trf"][2] - data_points["carousel_height"] - \ - data_points["vial_height"] - data_points['trf_gripper_bottom'] + data_points['tolerance_up'] + motor_position_x = data_points["robot_base"] + data_points[ + "wrf_to_trf"][2] - data_points["carousel_height"] - data_points[ + "vial_height"] - data_points['trf_gripper_bottom'] + data_points[ + 'tolerance_up'] + motor_position_z = motor_to_robot_mm - data_points["vial_attack"] - data_points["wrf_to_trf"][0] - data_points[ 'tolerance_forward'] - data_points["MEPG_thickness"] loading_zone_x = motor_to_robot_mm - data_points['vial_attack'] - data_points['tolerance_forward'] - \ data_points['MEPG_thickness'] + loading_zone_z = data_points['carousel_height'] + data_points['vial_height'] + data_points[ 'trf_gripper_bottom'] - data_points['robot_base'] + data_points["tolerance_up"] @@ -192,31 +225,23 @@ def prepare_config_data(self, data): } def move_robot_arm_to_loading_zone(self): - """ - - Returns - ------- - - """ + """ Move the robot arm to the loading zone""" loading_zone_manual = self.key_positions['loading_zone_manual'] engage_header_distance = self.key_positions['engage_header_distance'] if loading_zone_manual is None: loading_zone = self.key_positions['loading_zone'] x, y, z, Rx, Ry, Rz = loading_zone - self.robot_arm_controller.move_lin(x - engage_header_distance, y, z, Rx, Ry, Rz) + self.robot_arm_controller.move_lin( + x - engage_header_distance, y, z, Rx, Ry, Rz) else: x, y, z, Rx, Ry, Rz = loading_zone_manual - self.robot_arm_controller.move_lin(x - engage_header_distance, y, z, Rx, Ry, Rz) + self.robot_arm_controller.move_lin( + x - engage_header_distance, y, z, Rx, Ry, Rz) self.engage_header() self.remove_header_from_stage() def engage_header(self): - """ - - Returns - ------- - - """ + """ Engage the header. """ self.robot_arm_controller.open_gripper() engage_header_distance = self.key_positions["engage_header_distance"] self.robot_arm_controller.move_lin_rel_trf(0, 0, engage_header_distance, 0, 0, 0) @@ -224,24 +249,15 @@ def engage_header(self): self.robot_arm_controller.close_gripper() def remove_header_from_stage(self): - """ - - Returns - ------- - - """ + """ Remove the header from the stage. """ sample_height = - self.key_positions['sample_height'] - self.robot_arm_controller.move_lin_rel_trf(sample_height, 0, 0, 0, 0, 0) + self.robot_arm_controller.move_lin_rel_trf( + sample_height, 0, 0, 0, 0, 0) self.start_offline_program("Vertical_Oscillation") self.robot_arm_controller.zero_joints() def move_to_microscope(self): - """ - - Returns - ------- - - """ + """ Move to the microscope. """ microscope = self.key_positions['microscope'] x, y, z, Rx, Ry, Rz = microscope microscope_tolerance = 10 @@ -252,44 +268,41 @@ def move_to_microscope(self): self.remove_header_from_microscope(engage_header_distance=engage_header_distance) def engage_microscope(self, microscope_tolerance, engage_header_distance): - """ + """ Engage the microscope Parameters ---------- - microscope_tolerance - engage_header_distance - - Returns - ------- + microscope_tolerance : float + The tolerance for the microscope + engage_header_distance : float + The distance to engage the header """ - self.robot_arm_controller.move_lin_rel_trf(0, 0, engage_header_distance, 0, 0, 0) - self.robot_arm_controller.move_lin_rel_trf(-microscope_tolerance, 0, 0, 0, 0, 0) + self.robot_arm_controller.move_lin_rel_trf( + 0, 0, engage_header_distance, 0, 0, 0) + self.robot_arm_controller.move_lin_rel_trf( + -microscope_tolerance, 0, 0, 0, 0, 0) self.robot_arm_controller.open_gripper() def disengage_microscope(self, engage_header_distance): - """ + """ Disengage the microscope Parameters ---------- - engage_header_distance - - Returns - ------- + engage_header_distance : float + The distance to engage the header """ - self.robot_arm_controller.move_lin_rel_trf(0, 0, -engage_header_distance * 2, 0, 0, 0) + self.robot_arm_controller.move_lin_rel_trf( + 0, 0, -engage_header_distance * 2, 0, 0, 0) def remove_header_from_microscope(self, engage_header_distance): - """ + """ Remove the header from the microscope Parameters ---------- - engage_header_distance - - Returns - ------- - + engage_header_distance : float + The distance to engage the header """ shear_distance = self.key_positions['shear_distance'] z_tolerance = 50 @@ -301,12 +314,8 @@ def remove_header_from_microscope(self, engage_header_distance): self.robot_arm_controller.zero_joints() def return_header_to_carousel(self): - """ - - Returns - ------- + """ Return the header to the carousel. """ - """ loading_zone_manual = self.key_positions['loading_zone_manual'] sample_height = self.key_positions['sample_height'] engage_header_distance = self.key_positions['engage_header_distance'] @@ -331,23 +340,15 @@ def return_header_to_carousel(self): self.robot_arm_controller.move_lin_rel_trf(0, 0, -engage_header_distance, 0, 0, 0) def sample_iteration(self): - """ - - Returns - ------- + """ Sample iteration. """ - """ self.move_robot_arm_to_loading_zone() self.move_to_microscope() self.return_header_to_carousel() def automated_sample_handling(self): - """ + """ Automated sample handling. """ - Returns - ------- - - """ self.automation_controller.reset_automation_variables() num_samples = self.automation_controller.get_num_samples() og_position = 9.15 diff --git a/autonomous_robotic_sample_handling/view/frames/move_sequence.py b/autonomous_robotic_sample_handling/view/frames/move_sequence.py index 1d26b74..c624205 100644 --- a/autonomous_robotic_sample_handling/view/frames/move_sequence.py +++ b/autonomous_robotic_sample_handling/view/frames/move_sequence.py @@ -43,7 +43,7 @@ def __init__(self, settings_tab, *args, **kwargs): "offline_program": ttk.Button(self, text="Start program"), "automation_sequence": ttk.Button(self, text="Start automation sequence"), "process_sample": ttk.Button(self, text="Process a sample"), - "in_house": ttk.Button(self, text="In House Toools"), + "in_house": ttk.Button(self, text="In House Tools"), "import": ttk.Button(self, text="Load Positions from Disk"), } counter = 0 diff --git a/docs/source/user_guide/images/startup.rst b/docs/source/user_guide/images/startup.rst index 3668b84..79b44e5 100644 --- a/docs/source/user_guide/images/startup.rst +++ b/docs/source/user_guide/images/startup.rst @@ -22,3 +22,20 @@ Tuning. Usually done in MecaPortal. manual_tuning.rst... +Process a sample - grabs a sample, moves it to the microscope, releases it, +grabs it, and goes back to the carousel. Does not move the carousel, assumes +it is already in the proper location. + +Start automation sequence - does process a sample in a loop, for the number +of samples specified. + +Start program - Runs an offline program (e.g., one saved in the MecaPortal). +Currently hard-coded to run Vertical_Oscillation. + +Multiposition table - Not implemented. + +Load positions from disk. Pretty pointless without the table, and duplicated. + +The in house tools button throws errors + +