Using M201 and Python to Lookup a CSV Table File and Using It's Values

More
07 Aug 2022 13:52 #249271 by tommylight

I guess I will have to make some more video's of the progress along the way.

I concur ! :)
The following user(s) said Thank You: my1987toyota

Please Log in or Create an account to join the conversation.

More
08 Aug 2022 01:25 - 08 Aug 2022 01:28 #249313 by andypugh
I have had a bit of a play around, and with this as the .csv contents:

Feeder,X,Y
1,0,10
2,0,20
5,1,50
4,1,40

This Python looks to do what is required:

import csv
import sys

P = int(float(sys.argv[1]))

with open('test.csv', newline='') as csvfile:
    data = list(csv.DictReader(csvfile))
    for line in data:
        print(line)
        if int(line["Feeder"]) == P:
            print("self.execute('G0 X{X} Y{Y} Z0 C0')".format(X=line['X'], Y=line['Y']))
            exit(0)
print("Index {} not found".format(P))

I was running this separately from LinuxCNC and so I am printing what the self.execute command should be, rather than doing it...

Example run
iMac:csvtest andypugh$ python3 test.py 2
{'Feeder': '1', 'X': '0', 'Y': '10'}
{'Feeder': '2', 'X': '0', 'Y': '20'}
self.execute('G0 X0 Y20 Z0 C0')

You can see that the csv DictReader has interpreted the first line as a set of keys for a Python Dictionary object.
The code then iterates through each row looking for a row where the "Feeder" value matches the number passed in (at the command line here, but it would be as the P parameter in your remap, as previously done in your example in forum.linuxcnc.org/pnp/46555-using-m2-fo...eeder-advance#248858 using words (note that "words" is another dictionary, and you have used the 'p' key to extract the associated value)

 The bits you need to add to your code is the iteration through the dictionary to find your 'Feeder' and the formatting of the returned values into a string that can be executed.

You might want to use a more "pythonic" search through the list, see for example here: stackoverflow.com/questions/8653516/pyth...-dictionaries-search

You also probably want to strip leading spaces, possibly by defining a dialect as described here:
www.w3resource.com/python-exercises/csv/...n-csv-exercise-6.php
This will allow the header line to be Feeder, X, Y and similarly for the data.
Last edit: 08 Aug 2022 01:28 by andypugh.
The following user(s) said Thank You: my1987toyota

Please Log in or Create an account to join the conversation.

More
10 Aug 2022 01:59 #249436 by my1987toyota
Nice work Andypugh . I haven't messed around with DictReader yet but today this code is what I was working on.
I haven't crossed it over to the M201 code remap yet. I did it this way to simplify preliminary testing.
I hope conversion into the M201 remap wont be too complicated. But it will be a lot of typing. I am sure these codes
scream noobie.

csv file in txt format
Feeder Number,X-axis,Y axis,Z-axis,C-axis
Feeder 1,X0.125,Y-0.5118,Z-0.0,C0.0
Feeder 2,X0.125,Y-1.0235,Z-0.0,C0.0
Feeder 3,X0.125,Y-1.5354,Z-0.0,C0.0
Feeder 4,X0.125,Y-2.0472,Z-0.0,C0.0
Feeder 5,X0.125,Y-2.5590,Z-0.0,C0.0
Feeder 6,X0.125,Y-3.0708,Z-0.0,C0.0
Feeder 7,X0.125,Y-3.5826,Z-0.0,C0.0
Feeder 8,X0.125,Y-4.0994,Z-0.0,C0.0
Feeder 9,X0.125,Y-4.6062,Z-0.0,C0.0
Feeder 10,X0.125,Y-5.1180,Z-0.0,C0.0
Feeder 11,X0.125,Y-5.6298,Z-0.0,C0.0
Feeder 12,X0.125,Y-6.1416,Z-0.0,C0.0
Feeder 13,X0.125,Y-6.6534,Z-0.0,C0.0
Feeder 14,X0.125,Y-7.1652,Z-0.0,C0.0
Feeder 15,X0.125,Y-7.6770,Z-0.0,C0.0
Feeder 16,X0.125,Y-8.1888,Z-0.0,C0.0
Feeder 17,X0.125,Y-8.7006,Z-0.0,C0.0
Feeder 18,X0.125,Y-9.2124,Z-0.0,C0.0
Feeder 19,X0.125,Y-9.7242,Z-0.0,C0.0
Feeder 20,X0.125,Y-10.2360,Z-0.0,C0.0
Feeder 21,X0.125,Y-10.7478,Z-0.0,C0.0
Feeder 22,X0.125,Y-11.2596,Z-0.0,C0.0
Feeder 23,X0.125,Y-11.7714,Z-0.0,C0.0
Feeder 24,X0.125,Y-12.2832,Z-0.0,C0.0
Feeder 25,X15.875,Y-0.5118,Z-0.0,C0.0
Feeder 26,X15.875,Y-1.0235,Z-0.0,C0.0
Feeder 27,X15.875,Y-1.5354,Z-0.0,C0.0
Feeder 28,X15.875,Y-2.0472,Z-0.0,C0.0
Feeder 29,X15.875,Y-2.5590,Z-0.0,C0.0
Feeder 30,X15.875,Y-3.0708,Z-0.0,C0.0
Feeder 31,X15.875,Y-3.5826,Z-0.0,C0.0
Feeder 32,X15.875,Y-4.0994,Z-0.0,C0.0
Feeder 33,X15.875,Y-4.6062,Z-0.0,C0.0
Feeder 34,X15.875,Y-5.1180,Z-0.0,C0.0
Feeder 35,X15.875,Y-5.6298,Z-0.0,C0.0
Feeder 36,X15.875,Y-6.1416,Z-0.0,C0.0
Feeder 37,X15.875,Y-6.6534,Z-0.0,C0.0
Feeder 38,X15.875,Y-7.1652,Z-0.0,C0.0
Feeder 39,X15.875,Y-7.6770,Z-0.0,C0.0
Feeder 40,X15.875,Y-8.1888,Z-0.0,C0.0
Feeder 41,X15.875,Y-8.7006,Z-0.0,C0.0
Feeder 42,X15.875,Y-9.2124,Z-0.0,C0.0
Feeder 43,X15.875,Y-9.7242,Z-0.0,C0.0
Feeder 44,X15.875,Y-10.2360,Z-0.0,C0.0
Feeder 45,X15.875,Y-10.7478,Z-0.0,C0.0
Feeder 46,X15.875,Y-11.2596,Z-0.0,C0.0
Feeder 47,X15.875,Y-11.7714,Z-0.0,C0.0
Feeder 48,X15.875,Y-12.2832,Z-0.0,C0.0

python file in text format
import csv

print(' Choose "P" number ')
P = input()

endCoord = 'Z0.0 C0.0'
prefix1 = 'G53 G0 '
prefix2 = 'G53 G1 '
feeds1 = ' F150'
vacOn = 'M7'
pTime = 'G4 P0.5'
retract = 'G53 G1 Z0.0 F150'

feedersFile = open('feeder_V1.04.csv')
coordinatesReader = csv.reader(feedersFile)
locationData = list(coordinatesReader)

# Side 1 feeders
# the first number in exampleData is row and the second number is column
if P.upper() == 'P1':
    print(prefix1 + locationData[1][1] + ' ' + locationData[1][2] + ' ' + endCoord)
    print(prefix2 + locationData[1][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P1')

if P.upper() == 'P2':
    print(prefix1 + locationData[2][1] + ' ' + locationData[2][2] + ' ' + endCoord)
    print(prefix2 + locationData[2][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P2')

if P.upper() == 'P3':
    print(prefix1 + locationData[3][1] + ' ' + locationData[3][2] + ' ' + endCoord)
    print(prefix2 + locationData[3][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P3')

if P.upper() == 'P4':
    print(prefix1 + locationData[4][1] + ' ' + locationData[4][2] + ' ' + endCoord)
    print(prefix2 + locationData[4][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P4')

if P.upper() == 'P5':
    print(prefix1 + locationData[5][1] + ' ' + locationData[5][2] + ' ' + endCoord)
    print(prefix2 + locationData[5][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P5')

if P.upper() == 'P6':
    print(prefix1 + locationData[6][1] + ' ' + locationData[6][2] + ' ' + endCoord)
    print(prefix2 + locationData[6][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P6')

if P.upper() == 'P7':
    print(prefix1 + locationData[7][1] + ' ' + locationData[7][2] + ' ' + endCoord)
    print(prefix2 + locationData[7][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P7')

if P.upper() == 'P8':
    print(prefix1 + locationData[8][1] + ' ' + locationData[8][2] + ' ' + endCoord)
    print(prefix2 + locationData[8][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P8')

if P.upper() == 'P9':
    print(prefix1 + locationData[9][1] + ' ' + locationData[9][2] + ' ' + endCoord)
    print(prefix2 + locationData[9][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P9')

if P.upper() == 'P10':
    print(prefix1 + locationData[10][1] + ' ' + locationData[10][2] + ' ' + endCoord)
    print(prefix2 + locationData[10][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P10')

if P.upper() == 'P11':
    print(prefix1 + locationData[11][1] + ' ' + locationData[11][2] + ' ' + endCoord)
    print(prefix2 + locationData[11][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P11')

if P.upper() == 'P12':
    print(prefix1 + locationData[12][1] + ' ' + locationData[12][2] + ' ' + endCoord)
    print(prefix2 + locationData[12][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P12')

if P.upper() == 'P13':
    print(prefix1 + locationData[13][1] + ' ' + locationData[13][2] + ' ' + endCoord)
    print(prefix2 + locationData[13][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P13')

if P.upper() == 'P14':
    print(prefix1 + locationData[14][1] + ' ' + locationData[14][2] + ' ' + endCoord)
    print(prefix2 + locationData[14][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P14')

if P.upper() == 'P15':
    print(prefix1 + locationData[15][1] + ' ' + locationData[15][2] + ' ' + endCoord)
    print(prefix2 + locationData[15][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P15')

if P.upper() == 'P16':
    print(prefix1 + locationData[16][1] + ' ' + locationData[16][2] + ' ' + endCoord)
    print(prefix2 + locationData[16][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P16')

if P.upper() == 'P17':
    print(prefix1 + locationData[17][1] + ' ' + locationData[17][2] + ' ' + endCoord)
    print(prefix2 + locationData[17][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P17')


if P.upper() == 'P18':
    print(prefix1 + locationData[18][1] + ' ' + locationData[18][2] + ' ' + endCoord)
    print(prefix2 + locationData[18][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P18')

if P.upper() == 'P19':
    print(prefix1 + locationData[19][1] + ' ' + locationData[19][2] + ' ' + endCoord)
    print(prefix2 + locationData[19][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 19')

if P.upper() == 'P20':
    print(prefix1 + locationData[20][1] + ' ' + locationData[20][2] + ' ' + endCoord)
    print(prefix2 + locationData[20][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P20')

if P.upper() == 'P21':
    print(prefix1 + locationData[21][1] + ' ' + locationData[21][2] + ' ' + endCoord)
    print(prefix2 + locationData[21][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P21')

if P.upper() == 'P22':
    print(prefix1 + locationData[22][1] + ' ' + locationData[22][2] + ' ' + endCoord)
    print(prefix2 + locationData[22][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P22')

if P.upper() == 'P23':
    print(prefix1 + locationData[23][1] + ' ' + locationData[23][2] + ' ' + endCoord)
    print(prefix2 + locationData[23][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P23')


if P.upper() == 'P24':
    print(prefix1 + locationData[24][1] + ' ' + locationData[24][2] + ' ' + endCoord)
    print(prefix2 + locationData[24][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P24')


# Side 2 feeders

if P.upper() == 'P25':
    print(prefix1 + locationData[25][1] + ' ' + locationData[25][2] + ' ' + endCoord)
    print(prefix2 + locationData[25][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P25')

if P.upper() == 'P26':
    print(prefix1 + locationData[26][1] + ' ' + locationData[26][2] + ' ' + endCoord)
    print(prefix2 + locationData[26][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P26')

if P.upper() == 'P27':
    print(prefix1 + locationData[27][1] + ' ' + locationData[27][2] + ' ' + endCoord)
    print(prefix2 + locationData[27][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P27')

if P.upper() == 'P28':
    print(prefix1 + locationData[28][1] + ' ' + locationData[28][2] + ' ' + endCoord)
    print(prefix2 + locationData[28][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P28')

if P.upper() == 'P29':
    print(prefix1 + locationData[29][1] + ' ' + locationData[29][2] + ' ' + endCoord)
    print(prefix2 + locationData[29][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P29')

if P.upper() == 'P30':
    print(prefix1 + locationData[30][1] + ' ' + locationData[30][2] + ' ' + endCoord)
    print(prefix2 + locationData[30][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P30')

if P.upper() == 'P31':
    print(prefix1 + locationData[31][1] + ' ' + locationData[31][2] + ' ' + endCoord)
    print(prefix2 + locationData[31][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P31')

if P.upper() == 'P32':
    print(prefix1 + locationData[32][1] + ' ' + locationData[32][2] + ' ' + endCoord)
    print(prefix2 + locationData[32][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P32')

if P.upper() == 'P33':
    print(prefix1 + locationData[33][1] + ' ' + locationData[33][2] + ' ' + endCoord)
    print(prefix2 + locationData[33][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P33')

if P.upper() == 'P34':
    print(prefix1 + locationData[34][1] + ' ' + locationData[34][2] + ' ' + endCoord)
    print(prefix2 + locationData[34][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P34')

if P.upper() == 'P35':
    print(prefix1 + locationData[35][1] + ' ' + locationData[35][2] + ' ' + endCoord)
    print(prefix2 + locationData[35][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P35')

if P.upper() == 'P36':
    print(prefix1 + locationData[36][1] + ' ' + locationData[36][2] + ' ' + endCoord)
    print(prefix2 + locationData[36][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P36')

if P.upper() == 'P37':
    print(prefix1 + locationData[37][1] + ' ' + locationData[37][2] + ' ' + endCoord)
    print(prefix2 + locationData[37][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P37')

if P.upper() == 'P38':
    print(prefix1 + locationData[38][1] + ' ' + locationData[38][2] + ' ' + endCoord)
    print(prefix2 + locationData[38][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P38')

if P.upper() == 'P39':
    print(prefix1 + locationData[39][1] + ' ' + locationData[39][2] + ' ' + endCoord)
    print(prefix2 + locationData[39][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P39')

if P.upper() == 'P40':
    print(prefix1 + locationData[40][1] + ' ' + locationData[40][2] + ' ' + endCoord)
    print(prefix2 + locationData[40][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P40')

if P.upper() == 'P41':
    print(prefix1 + locationData[41][1] + ' ' + locationData[41][2] + ' ' + endCoord)
    print(prefix2 + locationData[41][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P41')

if P.upper() == 'P42':
    print(prefix1 + locationData[42][1] + ' ' + locationData[42][2] + ' ' + endCoord)
    print(prefix2 + locationData[42][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P42')

if P.upper() == 'P43':
    print(prefix1 + locationData[43][1] + ' ' + locationData[43][2] + ' ' + endCoord)
    print(prefix2 + locationData[43][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P43')

if P.upper() == 'P44':
    print(prefix1 + locationData[44][1] + ' ' + locationData[44][2] + ' ' + endCoord)
    print(prefix2 + locationData[44][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P44')

if P.upper() == 'P45':
    print(prefix1 + locationData[45][1] + ' ' + locationData[45][2] + ' ' + endCoord)
    print(prefix2 + locationData[45][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P45')

if P.upper() == 'P46':
    print(prefix1 + locationData[46][1] + ' ' + locationData[46][2] + ' ' + endCoord)
    print(prefix2 + locationData[46][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P46')

if P.upper() == 'P47':
    print(prefix1 + locationData[47][1] + ' ' + locationData[47][2] + ' ' + endCoord)
    print(prefix2 + locationData[47][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P47')

if P.upper() == 'P48':
    print(prefix1 + locationData[48][1] + ' ' + locationData[48][2] + ' ' + endCoord)
    print(prefix2 + locationData[48][3] + feeds1)
    print(vacOn)
    print(pTime)
    print(retract)
    print('M161 P48')

csv code file in txt format . just reformat to csv to use.
 

File Attachment:

File Name: feeder_V1.04.txt
File Size:2 KB


python file

 

File Attachment:

File Name: example_cs...er_02.py
File Size:12 KB

 
Attachments:

Please Log in or Create an account to join the conversation.

More
10 Aug 2022 02:29 - 10 Aug 2022 03:20 #249437 by my1987toyota
For those curious about how I got the code this is based off of see the book " Automate the Boring Stuff With Python" by Al Sweigart
link below to his free to read online version of the book released under Creative Commons License. See chapter 16

automatetheboringstuff.com/#toc

 
Last edit: 10 Aug 2022 03:20 by my1987toyota. Reason: updating info
The following user(s) said Thank You: tjtr33, tommylight

Please Log in or Create an account to join the conversation.

More
11 Aug 2022 17:07 - 11 Aug 2022 21:26 #249536 by my1987toyota
Well looks like I still have a lot to learn. The code works great in Python ide's but I keep getting an error in Linuxcnc when I tried to cross it over.
The error is
UnboundLocalError.local variable 'prefix1'
referenced before assignment

first I will have to look up what that means and then rework the code to correct it. I will most likely need to check into what andypugh posted
about dict.reader and rewrite accordingly.

The Faulty code is below

 

File Attachment:

File Name: remap_10.py
File Size:15 KB


just remove the _10 if testing in Linuxcnc otherwise Python don't care.

the csv file is in text format . just replace the extension with csv to return it to a csv file
 

File Attachment:

File Name: feeder_V1....8-11.txt
File Size:2 KB
Attachments:
Last edit: 11 Aug 2022 21:26 by my1987toyota.

Please Log in or Create an account to join the conversation.

More
11 Aug 2022 19:48 #249546 by rodw
 
Try adding
prefix1=''
prefix2=''
before your if statement
The errror message is telling you whats wrong.
You are creating your variables in the if statement.
in your elif statements you are trying to manipulate a variable that has not been created which obviously will not work
 
The following user(s) said Thank You: my1987toyota

Please Log in or Create an account to join the conversation.

More
11 Aug 2022 19:56 #249547 by rodw
Actually all of your variables are being defined inside the if statement. You likely need to move this block to be above the if statement.
# these codes can be taylored to your machine if needed
        endCoord = 'Z0.0 C0.0'    # G_codes to ensure Z and C axis are in there 0 position
        prefix1 = 'G53 G0 '    # machine coordinate system and G0 rapid move
        prefix2 = 'G53 G1 '    # machine coordinate system and G1 move
        feeds1 = ' F150'    # feed value for Z to pick up part
        vacOn = 'M7'    # M_code for turning on vaccum
        pTime = 'G4 P0.5'   # G_code for pause time to allow vaccum to asstablish
        retract = 'G53 G1 Z0.0 F150'    # Z retract speed with part attatched
        fdrCycl = 'M161 '   # M_code for feeder advance
In fact, you probably would move it to be above this line so its only executed once (eg as global variables) instead of each time the procedure is called.
def M201(self, **words):
The following user(s) said Thank You: tommylight, my1987toyota

Please Log in or Create an account to join the conversation.

More
11 Aug 2022 21:50 - 12 Aug 2022 12:37 #249556 by my1987toyota
Hit the nail on the head rodw.
I actually had to chase down a few other error's as well in my above code to get it to work  You are right Rod The main
one was I had to move the csv read code to be a global instead of a local. ( I didn't know anyone had replied to
my above post until after I posted this post). I am glad I didn't have to do a complete rewrite of my python code.

I had to correct a small error in this post but apparently the forum software decided to completely butcher the codes posted.
I will be posting just the codes in the next reply.
Attachments:
Last edit: 12 Aug 2022 12:37 by my1987toyota. Reason: correcting the mess the forum software made of my post
The following user(s) said Thank You: tommylight, rodw

Please Log in or Create an account to join the conversation.

More
11 Aug 2022 23:47 - 12 Aug 2022 12:40 #249564 by my1987toyota
  The working M201 Python script
 

File Attachment:

File Name: remap_11.0...08-12.py
File Size:14 KB



The CSV file
 

File Attachment:

File Name: feeder_V1....8-12.txt
File Size:2 KB
Attachments:
Last edit: 12 Aug 2022 12:40 by my1987toyota. Reason: correcting the major botch job from the forum software

Please Log in or Create an account to join the conversation.

More
12 Aug 2022 12:47 #249585 by my1987toyota
Now in readable format
M201
#remap version 11.02
import emccanon
import sys
import interpreter
import csv

feedersFile = open('feeder_V1.04.csv')
coordinatesReader = csv.reader(feedersFile)
locationData = list(coordinatesReader)
fdrPos = locationData

        # these codes can be changed to meet your machines needs
endCoord = 'Z0.0 C0.0'    # G_codes to ensure Z and C axis are in there 0 position
prefix1 = 'G53 G0 '    # machine coordinate system and G0 rapid move
prefix2 = 'G53 G1 '    # machine coordinate system and G1 move
feeds1 = ' F150'    # feed value for Z to pick up part
vacOn = 'M7'    # M_code for turning on vaccum
pTime = 'G4 P0.5'   # G_code for pause time to allow vaccum to asstablish
retract = 'G53 G1 Z0.0 F150'    # Z retract speed with part attatched
fdrCycl = 'M161 P'   # M_code to advance the feeder



def M201(self, **words):
    print(words)
    P = words['p']
    print(P)
    if P < 0:
        print("error, a P parameter must be passed")


#side 1 feeders

    elif P == 1:
        self.execute(prefix1 + fdrPos[1][1] + ' ' + fdrPos[1][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos [1][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '1')

    elif P == 2:
        self.execute(prefix1 + fdrPos[2][1] + ' ' + fdrPos[2][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[2][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '2')

    elif P == 3:
        self.execute(prefix1 + fdrPos[3][1] + ' ' + fdrPos[3][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[3][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '3')

    elif P == 4:
        self.execute(prefix1 + fdrPos[4][1] + ' ' + fdrPos[4][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[4][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '4')

    elif P == 5:
        self.execute(prefix1 + fdrPos[5][1] + ' ' + fdrPos[5][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[5][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '5')

    elif P == 6:
        self.execute(prefix1 + fdrPos[6][1] + ' ' + fdrPos[6][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[6][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '6')

    elif P == 7:
        self.execute(prefix1 + fdrPos[7][1] + ' ' + fdrPos[7][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[7][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '7')

    elif P == 8:
        self.execute(prefix1 + fdrPos[8][1] + ' ' + fdrPos[8][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[8][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '8')

    elif P == 9:
        self.execute(prefix1 + fdrPos[9][1] + ' ' + fdrPos[9][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[9][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '9')

    elif P == 10:
        self.execute(prefix1 + fdrPos[10][1] + ' ' + fdrPos[10][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[10][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '10')

    elif P == 11:
        self.execute(prefix1 + fdrPos[11][1] + ' ' + fdrPos[11][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[11][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '11')

    elif P == 12:
        self.execute(prefix1 + fdrPos[12][1] + ' ' + [12][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[12][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '12')

    elif P == 13:
        self.execute(prefix1 + fdrPos[13][1] + ' ' + fdrPos[13][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[13][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '13')

    elif P == 14:
        self.execute(prefix1 + fdrPos[14][1] + ' ' + fdrPos[14][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[14][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '14')

    elif P == 15:
        self.execute(prefix1 + fdrPos[15][1] + ' ' + fdrPos[15][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[15][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '15')

    elif P == 16:
        self.execute(prefix1 + fdrPos[16][1] + ' ' + fdrPos[16][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[16][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '16')

    elif P == 17:
        self.execute(prefix1 + fdrPos[17][1] + ' ' + fdrPos[17][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[17][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '17')

    elif P == 18:
        self.execute(prefix1 + fdrPos[18][1] + ' ' + fdrPos[18][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[18][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '18')

    elif P == 19:
        self.execute(prefix1 + fdrPos[19][1] + ' ' + fdrPos[19][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[19][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '19')

    elif P == 20:
        self.execute(prefix1 + fdrPos[20][1] + ' ' + fdrPos[20][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[20][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '20')

    elif P == 21:
        self.execute(prefix1 + fdrPos[21][1] + ' ' + fdrPos[21][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[21][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '21')

    elif P == 22:
        self.execute(prefix1 + fdrPos[22][1] + ' ' + fdrPos[22][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[22][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '22')

    elif P == 23:
        self.execute(prefix1 + fdrPos[23][1] + ' ' + fdrPos[23][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[23][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '23')

    elif P == 24:
        self.execute(prefix1 + fdrPos[24][1] + ' ' + fdrPos[24][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[24][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '24')

#side 2 feeders

    elif P == 25:
        self.execute(prefix1 + fdrPos[25][1] + ' ' + fdrPos[25][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[25][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '25')

    elif P == 26:
        self.execute(prefix1 + fdrPos[26][1] + ' ' + fdrPos[26][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[26][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '26')

    elif P == 27:
        self.execute(prefix1 + fdrPos[27][1] + ' ' + fdrPos[27][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[27][3] + feeds1)
        self.executevacOn(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '27')

    elif P == 28:
        self.execute(prefix1 + fdrPos[28][1] + ' ' + fdrPos[28][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[28][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '28')

    elif P == 29:
        self.execute(prefix1 + fdrPos[29][1] + ' ' + fdrPos[29][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[29][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '29')

    elif P == 30:
        self.execute(prefix1 + fdrPos[30][1] + ' ' + fdrPos[30][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[30][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '30')

    elif P == 31:
        self.execute(prefix1 + fdrPos[31][1] + ' ' + fdrPos[31][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[31][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '31')

    elif P == 32:
        self.execute(prefix1 + fdrPos[32][1] + ' ' + fdrPos[32][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[32][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '32')

    elif P == 33:
        self.execute(prefix1 + fdrPos[33][1] + ' ' + fdrPos[33][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[33][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '33')

    elif P == 34:
        self.execute(prefix1 + fdrPos[34][1] + ' ' + fdrPos[34][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[34][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '34')

    elif P == 35:
        self.execute(prefix1 + fdrPos[35][1] + ' ' + fdrPos[35][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[35][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '35')

    elif P == 36:
        self.execute(prefix1 + fdrPos[36][1] + ' ' + fdrPos[36][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[36][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '36')

    elif P == 37:
        self.execute(prefix1 + fdrPos[37][1] + ' ' + fdrPos[37][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[37][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '37')

    elif P == 38:
        self.execute(prefix1 + fdrPos[38][1] + ' ' + fdrPos[38][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[38][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '38')

    elif P == 39:
        self.execute(prefix1 + fdrPos[39][1] + ' ' + fdrPos[39][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[39][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '39')

    elif P == 40:
        self.execute(prefix1 + fdrPos[40][1] + ' ' + fdrPos[40][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[40][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '40')

    elif P == 41:
        self.execute(prefix1 + fdrPos[41][1] + ' ' + fdrPos[41][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[41][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '41')

    elif P == 42:
        self.execute(prefix1 + fdrPos[42][1] + ' ' + fdrPos[42][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[42][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '42')

    elif P == 43:
        self.execute(prefix1 + fdrPos[43][1] + ' ' + fdrPos[43][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[43][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '43')

    elif P == 44:
        self.execute(prefix1 + fdrPos[44][1] + ' ' + fdrPos[44][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[44][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '44')

    elif P == 45:
        self.execute(prefix1 + fdrPos[45][1] + ' ' + fdrPos[45][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[45][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '45')

    elif P == 46:
        self.execute(prefix1 + fdrPos[46][1] + ' ' + fdrPos[46][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[46][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '46')

    elif P == 47:
        self.execute(prefix1 + fdrPos[47][1] + ' ' + fdrPos[47][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[47][3] + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '47')

    elif P == 48:
        self.execute(prefix1 + fdrPos[48][1] + ' ' + fdrPos[48][2] + ' ' + endCoord)
        self.execute(prefix2 + fdrPos[48][3] + feeds1)
        self.execut(vacOn)
        self.execute(pTime)
        self.execute(retract)
        self.execute(fdrCycl + '48')


    return interpreter.INTERP_OK


The feeder_V1.04 csv file
Feeder Number,X-axis,Y axis,Z-axis,C-axis
Feeder 1,X0.125,Y-0.5118,Z-0.0,C0.0
Feeder 2,X0.125,Y-1.0235,Z-0.0,C0.0
Feeder 3,X0.125,Y-1.5354,Z-0.0,C0.0
Feeder 4,X0.125,Y-2.0472,Z-0.0,C0.0
Feeder 5,X0.125,Y-2.5590,Z-0.0,C0.0
Feeder 6,X0.125,Y-3.0708,Z-0.0,C0.0
Feeder 7,X0.125,Y-3.5826,Z-0.0,C0.0
Feeder 8,X0.125,Y-4.0994,Z-0.0,C0.0
Feeder 9,X0.125,Y-4.6062,Z-0.0,C0.0
Feeder 10,X0.125,Y-5.1180,Z-0.0,C0.0
Feeder 11,X0.125,Y-5.6298,Z-0.0,C0.0
Feeder 12,X0.125,Y-6.1416,Z-0.0,C0.0
Feeder 13,X0.125,Y-6.6534,Z-0.0,C0.0
Feeder 14,X0.125,Y-7.1652,Z-0.0,C0.0
Feeder 15,X0.125,Y-7.6770,Z-0.0,C0.0
Feeder 16,X0.125,Y-8.1888,Z-0.0,C0.0
Feeder 17,X0.125,Y-8.7006,Z-0.0,C0.0
Feeder 18,X0.125,Y-9.2124,Z-0.0,C0.0
Feeder 19,X0.125,Y-9.7242,Z-0.0,C0.0
Feeder 20,X0.125,Y-10.2360,Z-0.0,C0.0
Feeder 21,X0.125,Y-10.7478,Z-0.0,C0.0
Feeder 22,X0.125,Y-11.2596,Z-0.0,C0.0
Feeder 23,X0.125,Y-11.7714,Z-0.0,C0.0
Feeder 24,X0.125,Y-12.2832,Z-0.0,C0.0
Feeder 25,X15.875,Y-0.5118,Z-0.0,C0.0
Feeder 26,X15.875,Y-1.0235,Z-0.0,C0.0
Feeder 27,X15.875,Y-1.5354,Z-0.0,C0.0
Feeder 28,X15.875,Y-2.0472,Z-0.0,C0.0
Feeder 29,X15.875,Y-2.5590,Z-0.0,C0.0
Feeder 30,X15.875,Y-3.0708,Z-0.0,C0.0
Feeder 31,X15.875,Y-3.5826,Z-0.0,C0.0
Feeder 32,X15.875,Y-4.0994,Z-0.0,C0.0
Feeder 33,X15.875,Y-4.6062,Z-0.0,C0.0
Feeder 34,X15.875,Y-5.1180,Z-0.0,C0.0
Feeder 35,X15.875,Y-5.6298,Z-0.0,C0.0
Feeder 36,X15.875,Y-6.1416,Z-0.0,C0.0
Feeder 37,X15.875,Y-6.6534,Z-0.0,C0.0
Feeder 38,X15.875,Y-7.1652,Z-0.0,C0.0
Feeder 39,X15.875,Y-7.6770,Z-0.0,C0.0
Feeder 40,X15.875,Y-8.1888,Z-0.0,C0.0
Feeder 41,X15.875,Y-8.7006,Z-0.0,C0.0
Feeder 42,X15.875,Y-9.2124,Z-0.0,C0.0
Feeder 43,X15.875,Y-9.7242,Z-0.0,C0.0
Feeder 44,X15.875,Y-10.2360,Z-0.0,C0.0
Feeder 45,X15.875,Y-10.7478,Z-0.0,C0.0
Feeder 46,X15.875,Y-11.2596,Z-0.0,C0.0
Feeder 47,X15.875,Y-11.7714,Z-0.0,C0.0
Feeder 48,X15.875,Y-12.2832,Z-0.0,C0.0

Please Log in or Create an account to join the conversation.

Time to create page: 0.102 seconds
Powered by Kunena Forum