Ejemplo n.º 1
0
        def STOP(instance):
            print("RESET!!")
            self.terminal.text += "Reset\n"
            try:
                f = open("comm.pickle", "rb")
                pid = pickle.load(f)
                f.close()

                os.system("rm comm.pickle")
                os.system("kill " + str(pid))
            except:
                print("no comm.pickle")

            for motor in range(0, 4):
                b2, b3, b4, b5, b6, b7, b8 = i.MST(motor)
                b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(
                    1, b2, b3, b4, b5, b6, b7, b8)
                x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
                ser.write(x)
                sleep(0.001)
                b2, b3, b4, b5, b6, b7, b8 = i.SAP(1, motor, 0)
                b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(
                    1, b2, b3, b4, b5, b6, b7, b8)
                p = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
                ser.write(p)
                sleep(0.001)
            sleep(0.001)
            send = Gcode.M104(0)[1]
            ser.write(send)
Ejemplo n.º 2
0
def func():
    ser = serial.Serial("/dev/ttyACM0")
    microstepping = glob()[4]
    if microstepping == 256:
        steps = 8
    elif microstepping == 128:
        steps = 7
    elif microstepping == 64:
        steps = 6
    elif microstepping == 32:
        steps = 5
    elif microstepping == 16:
        steps = 4
    elif microstepping == 8:
        steps = 3
    elif microstepping == 4:
        steps = 2
    elif microstepping == 2:
        steps = 1
    else:
        steps = 0
    for motor in range(0, 4):
        b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, 5, 140, motor, 0, 0, 0,
                                                 steps)
        x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
        ser.write(x)
        sleep(0.001)
        b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, 7, 140, motor, 0, 0, 0, 0)
        x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
        ser.write(x)
        sleep(0.001)
    ser.close()
Ejemplo n.º 3
0
def G28():
    b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, 13, 0, 0, 0, 0, 0, 0)
    x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
    b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, 13, 0, 1, 0, 0, 0, 0)
    y = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
    b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, 13, 0, 2, 0, 0, 0, 0)
    a = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
    b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, 13, 0, 3, 0, 0, 0, 0)
    b = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
    return (x, y, a, b)
Ejemplo n.º 4
0
def G1(X, Y, A, B):
    b2, b3, b4, b5, b6, b7, b8 = i.MVP(mode, 0, X)
    b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7, b8)
    x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
    b2, b3, b4, b5, b6, b7, b8 = i.MVP(mode, 1, Y)
    b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7, b8)
    y = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
    b2, b3, b4, b5, b6, b7, b8 = i.MVP(mode, 2, A)
    b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7, b8)
    a = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
    b2, b3, b4, b5, b6, b7, b8 = i.MVP(mode, 3, B)
    b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7, b8)
    b = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
    return (x, y, a, b)
Ejemplo n.º 5
0
 def homeY(instance):
     b2, b3, b4, b5, b6, b7, b8 = i.SAP(193, 1, 1)
     b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                              b8)
     x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
     ser.write(x)
     b2, b3, b4, b5, b6, b7, b8 = i.SAP(194, 1, 2047)
     b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                              b8)
     s = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
     ser.write(s)
     b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, 13, 0, 1, 0, 0, 0, 0)
     y = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
     ser.write(y)
     self.terminal.text += "Home Y\n"
     self.yTravel.text = "0"
Ejemplo n.º 6
0
 def homeB(instance):
     b2, b3, b4, b5, b6, b7, b8 = i.SAP(193, 3, 1)
     b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                              b8)
     x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
     ser.write(x)
     b2, b3, b4, b5, b6, b7, b8 = i.SAP(194, 3, 2047)
     b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                              b8)
     s = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
     ser.write(s)
     b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, 13, 0, 3, 0, 0, 0, 0)
     a = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
     ser.write(b)
     self.terminal.text += "Home B\n"
     self.bTravel.text = "0"
Ejemplo n.º 7
0
def RESET():
    global globX, globY, globA, globB
    globX, globY, globA, globB = 0, 0, 0, 0
    b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, 255, 0, 0, 0, 0, 4, 210)
    x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
    ser.write(x)
    print("RESET!")
Ejemplo n.º 8
0
        def homeX(instance):

            b2, b3, b4, b5, b6, b7, b8 = i.SAP(193, 0, 1)
            b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                                     b8)
            x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
            ser.write(x)
            b2, b3, b4, b5, b6, b7, b8 = i.SAP(194, 0, 2000)
            b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                                     b8)
            s = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
            ser.write(s)
            b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, 13, 0, 0, 0, 0, 0, 0)
            x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
            ser.write(x)
            self.terminal.text += "Home X\n"
            self.xTravel.text = "0"
Ejemplo n.º 9
0
def M104(temp):
    if temp != 0:
        s = True
    else:
        s = False
    b2, b3, b4, b5, b6, b7, b8 = i.SIO(3, s)
    b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7, b8)
    x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
    return (temp, x)
Ejemplo n.º 10
0
 def sett(btn):
     if self.feed.text == "":
         print("error")
         self.terminal.text += "FeedrateError\n"
     else:
         value = int(self.feed.text)
         print(self.feed.text)
         for motor in range(0, 4):
             b2, b3, b4, b5, b6, b7, b8 = i.SAP(4, motor, value)
             b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(
                 1, b2, b3, b4, b5, b6, b7, b8)
             x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
             ser.write(x)
             sleep(0.001)
         self.terminal.text += "Feedrate set to: " + self.feed.text + "\n"
Ejemplo n.º 11
0
 def Bd(instance):
     global bb1, bb2
     b2, b3, b4, b5, b6, b7, b8 = i.MVP("REL", 3, negtravel)
     b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                              b8)
     x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
     if (bb1 == 0) and (bb2 > 0):
         bb1 = 1
         bb2 = bb2 - travel
         ser.write(bytearray([1, 138, 0, 0, 0, 0, 0, 8, 147]))
         ser.write(x)
         Thread(target=wait_until_reached).start()
         self.bTravel.text = str(bb2)
         self.terminal.text += "axis B descend: " + str(travel) + "mm\n"
     else:
         self.terminal.text += "axis B already moving or can't travel to negative\n"
Ejemplo n.º 12
0
 def Yd(instance):
     global y1, y2
     b2, b3, b4, b5, b6, b7, b8 = i.MVP("REL", 1, negtravel)
     b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                              b8)
     x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
     if (y1 == 0) and (y2 > 0):
         y1 = 1
         y2 = y2 - travel
         ser.write(bytearray([1, 138, 0, 0, 0, 0, 0, 2, 141]))
         ser.write(x)
         Thread(target=wait_until_reached).start()
         self.yTravel.text = str(y2)
         self.terminal.text += "axis Y descend: " + str(travel) + "mm\n"
     else:
         self.terminal.text += "axis Y already moving or can't travel to negative\n"
Ejemplo n.º 13
0
 def Xd(instance):
     global x1, x2
     b2, b3, b4, b5, b6, b7, b8 = i.MVP("REL", 0, negtravel)
     b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                              b8)
     x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
     if (x1 == 0) and (x2 > 0):
         x1 = 1
         x2 = x2 - travel
         ser.write(bytearray([1, 138, 0, 0, 0, 0, 0, 1, 140]))
         ser.write(x)
         Thread(target=wait_until_reached).start()
         self.xTravel.text = str(x2)
         self.terminal.text += "axis X descend: " + str(travel) + "mm\n"
     else:
         self.terminal.text += "axis X already moving or can't travel to negative\n"
Ejemplo n.º 14
0
 def Xa(instance):
     global x1, x2
     b2, b3, b4, b5, b6, b7, b8 = i.MVP("REL", 0, travel)
     b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                              b8)
     x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
     x2 = x2 + travel
     if (x1 == 0) and (x2 <= 900):
         x1 = 1
         ser.write(bytearray([1, 138, 0, 0, 0, 0, 0, 1, 140]))
         ser.write(x)
         Thread(target=wait_until_reached).start()
         self.terminal.text += "axis X ascend: " + str(travel) + "mm\n"
         self.xTravel.text = str(x2)
     else:
         self.terminal.text += "axis X already moving or can't travel more\n"
Ejemplo n.º 15
0
 def Ad(instance):
     global a1, a2
     b2, b3, b4, b5, b6, b7, b8 = i.MVP("REL", 2, negtravel)
     b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                              b8)
     x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
     if (a1 == 0) and (a2 > 0):
         a1 = 1
         a2 = a2 - travel
         ser.write(bytearray([1, 138, 0, 0, 0, 0, 0, 4, 143]))
         ser.write(x)
         Thread(target=wait_until_reached).start()
         self.aTravel.text = str(a2)
         self.terminal.text += "axis A descend: " + str(travel) + "mm\n"
     else:
         self.terminal.text += "axis A already moving or can't travel to negative\n"
Ejemplo n.º 16
0
def action(r):
    r = r.decode("utf-8")
    #import globalnich promennych do funkce
    global mode
    global st
    global proceed
    global lastx, lasty, lasta, lastb
    global feedG0, feedG1
    #zpracovani prikazu G0 pro pohyb
    if r.find("G0\n") != -1:
        log.write("G0")
        x = r.find("X")
        y = r.find("Y")
        a = r.find("A")
        b = r.find("B")
        if (x == -1) or (y == -1) or (a == -1) or (b == -1):
            return
        try:
            xx = float(r[x + 1:y - 1])
            yy = float(r[y + 1:a - 1])
            aa = float(r[a + 1:b - 1])
            bb = float(r[b + 1:])
            log.write("X " + str(xx) + "\n")
            log.write("Y " + str(yy) + "\n")
            log.write("A " + str(aa) + "\n")
            log.write("B " + str(bb) + "\n")

            yy = 420 - yy
            bb = 420 - bb
        except:
            return
        x, y, a, b = Gcode.G0(xx, yy, aa, bb)
        nx = abs(xx - lastx)
        ny = abs(yy - lasty)
        na = abs(aa - lasta)
        nb = abs(bb - lastb)
        mx = max(nx, ny, na, nb)
        log.write("new X " + str(nx) + "\n")
        log.write("new Y " + str(ny) + "\n")
        log.write("new A " + str(na) + "\n")
        log.write("new B " + str(nb) + "\n")
        log.write("max travel " + str(mx) + "\n")
        #------------------------------interpolation--------------------------------------------
        fx, fy, fa, fb = nx, ny, na, nb
        if mx == 0:
            mx = 1
        if fx == 0:
            fx = mx
        if fy == 0:
            fy = mx
        if fa == 0:
            fa = mx
        if fb == 0:
            fb = mx
        fx = int(feedG0 / (mx / fx))
        fy = int(feedG0 / (mx / fy))
        fa = int(feedG0 / (mx / fa))
        fb = int(feedG0 / (mx / fb))
        log.write("feed X " + str(fx) + "\n")
        log.write("feed Y " + str(fy) + "\n")
        log.write("feed A " + str(fa) + "\n")
        log.write("feed B " + str(fb) + "\n")

        b2, b3, b4, b5, b6, b7, b8 = i.SAP(4, 0, fx)
        b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7, b8)
        byte = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
        ser.write(byte)
        sleep(st)
        b2, b3, b4, b5, b6, b7, b8 = i.SAP(4, 1, fy)
        b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7, b8)
        byte = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
        ser.write(byte)
        sleep(st)
        b2, b3, b4, b5, b6, b7, b8 = i.SAP(4, 2, fa)
        b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7, b8)
        byte = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
        ser.write(byte)
        sleep(st)
        b2, b3, b4, b5, b6, b7, b8 = i.SAP(4, 3, fb)
        b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7, b8)
        byte = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
        ser.write(byte)
        sleep(st)
        #---------------------------interpolation-end-------------------------------------------
        lastx, lasty, lasta, lastb = xx, yy, aa, bb
        if nx == mx:
            ser.write(bytearray([1, 138, 0, 0, 0, 0, 0, 1, 140]))
            sleep(st)
            ser.write(x)
            sleep(st)
            ser.write(y)
            sleep(st)
            ser.write(a)
            sleep(st)
            ser.write(b)
            print("OK1")
            log.write("OK1\n")
            pass
        elif ny == mx:
            ser.write(bytearray([1, 138, 0, 0, 0, 0, 0, 2, 141]))
            sleep(st)
            ser.write(y)
            sleep(st)
            ser.write(x)
            sleep(st)
            ser.write(a)
            sleep(st)
            ser.write(b)
            print("OK2")
            log.write("OK2\n")
            pass
        elif na == mx:
            ser.write(bytearray([1, 138, 0, 0, 0, 0, 0, 4, 143]))
            sleep(st)
            ser.write(a)
            sleep(st)
            ser.write(y)
            sleep(st)
            ser.write(x)
            sleep(st)
            ser.write(b)
            print("OK3")
            log.write("OK3\n")
            pass
        else:
            ser.write(bytearray([1, 138, 0, 0, 0, 0, 0, 8, 147]))
            sleep(st)
            ser.write(b)
            sleep(st)
            ser.write(y)
            sleep(st)
            ser.write(a)
            sleep(st)
            ser.write(x)
            print("OK4")
            log.write("OK4\n")
            pass
    #zpracovani prikazu G1 pro pohyb
    elif r.find("G1") != -1:
        log.write("G1\n")
        x = r.find("X")
        y = r.find("Y")
        a = r.find("A")
        b = r.find("B")
        if (x == -1) or (y == -1) or (a == -1) or (b == -1):
            return
        try:
            xx = float(r[x + 1:y - 1])
            yy = float(r[y + 1:a - 1])
            aa = float(r[a + 1:b - 1])
            bb = float(r[b + 1:])
            log.write("X " + str(xx) + "\n")
            log.write("Y " + str(yy) + "\n")
            log.write("A " + str(aa) + "\n")
            log.write("B " + str(bb) + "\n")

            yy = 420 - yy
            bb = 420 - bb
        except:
            return
        x, y, a, b = Gcode.G0(xx, yy, aa, bb)
        nx = abs(xx - lastx)
        ny = abs(yy - lasty)
        na = abs(aa - lasta)
        nb = abs(bb - lastb)
        mx = max(nx, ny, na, nb)
        log.write("new X " + str(nx) + "\n")
        log.write("new Y " + str(ny) + "\n")
        log.write("new A " + str(na) + "\n")
        log.write("new B " + str(nb) + "\n")
        log.write("max travel " + str(mx) + "\n")
        #------------------------------interpolation--------------------------------------------
        fx, fy, fa, fb = nx, ny, na, nb
        if mx == 0:
            mx = 1
        if fx == 0:
            fx = mx
        if fy == 0:
            fy = mx
        if fa == 0:
            fa = mx
        if fb == 0:
            fb = mx
        fx = int(feedG1 / (mx / fx))
        fy = int(feedG1 / (mx / fy))
        fa = int(feedG1 / (mx / fa))
        fb = int(feedG1 / (mx / fb))
        log.write("feed X " + str(fx) + "\n")
        log.write("feed Y " + str(fy) + "\n")
        log.write("feed A " + str(fa) + "\n")
        log.write("feed B " + str(fb) + "\n")

        b2, b3, b4, b5, b6, b7, b8 = i.SAP(4, 0, fx)
        b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7, b8)
        byte = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
        ser.write(byte)
        sleep(st)
        b2, b3, b4, b5, b6, b7, b8 = i.SAP(4, 1, fy)
        b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7, b8)
        byte = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
        ser.write(byte)
        sleep(st)
        b2, b3, b4, b5, b6, b7, b8 = i.SAP(4, 2, fa)
        b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7, b8)
        byte = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
        ser.write(byte)
        sleep(st)
        b2, b3, b4, b5, b6, b7, b8 = i.SAP(4, 3, fb)
        b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7, b8)
        byte = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
        ser.write(byte)
        sleep(st)
        #---------------------------interpolation-end-------------------------------------------
        lastx, lasty, lasta, lastb = xx, yy, aa, bb
        if nx == mx:
            ser.write(bytearray([1, 138, 0, 0, 0, 0, 0, 1, 140]))
            sleep(st)
            ser.write(x)
            sleep(st)
            ser.write(y)
            sleep(st)
            ser.write(a)
            sleep(st)
            ser.write(b)
            print("OK1")
            log.write("OK1\n")
            pass
        elif ny == mx:
            ser.write(bytearray([1, 138, 0, 0, 0, 0, 0, 2, 141]))
            sleep(st)
            ser.write(y)
            sleep(st)
            ser.write(x)
            sleep(st)
            ser.write(a)
            sleep(st)
            ser.write(b)
            print("OK2")
            log.write("OK2\n")
            pass
        elif na == mx:
            ser.write(bytearray([1, 138, 0, 0, 0, 0, 0, 4, 143]))
            sleep(st)
            ser.write(a)
            sleep(st)
            ser.write(y)
            sleep(st)
            ser.write(x)
            sleep(st)
            ser.write(b)
            print("OK3")
            log.write("OK3\n")
            pass
        else:
            ser.write(bytearray([1, 138, 0, 0, 0, 0, 0, 8, 147]))
            sleep(st)
            ser.write(b)
            sleep(st)
            ser.write(y)
            sleep(st)
            ser.write(a)
            sleep(st)
            ser.write(x)
            print("OK4")
            log.write("OK4\n")
            pass
    #zpracovani prikazu G28 pro homeni
    elif r.find("G28") != -1:
        log.write("G28\n")
        for motor in range(0, 4):
            b2, b3, b4, b5, b6, b7, b8 = i.SAP(193, motor, 1)
            b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                                     b8)
            x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
            ser.write(x)
            sleep(sth)
            b2, b3, b4, b5, b6, b7, b8 = i.SAP(194, motor, 2047)
            b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                                     b8)
            s = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
            ser.write(s)
            sleep(sth)
        x, y, a, b = Gcode.G28()
        ser.write(x)
        sleep(sth)
        ser.write(y)
        sleep(sth)
        ser.write(a)
        sleep(sth)
        ser.write(b)
        sleep(sth)
    #zpracovani prikazu G90 pro zmenu modu na ABS
    elif r.find("G90") != -1:
        global mode
        mode = Gcode.G90()
        log.write("G90\n")
    #zpracovani prikazu G91 pro zmenu modu na REL
    elif r.find("G91") != -1:
        mode = Gcode.G91()
        log.write("G91\n")
    #zpracovani prikazu M104 pro nahrivani
    elif r.find("M104") != -1:
        a = r.find("S")
        if a == -1:
            return
        temp = int(r[a + 1:])
        heat, send = Gcode.M104(temp)
        ser.write(send)
        sleep(st)
        log.write("M104\n")
        log.write("Temp " + str(temp) + "\n")
    #zpracovani prikazu M600 pro cekani
    elif r.find("M600") != -1:
        a = r.find("S")
        if a == -1:
            return
        t = int(r[a + 1:])
        Gcode.M600(t)
        log.write("M600\n")
        log.write("Time " + str(t) + "\n")
    #zpracovani prikazu F, pro feedrate
    elif r.find("F") != -1:
        a = r.find("F")
        if a == -1:
            return
        t = int(r[a + 1:])
        if t <= 2047:
            feedG1 = t
            log.write("Feedrate " + str(feedG1) + "\n")
        else:
            print("Too much feedrate!")
            log.write("Too much feedrate!\n")
    #zpracovani prikazu MST pro okamzite zastaveni motoru (nepouzivane)
    elif r.find("MST") != -1:
        log.write("MST\n")
        for motor in range(0, 4):
            b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, 3, 0, motor, 0, 0, 0,
                                                     0)
            x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
            ser.write(x)
            sleep(st)
    #reseni prazdnych radku a radku s "#"
    elif r == "":
        nothing, temp = Gcode.M104(0)
        for motor in range(0, 4):
            b2, b3, b4, b5, b6, b7, b8 = i.SAP(4, motor, 2047)
            b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                                     b8)
            byte = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
            ser.write(byte)
            sleep(0.001)
        if os.path.exists("/home/pi") or os.path.exists("/home/rpi"):
            os.system("kill " + str(emerg_pid))
            GPIO.output(4, GPIO.LOW)
        ser.write(temp)
        log.write("Empty string\n")
        log.close()
    elif r == "#":
        nothing, temp = Gcode.M104(0)
        for motor in range(0, 4):
            b2, b3, b4, b5, b6, b7, b8 = i.SAP(4, motor, 2047)
            b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                                     b8)
            byte = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
            ser.write(byte)
            sleep(0.001)
        if os.path.exists("/home/pi") or os.path.exists("/home/rpi"):
            os.system("kill " + str(emerg_pid))
            GPIO.output(4, GPIO.LOW)
        ser.write(temp)
        log.write("String = #\n")
        log.close()
    else:
        nothing, temp = Gcode.M104(0)
        for motor in range(0, 4):
            b2, b3, b4, b5, b6, b7, b8 = i.SAP(4, motor, 2047)
            b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                                     b8)
            byte = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
            ser.write(byte)
            sleep(0.001)
        if os.path.exists("/home/pi") or os.path.exists("/home/rpi"):
            os.system("kill " + str(emerg_pid))
            GPIO.output(4, GPIO.LOW)
        ser.write(temp)
        log.write("Unknown string\n")
        log.close()
Ejemplo n.º 17
0
def cli(x):
    """
    This is CLI for hot wire EPP cutter. For help enter help.
    
    Instructions are:
        help - shows help
        port - takes one argument, for connecting to selected port
        listports - lists all available ports, no arguments
        connect - connect to port on which cutter is, no arguments
        disconnect - to disconnect from cutter, no arguments
        gcode - takes one argument, gcode which will be printing from
        cut - for cutting, no arguments
        stop - immediate stop of cutting, no arguments
        exit - to exit application, note that sender will continue sending gcode to the cutter
        G0, G1, G28, G90, G91, M104, MST - as genetral cutter commands, arguments:
            G0 X Y A B
            G1 X Y A B
            G28
            G90
            G91
            M104 S
        
        RESET - for resetting TMCM-6110, reconnect required    
        command - for direct single line shell command input. If needed more commands
                  it must be in form: <first command> ; <second command> ; ...
                  
    Default port is /dev/ttyACM0
    dimensions: X,A = 890;Y,B = 415
    """
    t = x
    global mode
    global serPort
    global ser
    global file
    global globX, globY, globA, globB

    #obsluha vlozenych prikazu
    if t.find("G0") != -1:
        x = t.find("X")
        y = t.find("Y")
        a = t.find("A")
        b = t.find("B")
        if (x == -1) or (y == -1) or (a == -1) or (b == -1):
            print("Command must be in form: G0 X Y A B\n")
            return
        try:
            xx = int(t[x + 1:y - 1])
            yy = int(t[y + 1:a - 1])
            aa = int(t[a + 1:b - 1])
            bb = int(t[b + 1:])
        except:
            print("Command must be in form: G0 X Y A B\n")
            return
        x, y, a, b = Gcode.G0(xx, yy, aa, bb)
        if mode == "REL":
            globX = globX + xx
            globY = globY + yy
            globA = globA + aa
            globB = globB + bb
            if globX <= 900 and globY <= 420 and globA <= 900 and globB <= 420:
                ser.write(x)
                sleep(0.001)
                ser.write(y)
                sleep(0.001)
                ser.write(a)
                sleep(0.001)
                ser.write(b)
            else:
                print("max travel X,A = 900 Y,B = 420")
                print("X = " + str(globX))
                print("Y = " + str(globY))
                print("A = " + str(globA))
                print("B = " + str(globB))
        else:
            if xx <= 900 and yy <= 420 and aa <= 900 and bb <= 420:
                globX = xx
                globY = yy
                globA = aa
                globB = bb
                ser.write(x)
                sleep(0.001)
                ser.write(y)
                sleep(0.001)
                ser.write(a)
                sleep(0.001)
                ser.write(b)
            else:
                print("max travel X,A = 900 Y,B = 420")
    elif t.find("G1") != -1:
        x = t.find("X")
        y = t.find("Y")
        a = t.find("A")
        b = t.find("B")
        if (x == -1) or (y == -1) or (a == -1) or (b == -1):
            print("Command must be in form: G1 X Y A B\n")
            return
        try:
            xx = int(t[x + 1:y - 1])
            yy = int(t[y + 1:a - 1])
            aa = int(t[a + 1:b - 1])
            bb = int(t[b + 1:])
        except:
            print("Command must be in form: G1 X Y A B\n")
            return
        x, y, a, b = Gcode.G1(xx, yy, aa, bb)
        if mode == "REL":
            globX = globX + xx
            globY = globY + yy
            globA = globA + aa
            globB = globB + bb
            if globX <= 900 and globY <= 420 and globA <= 900 and globB <= 420:
                ser.write(x)
                sleep(0.001)
                ser.write(y)
                sleep(0.001)
                ser.write(a)
                sleep(0.001)
                ser.write(b)
            else:
                print("max travel X,A = 900 Y,B = 420")
                print("X = " + str(globX))
                print("Y = " + str(globY))
                print("A = " + str(globA))
                print("B = " + str(globB))
        else:
            if xx <= 900 and yy <= 420 and aa <= 900 and bb <= 420:
                globX = xx
                globY = yy
                globA = aa
                globB = bb
                ser.write(x)
                sleep(0.001)
                ser.write(y)
                sleep(0.001)
                ser.write(a)
                sleep(0.001)
                ser.write(b)
            else:
                print("max travel X,A = 900 Y,B = 420")
    elif t.find("G28") != -1:
        x, y, a, b = Gcode.G28()
        for motor in range(0, 4):
            b2, b3, b4, b5, b6, b7, b8 = i.SAP(193, motor, 1)
            b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                                     b8)
            m = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
            ser.write(m)
            sleep(0.001)
            b2, b3, b4, b5, b6, b7, b8 = i.SAP(194, motor, 2047)
            b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(1, b2, b3, b4, b5, b6, b7,
                                                     b8)
            s = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
            ser.write(s)
            sleep(0.001)
        globX, globY, globA, globB = 0, 0, 0, 0
        ser.write(x)
        sleep(0.001)
        ser.write(y)
        sleep(0.001)
        ser.write(a)
        sleep(0.001)
        ser.write(b)
        sleep(0.001)
    elif t.find("G90") != -1:
        mode = Gcode.G90()
    elif t.find("G91") != -1:
        mode = Gcode.G91()
    elif t.find("M104") != -1:
        a = t.find("S")
        if a == -1:
            print("Command must be in form: M104 S\n")
            return
        temp = int(t[a + 1:])
        heat, send = Gcode.M104(temp)
        ser.write(send)
    elif t.find("RESET") != -1:
        RESET()
    #zadani serioveho portu
    elif t.find("port") != -1:
        serPort = t[5:]
    #pripojeni k portu
    elif t.find("connect") != -1:
        try:
            ser = Gcode.connection(serPort)
            sleep(0.2)
            config.func()
            for motor in range(0, 4):
                b2, b3, b4, b5, b6, b7, b8 = i.SAP(4, motor, 2047)
                b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(
                    1, b2, b3, b4, b5, b6, b7, b8)
                byte = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
                ser.write(byte)
                sleep(0.001)
        except:
            ""
    #odpojeni od portu
    elif t.find("disconnect") != -1:
        ser.close()
        ser = Exceptions()
    #zadani cesty k gcode souboru
    elif t.find("gcode") != -1:
        y = t[6:]
        gcoload(y)
    #spusteni rezani
    elif t.find("cut") != -1:
        if file != "":
            sendComm()
            print("Starting sender")
            sleep(1)
            openSender()
        else:
            print("no file for cutting selected")
    #zastaveni
    elif t.find("stop") != -1:
        STOP()
    #vypnuti CLI
    elif t.find("exit") != -1:
        pid = os.getpid()
        subprocess.call("kill " + str(pid), shell=True)
    #zadani shell prikazu
    elif t.find("command") != -1:
        if len(t) > 8:
            x = t[8:]
            subprocess.call(x, shell=True)
        else:
            subprocess.call(input("command: "), shell=True)
    elif t.find("listports") != -1:
        PortString = subprocess.check_output("ls /dev/tty*",
                                             shell=True).decode('utf-8')
        PortsAvailable = re.findall(r"ttyUSB[\w\.-]+|ttyACM[\w\.-]+",
                                    PortString)
        print(PortsAvailable)
    #vypsani help
    elif t.find("help") != -1:
        print(cli.__doc__)
    #osetreni nezadaneho nebo spatne zadaneho prikazu
    elif t == "":
        print("No command given\n")
    else:
        print("Unknown command: " + t)
Ejemplo n.º 18
0
                    log.write("Got third read\n")
                    break

                if r == b'\x02\x01\x80\x8a\x00\x00\x00\x08\x15':
                    log.write("Got fourth read\n")
                    break

        elif a.find("G28") != -1:
            action(line)  #provedeni prislusnych vypocetnich procedur
            Xh = 0
            Yh = 0
            Ah = 0
            Bh = 0
            while True:
                b2, b3, b4, b5, b6, b7, b8 = i.GAP(11, 0)
                b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(
                    1, b2, b3, b4, b5, b6, b7, b8)
                x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
                ser.write(x)
                a = ser.read(9)
                if a == b'\x02\x01\x64\x06\x00\x00\x00\x01\x6e':
                    Xh = 1
                else:
                    Xh = 0
                sleep(0.1)
                b2, b3, b4, b5, b6, b7, b8 = i.GAP(11, 1)
                b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(
                    1, b2, b3, b4, b5, b6, b7, b8)
                x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
                ser.write(x)
                a = ser.read(9)
                if a == b'\x02\x01\x64\x06\x00\x00\x00\x01\x6e':
Ejemplo n.º 19
0
        def command(instance):
            t = self.command.text
            global mode
            if t.find("G0") != -1:
                print("G0")
                x = t.find("X")
                y = t.find("Y")
                a = t.find("A")
                b = t.find("B")
                if (x == -1) or (y == -1) or (a == -1) or (b == -1):
                    self.terminal.text += "Command must be in form: G0 X Y A B\n"
                    return
                try:
                    xx = int(t[x + 1:y - 1])
                    yy = int(t[y + 1:a - 1])
                    aa = int(t[a + 1:b - 1])
                    bb = int(t[b + 1:])
                except:
                    self.terminal.text += "Command must be in form: G0 X Y A B\n"
                    return
                x, y, a, b = Gcode.G0(xx, yy, aa, bb)
                ser.write(x)
                sleep(0.001)
                ser.write(y)
                sleep(0.001)
                ser.write(a)
                sleep(0.001)
                ser.write(b)
                self.terminal.text += t + "\n"
                self.command.text = ""
            elif t.find("G1") != -1:
                print("G1")
                x = t.find("X")
                y = t.find("Y")
                a = t.find("A")
                b = t.find("B")
                if (x == -1) or (y == -1) or (a == -1) or (b == -1):
                    self.terminal.text += "Command must be in form: G1 X Y A B\n"
                    return
                try:
                    xx = int(t[x + 1:y - 1])
                    yy = int(t[y + 1:a - 1])
                    aa = int(t[a + 1:b - 1])
                    bb = int(t[b + 1:])
                except:
                    self.terminal.text += "Command must be in form: G1 X Y A B\n"
                    return
                x, y, a, b = Gcode.G1(xx, yy, aa, bb)
                ser.write(x)
                sleep(0.001)
                ser.write(y)
                sleep(0.001)
                ser.write(a)
                sleep(0.001)
                ser.write(b)
                self.terminal.text += t + "\n"
                self.command.text = ""
            elif t.find("G28") != -1:
                print("G28")
                x, y, a, b = Gcode.G28()
                for motor in range(0, 4):
                    b2, b3, b4, b5, b6, b7, b8 = i.SAP(193, motor, 1)
                    b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(
                        1, b2, b3, b4, b5, b6, b7, b8)
                    m = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
                    ser.write(m)
                    sleep(0.001)
                    b2, b3, b4, b5, b6, b7, b8 = i.SAP(194, motor, 2047)
                    b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(
                        1, b2, b3, b4, b5, b6, b7, b8)
                    s = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
                    ser.write(s)
                    sleep(0.001)
                ser.write(x)
                sleep(0.001)
                ser.write(y)
                sleep(0.001)
                ser.write(a)
                sleep(0.001)
                ser.write(b)
                self.terminal.text += t + "\n"
                self.command.text = ""
                self.xTravel.text = "0"
                self.yTravel.text = "0"
                self.aTravel.text = "0"
                self.bTravel.text = "0"
            elif t.find("G90") != -1:
                global mode
                mode = Gcode.G90()
                print("G90")
                self.terminal.text += t + "\n"
                self.command.text = ""
            elif t.find("G91") != -1:

                mode = Gcode.G91()
                print("G91")
                self.terminal.text += t + "\n"
                self.command.text = ""
            elif t.find("M104") != -1:
                a = t.find("S")
                if a == -1:
                    self.terminal.text += "Command must be in form: M104 S\n"
                    return
                temp = int(t[a + 1:])
                heat, send = Gcode.M104(temp)
                print(heat)
                ser.write(send)
                self.terminal.text += t + "\n"
                self.command.text = ""
            elif t.find("MST") != -1:
                for motor in range(0, 4):
                    b1, b2, b3, b4, b5, b6, b7, b8, b9 = par(
                        1, 3, 0, motor, 0, 0, 0, 0)
                    x = bytearray([b1, b2, b3, b4, b5, b6, b7, b8, b9])
                    ser.write(x)
                print("MST")
                self.terminal.text += t + "\n"
                self.command.text = ""
            elif t == "":
                self.terminal.text += "No command specified\n"
            elif t.find("command") != -1:
                if len(t) > 8:
                    x = t[8:]
                    subprocess.call(x, shell=True)
                else:
                    self.terminal.text += "Must be in form command <com>"
            else:
                self.terminal.text += "Unknown command: " + self.command.text + "\n"
                self.command.text = ""