Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: tatumoktfarm on August 24, 2021, 04:30:42 PM
-
Mach 4 question here:
My Mach 4 operated, CNC lathe, has a 4 position tool turret. It holds 8 tools, which would be 4 drills and 4 cutting tools. So I have assigned motor 1 to the turret, and A axis to motor 1
The 4 position turret has paws at its locking 90 degree positions.
Presently to change the turret position, I go to the Mach 4 Mill program, which lets me jog A-axis. It even gives me the counts. I jog just beyond 90 degrees, then back just a tad to catch the paw. Then I go back to Mach4 lathe to run the Gcode program. All the offsets are spot on, and everything is working great, I just don’t know how to rotate the turret automatically.
So I am looking for a new M6 macro to replace the one I got in the Mach 4 lathe macros folder so I can get the turret to rotate to proper tool upon T command in G code. I have been looking for a script that seems to call out a motor or axis assignment, rotate 91 degrees, and then back a degree. Or if not degrees, counts.
I know this has been discussed in the forum before, though I am very new, and I simply can’t find any of the scripts posted here that seem to look like they will do what I want it to do. If anyone can point me to the right thread, I would be grateful.
Regards
-
You could try this macro, I have no idea if its any good to you.
No warranty given or implied.
-- Mach4Turn 8 position tool Turret
function m6()
inst = mc.mcGetInstance()
selectedtool = 5 -- mc.mcToolGetSelected(inst)
currenttool = 1 -- mc.mcToolGetCurrent(inst)
Rlock = 1 -- ' Sets the Relock Movement in Degrees Value
if (selectedtool > 8) or (selectedtool < 1) then
mc.mcCntlSetLastError(inst,"Tool Number Out of Range.")
do return end
end
if (selectedtool == currenttool) then
mc.mcCntlSetLastError(inst,"No tool change needed.")
do return end
end
--'------ Select Tool ------------------------------------
mc.mcCntlSetLastError(inst,"Moving to Tool " ..selectedtool )
if (selectedtool > currenttool) then
Moves = selectedtool - currenttool
Moves = (Moves * 45) + 1
mc.mcCntlSetLastError(" G00 A" ..Moves);
end
if (selectedtool < currenttool) then
Moves = ((8 - currenttool) + selectedtool)
Moves = (Moves * 45) + 1
mc.mcCntlSetLastError(" G00 A " ..Moves);
end
mc.mcCntlSetLastError(inst,"Tool Loaded")
--'------------ end Tool Change ------------------------
mc.mcCntlSetLastError(inst," Turret Locking ")
mc.mcCntlGcodeExecuteWait(inst, "G52 A-" ..Moves);
mc.mcCntlGcodeExecuteWait(inst, "G00 G90 A0");
mc.mcCntlGcodeExecuteWait(inst, "G00 G91 A-" ..Rlock ); -- ' Lock Turret
mc.mcCntlGcodeExecuteWait(inst, "G52 A0");
mc.mcCntlGcodeExecuteWait(inst, "G90"); --' Reset to ABS
tool = selectedtool
mc.mcToolSetCurrent(inst, selectedtool)
if (mc.mcInEditor() == 1) then
m6()
end
end
-
Hi Graham Waterworth,
I really appreciate this macro and your help. It reads like it is exactly what I need. I replaced the manual tool change M6 macro with this one, and now I’m in the process of debugging it for my machine.
Presently I call out a tool in Gcode, like T2 M6, and nothing happens, except screen shows it moved to offset 2. Tool stays at tool 1, and turret doesn’t rotate. Looking through the macros I see when I ask for a tool, like T6, it asks the A motor to rotate forward, then back onto its paw. I am guessing I need to assign a value to this movement after the A in counts, replacing the A- with A2, and make sure my A motor’s counts per unit add up so the 2 units rotate the turret 45 degrees per station. Since I can rotate the motor in the mill program by jogging the A axis, I should be able to figure these units and/or counts out pretty quickly from the display. Anyway, thanks again for all your help thus far. If I am barking up the wrong tree entirely, I sure would appreciate some more direction. Regards George Tatum
-
To call a tool in Mach4 lathe you use T0202
(T02) Tool 2 (02) offset 2
You need to set your steps per for 1 degree of rotation on the turret, number of degrees is calculated for the number of tools moved.
8 Station turret needs to move 45 degrees per tool.
You also need to change these lines to the following lines
Change test data for real data
selectedtool = 5 -- mc.mcToolGetSelected(inst)
currenttool = 1 -- mc.mcToolGetCurrent(inst)
To
selectedtool = mc.mcToolGetSelected(inst)
currenttool = mc.mcToolGetCurrent(inst)
-
We are now getting an error that says no script engine found. I have attached an image of the error. Your help is greatly appreciated.
-
Hi can i please try this Macro and find out if its working or not