M6 remap in pure python lessons learned

More
01 Nov 2021 13:19 #224874 by bevins

Yeah, I saw the way you call prolog procedure inside the remap function.
Back to the question.
As well as you do I would like to remap M6 command using pure python. U use the interpreter module, emccanon module and linucxnx mudule. For linuxcnc documentation is easy to find and it's pretty good. But for the interpreter module and for emccanon I couldn't find the documentation.
For example, a description of self.params dicirionary is implicit, as well as **words argument.
That is what I hoped you've found and can share with me))

It has been several years since I wrote that code. The machine is still working btw. The documentation I struggled with because there is not alot of info on remapping in pure python. Most of the remapping is geared towards ngc remaps. There are bits and pieces in the remap docs that help. Otherwise you have to look at examples and source code.

The Remap extending Gcode,  section 8. configuring embedded python  has some good info.
You can also try contacting the author of the Remap Michael Halber, (I think his name is), over at MachineKit. I tried contacting him and he never responded, I dont think he is interested in responding to linuxcnc questions on remapping. The MachinKit forum has some topics on remapping in python also.

But all in all, the basic structure is in the docs but the details are in the source code, and your trying different things.

So you have to pull bits and pieces from the ngc remap docs like below. 
re: remap docs:9.5. Calling conventions: Python to NGCNGC code is executed from Python when:
  • the method 
    self.execute(<NGC code>[,<line number>])
     is executed
  • during execution of a remapped code, if a 
    prolog=
     function is defined, the NGC procedure given in 
    ngc=
     is executed immediately thereafter.
The prolog handler does not call the handler, but it prepares its call environment, for instance by setting up predefined local parameters.
Inserting parameters in a prolog, and retrieving them in an epilogConceptually a prolog and an epilog execute at the same call level like the O-word procedure, that is: after the subroutine call is set up, and before the subroutine endsub or return.This means that any local variable created in a prolog will be a local variable in the O-word procedure, and any local variables created in the O-word procedure are still accessible when the epilog executes.The 
self.params
 array handles reading and setting numbered and named parameters. If a named parameter begins with 
_
 (underscore), it is assumed to be a global parameter; if not, it is local to the calling procedure. Also, numbered parameters in the range 1..30 are treated like local variables; their original values are restored on return/endsub from an O-word procedure.Here is an example remapped code demonstrating insertion and extraction of parameters into/from the O-word procedure:
REMAP=m300 prolog=insert_param ngc=testparam epilog=retrieve_param modalgroup=10

So what is it you are trying to do that the NGC remap cannot?

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

More
01 Nov 2021 13:21 #224875 by bevins
I've given up in trying to format this forums posts. It comes out the way it wants to. Sorry for the confusion above in the way it is formatted.

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

More
01 Nov 2021 13:27 - 01 Nov 2021 13:28 #224877 by bevins
Last edit: 01 Nov 2021 13:28 by bevins.

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

More
01 Nov 2021 13:47 #224880 by bazhenov4job
Thanks a lot for your notes!

There is some customization in our device that is hard (or maybe impossible) to drive using standart NGC procedures, mostly based on state analysys on tool change and other remappable codes.

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

More
01 Nov 2021 13:56 #224883 by bevins
ok well, just a hint, try and keep things as simple as possible. Just don't go too deep with nested functions as the interpreter will start ignoring commands.

Also do exhaustive testing, as simple things like having two or three toolchanges in a gcode file  may not work as expected. So make sure you test this stuff well.

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

More
09 Nov 2021 14:09 #225825 by bazhenov4job
May be there is something you can help me to deal with.

I'm trying to read mist and flood state during my remap procedure using linuxcnc.stat() object. But when I run my .ngc file to execute, the state of mist and flood measured equals to its state on the begining of the execution, not on the moment I really want them to be measured. In other words, my script is readahead. I tried to use INTERP_EXEC_FINISH to performe a queuebreaker operation, but failed. Is there any moments in usage of INTERP_EXEC_FINISH you faced and solved, similarly to mine one?

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

More
09 Nov 2021 15:07 #225838 by bevins
Not sure I can be of any help here as most of this is not documented very well. You have to work through it.

Are you polling when requesting the status?
 

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

More
10 Nov 2021 05:38 - 10 Nov 2021 06:10 #225924 by bazhenov4job
Yes, I do.

The interpreter just performs poll simulteneously  to I click "run" button.
Last edit: 10 Nov 2021 06:10 by bazhenov4job.

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

More
17 Nov 2021 23:08 #226806 by andypugh
Not elegant... But you could net the coolant pin to a G0-code digital input and read it with M65.

linuxcnc.org/docs/2.8/html/gcode/m-code.html#mcode:m66

But not, sadly, in pure Python (belatedly reading the title)

You could try reading the HAL pin in Python, though. That might work.

(I am confident that you can read a pin value in Python after "import hal" but I can't remember how, and do recall that the docs on halmodule are something that I have struggled to find in the past.

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

More
17 Nov 2021 23:58 #226811 by bevins
You can check an input in a pure python remap. 

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

Time to create page: 0.149 seconds
Powered by Kunena Forum