Example #1
0
def PFOParse(RobotDict, LaserDict, PFOFile):
    print("Begin PFO Parse")
    PFODict = {}
    k = 0
    j = 0

    for key in RobotDict:
        x = RobotDict[key]
        if x.pfonr != 0:
            tree = ET.ElementTree(file=str(PFOFile) + str(x.pfonr) + ".xml")
            Name = tree.find("Name")
            Name = replaceMULT(Name.text, ",", "-")
            Name = Name.lstrip()
            Num = tree.find("Number")
            y = x.pfonr
            PFODict[y] = ClassPFO(Name, Num.text, 0)
            k += 1

    for key in LaserDict:
        x = LaserDict[key].pfo
        for i in range(len(x)):
            tree = ET.ElementTree(file=str(PFOFile) + str(x[i]) + ".xml")
            Name = tree.find("Name")
            Name = replaceMULT(Name.text, ",", "-")
            Name = Name.lstrip()
            Num = tree.find("Number")
            y = x[i]
            PFODict[y] = ClassPFO(Name, Num.text, 0)
            j += 1

    print("PFO parse complete, found ", k,
          " PFOs from ", k, " Global Calls and ", j, " PFOs from ",
          len(LaserDict), " Laser Files")
    return PFODict
Example #2
0
def ListFilter():

    L0 = []
    L1 = []

    with open("Input/ListFilter/In") as index:
        for line in index:
            L0.append(line)
    # with open("Output/RobotProgram/Chevy_2017HD_A.mod.csv") as index:
    #     for line in index:
    #         L0.append(line.split(', '))

        print(L0)

        for i in range(len(L0)):
            L0[i] = str(replaceMULT(L0[i], "'\n'", ""))
            L0[i] = int(replaceMULT(L0[i], "'", ""))
        # for i in range(len(L0)):
        #     L0[i] = int(replaceMULT(L0[i][1],"'",""))

        print(L0)

    for x in L0:
        if x not in L1:
            L1.append(x)

    print(L1)

    with open('./Output/ListFilter/Out', 'w+') as opr:
        for x in L1:
            opr.write(str(x) + '\n')
Example #3
0
def LaserParse(RobotDict, LaserFile, GlobalCall):
    print("Begin Laser Parse")
    LaserDict = {}
    i = 0
    j = 0
    for key in RobotDict:
        if RobotDict[key].lasernr in GlobalCall:
            i += 1
        elif RobotDict[key].lasernr not in GlobalCall:
            pfolist = []
            rotationlist = []
            position = RobotDict[key].position
            tree = ET.ElementTree(file=str(LaserFile) +
                                  str(RobotDict[key].lasernr) + ".xml")
            LaserName = tree.find("ProgName")
            LaserName = replaceMULT(LaserName.text, ", ", "-")
            LaserNum = tree.find("ProgNr")
            for y in tree.findall(
                    "./LaserProgParams/LaserProgParam[ParamName = 'PFOProgNo']/ParamValue"
            ):
                target = int(replaceMULT(y.text, "' ", ""))
                pfolist.append(target)
            for y in tree.findall(
                    "./LaserProgParams/LaserProgParam[ParamName = 'PFORotation']/ParamValue"
            ):
                target = int(replaceMULT(y.text, "' ", ""))
                rotationlist.append(target)

            LaserDict[key] = ClassLaser(position, LaserName, LaserNum.text,
                                        None, pfolist, [], rotationlist)
            j += 1

    print("Laser Parse completed. Discovered " + str(i) +
          " Global Calls and " + str(j) + " Laser Files")
    return LaserDict
Example #4
0
def PFOWrite():
    L0 = []
    with open(
            "C:\Users\vtang\PycharmProjects\LaserUtil\Input\Index\Chevy_2017HD_A"
    ) as index:
        for line in index:
            L0.append(line.split())

    for i in range(len(L0)):
        L0[i][0] = int(replaceMULT(L0[i][0], "'", ""))
        L0[i][1] = int(replaceMULT(L0[i][1], "'", ""))
        L0[i][2] = int(replaceMULT(L0[i][2], "'", ""))
        L0[i][3] = int(replaceMULT(L0[i][3], "'", ""))
        L0[i][4] = int(replaceMULT(L0[i][4], "'", ""))

    for i in range(len(L0)):
        tree = ET.ElementTree(
            file="Input/PFOProgram/AfterDave/L3222M0327_PfoProgram_1_" +
            str(L0[i][3]) + ".xml")

        ProgNr = tree.find('Number')
        print('Updated PFO #' + str(ProgNr.text) + ' to ' + str(L0[i][4]))
        ProgNr.text = str(L0[i][4])

        tree.write("Output/PFOFiles/Chevy_2017HD_A_" + str(L0[i][4]) + ".xml",
                   encoding='UTF-8',
                   xml_declaration=True)
Example #5
0
def LaserParser():
    rawListLaser = []
    laserParsedOut = []

    with open("Output/RobotProgram/BeforeDave/GM2960_S_534New.mod.csv",
              "r") as rawListIn:
        for line in rawListIn:
            rawListLaser.append(line.split(","))

        for i in range(len(rawListLaser)):
            rawListLaser[i] = int(replaceMULT(rawListLaser[i][1], "'", ""))

    for x in range(len(rawListLaser)):

        try:
            with open(
                    "Input/LaserProgram/BeforeDave/L3222M0327_LaserProgram_" +
                    str(rawListLaser[x]) + ".xml") as XmlFile:

                tree = ET.parse(XmlFile)
                root = tree.getroot()

                L0 = []
                L1 = []
                for y in tree.findall(
                        "./LaserProgParams/LaserProgParam[ParamName = 'PFOProgNo']/ParamValue"
                ):
                    L0.append(y.text)

                ProgName = tree.find('ProgName')
                ProgNr = tree.find('ProgNr')

                for i in range(len(L0)):
                    L1 = [
                        x + 1,
                        replaceMULT(ProgName.text, ",", "-"), ProgNr.text,
                        i + 1, L0[i]
                    ]
                    laserParsedOut.append(L1)
                    print('exported line')
        except:
            error = "missing file no or global call: " + str(rawListLaser[x])
            print(error)
            laserParsedOut.append(error)

    # print(laserParsedOut)
    with open("./Output/LaserProgram/BeforeDave/GM2960_S_534New.mod.csv",
              "w") as outfile:
        for i in range(len(laserParsedOut)):
            line = str(laserParsedOut[i])
            line = replaceMULT(line, "()[]'", "") + '\n'
            outfile.write(line)

    print('complete')
Example #6
0
    def GenIndex(RobotDict, LaserDict, PFODict):
        L1 = []

        for key in RobotDict:
            Position = RobotDict[key].position
            RobotLineNr = RobotDict[key].robotlinenr
            Laser = RobotDict[key].lasernr
            PFO = RobotDict[key].pfonr

            if Laser in GlobalCall:
                L1.append([
                    Position, RobotLineNr, Laser, "Global Call", 0, PFO,
                    PFODict[PFO].name
                ])

            else:
                LaserName = LaserDict[Position].name
                LaserPFO = LaserDict[Position].pfo
                for j in range(len(LaserPFO)):
                    L1.append([
                        Position, RobotLineNr, Laser, LaserName, j + 1,
                        LaserPFO[j], PFODict[LaserPFO[j]].name
                    ])

        with open("Output/OriginalIndex/" + str(ProgramName) + ".csv",
                  "w") as OutputFile:
            OutputFile.write(
                "Position,RobotLineNr,Laser,Laser Name,Row,PFO, PFO Name,New Laser,New PFO"
                + "\n")
            for i in range(len(L1)):
                string = replaceMULT(str(L1[i]), "[]'", "") + "\n"
                OutputFile.write(string)

        print("Generated Index File for " + ProgramName)
Example #7
0
def LRD():
    rawListLaser = []
    laserParsedOut = []

    with open("./Input/ParsedRobot/ParsedLaser", "r") as rawListIn:
        for line in rawListIn:
            rawListLaser.append(int(line))

    for x in range(len(rawListLaser)):

        try:
            with open("./Input/LaserProgram/L3222M0327_LaserProgram_" +
                      str(rawListLaser[x]) + ".xml") as XmlFile:

                tree = ET.parse(XmlFile)
                root = tree.getroot()

                L0 = []
                L1 = []
                for y in tree.findall(
                        "./LaserProgParams/LaserProgParam[ParamName = 'PFORotation']/ParamValue"
                ):
                    if y.text != 0:
                        L0.append(y.text)
                        print('found rotation')

                ProgName = tree.find('ProgName')
                ProgNr = tree.find('ProgNr')

                for i in range(len(L0)):
                    L1 = [
                        x + 1,
                        replaceMULT(ProgName.text, ",", "-"), ProgNr.text,
                        i + 1, L0[i]
                    ]
                    laserParsedOut.append(L1)
        except:
            error = "missing file no or global call: " + str(rawListLaser[x])
            print(error)
            laserParsedOut.append(error)

    # print(laserParsedOut)
    with open("./Output/LaserProgram/LaserRotationOut", "w") as outfile:
        for i in range(len(laserParsedOut)):
            line = str(laserParsedOut[i])
            line = replaceMULT(line, "()[]'", "") + '\n'
            outfile.write(line)
Example #8
0
def RobotParse(RobotFile):
    print("Begin robot parse")
    RobotDict = {}
    with open(str(RobotFile), 'r') as robotProgram:
        lines = robotProgram.readlines()
        position = 1
        for linenum in range(len(lines)):
            lines[linenum] = str(lines[linenum].lstrip())
            if lines[linenum].startswith(
                    'rSetLaser_PFO_Prog_Num'):  # keyword query
                sep = lines[linenum].partition(",")
                numL = int(sep[0][-2::].lstrip())
                numP = int(replaceMULT(sep[2][-6::], " ';\n'", ""))
                RobotDict[position] = RobotProgram(position, "rSet", linenum,
                                                   numL, numP)
                position += 1

            elif lines[linenum].startswith(
                    'SetGO LaserProgReq,'):  # keyword query
                if lines[linenum - 1].startswith('SetGO PFOProgReq,'):
                    numL = lines[linenum][-8::]
                    numL = int(replaceMULT(numL, "Req,'\n' ;", ""))
                    numP = lines[linenum - 1][-8::]
                    numP = int(replaceMULT(numP, "Req,'\n' ;", ""))
                    RobotDict[position] = RobotProgram(position, "SetGo2",
                                                       linenum, numL, numP)
                    position += 1
                else:
                    numL = lines[linenum][-8::]
                    numL = int(replaceMULT(numL, "Req,'\n' ;", ""))
                    RobotDict[position] = RobotProgram(position, "SetGo1",
                                                       linenum, numL, 0)
                    position += 1

    unique = []
    repeat = []
    for key in RobotDict:
        if RobotDict[key].lasernr not in unique:
            unique.append(RobotDict[key].lasernr)
        else:
            repeat.append(RobotDict[key].lasernr)

    print("Robot Parse complete. RobotDict generated")
    print("Global Call Detected as:", set(repeat))
    return RobotDict
Example #9
0
def LaserWrite():
    L0 = []
    with open("Input/Index/Chevy_2017HD_B") as index:
        for line in index:
            L0.append(line.split())

    for i in range(len(L0)):
        L0[i][0] = int(replaceMULT(L0[i][0], "'", ""))
        L0[i][1] = int(replaceMULT(L0[i][1], "'", ""))
        L0[i][2] = int(replaceMULT(L0[i][2], "'", ""))
        L0[i][3] = int(replaceMULT(L0[i][3], "'", ""))
        L0[i][4] = int(replaceMULT(L0[i][4], "'", ""))

    for i in range(len(L0)):

        tree = ET.ElementTree(
            file="Input/LaserProgram/AfterDave/L3222M0327_LaserProgram_" +
            str(L0[i][0]) + ".xml")
        tree.write(
            "Output/LaserFiles/TEST_Chevy_2017HD_B_" + str(L0[i][1]) + ".xml",
            "UTF-8")

    for i in range(len(L0)):
        if L0[i][0] != 1:
            tree = ET.ElementTree(
                file="Output/LaserFiles/TEST_Chevy_2017HD_B_" + str(L0[i][1]) +
                ".xml")

            ProgNr = tree.find('ProgNr')
            print('Updated laser #' + str(ProgNr.text) + ' to ' +
                  str(L0[i][1]))
            ProgNr.text = str(L0[i][1])

            for y in tree.findall(
                    "./LaserProgParams/LaserProgParam[ProgRowNr='" +
                    str(L0[i][2]) + "'][ParamName = 'PFOProgNo']/ParamValue"):
                print('found pfo # ' + str(y.text) + ' updated to ' +
                      str(L0[i][4]))
                y.text = str(L0[i][4])

            tree.write(
                "Output/LaserFiles/TEST_Chevy_2017HD_B_" + str(L0[i][1]) +
                ".xml", "UTF-8")