Machsupport Forum
Mach Discussion => Mach4 General Discussion => Mach4 Toolbox => Topic started by: ChrisO on February 11, 2022, 06:11:26 PM
-
I have a floating head plasma torch mount with Proximity switch to be used for two purposes. 1: Sense material height during M3 Probing/start torch and 2: Use as protection against torch damage from collision during cutting. I have the following “work in progress” where I’ve added code to signal library, and monitor the Probe/collision input signal. The plan is to check to see if were performing an M3 move, and if we are, do nothing otherwise, do a STOPmovement().
I unsuccessfully placed a M3Probing variable in the M3 Macro to =1 when performing probing, but I can’t figure out how to get the signal Library code to see the variable. The scripting manual says the variable has to be in a Module to share it between macros and signal library, but everything I’ve tried has failed.
Can someone point me in the right direction?
Thanks.
--Signal Library Code
[mc.ISIG_INPUT9]= function (state) -- Torch Probe/collision switch state has changed
if(state==1) then
If (M3Probing==1) then -- THIS VARIABLE IS SUPPOSED TO BE SET BY m3() However it is not seen by this signal library code, so it does not work.
--do nothing
Else
STOPmovement() -- call function to stop movement
mc.mcCntlSetLastError(inst, "Error- Torch Collision Detected") -- Put message in message box
End
end
end,
-- added function to bottom of screen script
function STOPmovement ()
local inst = mc.mcGetInstance()
mc.mcSpindleSetDirection(inst,0) -- Set to 0 to turn spindle off
mc.mcCntlCycleStop(inst) -- stops Gcode file that is running.
end
-
Hi,
when an m3 is executed it is the Gcode interpreter and trajectory planner chunk that is operating.......when the Signal Library code is executing its the Screen code chunk which is operating.
The variable in the Screen chunk is NOT available to the Gcode/Interpreter chunk, and only one can run at a time. In practice Machs core is bouncing back and forth between the two chunks
that give the impression that that the two chunks run simultaneously.
Set up and use a register. A register can be accessed by any Lua chunk at any time and is a great way to pass data from one chunk to another.
Craig
-
Great!, I will begin the journey to learn about registers. Thanks for the insight!
-
Hi,
1) Open the Regfile plugin
2) Assign a name, and initial value if required,a description if required and whether it will be persistent, ie saved an shut down.
3) <Apply> and close.
The register of that name now resides at iRegs0/<register name>.
To access it from a Lua script:
local registerHandle=mc.mcRegGetHandle(inst,'iRegs0/MyRegister')
local registerValue=mc.mcRegGetValue(registerHandle)
There are a number of APIs of this general type in Mach4Hobby/Docs in the Register category.
Craig