Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: KatzYaakov on August 03, 2021, 01:00:21 AM
-
is some one know how can i read the encoder in mach?
i use pokeys
ther encoder input options
there is tab on mach for encoder
but no any sample or instruction how use
-
I use an ESS and it puts the encoder value into a register.
Bill
-
thanks
do you make loop that read all the time the encoder and do something until ...
or act according event value changeg?
-
I use it to verify and correct the position on a machine that does not need to be correct until the end.
-
how you correct the position if need? i asked in the past here if there option to modify the machine cordinate but answer was no
only by G52 or similar tool but not real modify the machine cordinate
-
I wrote a special M code.
At the end of the move I put in the M code.
It looks at the distance it was supposed to move, looks how far the encoder says it did move then corrects the move.
It will not work for an xy machine.
It only corrects at the end of the move.
-
but after you correct the move,how do you reset the new position ? so mach will know its correct position?
-
This is my code in the macro
local inst = mc.mcGetInstance()
--get starting positon and encoder postion
local hreg = mc.mcRegGetHandle(inst, 'iRegs0/StartPos')
local hreg2 = mc.mcRegGetHandle(inst, 'iRegs0/StartEncPos')
local StartEncPos = mc.mcRegGetValue(hreg2)
--read rough position from position dro and set temp postion dro
local TempPos = mc.mcAxisGetPos(inst, 0)
--determine encoder counts moved
local hreg3 = mc.mcRegGetHandle(inst, 'ESS/Encoder_0')
local EncRawVal = mc.mcRegGetValue(hreg3)
local EncMove = EncRawVal - StartEncPos
--determine distace encoder moved
local hreg4 = mc.mcRegGetHandle(inst, 'iRegs0/EncScale')
local EncScale = mc.mcRegGetValue(hreg4)
local EncPos = EncMove / EncScale
--set position to encoder postion
local GCode = string.format("G92 X%.4f\n", EncPos)
mc.mcCntlGcodeExecute(inst, GCode)
--wx.wxMilliSleep(2000)
--calculate distance off
local hreg5 = mc.mcRegGetHandle(inst, 'iRegs0/DistOff')
local DistOff = EncPos - TempPos
local rc = mc.mcRegSetValue(hreg5, DistOff)
--wx.wxMilliSleep(2000)
--if distance off too great move to position
if (DistOff >= 0.010) then
--move to position after actual position determined
GCode = string.format("G1 F100 X%.4f\n", TempPos)
mc.mcCntlGcodeExecute(inst, GCode)
end
if (DistOff <= -0.010) then
--move to position after actual position determined
GCode = string.format("G1 F100 X%.4f\n", TempPos)
mc.mcCntlGcodeExecute(inst, GCode)
end