Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: DAAD on December 30, 2020, 10:42:47 AM

Title: Adding Physical button check code Take 2
Post by: DAAD on December 30, 2020, 10:42:47 AM
At the moment i'm implementing some Physical buttons for easier acces to some of my most used functions.

2 of them are Park and goto zero, both of the use an input signal from the button to run some g code.
Problem is that it's possible to press both buttons after each other which is no good news for my machine!

I've tried to solde this with an axisisstill api, but it's not working smoothly at the moment. If i press the button when the machine moves, it does what it's need to do (nothing + return error axis moving). But when i press the button when the machine is not moving, it starts whit a little yerk and moves into the correct spot. But it also returns the error "machine is moving"

I've already added a millisleep, to overcome this, but the problem persists.

Any idea howto implement this the correct way?

Code: [Select]
mc.ISIG_INPUT4 = Function (state) -- Park Button

local MotorIsStillX = mc.mcAxisIsStill (inst, 1)
local MotorIsStillXs = mc.mcAxisIsStill (inst, 3)
local MotorIsStillY = mc.mcAxisIsStill (inst, 0)

if (( state==1) and (MotorIsStillX == 1) and (MotorIsStillXs == 1) and (MotorIsStillY == 1)) then
wx.wxMillisleep (500)
local msg = " G00 G53 X3100 Y1200"
mc.mcCntlSetLastError(inst, "Goto Park")
mc.mcCntlGcodeExecute(inst, msg)

else

mc.mcCntlSetLastError (inst, "Machine is moving")

end
end,





Keep Safe & Best wishes for the year to come!

Adam
Title: Re: Adding Physical button check code Take 2
Post by: Brian Barker on December 31, 2020, 11:17:54 AM
Better way would be to look at the state machine in Mach4.. You can see if you are in Idle or not.
Title: Re: Adding Physical button check code Take 2
Post by: DAAD on January 04, 2021, 05:40:06 AM
Thanks for the pointer!

Machine setup and working as i want.

Many thanks