Example #1
0
 def goHomeSafely(self):
     # go to home without interference to the labware and switch to absolute coordinate mode
     gcode_list = [f'G0 Z{self.highest_z + 10} F1500;','G28', 'G90']
     print(gcode_list)
     gcode = gcoder.LightGCode(gcode_list)
     self.printcore.startprint(gcode)
     self.current_position = Point()
Example #2
0
def send_gcode(file, printer):
  # time.sleep(1)
  gcode=[i.strip() for i in open(file)] # or pass in your own array of gcode lines instead of reading from a file
  gcode = gcoder.LightGCode(gcode)
  printer.startprint(gcode)
  while (printer.printing):
      time.sleep(0.1)
Example #3
0
    def postProcess(self, msg=None, gCodeFile=None, tabRunOptStr=None):

        if msg is not None:
            os.system('%s %s %s -0"%s" > temp.gcode' %
                      (self.pythonBin, self.ppBin, self.tabRunOpt, msg))
            self.gCode = [i.strip() for i in open("temp.gcode")]
            self.gCode = gcoder.LightGCode(self.gCode)
            pass
        elif gCodeFile is not None:
            if os.path.exists(gCodeFile):
                self.gCode = [i.strip() for i in open(gCodeFile)]
                self.gCode = gcoder.LightGCode(self.gCode)
            else:
                print("File %s does not exists!" % (gCodeFile))
        else:
            print("At least one among msg or g-code file must be not none.")
Example #4
0
def begin_print(fname, state_add=0):
    global gcode, current_state, printcount
    printcount += 1
    current_state[0] = 1
    if state_add:
        current_state.append(state_add)
    gcode = [i.strip() for i in open(fname)]
    gcode = gcoder.LightGCode(gcode)
    p.startprint(gcode)
    print("PRINTING", fname)
Example #5
0
    def Print(self, file):
        from printrun import gcoder
        from printrun.printcore import printcore

        printer = printcore(self.comPort, self.baudRate)

        time.sleep(2)

        disectedGCode = [i.strip() for i in open(file)]

        disectedGCode = gcoder.LightGCode(disectedGCode)

        printer.startprint(disectedGCode)
Example #6
0
    def queue_printer_command(self, gcode):
        garray=robotcontrol.make_array(gcode)
        #print("gcode raw", gcode, garray)

        gcoded = gcoder.LightGCode(garray)
        #print("gcoded", gcoded)
        if hasattr(self,'print') and self.print is not None:
            if not self.print.online or not self.print.printer:
                print("Problem with printer", self.print.online, self.print.printer)
            if self.print.printing:
                self.print.send(gcoded)
            else:
                self.print.startprint(gcoded)
        else:
            print("Problem with printer interface")
def roundRobinSch():
    #Premliminary variables and function go here.
    mode = 0
    #Mode 0: Camera Mode - Communicates with Camera to establish connection and waits for data to be sent.
    #Mode 1: Conversion Mode - Converts and Builds Gcode file to be sent to printer movement.
    #Mode 2: Movement Mode - Establish connection with printer and moves the actuator to the target location based on gcode file.
    #Mode 3: Pump Mode - Establish connection with pump system and sends a pulse to the actuator to eject suficient amount of solution.
    p = printcore(
        'COM4', 115200
    )  #Establish connection with printer- Arguments:port name, Baud Rate
    n = 0
    remTargetfiles()
    while (True):
        if (mode == 0):
            x = int(input("Enter the x-coordinate:"))
            y = int(input("Enter the y-coordinate:"))
            n += 1
            mode += 1
        elif (mode == 1):
            createFile(x, y)
            gcode = [
                i.strip()
                for i in open("./targets/TargetLoc" + str(n) + ".gcode")
            ]
            gcode1 = gcoder.LightGCode(gcode)
            mode += 1
        elif (mode == 2):
            #SEND code file to printer
            p.startprint(gcode1)
            mode += 1
        elif (mode == 3):
            #SEND code to activate laser actuator.
            time.sleep(5)
            #SEND code to disactivate laser actuator.
            mode += 1
        else:  ##Default Path.
            #Resets Round-Robin Scheduler
            mode = 0
        ##Clean up routine when microcontroller s waiting for a response or data.

    return
Example #8
0
def callback(message):
    print("in call back")
    # gcodeFileName = '/home/xueyelin/Thermite_Boom_Boom/Code/Examples/test2Offset.gcode'
    gcodeFileName = message.data
    # gcodeFileName = data
    print("trying gcode sender")
    print(gcodeFileName)
    # or p.printcore('COM3',115200) on Windows
    p = printcore('/dev/ttyACM1', 115200)

    # Sleeps for 1 sec t o allow for UArm's serial jiberish
    # or pass in your own array of gcode lines instead of reading from a file

    rospy.sleep(1)

    gcode = [i.strip() for i in open(gcodeFileName)]
    gcode = gcoder.LightGCode(gcode)
    p.startprint(gcode)  # this will start a print

    prev_cmd = None
    while (p.printing is True):
        if (prev_cmd != p.sent[-1]):
            print(p.sent[-1])
            prev_cmd = p.sent[-1]
Example #9
0
            statusreport = True

    if len(args) <= 1:
        print("Error: Port or gcode file were not specified.\n")
        print(usage)
        sys.exit(2)
    elif len(args) > 1:
        port = args[-2]
        filename = args[-1]
        print("Printing: %s on %s with baudrate %d" % (filename, port, baud))

    p = printcore(port, baud)
    p.loud = loud
    time.sleep(2)
    gcode = [i.strip() for i in open(filename)]
    gcode = gcoder.LightGCode(gcode)
    p.startprint(gcode)

    try:
        if statusreport:
            p.loud = False
            sys.stdout.write("Progress: 00.0%\r")
            sys.stdout.flush()
        while p.printing:
            time.sleep(1)
            if statusreport:
                progress = 100 * float(p.queueindex) / len(p.mainqueue)
                sys.stdout.write("Progress: %02.1f%%\r" % progress)
                sys.stdout.flush()
        p.disconnect()
        sys.exit(0)
import time
import serial
import sys
import pickle
from printrun.printcore import printcore
from printrun import gcoder
from imageProc import objectDet
from interface import start, insert, FPickupErr, PPickupErr, AssemFail, restockF, restockP, calib, feedIns, Xadj, Yadj

printer = printcore('/dev/ttyUSB1', 115200)  #Connects to the printer.
arduino = serial.Serial('/dev/ttyUSB0', 9600)  #Connects to the arduino.

#The following imports gcode text files and assigns them to arrays to be sent to the printer.
home = [i.strip() for i in open('/home/pi/Printrun/testfiles/home.gcode')]
home = gcoder.LightGCode(home)
getComponent = [
    i.strip() for i in open('/home/pi/Printrun/testfiles/getComponent.gcode')
]
getComponent = gcoder.LightGCode(getComponent)
feedthroughView = [
    i.strip()
    for i in open('/home/pi/Printrun/testfiles/feedthroughView.gcode')
]
feedthroughView = gcoder.LightGCode(feedthroughView)
preformView = [
    i.strip() for i in open('/home/pi/Printrun/testfiles/preformView.gcode')
]
preformView = gcoder.LightGCode(preformView)
feedthroughPickup = [
    i.strip()
    for i in open('/home/pi/Printrun/testfiles/feedthroughPickup.gcode')
def roundRobinSch():

    actMode = 2  # 1 for Laser, 2 for pump
    lamp = 0  #controls pixy lamp during cord_grab() call 0=off 1=half brightness, 2=full brightness
    lTime = 0.5  #time lamp stays on when lamp==1 or lamp==2
    iniDelay = 2  #wait time for starting movements
    pumTime = 0.05  #activation time for pump

    mode = 0  #Starting mode for Round Robin
    GPIO.setwarnings(False)

    posZ = 20  #operation Height of actuator
    speed = 8000  #speed setting for stepper motors
    numCords = 20  #size of coordinate array
    lasTime = 0.5  #activation time for laser
    actDelay = 0.5  #wait time for after activation

    #Mode 0: Camera Mode - Communicates with Camera to establish connection and waits for data to be sent.
    #Mode 1: Conversion Mode - Converts and Builds Gcode file to be sent to printer movement.
    #Mode 2: Movement Mode - Establish connection with printer and moves the actuator to the target location based on gcode file.
    #Mode 3: Actuator Mode - Establish connection with pump system and sends a pulse to the actuator to eject suficient amount of solution.
    p = printcore(
        "/dev/ttyUSB0", 115200
    )  #Establish connection with printer- Arguments:port name, Baud Rate
    time.sleep(4)
    print("Printer is now online.")
    p.send_now("G90")
    #p.send_now("G28 F"+str(speed))
    p.send_now("M92 X80 y80")
    #p.send_now("G0 Z"+str(posZ)+" F"+str(speed))
    p.send_now("G0 X234.9 Y234.9 Z" + str(posZ) + " F" + str(speed))
    print("...Waiting")
    #     for j in range (0,iniDelay):
    #         print(iniDelay-j)
    #         time.sleep(1)
    time.sleep(iniDelay)

    n = 1
    remTargetfiles()
    createLog()
    pixyArray = coordinates(numCords, actMode, lamp, lTime)
    #Calls PixyCam's function and returns array.
    populateLog(pixyArray)  #Populate Log File with PixyCam's Coords.

    while (True):

        if (mode == 0):
            print("Coordinate Read MODE")
            if ((int(pixyArray[n][0]) == 0) and (int(pixyArray[n][1]) == 0)):
                break
            x = int(pixyArray[n][0])
            y = int(pixyArray[n][1])
            n += 1
            mode += 1

        elif (mode == 1):
            print("Coordinate Conversion MODE")
            print("Point #" + str(n - 1) + "\n")
            createFile(x, y, actMode)
            gcode = [
                i.strip()
                for i in open("./targets/TargetLoc" + str(n - 1) + ".gcode")
            ]
            gcode1 = gcoder.LightGCode(gcode)
            mode += 1

        elif (mode == 2):
            print("Movement MODE")
            #SEND code file to printer
            p.startprint(gcode1)
            #time.sleep(2)
            #while (position == False):
            #    position = checkPos()
            time.sleep(
                1
            )  #At least one second needs to pass before the function is called.
            while (
                    p.endChecker()
            ):  #Function call that returns true or false whether the actuator movement system is running gcode.
                #time.sleep(1)
                continue
            mode += 1

        elif (mode == 3):
            if (actMode == 1):
                print("Laser MODE")
                print("\nLaser On")
                activationL(lasTime)
                print("Laser Off\n")
                time.sleep(actDelay)
                mode += 1
            elif (actMode == 2):
                print("PUMP MODE")
                print("\nPump On")
                activationP(pumTime)
                print("Pump Off\n")
                time.sleep(actDelay)
                mode += 1

        else:  ##Default Path.
            #Resets Round-Robin Scheduler
            mode = 0
        ##Clean up routine when microcontroller is waiting for a response or data.
    print("Process Complete!\n")
    p.send_now("G1 X235 Y235 Z" + str(posZ) + " F" + str(speed))
    return
Example #12
0
def gcode_reader(file):
    gcode = [
        i.strip() for i in open(file)
    ]  # or pass in your own array of gcode lines instead of reading from a file
    gcode = gcoder.LightGCode(gcode)
    return (gcode)
Example #13
0
import socket, json, struct, os, time
from printrun.printcore import printcore
from printrun import gcoder

HOST = '0.0.0.0'
PORT = 49372
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
data = []
while conn:
	raw = conn.recv(4)
	if raw:
		len = struct.unpack('>I', raw)[0]
		line = conn.recv(len).decode()
		if line == ";||":
			if data:
				while True:
					if os.access("/dev/ttyUSB0", os.W_OK):
						p = printcore('/dev/ttyUSB0',115200)
						gcode = gcoder.LightGCode(data)
						if p.startprint(gcode):
							print("Printing...")
						data = ""
						break
					else:
						print("Can't Connect to the 3D Printer. Is it attached?")
						time.sleep(10)
		elif line:
			data.append(line)