NC Macros start from the GUI

More
3 years 1 month ago #281000 by mBender
Hi all, 

I have written a few macros which I want to start from the GUI. I am fine with the pyvcp part, But how do I get a specific NC Programm as a Hal pin? I know it’s possible, saw it in a video on YouTube, but can’t find that video and can’t find it in the documentation either. 

Mike

Please Log in to join the conversation.

More
3 years 1 month ago #281002 by Aciera
Replied by Aciera on topic NC Macros start from the GUI
Add the MDI-Command to call your macros to the [HALUI] section of your ini file:


MDI_COMMAND = " your first command here (this will be halui.mdi-command-00)
MDI_COMMAND = " your second command here (this will be halui.mdi-command-01)
...

Then create the hal connection in your 'postguihal' file:

net :type0-button <= pyvcp.type0-button => halui.mdi-command-00
net :type1-button <= pyvcp.type1-button => halui.mdi-command-01
...

Please Log in to join the conversation.

More
3 years 1 month ago #281223 by mBender
Thanks, that all worked out. I have a few questions:

1. How can I contribute to the documentation of LinuxCNC? I don't see it on Github,... I would love to add some comments to it.

3. I was able to call a subroutine and use a GUI variable to work within this subroutine. My question is: I thought I could give a subroutine a parameter/variable when I call the subroutine. However, I can not find a good example or documentation on how to do that.

I currently have solved it with having the hal pin variable directly in the subroutine. My subroutine and ini call below:

My file probeximinus.ngc
Code:
o<probexminus> sub                              ; Beginning of subprogram probexminus N10 G91 G38.2 x-20 F100                         ; Go fast to workpiece until Probe pin changes signal N20 G1 x1 F900                                  ; Retract 1mm N30 G91 G38.2 x-3 F10                           ; Go slow to workpiece until Probe pin changes signal N40 G1 x#<_hal[pyvcp.retract-distance-f]> F900  ; Retract according to GUI variable o<probexminus> endsub                           ; End of subprogram M99                                             ; Return from subprogram 100

My current ini call looks like this:
Code:
MDI_COMMAND = O<probexminus> CALL

What I would like is something like is:
Code:
MDI_COMMAND = O<probexminus> #<_hal[pyvcp.retract-distance-f]> CALL

With this subroutine:
Code:
o<probexminus> sub                              ; Beginning of subprogram probexminus #1 = #<_hal[pyvcp.retract-distance-f]> N10 G91 G38.2 x-20 F100                         ; Go fast to workpiece until Probe pin changes signal N20 G1 x1 F900                                  ; Retract 1mm N30 G91 G38.2 x-3 F10                           ; Go slow to workpiece until Probe pin changes signal N40 G1 x#1 F900  ; Retract according to GUI variable o<probexminus> endsub                           ; End of subprogram M99                                             ; Return from subprogram 100

However, that does not work.

Please Log in to join the conversation.

More
3 years 1 month ago #281240 by Aciera
Replied by Aciera on topic NC Macros start from the GUI
1. Have a look in the 'man' folders (man1, man3, man9):
github.com/LinuxCNC/linuxcnc/tree/master/docs/man

3. Yes you can pass parameter values with an o-call. Have a look at 'configs/sim/axis/vismach/5axis/table-rotary-tilting/demos/xyzac_switchkins.ngc':
Code:
;                                               zmax zmin r   frate n  a   b  c   dist o<xyzac_switchkins_sub> call [10] [5]  [10][1000][3][20][0][45][20] m2

With 'configs/sim/axis/vismach/5axis/table-rotary-tilting/remap_subs/xyzac_switchkins_sub.ngc':
Code:
; ngcgui-compatible subroutine (info: helix in each quadrant at angles A,C) o<xyzac_switchkins_sub>sub    #<zmax> = #1 (=10)    #<zmin> = #2 (= 5)       #<r> = #3 (=10 radius)   #<frate> = #4 (=1000 feedrate)       #<n> = #5 (=3  n circles)       #<a> = #6 (=30 A angle)       #<b> = #7 (=0  B angle NA)       #<c> = #8 (=45 C angle)    #<dist> = #9 (=20 distance) ; quadrant I M429                            ;Identity kinematics g53 g0   x0y0 z#<zmax> a0 c0    ;MACHINE coordinates g10l20p0 x0y0 z#<zmax> a0 c0    ;new g54 g0 x+#<dist> y+#<dist> z#<zmax> ;move to pattern center position o<helix_ac> call [#<zmax>][#<zmin>][#<r>][#<frate>][#<n>][#<a>][#<b>][#<c>] ; quadrant II M429                            ;Identity kinematics g53 g0   x0y0 z#<zmax> a0 c0 g10l20p0 x0y0 z#<zmax> a0 c0 g0 x-#<dist> y+#<dist> z#<zmax> o<helix_ac> call [#<zmax>][#<zmin>][#<r>][#<frate>][#<n>][#<a>][#<b>][#<c>] ; quadrant III M429                            ;Identity kinematics g53 g0   x0y0 z#<zmax> a0 c0 g10l20p0 x0y0 z#<zmax> a0 c0 g0 x-#<dist> y-#<dist> z#<zmax> o<helix_ac> call [#<zmax>][#<zmin>][#<r>][#<frate>][#<n>][#<a>][#<b>][#<c>] ; quadrant IV M429                            ;Identity kinematics g53 g0   x0y0 z#<zmax> a0 c0 g10l20p0 x0y0 z#<zmax> a0 c0 g0 x+#<dist> y-#<dist> z#<zmax> o<helix_ac> call [#<zmax>][#<zmin>][#<r>][#<frate>][#<n>][#<a>][#<b>][#<c>] ;final position M429                            ;Identity kinematics g53 g0   x0y0 z#<zmax> ;MACHINE coordinates g10l20p0 x0y0 z#<zmax> ;new g54 o<xyzac_switchkins_sub>endsub

Please Log in to join the conversation.

More
3 years 1 month ago #281242 by Aciera
Replied by Aciera on topic NC Macros start from the GUI
Documentation on subroutine call arguments see:
linuxcnc.org/docs/devel/html/gcode/o-code.html

O- Call takes up to 30 optional arguments, which are passed to the subroutine as #1, #2 , …, #N. Parameters from #N+1 to #30 have the same value as in the calling context. On return from the subroutine, the values of parameters #1 through #30 (regardless of the number of arguments) will be restored to the values they had before the call. Parameters #1 - #30 are local to the subroutine.

Because 1 2 3 is parsed as the number 123, the parameters must be enclosed in square brackets. The following calls a subroutine with 3 arguments:
O- Call Example

o100 sub
(test if parameter #2 is greater than 5)
o110 if [#2 GT 5]
(return to top of subroutine if test is true)
o100 return
o110 endif
(this only gets executed if parameter #2 is not greater than 5)
(DEBUG, parameter 1 is [#1])
(DEBUG, parameter 3 is [#3])
o100 endsub

o100 call [100] [2] [325]

Subroutine bodies may not be nested. They may only be called after they are defined. They may be called from other functions, and may call themselves recursively if it makes sense to do so. The maximum subroutine nesting level is 10.

Subroutines can change the value of parameters above #30 and those changes will be visible to the calling code. Subroutines may also change the value of global named parameters (i.e. parameters whose names begin with the underscore character "_").

Please Log in to join the conversation.

More
3 years 1 month ago #281260 by mBender
I will try that, but I believe the issue was that in the Ini file, I could not pass on Hal Variables or the issue was regarding the [ in the ini file. Will test again and circle back.

Please Log in to join the conversation.

More
3 years 1 month ago #281343 by mBender
It all worked out. Thank you!

Please Log in to join the conversation.

More
3 years 1 month ago #281527 by mBender

1. Have a look in the 'man' folders (man1, man3, man9):
github.com/LinuxCNC/linuxcnc/tree/master/docs/man
Sorry to bring this up again, i just wanted to update the documents, but under that link I can‘t find it. I don‘t think this  linuxcnc.org/docs/stable/html/config/ini-config.html comes from git.

Please Log in to join the conversation.

More
3 years 1 month ago #281528 by phillc54

Please Log in to join the conversation.

Time to create page: 0.092 seconds
Powered by Kunena Forum