namedparams how to ?

More
28 Apr 2021 19:50 #207324 by Earlton2
2021: linuxcnc/axis version 2.7.15
I was trying to create a named parameter #<_random.py>, but first testing the #<_pi.py> example from the manual:
LinuxCNC V2.7.14-71-g77389eb, 2019-01-08
I have created a file namedparams.py in ../linuxcnc/nc_files but just in case namedparams is a generic name I also added:
_pi.py, pi.py, PI.PY all of which contain the same code:
def _pi(self):
return 3.1415926535

Q1: is namedparams.py the correct name?
Q2: can namedparams.py contain more than one definition?
Q3. do I have it in the proper folder re: "add a namedparams module so it can be found by the interpreter."

Q4. what is the what, where, when ... re: "import the module from the top level script."
I have tried ;py,"from namedparams import *" and ;py,from namedparams import *

My ngc file contains:
;py,import sys
;py,sys.path.append('/home/cnc/linuxcnc/nc_files')
;py,from namedparams import *

no errors are apparent from the above but:

#<rr> = #<_pi>

gives: named parameter #<_pi> not defined

My g-code cuts out the front of a birdhouse to look like a series of books, some leaning over. The random number was to be applied to the height and width of each book. The third book is determined by the size of the door hole which sits atop it.

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

More
29 Apr 2021 00:29 - 29 Apr 2021 00:30 #207343 by BigJohnT
Replied by BigJohnT on topic namedparams how to ?
A named parameter is just a placeholder for a value.

linuxcnc.org/docs/2.7/html/gcode/overvie...ml#_named_parameters

An example global named parameter
#<_endmill_dia> = 0.049

If your trying to execute a program which it seems you do using .py you need to look at M1xx user defined commands.

linuxcnc.org/docs/2.7/html/gcode/m-code.html#mcode:m100-m199

In a ngc file anything that follows a semi-colon is a comment.

JT
Last edit: 29 Apr 2021 00:30 by BigJohnT.

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

More
30 Apr 2021 20:07 #207478 by Earlton2
Replied by Earlton2 on topic namedparams how to ?
Thanks John but I was playing with the 'remap' operation listed under www.linuxcnc.org/docs/html/remap/remap.html and have run through the initialization of my .../congfig/xxx/python directory. For sure my linuxcnc installation includes the stdglue.py file at /usr/share/linuxcnc/ncfiles/remap_lib/python-stdglue/stdglue.py The _pi() user definition is one of their examples. i.e. def _pi(self): return 3.1415926535 so I'm still hoping for a similar _random(self)...
Of course I don't understand a word of it but we must live in hope!

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

More
30 Apr 2021 22:05 #207494 by BigJohnT
Replied by BigJohnT on topic namedparams how to ?
I've never messed with remap so I can't help with that... someone else will have to step in.

JT

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

More
01 May 2021 22:06 #207582 by andypugh
Replied by andypugh on topic namedparams how to ?
The handler code that creates your named parameters will only run as part of a remap.

ie, just referring to the parameter in the G-code will not cause any code to run.

You could remap a G or M-code such that it runs your Python to create the parameter and give it a value, but it seems a rather roundabout way to do it.

It seems that what you are trying to do is equivalent to creating a custom function. I don't think that LinuxCNC has any sensible way to do that, so perhaps roundabout ways are the only ways.

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

Time to create page: 0.313 seconds
Powered by Kunena Forum