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

More
4 years 2 months ago #248924 by my1987toyota
The Title says it all the goal of this post is to use python to
1 remap M201.
2 use a csv. file as a look up table to update part and feeder offsets.
3 Use said offsets to guide the placing head to it's correct location.
4 advance the correct feeder.

This will be a lot of work considering I haven't done much coding in python
add to the fact that since I'm using LCNC 2.8.0 I will have to work in
python 2. Never a dull moment.

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

More
4 years 2 months ago #248977 by andypugh
I think I would start with "import csv" and see what happens.

xkcd.com/353/

And, actually, it looks like a good guess:
docs.python.org/2/library/csv.html
The following user(s) said Thank You: my1987toyota

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

More
4 years 2 months ago - 4 years 2 months ago #248995 by my1987toyota
A while back I had thought about copying and renaming the tool.tbl file and another poster had commented on using csv.
At that time it was way on the back burner. forum.linuxcnc.org/20-g-code/43613-bash-...word?start=30#220957

When I started checking out stuff in the book "Automating The Boring Stuff With Python"  in chapter 14
it talks about csv and Json both have modules for python to work with them. I figured csv would be my best starting point. But I am still
getting way ahead of myself being barely a noob at best.

I thought the xkcd comic was hilarious by the way.
Last edit: 4 years 2 months ago by my1987toyota. Reason: correcting info

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

More
4 years 2 months ago - 4 years 2 months ago #248997 by my1987toyota
Something that will be added WAY down the line on my project will be a GUI to update the locations and keep track of
the status of the feeders. A lot has to happen in between for that to work so we will see. I have been told that one of
the best ways to learn a programming language is through projects . This is as good of place as any. LOL
Last edit: 4 years 2 months ago by my1987toyota.

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

More
4 years 2 months ago - 4 years 2 months ago #249047 by tjtr33
Hello again

Back in 2013 i needed data tables
and found the tool table just didnt do what i wanted

I come from Heidenhain TNC background
where data files are simple flat db files with number names and number line indexes

So i wrote simple flat db files ( whitespace delimited)
that were named as numbers
( this is a key element to use with Mcodes
eg: M1xx PNNNNNNNN QNNN format)
and wrote a python script (M122)
to read file NNNNNNNN (the P parm)
and parse the data on index line NNN ( the Q parm)

limitations:
the data file name is numeric
the line index is numeric
the data can be non numeric
the number of data entries per index have to be same

remember:
hal pins dont like strings, so hand them numeric data

I include an example etab
and a version of the Mcode that prints data read to the terminal running lcnc

you can exercise it (in MDI) from any config you like
that has in the .ini
[RS274NGC]
...
USER_M_PATH = /your/linuxcnc/maybe/-dev/mcodes

with this i get umpteen values per line in the table

hth
tomp

due to restrictions in file extents here on forum
just remove the .txt from the files

edit 07aug2022
to use sumple txt files fro data storage...
in your python script use
Code:
import sys, subprocess

then build your command string
  like 
Code:
cmdstr = "halcmd setp testEtab.0.mypin"
and add the value to be set
  like
Code:
cmdstr = cmdstr + str(myval)
then have the system exec the cmdstr
  like
   
Code:
subprocess.call(cmdstr, shell=True)

loop that recipe thru all the pins to be set

hth tomp

watch in action



 
Last edit: 4 years 2 months ago by tjtr33. Reason: add python subprocess invocation
The following user(s) said Thank You: my1987toyota

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

More
4 years 2 months ago #249154 by my1987toyota
  Thank you tjtr33 I have been looking for examples to get ideas from.
Through my reading on python I have come across both examples
of using csv. and txt. files. Being still very new to python I have a
ways to go. Then add in using it in Linuxcnc and you have multiple
mountains that need to be traversed. So to speak.

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

Time to create page: 0.243 seconds
Powered by Kunena Forum