diff --git a/alab_control/SEM_autoprep/Positions/disks_tray_clean.csv b/alab_control/SEM_autoprep/Positions/disks_tray_clean.csv new file mode 100644 index 0000000..f124e8e --- /dev/null +++ b/alab_control/SEM_autoprep/Positions/disks_tray_clean.csv @@ -0,0 +1,13 @@ +CDISK1,23.8,173.8,None +CDISK2,23.8,173.8,None +CDISK3,23.8,173.8,None +CDISK4,23.8,173.8,None +CDISK5,23.8,173.8,None +CDISK6,23.8,173.8,None +CDISK7,23.8,173.8,None +CDISK8,23.8,173.8,None +CDISK9,23.8,173.8,None +CDISK10,23.8,173.8,None +CDTRAY_Z1,None,None,133 +CDTRAY_Z2,None,None,141.5 +CDTRAY_Z3,None,None,137 \ No newline at end of file diff --git a/alab_control/SEM_autoprep/Positions/disks_tray_used.csv b/alab_control/SEM_autoprep/Positions/disks_tray_used.csv new file mode 100644 index 0000000..ee62bd6 --- /dev/null +++ b/alab_control/SEM_autoprep/Positions/disks_tray_used.csv @@ -0,0 +1,13 @@ +UDISK1,23.8,173.8,None +UDISK2,23.8,173.8,None +UDISK3,23.8,173.8,None +UDISK4,23.8,173.8,None +UDISK5,23.8,173.8,None +UDISK6,23.8,173.8,None +UDISK7,23.8,173.8,None +UDISK8,23.8,173.8,None +UDISK9,23.8,173.8,None +UDISK10,23.8,173.8,None +UDTRAY_Z1,None,None,133 +UDTRAY_Z2,None,None,141.5 +UDTRAY_Z3,None,None,137 \ No newline at end of file diff --git a/alab_control/SEM_autoprep/Positions/equipment.csv b/alab_control/SEM_autoprep/Positions/equipment.csv new file mode 100644 index 0000000..f1a24b4 --- /dev/null +++ b/alab_control/SEM_autoprep/Positions/equipment.csv @@ -0,0 +1,10 @@ +ROTATOR_A,23.8,173.8,None +ROTATOR_B,23.8,173.8,None +ROTATOR_C,23.8,173.8,None +ROTATOR_D,23.8,173.8,None +CHARGER,23.8,173.8,None +CHARGER_Z1,23.8,173.8,None +CHARGER_Z2,23.8,173.8,None +LASER,23.8,173.8,None +LASER_Z1,23.8,173.8,None +LASER_Z2,23.8,173.8,None \ No newline at end of file diff --git a/alab_control/SEM_autoprep/Positions/intermediate_positions.csv b/alab_control/SEM_autoprep/Positions/intermediate_positions.csv new file mode 100644 index 0000000..4075fd3 --- /dev/null +++ b/alab_control/SEM_autoprep/Positions/intermediate_positions.csv @@ -0,0 +1 @@ +HOME,20,20,20 \ No newline at end of file diff --git a/alab_control/SEM_autoprep/Positions/phenom_handler.csv b/alab_control/SEM_autoprep/Positions/phenom_handler.csv new file mode 100644 index 0000000..1d9477a --- /dev/null +++ b/alab_control/SEM_autoprep/Positions/phenom_handler.csv @@ -0,0 +1,5 @@ +PH_OPENED,23.8,173.8,None +PH_CLOSED,23.8,173.8,None +PH_L1,23.8,173.8,None +PH_L2,23.8,173.8,None +PH_L3,23.8,173.8,None \ No newline at end of file diff --git a/alab_control/SEM_autoprep/Positions/phenom_stubs.csv b/alab_control/SEM_autoprep/Positions/phenom_stubs.csv new file mode 100644 index 0000000..e7e407d --- /dev/null +++ b/alab_control/SEM_autoprep/Positions/phenom_stubs.csv @@ -0,0 +1,18 @@ +PH_STUB1,23.8,173.8,None +PH_STUB2,23.8,173.8,None +PH_STUB3,23.8,173.8,None +PH_STUB4,23.8,173.8,None +PH_STUB5,23.8,173.8,None +PH_STUB6,23.8,173.8,None +PH_STUB7,23.8,173.8,None +PH_STUB8,23.8,173.8,None +PH_STUB9,23.8,173.8,None +PH_STUB10,23.8,173.8,None +PH_STUB11,23.8,173.8,None +PH_STUB12,23.8,173.8,None +PH_STUB13,23.8,173.8,None +PH_STUB14,23.8,173.8,None +PH_STUB15,23.8,173.8,None +PH_Z1,None,None,133 +PH_Z2,None,None,141.5 +PH_Z3,None,None,137 \ No newline at end of file diff --git a/alab_control/SEM_autoprep/Positions/stubs_tray.csv b/alab_control/SEM_autoprep/Positions/stubs_tray.csv new file mode 100644 index 0000000..15c3aff --- /dev/null +++ b/alab_control/SEM_autoprep/Positions/stubs_tray.csv @@ -0,0 +1,21 @@ +TSTUB1,23.8,173.8,None +TSTUB2,23.8,173.8,None +TSTUB3,23.8,173.8,None +TSTUB4,23.8,173.8,None +TSTUB5,23.8,173.8,None +TSTUB6,23.8,173.8,None +TSTUB7,23.8,173.8,None +TSTUB8,23.8,173.8,None +TSTUB9,23.8,173.8,None +TSTUB10,23.8,173.8,None +TSTUB11,23.8,173.8,None +TSTUB12,23.8,173.8,None +TSTUB13,23.8,173.8,None +TSTUB14,23.8,173.8,None +TSTUB15,23.8,173.8,None +TSTUB16,23.8,173.8,None +TSTUB17,23.8,173.8,None +TSTUB18,23.8,173.8,None +STRAY_Z1,None,None,133 +STRAY_Z2,None,None,141.5 +STRAY_Z3,None,None,137 \ No newline at end of file diff --git a/alab_control/SEM_autoprep/Tests/SampleFile.csv b/alab_control/SEM_autoprep/Tests/SampleFile.csv deleted file mode 100644 index 9f03fee..0000000 --- a/alab_control/SEM_autoprep/Tests/SampleFile.csv +++ /dev/null @@ -1,3 +0,0 @@ -HOME,90,120,60 -STUB1,23.8,173.8,None -STUB2,23.8,173.8,None \ No newline at end of file diff --git a/alab_control/SEM_autoprep/Tests/csv_helper.py b/alab_control/SEM_autoprep/Tests/csv_helper.py index 3ff5041..bf51a87 100644 --- a/alab_control/SEM_autoprep/Tests/csv_helper.py +++ b/alab_control/SEM_autoprep/Tests/csv_helper.py @@ -15,7 +15,6 @@ def read_CSV_into_positions(path=CWD + '\\alab_control\\SEM_autoprep\\Tests\\Sam for lines in csvFile: #Each line has a list of 4 arguments, argument 0 is the name of the position, and argument 1, 2, 3 correspond to x, y, z, respectively positions[lines[0]] = ((float_or_none(lines[1]), float_or_none(lines[2]), float_or_none(lines[3]))) - return positions diff --git a/alab_control/SEM_autoprep/Tests/stubs.csv b/alab_control/SEM_autoprep/Tests/stubs.csv new file mode 100644 index 0000000..370e317 --- /dev/null +++ b/alab_control/SEM_autoprep/Tests/stubs.csv @@ -0,0 +1,21 @@ +BCP1,90,120,60 +BCP2,90,120,60 +BCP3,90,120,60 +BCP4,90,120,60 +HOME,90,120,60 +REST,15,15,15 +STUB1,23.8,173.8,None +STUB2,23.8,173.8,None +STUB3,23.8,173.8,None +STUB4,23.8,173.8,None +STUB5,23.8,173.8,None +STUB6,23.8,173.8,None +STUB7,23.8,173.8,None +STUB8,23.8,173.8,None +STUB9,23.8,173.8,None +STUB10,23.8,173.8,None +STUB11,23.8,173.8,None +STUB12,23.8,173.8,None +STUB13,23.8,173.8,None +STUB14,23.8,173.8,None +STUB15,23.8,173.8,None \ No newline at end of file diff --git a/alab_control/SEM_autoprep/csv_helper.py b/alab_control/SEM_autoprep/csv_helper.py new file mode 100644 index 0000000..bf51a87 --- /dev/null +++ b/alab_control/SEM_autoprep/csv_helper.py @@ -0,0 +1,20 @@ +import csv +import os +CWD = os.getcwd() +positions = {} + +def float_or_none(s): + if s == 'None': + return None + return float(s) + + +def read_CSV_into_positions(path=CWD + '\\alab_control\\SEM_autoprep\\Tests\\SampleFile.csv'): + with open(path, mode ='r') as file: + csvFile = csv.reader(file) + for lines in csvFile: + #Each line has a list of 4 arguments, argument 0 is the name of the position, and argument 1, 2, 3 correspond to x, y, z, respectively + positions[lines[0]] = ((float_or_none(lines[1]), float_or_none(lines[2]), float_or_none(lines[3]))) + return positions + + diff --git a/alab_control/SEM_autoprep/sample_prep.py b/alab_control/SEM_autoprep/sample_prep.py index 87d82eb..e398876 100644 --- a/alab_control/SEM_autoprep/sample_prep.py +++ b/alab_control/SEM_autoprep/sample_prep.py @@ -1,11 +1,18 @@ from alab_control.ender3 import Ender3 -from alab_control.SEM_autoprep.Tests import csv_helper +from alab_control.SEM_autoprep import csv_helper #from ender3 import Ender3 import serial import os CWD = os.getcwd() -path = CWD + '\\alab_control\\SEM_autoprep\\Tests\\SampleFile.csv' +path = CWD + '\\alab_control\\SEM_autoprep\\Positions\\' +clean_disks_filename = 'disks_tray_clean.csv' +used_disks_filename = 'disks_tray_used.csv' +equipment_filename = 'equipment.csv' +intermediate_positions_filename = 'intermediate_positions.csv' +phenom_holder_positions_filename = 'phenom_stubs.csv' +phenom_handler_filename = 'phenom_handler.csv' +stubs_tray_filename = 'stubs_tray.csv' class SamplePrepEnder3(Ender3): """This class is for controlling the Ender3 3D printer for sample preparation.""" @@ -14,7 +21,13 @@ class SamplePrepEnder3(Ender3): CRUCIBLE_HEIGHT = 39 # positions - positions = csv_helper.read_CSV_into_positions(path) + clean_disk_pos = csv_helper.read_CSV_into_positions(path + clean_disks_filename) + used_disk_pos = csv_helper.read_CSV_into_positions(path + used_disks_filename) + equipment_pos = csv_helper.read_CSV_into_positions(path + equipment_filename) + intermediate_pos = csv_helper.read_CSV_into_positions(path + intermediate_positions_filename) + used_stub_pos = csv_helper.read_CSV_into_positions(path + phenom_holder_positions_filename) + phenom_handler_pos = csv_helper.read_CSV_into_positions(path + phenom_handler_filename) + clean_stub_pos = csv_helper.read_CSV_into_positions(path + stubs_tray_filename) if __name__ == "__main__": @@ -25,9 +38,6 @@ class SamplePrepEnder3(Ender3): print( "**************************************************************************** \n " ) - print( - "The following lines show your COM ports.\nPlease select your MAPPLE printer by typing its number: \n" - ) try: r = SamplePrepEnder3("COM3") @@ -37,14 +47,15 @@ class SamplePrepEnder3(Ender3): ports = list(serial.tools.list_ports.comports()) for p in ports: print(p) - input("\n Press enter to end the program.") + input("\n Edit the source code to match the MAPLE COM port. Press enter to end the program.") exit() print("Printer is resetting the positioning system. Please wait... \n") r.gohome() + print("Homing head unit. Please wait...") - r.moveto(*r.positions["HOME"]) + r.moveto(*r.intermediate_pos["HOME"]) r.speed = 0.5 print("Done.") @@ -65,34 +76,35 @@ class SamplePrepEnder3(Ender3): while True: # Ask the user to choose part 1 or part 2 - stub_choice = input("Please enter 1 for Stub 1 or 2 for Stub 2: ") - r.moveto(x=35, y=173.8, z=60) - r.moveto(z=115) - pump_confirm = input("Please turn on vacuum pump and press enter.") + stub_choice = input("Please enter the number of the stub you want to pick:") + try: int(stub_choice) - r.moveto(*r.positions["STUB" + stub_choice]) + #r.moveto(x=35, y=173.8, z=60) + r.moveto(*r.clean_stub_pos["TSTUB" + stub_choice]) + #r.moveto(z=115) + pump_confirm = input("Please turn on vacuum pump and press enter.") break except Exception: print("Invalid choice. Please try again.") - r.moveto(z=133) + r.moveto(*r.clean_stub_pos["STRAY_Z1"]) r.speed = 0.005 - r.moveto(z=141.5) + r.moveto(*r.clean_stub_pos["STRAY_Z2"]) - r.moveto(z=137) + r.moveto(*r.clean_stub_pos["STRAY_Z3"]) while True: picked_confirm = input( - "Stub picked? C to continue, R to try again, M for manual, A to abort." + "Stub picked? C to continue, R to try again, M for manual, A to abort." # abort not available yet ) - if picked_confirm.lower() == "c": # abort not available yet + if picked_confirm.lower() == "c": break elif picked_confirm.lower() == "r": - r.moveto(z=141.5) - r.moveto(z=137) + r.moveto(*r.clean_stub_pos["STRAY_Z2"]) + r.moveto(*r.clean_stub_pos["STRAY_Z3"]) picked_confirm = input( "Stub picked? If not, R to try again, C to continue." ) @@ -128,12 +140,7 @@ class SamplePrepEnder3(Ender3): exp_confirm = input("Please press enter when the exposing is finished.") r.moveto(z=60) - if stub_choice == "1": - r.moveto(x=23.8, y=173.8) - elif stub_choice == "2": - r.moveto(x=23.8, y=173.8) - else: - print("Invalid choice. Please try again.") + r.moveto(*r.stub_positions["STUB" + stub_choice]) r.moveto(z=137) r.speed = 0.005 diff --git a/alab_control/_base_gcode_robot.py b/alab_control/_base_gcode_robot.py index 510d6f8..98bb507 100644 --- a/alab_control/_base_gcode_robot.py +++ b/alab_control/_base_gcode_robot.py @@ -122,6 +122,7 @@ def moveto( zhop (bool): Whether to z-hop (raise the z-axis) before moving to the target position. This is useful to avoid collisions. """ x, y, z = self.check_move_is_valid(x, y, z) # check for invalid move + print("Moving to " + str((x, y, z))) if (x == self.position[0]) and (y == self.position[1]): zhop = False # turn off zhopping if we're not moving in x or y @@ -174,6 +175,7 @@ def get_current_position(self) -> None: def gohome(self) -> None: """Homes the robt (calls the G28 command) and updates the position.""" + self.write("G28 Z") self.write("G28 X Y Z") self.get_current_position()