G7x and profile in subroutine with parameters
- MalteS
- Offline
- Junior Member
-
Less
More
- Posts: 33
- Thank you received: 11
02 Mar 2025 20:02 - 02 Mar 2025 20:08 #323043
by MalteS
G7x and profile in subroutine with parameters was created by MalteS
Hi,
I'm trying to write a macro for touchy that provides the option to specify the x/z coordinates of the G7x profile on the touchy user interface.
My initial thought was subroutine nesting but I just found out that I cannot nest subroutines. So this does not work:
What works (a bit) is to put the profile subroutine after the main macro (before does not work).
But now I struggle with getting parameters to the subroutine. Does anybody have an idea here?
I'm trying to write a macro for touchy that provides the option to specify the x/z coordinates of the G7x profile on the touchy user interface.
My initial thought was subroutine nesting but I just found out that I cannot nest subroutines. So this does not work:
O<g7x_macro> sub
O100 SUB
...
O100 ENDSUB
G71.1 Q100 ....
O<g7x_macro> endsub
What works (a bit) is to put the profile subroutine after the main macro (before does not work).
O<g7x_macro> sub
G71.1 Q100 ....
O<g7x_macro> endsub
O100 SUB
...
O100 ENDSUB
But now I struggle with getting parameters to the subroutine. Does anybody have an idea here?
Last edit: 02 Mar 2025 20:08 by MalteS.
Please Log in or Create an account to join the conversation.
- MalteS
- Offline
- Junior Member
-
Less
More
- Posts: 33
- Thank you received: 11
02 Mar 2025 20:10 - 02 Mar 2025 20:10 #323045
by MalteS
Replied by MalteS on topic G7x and profile in subroutine with parameters
If there is interest. The full code is shown below (bear with me - comments are a mixture of German and English
:

O<g7x_macro> sub
; #1 b_Modus (todo)
; #2 ae - Arbeitseingriff (Zustellung) (0.5mm)
; #3 Feed per revolution (0.1mm/u)
; #4 Surface speed (vc) (50m/min)
; #5 Max RPM (1400)
; Set default values
O100 IF [#2 EQ 0]
#2 = 0.5
O100 ENDIF
O101 IF [#3 EQ 0]
#3 = 0.1
O101 ENDIF
O102 IF [#4 EQ 0]
#4 = 50
O102 ENDIF
O103 IF [#5 EQ 0]
#5 = 1400
O103 ENDIF
(Allgemeiner Header)
G8 ; Lathe Diameter Mode
G18 ; XZ Plane
G21 ; Metric Units
G90 ; Absolute Distance
(Spindle Steuerung)
G96 D#5 S#4 ; Constant Surface Speed Mode
M3
G95 F#3 ; Feed-Per-Rev Mode
G4 P.2 ; Wait to reach speed
(Anfangspositionen merken)
#<x_start> = #<_x>
#<z_start> = #<_z>
G71.1 Q100 D[#2 / 2] I#2
G70 Q100 D[#2 / 2]
M5
M2
O<g7x_macro> endsub
O100 SUB
G0 X5 Z0
G0 x5 z-11.5
G0 x10 Z-14
O100 ENDSUB
%
Last edit: 02 Mar 2025 20:10 by MalteS.
Please Log in or Create an account to join the conversation.
- MaHa
- Offline
- Platinum Member
-
Less
More
- Posts: 414
- Thank you received: 170
02 Mar 2025 21:44 #323053
by MaHa
Replied by MaHa on topic G7x and profile in subroutine with parameters
M2 should always be outside a subroutine, so place M2 after each endsub, and your construct should work.
As you can only use 2 variables, and there is no option to enter a global variable in MDI, it will be difficult to bring the values to your code.
The contur o100sub is in the macro file. If you keep it like that, you need to modify in the macrofile anyway. how about use the default values #3 #4 #5 as this might not change often, only submit #1 and #2 as variable.
As you can only use 2 variables, and there is no option to enter a global variable in MDI, it will be difficult to bring the values to your code.
The contur o100sub is in the macro file. If you keep it like that, you need to modify in the macrofile anyway. how about use the default values #3 #4 #5 as this might not change often, only submit #1 and #2 as variable.
Please Log in or Create an account to join the conversation.
- MalteS
- Offline
- Junior Member
-
Less
More
- Posts: 33
- Thank you received: 11
03 Mar 2025 20:16 - 03 Mar 2025 20:18 #323111
by MalteS
Replied by MalteS on topic G7x and profile in subroutine with parameters
Thanks. I'm calling this subroutine as a macro from
Touchy
. M2 must be inside the subroutine. There is no other GCode executed in Touchy.
I solved the variable problem in the meantime by copying the subroutine arguments to global variables. I consider this ugly as s**t but it gets the job done.
I then ran into the issue that Touchy has limited space for Macro arguments on the UI and no option to scroll through the argument list. This effectively limits the UI to enter 4 (maybe 5) points. This significantly limits the usefulness. Probably not an issue on a bigger screen but is a problem on the 1024x600 pixels display that I use.
Full program is copied below should this be of use to anybody.
I solved the variable problem in the meantime by copying the subroutine arguments to global variables. I consider this ugly as s**t but it gets the job done.
I then ran into the issue that Touchy has limited space for Macro arguments on the UI and no option to scroll through the argument list. This effectively limits the UI to enter 4 (maybe 5) points. This significantly limits the usefulness. Probably not an issue on a bigger screen but is a problem on the 1024x600 pixels display that I use.
Full program is copied below should this be of use to anybody.
#;g7x_macro
O<g7x_macro> sub
; #1 Punkte (TODO)
; #2 X1 (Erster Punkt)
; #3 Z1 (Erster Punkt)
; #4 X2 (Zweiter Punkt)
; #5 Z2 (Zweiter Punkt)
; #6 X3 (Dritter Punkt)
; #7 Z3 (Dritter Punkt)
; #8 X4 (Vierter Punkt)
; #9 Z4 (Vierter Punkt)
(Use global variables to store the points for the Subroutine below)
#<_g7x_points>=#1
#<_g7x_x1>=#2
#<_g7x_z1>=#3
#<_g7x_x2>=#4
#<_g7x_z2>=#5
#<_g7x_x3>=#6
#<_g7x_z3>=#7
#<_g7x_x4>=#8
#<_g7x_z4>=#9
(Allgemeiner Header)
G8 ; Lathe Diameter Mode
G18 ; XZ Plane
G21 ; Metric Units
G90 ; Absolute Distance
(Spindle Steuerung)
G96 D1400 S50 ; Constant Surface Speed Mode
M3
G95 F0.1 ; Feed-Per-Rev Mode
G4 P.2 ; Wait to reach speed
(Anfangspositionen merken)
#<x_start> = #<_x>
#<z_start> = #<_z>
(G71, G72 -> Lang-, Plandrehen)
(mit .1,.2 für Taschen )
(Q -> Subroutine Nr)
(x,z -> Startposition)
(D -> Distanz zum Profil zwischen roughing und finish cut)
(E -> G70 distanz zum profil am ende)
(P -> G70 anzahl der durchläufe)
(I -> Zustellung)
(R -> Rückzug, default ist 0.5)
G71.1 Q100 D0.25 I0.5
G70 Q100 D0.25
G0 X#<x_start> Z#<z_start>
M5
M2
O<g7x_macro> endsub
O100 SUB
O200 IF [#<_g7x_points> GT 0]
G0 X#<_g7x_x1> Z#<_g7x_z1>
O200 ENDIF
O201 IF [#<_g7x_points> GT 1]
G0 X#<_g7x_x2> Z#<_g7x_z2>
O201 ENDIF
O202 IF [#<_g7x_points> GT 2]
G0 X#<_g7x_x3> Z#<_g7x_z3>
O202 ENDIF
O203 IF [#<_g7x_points> GT 3]
G0 X#<_g7x_x4> Z#<_g7x_z4>
O203 ENDIF
O100 ENDSUB
%
Last edit: 03 Mar 2025 20:18 by MalteS.
Please Log in or Create an account to join the conversation.
Time to create page: 0.054 seconds