671
Mach4 General Discussion / Re: mc.mcCntlGcodeExecuteWait problems
« on: November 21, 2017, 06:27:32 PM »
Use a register (in place of the global var) if you want more than the screen scripts to use it.
Steve
Steve
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Zprobe = 0 -- the initial state of the state machine. 0 == not running.
if (Zprobe == 0) then -- Only start the task is it isn't already running.
Zprobe = 1 -- 1 == start the Z probe.
end
controlState = mc.mcCntlGetState(inst) -- what state is the control in?
if ((Zprobe == 1) and (controlState == mc.MC_STATE_IDLE)) then
mc.mcCntlGcodeExecute(inst, "G91 G31 Z-5 F1000") -- start the Z probe. Notice that we don't use the Wait version of this function
--Wait on the machine to NOT be idle. This won't take long at all. But we need to make sure that the control has entered the running state.
while (controlState == mc.MC_STATE_IDLE) do
controlState = mc.mcCntlGetState(inst)
end
Zprobe = 2 -- change the state. 2 == Z probe running.
elseif ((Zprobe == 2) and (controlState == mc.MC_STATE_IDLE)) then
-- the task is done. Record the Z probe pos, if needed, and retract the spindle to
local zMachineProbePos = mc.mcAxisGetProbePos(inst, mc.Z_AXIS, 1); -- Do something with it? I dunno... :)
mc.mcCntlGcodeExecute(inst, "G53 G00 Z0") -- Raise Z to machine pos Z0. Notice that we don't use the Wait version of this function either.
--Wait on the machine to NOT be idle. This won't take long at all. But we need to make sure that the control has entered the running state.
while (controlState == mc.MC_STATE_IDLE) do
controlState = mc.mcCntlGetState(inst)
end
Zprobe = 3 -- change the state. 3 == Z retracting.
elseif ((Zprobe == 2) and (controlState == mc.MC_STATE_IDLE)) then
-- everything is done. Simply change the state of your state machine.
Zprobe = 0 -- change the state. 0 == not running.
end