7
« on: July 08, 2023, 06:48:57 AM »
After some trial and error, it worked.
There may be fixes as we proceed with testing.
Below is the preamble.
Thank you everyone.
*************************
1 : function m6()
2 :
3 : local inst = mc.mcGetInstance()
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 : add
14 : ----------- Get Work position --------------
15 : --local StartPos = mc.mcCntlGetPoundVar(inst, ZVar);--Get a pound var value
16 : local StartPos= mc.mcAxisGetPos(inst, mc.Z_AXIS)
17 :
18 : if selectedTool == currentTool then
19 : return
20 : mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
21 : else
22 :
23 : mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0");--Move the Z axis all the way up
24 : mc.mcCntlGcodeExecute(inst, "G53 X5 y0");--Move the X axis to the middle and Y axis to the end and
25 : mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to continue") --Message at beginning of tool change
26 : mc.mcCntlToolChangeManual(inst, true) --This will pause the tool change here and wait for a press of cycle start to continue
27 : mc.mcCntlGcodeExecute(inst, "G53 G01 X5 y5 f350");--Move the X axis and Y axis to the tool setter
28 : --mc.mcCntlGcodeExecute(inst, "G53 G0 z-2")--Moves the z axis down 5 inches rapid
29 :
30 : mc.mcCntlGcodeExecute(inst, "g53 G31 z-4 f15")--Probes z axis to the tool setter
31 : mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. " Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
32 : mc.mcToolSetCurrent(inst, selectedTool) --sets the current tool displayed in mach to the selected tool
33 : --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
34 : 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
35 : 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
36 : mc.mcCntlSetLastError(inst, "Tool Length" .. tostring(ToolLength))
37 : 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
38 : mc.mcCntlGcodeExecute(inst, "G04 p.5")
39 : mc.mcCntlGcodeExecute(inst, "G90 G53 G1 Z0 F80") --Retract back to Z home
40 :
41 : local MyChoice = wx.wxMessageBox("Remove tool Setter","Click OK to continue" , 16) -- brings up a dialog box and waits for a selection to proceed
42 :
43 : if (MyChoice == 16) then --16 is cancel
44 : rc = mc.mcCntlSetLastError(inst, 'probing.')
45 :
46 : return
47 : elseif (MyChoice == 4) then
48 :
49 : mc.mcCntlGcodeExecute(inst, string.format('G ' .. posmode))--return to pre macro mode G90, or G91
50 : mc.mcCntlGcodeExecute(inst, "G90 G53 G0 X" .. tonumber(valX) .. "Y" .. tonumber(valY)) --Move back to X & Y initial location
51 : mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z" .. tonumber(valZ)) --Move back to Z initial location
52 :
53 : add
54 : local ZOffset =30.0 --Plate Hight
55 : local ZZ = valZ - probedz + ZOffset
56 : mc.mcAxisSetPos(inst,2,ZZ)
57 :
58 : mc.mcCntlSetLastError(inst, "Tool Change Complete H ".. tostring(selectedTool) .. " set to ".. tostring(ToolLength).." mm")
59 : local MyChoice = wx.wxMessageBox("End of m6. Start OK?","Click OK to Start" , 16)
60 : end
61 :
62 : end
63 :
64 : end
65 :
66 : if (mc.mcInEditor() == 1) then
67 : m6()
68 : end