Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Azalin on April 01, 2022, 05:39:51 PM

Title: Crash after tool change
Post by: Azalin on April 01, 2022, 05:39:51 PM
Hi,

I have a very weird problem and I broke too many end mills in one week. Here's the problem:
- I start a program.
- Mach4 pauses on tool change.
- I manually change the tool, move Z axis to position then click I click "ZERO Z" button.
- Then I click cycle start to continue the program.
- Program continues and the Z axis dives into the part and crashes.

I tried the same code on my cnc router with Mach3 but it works good.

The tool change line in the code is:
N115 T2 M6 D2 H2

Note: The M6.mcs is attached

What could cause this?

Thanks in advance,
Suat
Title: Re: Crash after tool change
Post by: Azalin on April 01, 2022, 05:44:38 PM
Forum wont let me attach the M6.mcs file somehow. But here it is:

function m6()

   local inst = mc.mcGetInstance()
   local selectedTool = mc.mcToolGetSelected(inst)
   selectedTool = math.tointeger(selectedTool)
   local currentTool = mc.mcToolGetCurrent(inst)
   currentTool = math.tointeger(currentTool)
   
   if selectedTool == currentTool then
      mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
   else
      mc.mcSpindleSetDirection(inst, 0)
      --Remove this line if you would not like the Z axis to move
      --mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0");--Move the Z axis all the way up
      mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to continue") --Message at beginning of tool change
      mc.mcCntlToolChangeManual(inst, true) --This will pause the tool change here and wait for a press of cycle start to continue
      mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. "   Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
      mc.mcToolSetCurrent(inst, selectedTool)
   end
end

if (mc.mcInEditor() == 1) then
   m6()
end
Title: Re: Crash after tool change
Post by: Azalin on April 02, 2022, 02:53:54 PM
OK I added a quick video.

In the video I used a simplified g-code. It starts with a drill operation. After drilling is complete (at second 0:42) Mach4 pauses and waits for me to change the tool. Once I change the tool I move the Z Axis to the location then I hit Zero Z. Now I hit Cycle Start to continue then I expect the Z axis to go and stop at -1 but it actually goes to -33 (and crashes).

It is really annoying and I need to know why Mach4 does this.

https://www.youtube.com/watch?v=tklMVuiullY (https://www.youtube.com/watch?v=tklMVuiullY)
Title: Re: Crash after tool change
Post by: joeaverage on April 02, 2022, 03:39:59 PM
Hi,
my only guess is that you have tool length offset active.

I notice that while you change to tool number two, the tool length stays the same as tool one.

Try putting a g44 at the top of the code and try again.

Craig
Title: Re: Crash after tool change
Post by: joeaverage on April 02, 2022, 03:45:27 PM
Hi,
just had a much closer look at your video and you have a line:
N50 H43 H1 Z2

That's where your tool length offset is being applied. Tool length offsets work really well PROVIDED you keep clear in your mind what offset is being
applied at any given time. If you don't keep a track of it the DON'T use them.

Craig
Title: Re: Crash after tool change
Post by: Azalin on April 02, 2022, 05:05:59 PM
Hey Craig,
Which line exactly?


%
O1 (CYCLOIDAL WHEEL)
N5 G0 G40 G49 G80 G21 (Initialisation)
N10 G0 Z0 (Retour aux origines machine)
N15 G0 X0 Y0
N20 (Outil n° 1 - Diametre 6.0 D1 H1)
N25 T1 M6 D1 H1
N30 S2000 M3
N35 M8
N40 (D-drill1)
N45 G0 G54 X-14.141 Y-14.036
N50 G43 H1 Z2.
N55 G83 Z-8. R2. Q2. P0 F150
N60     X-19.999 Y0.106
N100 G80
N105 G0 Z25.
N110 (Outil n° 2 - Diametre 6.0 D2 H2)
N115 T2 M6 D2 H2
N120 S3000 M3
N125 M8
N130 (P-contour)
N135 G0 G54 X-14.848 Y-14.743
N140 G43 H2 Z25.
N145 G0 Z-1
N104385 G0 X0 Y0 M5
M30
%
Title: Re: Crash after tool change
Post by: joeaverage on April 02, 2022, 07:36:53 PM
Hi,
I can see two lines, N50 and N140, they both have a g43 in them. Do you really intend to use tool length offsets?

Your zeroing procedure is like my own, because I have a manual change mill I have touch off each and every tool,
and I zero the z axis but specifically DO NOT USE tool length offsets.

With an ATC mill each tool is measured and ascribed a tool length offset from the master tool and stored in the tool table.
Each time that tool is called and fitted into the machine you use a g43 hnnn, where nnn is the new tool number, and that tool length offset
is applied such that the tip of the tool is exactly where the tip of the master tool would be. Is that want you want
to do?.  If not then get rid of any and all g43's....they will cause crashes UNLESS you specifically require them and use them as intended.

Craig
Title: Re: Crash after tool change
Post by: Azalin on April 03, 2022, 07:21:54 AM
Hi Craig,

Removing G43 from the code didn't help. Then I've removed whole N50 and N140 but didn't help too.
Title: Re: Crash after tool change
Post by: Azalin on April 03, 2022, 10:00:47 AM
Very interesting. I did a fresh install on another PC and it does the same. I removed G43 and also tried to add G49 but it just behaves the same.
Title: Re: Crash after tool change
Post by: joeaverage on April 03, 2022, 02:55:02 PM
Hi,

Try editing this line:

Code: [Select]
N115 T2 M6 D2 H2
Remove the D2 and H2, they apply the tool length and tool diameter offsets.

Craig
Title: Re: Crash after tool change
Post by: Azalin on April 03, 2022, 03:17:05 PM
Hi,

Still the same.

Are you able to do a test for me? I just wonder if it works for you.

Run the code,
on M6 jog the Z axis down then ZERO Z.
Hit cycle start and see if Z axis goes and stops at -1.

Thanks in advance,
Suat
Title: Re: Crash after tool change
Post by: joeaverage on April 03, 2022, 03:53:25 PM
Hi,
look at the diagnostics page. If a tool length offset is applied it will be listed.

Clearly you have a problem with offsets.

Craig
Title: Re: Crash after tool change
Post by: Azalin on April 03, 2022, 04:00:37 PM
Hi,

No offset output in the log:

2022-04-03 22:54:49.638 - Logging Enabled.
2022-04-03 22:54:51.586 - API: mcCntlCycleStart(inst = 0) (unknown caller)
2022-04-03 22:54:51.698 - Attempt transition from "Macro Hold" on event "Cycle Start" machapi.cpp:3085
2022-04-03 22:54:51.699 - S_FILE_MACRO_HOLD_on_exit
2022-04-03 22:54:51.699 - ACTION_start_cycle
2022-04-03 22:54:51.699 - S_FILE_RUNNING2_on_entry
2022-04-03 22:54:51.713 - Signal id 1121, (Tool Change), changed from HIGH to LOW.
2022-04-03 22:54:51.714 - Spindle speed capped by current range!
2022-04-03 22:54:51.716 - Signal id 1142, (Spindle Fwd), changed from LOW to HIGH.
2022-04-03 22:54:51.716 - Signal id 1141, (Spindle On), changed from LOW to HIGH.
2022-04-03 22:54:51.717 - Waiting 0.000000 seconds for spindle at speed... spindle.cpp:300
2022-04-03 22:54:51.717 - Done. spindle.cpp:305
2022-04-03 22:54:51.718 - Signal id 1144, (Coolant On), changed from LOW to HIGH.
2022-04-03 22:55:30.202 - WaitOnMacro() thisTc = 0, isDone = 1
2022-04-03 22:55:30.266 - Waiting on planner to drain before waiting on SetStill... runcanon.cpp:92
2022-04-03 22:55:30.266 - Waiting on SetStill...
2022-04-03 22:55:30.266 - Controller::RunCanonBuffer called AddStopReportRequest() runcanon.cpp:101
2022-04-03 22:55:30.266 - Requesting a stopped report for axis 0 motors.
2022-04-03 22:55:30.266 - Requesting a stopped report for motor 0.
2022-04-03 22:55:30.266 - Requesting a stopped report for axis 1 motors.
2022-04-03 22:55:30.266 - Requesting a stopped report for motor 1.
2022-04-03 22:55:30.266 - Requesting a stopped report for axis 2 motors.
2022-04-03 22:55:30.266 - Requesting a stopped report for motor 2.
2022-04-03 22:55:30.266 - Requesting a stopped report for axis 3 motors.
2022-04-03 22:55:30.267 - Requesting a stopped report for motor 3.
2022-04-03 22:55:30.267 - API: mcMotionSetStill(inst = 0, motor = 0) (Sim)
2022-04-03 22:55:30.267 - SetStill(): Motor 0 last position reported = -7873.6220 controller.cpp:1400
2022-04-03 22:55:30.267 - Axis 1 reports that it is still moving! controller.cpp:1407
2022-04-03 22:55:30.267 - API: mcMotionSetStill(inst = 0, motor = 1) (Sim)
2022-04-03 22:55:30.267 - SetStill(): Motor 1 last position reported = 41.7323 controller.cpp:1400
2022-04-03 22:55:30.267 - Axis 2 reports that it is still moving! controller.cpp:1407
2022-04-03 22:55:30.267 - API: mcMotionSetStill(inst = 0, motor = 2) (Sim)
2022-04-03 22:55:30.268 - SetStill(): Motor 2 last position reported = 9065.9727 controller.cpp:1400
2022-04-03 22:55:30.268 - Axis 3 reports that it is still moving! controller.cpp:1407
2022-04-03 22:55:30.268 - API: mcMotionSetStill(inst = 0, motor = 3) (Sim)
2022-04-03 22:55:30.268 - SetStill(): Motor 3 last position reported = 0.0000 controller.cpp:1400
2022-04-03 22:55:30.268 - All motors marked as still.
2022-04-03 22:55:30.268 - Waiting on SetStill is Done!
2022-04-03 22:55:30.283 - API: mcMotionSetStill(inst = 0, motor = 0) (Sim)
2022-04-03 22:55:30.283 - SetStill(): Motor 0 last position reported = -7873.6220 controller.cpp:1400
2022-04-03 22:55:30.283 - All motors marked as still.
2022-04-03 22:55:30.283 - API: mcMotionSetStill(inst = 0, motor = 1) (Sim)
2022-04-03 22:55:30.283 - SetStill(): Motor 1 last position reported = 41.7323 controller.cpp:1400
2022-04-03 22:55:30.283 - All motors marked as still.
2022-04-03 22:55:30.283 - API: mcMotionSetStill(inst = 0, motor = 2) (Sim)
2022-04-03 22:55:30.283 - SetStill(): Motor 2 last position reported = 9065.9727 controller.cpp:1400
2022-04-03 22:55:30.284 - All motors marked as still.
2022-04-03 22:55:30.284 - API: mcMotionSetStill(inst = 0, motor = 3) (Sim)
2022-04-03 22:55:30.284 - SetStill(): Motor 3 last position reported = 0.0000 controller.cpp:1400
2022-04-03 22:55:30.284 - All motors marked as still.
2022-04-03 22:55:30.298 - Signal id 1121, (Tool Change), changed from LOW to HIGH.
2022-04-03 22:55:30.314 - API: mcCntlToolChangeManual(inst = 0) (unknown caller)
2022-04-03 22:55:30.314 - Attempt transition from "File Running" on event "Macro Hold" controller.cpp:4657
2022-04-03 22:55:30.314 - S_FILE_RUNNING2_on_exit
2022-04-03 22:55:30.314 - ACTION_start_macro_hold
2022-04-03 22:55:30.314 - S_FILE_MACRO_HOLD_on_entry
2022-04-03 22:55:37.648 - Attempt transition from "Macro Hold" on event "Jog" axis.cpp:753
2022-04-03 22:55:37.649 - S_FILE_MACRO_HOLD_on_exit
2022-04-03 22:55:37.649 - ACTION_start_jogging
2022-04-03 22:55:37.649 - S_FILE_MACRO_JOGGING_on_entry
2022-04-03 22:55:37.664 - API: mcJogVelocityStart(inst = 0, axis = 2, dir = -1) = 0 (Mach4GUI Button)
2022-04-03 22:55:41.144 - API: mcJogVelocityStop(inst = 0, axis = 2) = 0 (Mach4GUI Button)
2022-04-03 22:55:41.967 - Attempt transition from "Macro Hold Jogging" on event "Stop Jog" controller.cpp:1815
2022-04-03 22:55:41.967 - S_FILE_MACRO_JOGGING_on_exit
2022-04-03 22:55:41.967 - S_FILE_RUNNING_stop_jogging
2022-04-03 22:55:41.967 - Signal id 1127, (Jog Enabled), changed from LOW to HIGH.
2022-04-03 22:55:41.968 - S_FILE_MACRO_HOLD_on_entry
2022-04-03 22:55:53.057 - API: mcCntlCycleStart(inst = 0) (unknown caller)
2022-04-03 22:55:53.171 - Attempt transition from "Macro Hold" on event "Cycle Start" machapi.cpp:3085
2022-04-03 22:55:53.172 - Signal id 1127, (Jog Enabled), changed from HIGH to LOW.
2022-04-03 22:55:53.173 - S_FILE_MACRO_HOLD_on_exit
2022-04-03 22:55:53.173 - ACTION_start_cycle
2022-04-03 22:55:53.173 - S_FILE_RUNNING2_on_entry
2022-04-03 22:55:53.202 - Signal id 1121, (Tool Change), changed from HIGH to LOW.
2022-04-03 22:55:53.203 - Spindle speed capped by current range!
2022-04-03 22:55:53.204 - Signal id 1142, (Spindle Fwd), changed from HIGH to LOW.
2022-04-03 22:55:53.205 - Signal id 1142, (Spindle Fwd), changed from LOW to HIGH.
2022-04-03 22:55:53.205 - Waiting 0.000000 seconds for spindle at speed... spindle.cpp:300
2022-04-03 22:55:53.205 - Done. spindle.cpp:305
2022-04-03 22:55:58.070 - WaitOnMacro() thisTc = 0, isDone = 1
2022-04-03 22:55:58.133 - Waiting on planner to drain before waiting on SetStill... runcanon.cpp:92
2022-04-03 22:55:58.133 - Waiting on SetStill...
2022-04-03 22:55:58.133 - Controller::RunCanonBuffer called AddStopReportRequest() runcanon.cpp:101
2022-04-03 22:55:58.133 - Requesting a stopped report for axis 0 motors.
2022-04-03 22:55:58.133 - Requesting a stopped report for motor 0.
2022-04-03 22:55:58.133 - Requesting a stopped report for axis 1 motors.
2022-04-03 22:55:58.133 - Requesting a stopped report for motor 1.
2022-04-03 22:55:58.133 - Requesting a stopped report for axis 2 motors.
2022-04-03 22:55:58.133 - Requesting a stopped report for motor 2.
2022-04-03 22:55:58.133 - Requesting a stopped report for axis 3 motors.
2022-04-03 22:55:58.133 - Requesting a stopped report for motor 3.
2022-04-03 22:55:58.134 - API: mcMotionSetStill(inst = 0, motor = 0) (Sim)
2022-04-03 22:55:58.134 - SetStill(): Motor 0 last position reported = -5845.6693 controller.cpp:1400
2022-04-03 22:55:58.134 - Axis 1 reports that it is still moving! controller.cpp:1407
2022-04-03 22:55:58.134 - API: mcMotionSetStill(inst = 0, motor = 0) (Sim)
2022-04-03 22:55:58.135 - SetStill(): Motor 0 last position reported = -5845.6693 controller.cpp:1400
2022-04-03 22:55:58.135 - Axis 1 reports that it is still moving! controller.cpp:1407
2022-04-03 22:55:58.135 - API: mcMotionSetStill(inst = 0, motor = 1) (Sim)
2022-04-03 22:55:58.135 - SetStill(): Motor 1 last position reported = -5804.3307 controller.cpp:1400
2022-04-03 22:55:58.135 - Axis 2 reports that it is still moving! controller.cpp:1407
2022-04-03 22:55:58.135 - API: mcMotionSetStill(inst = 0, motor = 1) (Sim)
2022-04-03 22:55:58.135 - SetStill(): Motor 1 last position reported = -5804.3307 controller.cpp:1400
2022-04-03 22:55:58.135 - Axis 2 reports that it is still moving! controller.cpp:1407
2022-04-03 22:55:58.135 - API: mcMotionSetStill(inst = 0, motor = 2) (Sim)
2022-04-03 22:55:58.135 - SetStill(): Motor 2 last position reported = -13957.7281 controller.cpp:1400
2022-04-03 22:55:58.135 - Axis 3 reports that it is still moving! controller.cpp:1407
2022-04-03 22:55:58.136 - API: mcMotionSetStill(inst = 0, motor = 2) (Sim)
2022-04-03 22:55:58.136 - SetStill(): Motor 2 last position reported = -13957.7281 controller.cpp:1400
2022-04-03 22:55:58.136 - Axis 3 reports that it is still moving! controller.cpp:1407
2022-04-03 22:55:58.136 - API: mcMotionSetStill(inst = 0, motor = 3) (Sim)
2022-04-03 22:55:58.136 - SetStill(): Motor 3 last position reported = 0.0000 controller.cpp:1400
2022-04-03 22:55:58.136 - All motors marked as still.
2022-04-03 22:55:58.136 - Waiting on SetStill is Done!
2022-04-03 22:55:58.136 - API: mcMotionSetStill(inst = 0, motor = 3) (Sim)
2022-04-03 22:55:58.136 - SetStill(): Motor 3 last position reported = 0.0000 controller.cpp:1400
2022-04-03 22:55:58.136 - All motors marked as still.
2022-04-03 22:55:58.137 - Signal id 1142, (Spindle Fwd), changed from HIGH to LOW.
2022-04-03 22:55:58.137 - Signal id 1141, (Spindle On), changed from HIGH to LOW.
2022-04-03 22:55:58.138 - Waiting 0.000000 seconds for spindle to stop... spindle.cpp:348
2022-04-03 22:55:58.138 - Done. spindle.cpp:353
2022-04-03 22:56:00.193 - WaitOnMacro() thisTc = 0, isDone = 1
2022-04-03 22:56:00.257 - Waiting on planner to drain before waiting on SetStill... runcanon.cpp:92
2022-04-03 22:56:00.257 - Waiting on SetStill...
2022-04-03 22:56:00.257 - Controller::RunCanonBuffer called AddStopReportRequest() runcanon.cpp:101
2022-04-03 22:56:00.257 - Requesting a stopped report for axis 0 motors.
2022-04-03 22:56:00.257 - Requesting a stopped report for motor 0.
2022-04-03 22:56:00.257 - Requesting a stopped report for axis 1 motors.
2022-04-03 22:56:00.257 - Requesting a stopped report for motor 1.
2022-04-03 22:56:00.257 - Requesting a stopped report for axis 2 motors.
2022-04-03 22:56:00.257 - Requesting a stopped report for motor 2.
2022-04-03 22:56:00.257 - Requesting a stopped report for axis 3 motors.
2022-04-03 22:56:00.258 - Requesting a stopped report for motor 3.
2022-04-03 22:56:00.258 - API: mcMotionSetStill(inst = 0, motor = 0) (Sim)
2022-04-03 22:56:00.258 - SetStill(): Motor 0 last position reported = 0.0000 controller.cpp:1400
2022-04-03 22:56:00.259 - Axis 1 reports that it is still moving! controller.cpp:1407
2022-04-03 22:56:00.259 - API: mcMotionSetStill(inst = 0, motor = 0) (Sim)
2022-04-03 22:56:00.259 - SetStill(): Motor 0 last position reported = 0.0000 controller.cpp:1400
2022-04-03 22:56:00.259 - Axis 1 reports that it is still moving! controller.cpp:1407
2022-04-03 22:56:00.259 - API: mcMotionSetStill(inst = 0, motor = 1) (Sim)
2022-04-03 22:56:00.259 - SetStill(): Motor 1 last position reported = 0.0000 controller.cpp:1400
2022-04-03 22:56:00.259 - Axis 2 reports that it is still moving! controller.cpp:1407
2022-04-03 22:56:00.259 - API: mcMotionSetStill(inst = 0, motor = 1) (Sim)
2022-04-03 22:56:00.259 - SetStill(): Motor 1 last position reported = 0.0000 controller.cpp:1400
2022-04-03 22:56:00.259 - Axis 2 reports that it is still moving! controller.cpp:1407
2022-04-03 22:56:00.259 - API: mcMotionSetStill(inst = 0, motor = 2) (Sim)
2022-04-03 22:56:00.259 - SetStill(): Motor 2 last position reported = -13957.7281 controller.cpp:1400
2022-04-03 22:56:00.260 - Axis 3 reports that it is still moving! controller.cpp:1407
2022-04-03 22:56:00.260 - API: mcMotionSetStill(inst = 0, motor = 2) (Sim)
2022-04-03 22:56:00.260 - SetStill(): Motor 2 last position reported = -13957.7281 controller.cpp:1400
2022-04-03 22:56:00.260 - Axis 3 reports that it is still moving! controller.cpp:1407
2022-04-03 22:56:00.260 - API: mcMotionSetStill(inst = 0, motor = 3) (Sim)
2022-04-03 22:56:00.260 - SetStill(): Motor 3 last position reported = 0.0000 controller.cpp:1400
2022-04-03 22:56:00.260 - All motors marked as still.
2022-04-03 22:56:00.260 - Waiting on SetStill is Done!
2022-04-03 22:56:00.260 - API: mcMotionSetStill(inst = 0, motor = 3) (Sim)
2022-04-03 22:56:00.260 - SetStill(): Motor 3 last position reported = 0.0000 controller.cpp:1400
2022-04-03 22:56:00.260 - All motors marked as still.
2022-04-03 22:56:00.261 - Signal id 1144, (Coolant On), changed from HIGH to LOW.
2022-04-03 22:56:00.262 - Waiting for motions to complete: MC_CANON_REWIND. gcodeexec.cpp:883
2022-04-03 22:56:00.273 - Attempt transition from "File Running" on event "Stop" gcodeexec.cpp:903
2022-04-03 22:56:00.273 - S_FILE_RUNNING2_on_exit
2022-04-03 22:56:00.273 - S_FILE_RUNNING_on_exit
2022-04-03 22:56:00.273 - Signal id 1114, (Gcode Running), changed from HIGH to LOW.
2022-04-03 22:56:00.274 - ACTION_stop
2022-04-03 22:56:00.306 - S_IDLE_on_entry
2022-04-03 22:56:00.310 - Signal id 1172, (Machine Idle), changed from LOW to HIGH.
Title: Re: Crash after tool change
Post by: Azalin on April 03, 2022, 06:06:22 PM
OK guess what! I downloaded an earlier version from here https://www.machsupport.com/ftp/Mach4/DevlopmentVersions/Mach4Hobby_Installer-4.2.0.4385.exe

And it works as it should. So is this a bug in newer versions?
Title: Re: Crash after tool change
Post by: Azalin on April 03, 2022, 06:26:42 PM
I uploaded a new video. Mach4 version in the video is 4.2.0.4385 and it works perfect.

So my new question is what is the different between the latest Mach4 and 4.2.0.4385 that causes this problem? Is there a workaround I can apply to the latest version I have in my machine? I need to use the latest because I have lots of custom things in it. I mean I can't simply give up the latest and use 4.2.0.4385.

https://www.youtube.com/watch?v=eO5-Z0OttI0 (https://www.youtube.com/watch?v=eO5-Z0OttI0)
Title: Re: Crash after tool change
Post by: Azalin on April 04, 2022, 06:57:30 AM
I tried all these builds. I can confirm that the build 4582 and previous versions are good. I mean removing G43 works on these builds however the problem starts on build 4584 and remains. The latest build is also buggy.


4385 good
4524 good
4543 good
4559 good
4566 good
4563 good
4580 good
4582 good

4584 bad
4596 bad
4682 bad
4744 bad
.....
4824 bad (latest build)
Title: Re: Crash after tool change
Post by: Rob G on April 04, 2022, 09:04:45 AM
Please open the docs folder within Mach4.  Read the document called "Tool Offsets Mach4 Mill"
This goes into extreme detail on setting up single and multiple tool for use while running G code files.

Rob
Title: Re: Crash after tool change
Post by: Azalin on April 04, 2022, 09:15:17 AM
Hi,

The doc says:
"Once the tool change is complete in the MDI tab, enter G43 H1, and hit Cycle Start. This will activate the tool offset for tool 1. These
commands can also be on the same line."

I do the tool changing manually so I don't use G43 but Mach4 keeps behaving there is G43 in the code. When there is no G43 in the code Mach4 moves the Z axis down and crashes.

Have you watched the two videos I posted?
Title: Re: Crash after tool change
Post by: Azalin on April 04, 2022, 02:44:13 PM
Am I the only one having this problem?
Title: Re: Crash after tool change
Post by: Azalin on April 14, 2022, 03:29:30 PM
This M6 function seems to be working fine. I found this code from this video: https://www.youtube.com/watch?v=tCU1bzuDNvI (https://www.youtube.com/watch?v=tCU1bzuDNvI). I simplified and removed some unnecessary (for me) code.


function m6()
 local inst = mc.mcGetInstance() ;
 
 local currentTool = mc.mcToolGetCurrent(inst)
 local selectedTool = mc.mcToolGetSelected(inst)
 local posmode = mc.mcCntlGetPoundVar(inst, mc.SV_MOD_GROUP_3) --get the current mode so we can return to it when macro ends
         
  --Get positions before moving to do tool change
 local valX, rc = mc.mcAxisGetMachinePos(inst, mc.X_AXIS) --Get the position of the X axis in Machine Position
 local valY, rc = mc.mcAxisGetMachinePos(inst, mc.Y_AXIS) --Get the position of the Y axis in Machine Position
 local valZ, rc = mc.mcAxisGetMachinePos(inst, mc.Z_AXIS) --Get the position of the Z axis in Machine Position
 
 
 if selectedTool == currentTool then
  return
  mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
 else
  mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to continue") --Message at beginning of tool change
  mc.mcCntlToolChangeManual(inst, true) --This will pause the tool change here and wait for a press of cycle start to continue

  mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. "   Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
  mc.mcToolSetCurrent(inst, selectedTool) --sets the current tool displayed in mach to the selected tool

  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
   local ToolLength = math.abs(9.5238 + 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
 
  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

  mc.mcCntlGcodeExecute(inst, string.format('G ' .. posmode))--return to pre macro mode G90, or G91
     
 end
 
end

if (mc.mcInEditor() == 1) then
 m6()
enda
Title: Re: Crash after tool change
Post by: Azalin on April 15, 2022, 11:29:19 AM
In the meantime Rob send me an email with an M6 function. I tested it and it worked fine too. Only difference from the stock M6 is it has an extra line which is:
mc.mcMotionSync(inst)

Since it is official I prefer this one.

Thanks Rob


function m6()

   local inst = mc.mcGetInstance()
   local selectedTool = mc.mcToolGetSelected(inst)
   selectedTool = math.tointeger(selectedTool)
   local currentTool = mc.mcToolGetCurrent(inst)
   currentTool = math.tointeger(currentTool)
   
   if selectedTool == currentTool then
      mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
   else
      --Remove this line if you would not like the Z axis to move
      --mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0");--Move the Z axis all the way up
      mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to continue") --Message at beginning of tool change
      mc.mcCntlToolChangeManual(inst, true) --This will pause the tool change here and wait for a press of cycle start to continue
      mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. "   Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
      mc.mcToolSetCurrent(inst, selectedTool)
      mc.mcMotionSync(inst)
   end
end

if (mc.mcInEditor() == 1) then
   m6()
end