Skip to content

Commit

Permalink
Safety Z home and CSV files created
Browse files Browse the repository at this point in the history
A Z homing safety (G28 Z) code was added and now the printer starts its gohome function by homing Z before the other axes. Many CSV files were created and already have the placeholders for the predicted positions. The main code was updated to implement some of the CSV-based positions
  • Loading branch information
dmilsted committed Dec 23, 2023
1 parent 37f2b2a commit 736896d
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 30 deletions.
13 changes: 13 additions & 0 deletions alab_control/SEM_autoprep/Positions/disks_tray_clean.csv
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions alab_control/SEM_autoprep/Positions/disks_tray_used.csv
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions alab_control/SEM_autoprep/Positions/equipment.csv
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HOME,20,20,20
5 changes: 5 additions & 0 deletions alab_control/SEM_autoprep/Positions/phenom_handler.csv
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions alab_control/SEM_autoprep/Positions/phenom_stubs.csv
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions alab_control/SEM_autoprep/Positions/stubs_tray.csv
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions alab_control/SEM_autoprep/Tests/SampleFile.csv

This file was deleted.

1 change: 0 additions & 1 deletion alab_control/SEM_autoprep/Tests/csv_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


21 changes: 21 additions & 0 deletions alab_control/SEM_autoprep/Tests/stubs.csv
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions alab_control/SEM_autoprep/csv_helper.py
Original file line number Diff line number Diff line change
@@ -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


59 changes: 33 additions & 26 deletions alab_control/SEM_autoprep/sample_prep.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand All @@ -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__":
Expand All @@ -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")
Expand All @@ -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.")

Expand All @@ -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."
)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions alab_control/_base_gcode_robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 736896d

Please sign in to comment.