User input / dialog box in EMC2

  • mp@cnc
  • mp@cnc's Avatar Topic Author
  • Visitor
  • Visitor
21 Jul 2014 17:35 #48997 by mp@cnc
User input / dialog box in EMC2 was created by mp@cnc
Hello everybody !
I'm new to EMC2 and want to know if it is possible to use keyboard input to change the execution of a gcode program. E.g. I want to ask the user if a desired position is reached. Depending on the answer (yes/no) the program will continue with different subroutines.

Thanks for any help!

Regards!

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

More
21 Jul 2014 18:43 #48998 by ArcEye
Hi

Anything is possible, some more difficult than others.

In theory you could have a user M Code which launches a pop up dialog and dependent upon the return value sets a variable, which the program can use to decide a conditional test.
In practice getting values into gcode is hard, perhaps M66 could be used.

Probably need to know exactly what you are thinking of using it for.
Don't quite get the user input as to whether a position has been reached. If the position was commanded and it has not been reached, that is an error?

regards

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

  • mp@cnc
  • mp@cnc's Avatar Topic Author
  • Visitor
  • Visitor
21 Jul 2014 19:17 #48999 by mp@cnc
Replied by mp@cnc on topic User input / dialog box in EMC2
My intention is to measure the height (z) of an uneven surface at different x,y-coordinates. Therefore I will move the tool to a defined x,y-location and then I will step-by-step lower the tool until it touches the surface. After each step the user is asked if the surface is reached. If he answers "no" then the tool is further lowered, otherwise the current z-value is stored and the measurement starts again at the next xy-location.

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

More
21 Jul 2014 19:38 #49000 by ArcEye
Hi

You should look at the probing routines, that can all be done automatically.

www.linuxcnc.org/docs/devel/html/gcode/gcode.html#sec:G38-probe

regards

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

More
22 Jul 2014 07:11 #49005 by andypugh

I'm new to EMC2 and want to know if it is possible to use keyboard input to change the execution of a gcode program. E.g. I want to ask the user if a desired position is reached. Depending on the answer (yes/no) the program will continue with different subroutines.


This seems like it should be easier than it is. Here is one way that I think will work. It takes advantage of the fact that it is possible to set the state of mist-cooling (and other things, but mist seemed likely to be spare) from Python, and it is possible to read back the mist status in G-code (but only in version 2.6+, you will need to upgrade, packages are available from buildbot.linuxcnc.org)

Create a file called M101 (capital M) and place it in nc_files, it needs to be set to executable (right-click, properties, "allow execution") The contents should be
#!/usr/bin/python

import Tkinter
import tkMessageBox
import linuxcnc

if tkMessageBox.askyesno("Finished", "Are we nearly there yet?"):
	linuxcnc.command().mist(1)
	exit(0)

linuxcnc.command()mist(0)
exit(0)

A sample usage g-code file:
M101
O100 if [#<_mist> GT 0.5] 
	G0 X1
O100 else
	G0 X0
O100 endif
M2

I haven't actually tested it :-), the VM I have on this machine is 2.5.4. However it very nearly worked using linuxcnc.command().mdi("#<retval> = 1") and I only abandoned that much neater approach when I realised that would be in "AUTO" mode when running G-code so command().mdi wouldn't be valid.

The docs on the three things used here are:
www.linuxcnc.org/docs/html/gcode/m-code.html#sec:M100-to-M199
www.linuxcnc.org/docs/2.6/html/gcode/ove...ub:system-parameters
linuxcnc.org/docs/html/common/python-int..._linuxcnc_command_tt

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

  • mp@cnc
  • mp@cnc's Avatar Topic Author
  • Visitor
  • Visitor
22 Jul 2014 15:49 #49007 by mp@cnc
Replied by mp@cnc on topic User input / dialog box in EMC2
Wow, that is exactly what I was looking for. :)

Thanks!

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

More
24 Jul 2014 02:19 #49062 by andypugh

Wow, that is exactly what I was looking for. :)


Does it work?

I just realised that I have already written a python routine that creates params on the fly, but I can't figure out where it imported the capability from...

I think it might be the emccanon library, that is not necessarily available in 2.5.4. (But is in 2.6)

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

Time to create page: 0.078 seconds
Powered by Kunena Forum