Here's the code from an old backup I've got on my laptop, although I have a niggle in my mind that I had to change the offset calculation on the lathe.
I would got out to the workshop to check, but I'm choked with a cold so have been having a very lazy weekend staying inside where it's warm!
Couple notes are this checks to ensure you're in metric mode, and you have to move the X axis back to the cut position before setting the offset I.e. if you do a pass at 10mm then pull out to stop rubbing, you have to ensure the axis is moved back to 10mm before running this offset program. I normally do a single pass, pull out, move far enough in Z to clear the stock, move X back to the cut depth, then run the program.
Code:
#include "KMotionDef.h"
#include "cyclone.h"
#include "KflopToKMotionCNCFunctions.c"
main()
{
int Units, TWORD, HWORD, DWORD;
double DROx, DROy, DROz, DROa, DROb, DROc, OffsetX;
double XMeasured, XDiff, XNewOffset;
float XEntered;
// get current DRO reading (we only need X, but we have to handle them all)
GetDROs(&DROx, &DROy, &DROz, &DROa, &DROb, &DROc);
// get the current Units and ToolTblID (and ignore the H and D Words)
GetMiscSettings(&Units, &TWORD, &HWORD, &DWORD);
// if KMotionCNC is in inch/G20 mode, then quit as it shouldn't be
if(Units == CANON_UNITS_INCHES){
MsgBox("KMotion set to inches. Set to MM and retry",MB_OK|MB_ICONEXCLAMATION);
ThreadDone();
}
// get the X offset from the tool table using the TWORD as index
GetToolOffsetX(TWORD, &OffsetX);
// now we have those, ask the operator for the actual size
int Answer = InputBox("Enter measured diameter in MM",&XEntered);
printf("Entered Value-%f\n",XEntered);
XMeasured = XEntered;
if(Answer) { // if true/1, then user cancelled
MsgBox("X Offset adjustment cancelled",MB_OK|MB_ICONEXCLAMATION);
ThreadDone; // and kill the thread
} else { // else we got a value and need to do some calcs
// first up we'll calculate the difference
XDiff = DROx - XMeasured;
// then the new offset with some rounding
XNewOffset = RoundToReasonable(OffsetX + XDiff,Units);
// and finally update the tool table
SetToolOffsetX(TWORD, XNewOffset);
}
}
And I've just noticed that calls my cyclone header file. You can delete that line, and just add a define for TMP if you don't already have one.
This was one of the included example files that I modified.