Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Toshio.K 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
-
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
-
partial fix
For m6, we found that the tool length is related to the Z-axis movement distance.
So I modified line 37.
Revised
Line 37: mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, selectedTool, 0)
Also, thank you for all the access.
-
Hello everyone.
In the Scripting Manual, ------------ Check Probe -------------
A script was written to check for probes.
It seems very useful, so I added it to this program.
If you have any good opinions, please post them.