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

More
14 Aug 2022 03:07 #249692 by my1987toyota
Slight update of the code now P, i, and s output the true Float, Integer, and String when Linuxcnc is loaded through
Terminal

the readable text version
#remap version 12.02
import emccanon
import sys
import interpreter
import csv

            # These Global Variables are mainly intended for M201 but can be used elsewhere
            # these codes can be changed to meet your machines need
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 stabilize


def M201(self, **words):
    print(words)
    P = words['p']       # outputs a Float value
    i = int(words['p'])  # Converts Float value to integer
    s = str(i)           # Converts integer to string

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

    if P < 0:
        print("error, a P parameter must be passed")

    if P > 0:
        print('P = ' , float(P))    # open linuxcnc in terminal to read the float output of 'P'
        print('i = ', int(i))       # open linuxcnc in terminal to read the integer output of 'i'
        print('s = ', (s))          # open linuxcnc in terminal to read the string output of 's'
        print('Going to Feeder' + ' ' + s)
        self.execute('G53 G0' + ' ' + fdrPos[i][1] + ' ' + fdrPos[i][2] + ' ' + 'Z0.0 C0.0')
        self.execute('G53 G1' + ' ' + fdrPos [i][3] + ' ' + feeds1)
        self.execute(vacOn)
        self.execute(pTime)
        self.execute('G53 G1 Z0.0 C0.0' + ' ' + feeds1)
        self.execute('M161 P' + s)




    return interpreter.INTERP_OK

the python file
 

File Attachment:

File Name: remap_12.02.py
File Size:2 KB
Attachments:
The following user(s) said Thank You: tjtr33, tommylight

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

Time to create page: 0.087 seconds
Powered by Kunena Forum