NC Macros start from the GUI

More
17 Sep 2023 12:51 #281000 by mBender
NC Macros start from the GUI was created 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 or Create an account to join the conversation.

More
17 Sep 2023 13:01 #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
...
The following user(s) said Thank You: mBender

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

More
20 Sep 2023 14:44 - 20 Sep 2023 14:47 #281223 by mBender
Replied by mBender on topic NC Macros start from the GUI
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
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:
MDI_COMMAND = O<probexminus> CALL

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

With this subroutine:
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.
Last edit: 20 Sep 2023 14:47 by mBender.

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

More
20 Sep 2023 17:42 #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':
;                                               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':
; 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 or Create an account to join the conversation.

More
20 Sep 2023 17:48 #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 or Create an account to join the conversation.

More
20 Sep 2023 23:10 #281260 by mBender
Replied by mBender on topic NC Macros start from the GUI
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 or Create an account to join the conversation.

More
22 Sep 2023 02:06 #281343 by mBender
Replied by mBender on topic NC Macros start from the GUI
It all worked out. Thank you!
The following user(s) said Thank You: Aciera

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

More
24 Sep 2023 02:13 #281527 by mBender
Replied by mBender 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

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 or Create an account to join the conversation.

More
24 Sep 2023 02:17 #281528 by phillc54
The following user(s) said Thank You: Aciera

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

Time to create page: 0.091 seconds
Powered by Kunena Forum