Lathe Tool Z offset

Moderators: TomKerekes, dynomotion

User avatar
TomKerekes
Posts: 2677
Joined: Mon Dec 04, 2017 1:49 am

Re: Lathe Tool Z offset

Post by TomKerekes » Sun May 26, 2019 5:59 pm

Hi Troy,

Sorry for the delay, but I haven't been able to reproduce this. Is this still an issue?

But I suspect the problem is caused by having 2 Threads sending commands to KMotionCNC. The KflopToKMotionCNCFunctions.c are not currently written to be Thread safe. That is they only work reliably if only one Thread at a time is sending commands. The code assumes that KMotionCNC is idle and not processing any commands. It then assumes it can immediately tell KMotionCNC to do something. It then waits until KMotionCNC finishes and again is idle before returning and allowing other commands. So things get confused when more than one Thread is issuing commands.

It isn't clear to me what would cause the Init Thread to be issuing commands during a Tool Change. Maybe Analog noise causing Override commands?

But anyway, I think a safer approach would be to have the M6 program set a Virtual Bit to request that the Init Program perform the KMotionCNC commands. That would result in only one Thread sending commands.

Here is an M6 C Program to perform a request and wait until the request has been completed:

Code: Select all

#include "KMotionDef.h"

#define TOOL_CHANGE_REQUEST 1056

main()
{
	SetBit(TOOL_CHANGE_REQUEST);  // request halt and display message
	
	while (ReadBit(TOOL_CHANGE_REQUEST)) ;  // wait until finished
}


Here is some code to add to the Init Program forever loop to perform the request and acknowledge it has been performed:

Code: Select all

	#define TOOL_CHANGE_REQUEST 1056
		
	/// Handle Tool Change
	if  (ReadBit(TOOL_CHANGE_REQUEST))
	{
		DoPC(PC_COMM_HALT_NEXT_LINE);
		MsgBox("!!!Change Tool!!!",MB_OK|MB_ICONEXCLAMATION);
		ClearBit(TOOL_CHANGE_REQUEST);
	}
I've also attached your files with the changes.
HTH
Attachments
KMCNC2AxisAnalogM6 V5,1.c
(15.6 KiB) Downloaded 177 times
ManualToolChange2 Request.c
(215 Bytes) Downloaded 157 times
Regards,

Tom Kerekes
Dynomotion, Inc.

tmday7
Posts: 51
Joined: Fri May 11, 2018 10:17 pm

Re: Lathe Tool Z offset

Post by tmday7 » Mon May 27, 2019 3:27 pm

Hi Tom,
No worries about delay. :)

Yes it is still an issue. Currently i have a work around. Iam replacing the M6 with a M0 and executing my M0 c code that does an MDI "M0". Obviously there is no pop up message but at least this way the Gcode will stop for a tool change.
Tried your updated ccode and after clicking the OK on pop up, that gcode still rewinds to beginning. I checked to see that Virtual bit 1056 is being set and it is until the OK is clicked.
Something else i noticed when using the Single Step button to run a Gcode. After one click of Single Step the pointer beside the Gcode only moves down one line then rewinds back to beginning. Never used this button until now, so dont know if it worked on my lathe at some point or not.

Thanks again,
Troy

User avatar
TomKerekes
Posts: 2677
Joined: Mon Dec 04, 2017 1:49 am

Re: Lathe Tool Z offset

Post by TomKerekes » Tue May 28, 2019 4:23 pm

Hi Troy,

Strange. I'm having no luck reproducing the problem. It must be something very specific to your system.

Could I ask you to do some troubleshooting? Please try reverting your system back to a default configuration step-by-step in order to determine by process of elimination what things are causing the issue.

The single step problem, if it is consistent, would probably be the simplest test to determine if the problem exists or not.

You might use KMotion.exe to halt your Init Program to see if that is involved in the issue.

And/or change the Actions in KMotionCNC Tool Setup to "None" to see if that makes a difference.

As a sanity check you might do a fresh install of V4.34 to a dummy directory to see if it behaves properly in its original configuration.
Regards,

Tom Kerekes
Dynomotion, Inc.

tmday7
Posts: 51
Joined: Fri May 11, 2018 10:17 pm

Re: Lathe Tool Z offset

Post by tmday7 » Sat Jun 01, 2019 1:23 am

Hi Tom,
Well, did some trouble shooting threw the week with no results. So i just tried the good old sanity check and all seems to be working good now:)
Step works correctly and so does the M6 pop up code. I think something may have got corrupted when i changed PCs at beginning of retrofit and copied over files from old PC. Anyway all looks good.

Thanks again for your hard work Tom,its always appreciated,
Troy

Post Reply