Hello Guest it is April 16, 2024, 03:05:53 AM

Author Topic: Read encoder  (Read 694 times)

0 Members and 1 Guest are viewing this topic.

Read encoder
« 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

Offline Bill_O

*
  •  563 563
    • View Profile
Re: Read encoder
« Reply #1 on: August 03, 2021, 12:22:23 PM »
I use an ESS and it puts the encoder value into a register.

Bill
Re: Read encoder
« Reply #2 on: August 03, 2021, 03:41:48 PM »
thanks
do you make loop that read all the time the encoder and do something until ...
or act according event value changeg?

Offline Bill_O

*
  •  563 563
    • View Profile
Re: Read encoder
« Reply #3 on: August 04, 2021, 02:21:06 PM »
I use it to verify and correct the position on a machine that does not need to be correct until the end.
Re: Read encoder
« Reply #4 on: August 04, 2021, 02:33:40 PM »
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

Offline Bill_O

*
  •  563 563
    • View Profile
Re: Read encoder
« Reply #5 on: August 04, 2021, 05:37:31 PM »
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.
Re: Read encoder
« Reply #6 on: August 04, 2021, 10:40:10 PM »
but after you correct the move,how do you reset the new position ? so mach will know its correct position?

Offline Bill_O

*
  •  563 563
    • View Profile
Re: Read encoder
« Reply #7 on: August 05, 2021, 08:46:34 AM »
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