2
« on: July 06, 2023, 01:38:52 AM »
Hello.
I used the following "m6" that was on YouTube, but I would like to adjust the "tool setter: H = 31 mm".
"I did some research on my own, but I didn't understand."
Please someone tell me the solution.
problem
Line 46 returns to the machine coordinates of line 11.
After this, I want to correct "tool setter: H = 31mm".
***************************
1 : function m6()
2 : local inst = mc.mcGetInstance() ;
3 :
4 : local currentTool = mc.mcToolGetCurrent(inst)
5 : local selectedTool = mc.mcToolGetSelected(inst)
6 : local posmode = mc.mcCntlGetPoundVar(inst, mc.SV_MOD_GROUP_3) --get the current mode so we can return to it when macro ends
7 :
8 : --Get positions before moving to do tool change
9 : local valX, rc = mc.mcAxisGetMachinePos(inst, mc.X_AXIS) --Get the position of the X axis in Machine Position
10 : local valY, rc = mc.mcAxisGetMachinePos(inst, mc.Y_AXIS) --Get the position of the Y axis in Machine Position
11 : local valZ, rc = mc.mcAxisGetMachinePos(inst, mc.Z_AXIS) --Get the position of the Z axis in Machine Position
12 :
13 : if selectedTool == currentTool then
14 : return
15 : mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
16 : else
17 :
18 : mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0");--Move the Z axis all the way up
19 : mc.mcCntlGcodeExecute(inst, "G53 X10 y0");--Move the X axis to the middle and Y axis to the end and
20 : mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to continue") --Message at beginning of tool change
21 : mc.mcCntlToolChangeManual(inst, true) --This will pause the tool change here and wait for a press of cycle start to continue
22 : mc.mcCntlGcodeExecute(inst, "G53 G01 X10 y10 f350");--Move the X axis and Y axis to the tool setter
23 : --mc.mcCntlGcodeExecute(inst, "G53 G0 z-2")--Moves the z axis down 5 inches rapid
24 :
25 : mc.mcCntlGcodeExecute(inst, "g53 G31 z-4 f15")--Probes z axis to the tool setter
26 : mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. " Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
27 : mc.mcToolSetCurrent(inst, selectedTool) --sets the current tool displayed in mach to the selected tool
28 : --local probedzW = mc.mcAxisGetPos(inst, 2) --This would give 0 axis (z on my machine) coordinates in work coordinate syste, ive shown it just for educational purposes
29 : local probedz = mc.mcCntlGetPoundVar(inst, 5073) --this retreives the Saved varible of the z position (#5073) in machine coordinates and assigns it to the name probedz
30 : local ToolLength =math.abs(probedz) -- this calculates the value of the tool lenght by using a gage line off of my spindle to the tool setter. uses the absolute value fuction
31 : mc.mcCntlSetLastError(inst, "Tool Length" .. tostring(ToolLength))
32 : mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, selectedTool, ToolLength) --- this sets the tool length value into the tool table into the selected tool position number, Note - i havent reassigned current tool varible so i have to use the "selectedTool" name
33 : mc.mcCntlGcodeExecute(inst, "G04 p.5")
34 : mc.mcCntlGcodeExecute(inst, "G90 G53 G1 Z0 F80") --Retract back to Z home
35 :
36 : local MyChoice = wx.wxMessageBox("Remove Probe Clip","Click OK to continue" , 16) -- brings up a dialog box and waits for a selection to proceed
37 :
38 : if (MyChoice == 16) then --16 is cancel
39 : rc = mc.mcCntlSetLastError(inst, 'probing.')
40 :
41 : return
42 : elseif (MyChoice == 4) then
43 :
44 : mc.mcCntlGcodeExecute(inst, string.format('G ' .. posmode))--return to pre macro mode G90, or G91
45 : mc.mcCntlGcodeExecute(inst, "G90 G53 G0 X" .. tonumber(valX) .. "Y" .. tonumber(valY)) --Move back to X & Y initial location
46 : mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z" .. tonumber(valZ)) --Move back to Z initial location
47 :
48 : mc.mcCntlSetLastError(inst, "Tool Change Complete H ".. tostring(selectedTool) .. " set to ".. tostring(ToolLength).." inches")
49 : end
50 :
51 : if (mc.mcInEditor() == 1) then
52 : m6()
53 : end