OK, lets work with an actual script that I try to modify as an example. In fact while writing this post I figured some of the stuff out, but a comment if I'm doing it correctly would be welcome.
I have a Wireless Probe from https://vers.by/
The Receiver has a error Pin that is connected to input 1 of my controller. This error pin is triggert on several occasions.
1. If the Probe is turned of and not ready
2. the Delay of the Measurement was too high due to problems with the wireless connection.
To ensure a robust measurement the error pin needs to be check on multiple occasions.
1. before each G38 it needs to be checked if the probe is ready, G38 should only be executed if the probe is ready.
2. after each G38 it needs to be checked to validate if the Measurement was accurate, if not a error message should be displayed to warn the user
I tried to implement this in the Measure/Axis script (attached at the end of this post). In general this is working OK, but I'm not 100% happy with it due to the following reasons:
a. [#<_hw_input_num|1> is repeated multiple times throughput the script. I would like to define the input pin once at the beginning of the script to avoid any issues should I change the port sometime in the future, or someone else uses the code and want to use a different port. While writing this I figured that I can just put a #<_Probe_error_pin>=1 at the beginning of the script and use this as the pin info. So this questions is answered.
b. I'm currently setting the variable #<_measure_failed> in the sub routine O<probe>, can I return the value of #<_measure_failed> together with #<_measure> to access its value outside of the sub? I assume that every variable starting with a _ is threated as global (at last the _ was required for the _Probe_error_pin to work within the sub and not only outside of it), Is the modified value of #<_measure_failed> available outside of the Sub? If yes, why is the measure value set to the return value with #<_measure> = #<_return> after calling the sub.
I assume its quiet obvious that I'm new to this kind of gcode programming (I typically Programm in Python, C#, Javascript etc...) and it seems I'm missing a lot of information about the syntax and code words. Sorry if this are somewhat obvious or stupid questions. Is there some documentation about the programming capabilities of Planet CNC beside the GCODE pdf file?
Or is Planet CNC using some kind of a open standard syntax that I can look up somewhere else?
Code:
(name,Measure Axis)
#<_Probe_error_pin>=1
O<Probe_check> if [[#<_hw_input_num|#<_Probe_error_pin>>]]
(msg,Probe not turned on or in sleep!!!)
M2
O<Probe_check> else
O<PlanetCNC> if[[#<_probe_pin_1> EQ 0] AND [#<_probe_pin_2> EQ 0]]
(msg,Sensor is not configured)
M2
O<PlanetCNC> endif
(dlgname,Measure Axis)
(dlg,Select start postition, typ=label, x=20, w=455, color=0xffa500)
(dlg,data::MeasureAxis, typ=image, x=0)
(dlg,|X+|X-|Y+|Y-, typ=checkbox, x=50, w=425, def=1, param=strt)
(dlgshow)
M73 ;store state, auto restore
G17 G90 G91.1 G90.2 G08 G15 G94
M50P0 ;disable speed override
M55P0 ;disable trans
M56P0 ;disable warp
M57P0 ;disable swap
M10P1 ;motor enable
M11P1 ;limits/probe enable
o<st> if [#<strt> EQ 1]
#<axis> = 0
#<dir> = +1
o<st> elseif [#<strt> EQ 2]
#<axis> = 0
#<dir> = -1
o<st> elseif [#<strt> EQ 3]
#<axis> = 1
#<dir> = +1
o<st> elseif [#<strt> EQ 4]
#<axis> = 1
#<dir> = -1
o<st> else
(msg,Error)
M2
o<st> endif
#<pos> = #<_machine_axis|#<axis>>
O<probe> call [#<axis>] [#<dir>]
#<_measure> = #<_return>
G53 G00 H#<axis> E#<pos>
G53 G00 Z#<_probe_safeheigh>
G53 G00 H#<axis> E#<_measure>
o<st> if [#<strt> EQ 1]
(print,Measure result: X=#<_measure>)
o<st> elseif [#<strt> EQ 2]
(print,Measure result: X=#<_measure>)
o<st> elseif [#<strt> EQ 3]
(print,Measure result: Y=#<_measure>)
o<st> elseif [#<strt> EQ 4]
(print,Measure result: Y=#<_measure>)
o<st> else
(msg,Error)
M2
o<st> endif
M2
O<Probe_check> endif
O<probe> sub
M73
#<axis> = #1
#<dir> = #2
#<_measure_failed> = 0
O<Probe_check_1> if [[#<_hw_input_num|#<_Probe_error_pin>>]]
(msg,Probe not turned on or in sleep, Measurement Failed!!!)
#<_measure_failed> = 1
M2
O<Probe_check_1> else
M11P0 G38.2 H#<axis> E[#<dir> * 100000] F#<_probe_speed>
G91 G01 H#<axis> E[-#<dir> * #<_probe_swdist>]
o<low> if [#<_probe_speed_low> GT 0]
O<Probe_check_2> if [[#<_hw_input_num|#<_Probe_error_pin>>]]
(msg,Probe not turned on or in sleep, Measurement Failed!!!)
#<_measure_failed> = 1
M2
O<Probe_check_2> else
G90 G38.2 H#<axis> E[#<dir> * 100000] F#<_probe_speed_low>
O<Probe_check_3> if [[#<_hw_input_num|#<_Probe_error_pin>>]]
(msg,Probe delay too big. Measurement inaccurate!!!)
#<_measure_failed> = 1
M2
O<Probe_check_3> endif
G91 G01 H#<axis> E[-#<dir> * #<_probe_swdist>] F#<_probe_speed>
O<Probe_check_2> endif
o<low> endif
M11P1 G90
#<_measure> = [#<_probe_axis|#<axis>> + #<dir> * #<_probe_size_axis|#<axis>>]
O<Probe_check_1> endif
O<probe> endsub [#<_measure>]