function m101() local inst = mc.mcGetInstance() --check to see if material past home switch and move back if it is local hsig = mc.mcSignalGetHandle(inst, mc.ISIG_MOTOR0_HOME) local MatHmLimit = mc.mcSignalGetState(hsig) if (MatHmLimit == 1) then mc.mcCntlGcodeExecute(inst, "G91 G0 X-5") mc.mcCntlGcodeExecute(inst, "G90") end --lower bend arm local bendb, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5) mc.mcSignalSetState(bendb, 1); --sets OUTPUT_5 to True local hreg8 = mc.mcRegGetHandle(inst, 'iRegs0/ArmTimeRe') local time8 = mc.mcRegGetValue(hreg8) wx.wxMilliSleep(time8) --home material and arm then zero local zero = 0 mc.mcCntlGcodeExecute(inst, "G91 G1 X-0.5 F200.0") mc.mcCntlGcodeExecute(inst, "G90") local rc = mc.mcCntlGcodeExecute(inst, "G28.1 X0.0 Y0.0") local GCodeXY0 = string.format("G92 X" .. zero .. "Y" .. zero) local rc = mc.mcCntlGcodeExecute(inst, GCodeXY0) --get encoder raw data and set encoder start to raw local hreg = mc.mcRegGetHandle(inst, 'ESS/Encoder_0') local EncStart = mc.mcRegGetValue(hreg) --move to rough position local hreg2 = mc.mcRegGetHandle(inst, 'iRegs0/HmDistMat') local HmDistMat = mc.mcRegGetValue(hreg2) local hreg3 = mc.mcRegGetHandle(inst, 'iRegs0/HmDistArm') local HmDistArm = mc.mcRegGetValue(hreg3) local HmDist = "G1 X" .. HmDistMat .."Y" .. HmDistArm .. "F2000.0" local rc = mc.mcCntlGcodeExecute(inst, HmDist) --read rough position from position dro and set temp postion dro local TempPos = mc.mcAxisGetPos(inst, 0) --determine encoder counts moved local EncStart = tonumber(EncStart) local EncRawVal = mc.mcRegGetValue(hreg) local EncMove = EncRawVal - EncStart --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) --move to position after actual position determined GCode = string.format("G1 F100 X%.4f\n", TempPos) mc.mcCntlGcodeExecute(inst, GCode) --set dros to zero local rc = mc.mcCntlGcodeExecute(inst, "G92 X0.0 Y0.0") local rc = mc.mcCntlGcodeExecute(inst, "G0 Y20.0") --set starting positions local StartPos = mc.mcAxisGetPos(inst, 0) local hreg5 = mc.mcRegGetHandle(inst, 'ESS/Encoder_0') local StartEncPos = mc.mcRegGetValue(hreg5) local hreg6 = mc.mcRegGetHandle(inst, 'iRegs0/StartPos') local hreg7 = mc.mcRegGetHandle(inst, 'iRegs0/StartEncPos') local rc = mc.mcRegSetValue(hreg6, StartPos) local rc = mc.mcRegSetValue(hreg7, StartEncPos) end if (mc.mcInEditor() == 1) then m101() end