Automatic tool length measurement
Hi everybody.
Now do automatic length measuring instruments, and then writing it to a table.
Code length measurement works. That is:
Code:
#include "KMotionDef.h"
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"
#define Zaxis 2
main()
{
int FixtureIndex,Units, TWORD, HWORD, DWORD;
double NewToolLength,OriginOffsetZ,AxisOffsetZ;
double Machinex,Machiney,Machinez,Machinea,Machineb,Machinec;
double P0,P1;
SetBitDirection(0,0); // для оси Z
//сначала ось Z - 5000 имп/мм
Jog(2,-4000);
while (!ReadBit(0)) ;
Jog(2,0);
P0 = chan[Zaxis].Dest;
P1=P0+1000;
MoveAtVel(Zaxis,P1,2000);
while (ch2->Dest < P1) ;
Jog(2,-1000);
while (!ReadBit(0)) ;
Jog(2,0);
//
GetMiscSettings(&Units, &TWORD, &HWORD, &DWORD);
GetFixtureIndex(&FixtureIndex);
GetOriginOffset(&OriginOffsetZ, FixtureIndex, Zaxis);
GetAxisOffset(&AxisOffsetZ, Zaxis);
GetMachine(&Machinex,&Machiney,&Machinez,&Machinea,&Machineb,&Machinec);
// Compute Tool Offset to make DRO zero when Tool Length selected and enabled
//
// Since Machine = DRO + OriginOffset + AxisOffset + ToolOffset
//
// Set DRO = 0 and solve for ToolOffset
//
NewToolLength = RoundToReasonable(Machinez - OriginOffsetZ - AxisOffsetZ,Units);
// Change Currently Selected Tool Length
SetToolLength(TWORD,NewToolLength);
}
But I have a different diameter tools. And I need to do offset of X and Y to the edge cutter hit the center of the sensor.
How to read the offset of X and Y from the tool table?
Sincerely, Alexander.
Re: Automatic tool length measurement
Hi Alexander,
I think we will need to add in KFLOP to PC commands like SetToolLength for X and Y Tool Offsets. Or is it Diameter that you need?
What exactly would you like to do?
Regards
TK
1 Attachment(s)
Re: Automatic tool length measurement
Hi Tom.
Thanks for the answer.
I need to read a variable from a table tool radius or offset. No matter what.
I want to when measuring the length of the tool was its automatic shift from the center of the sensor. Need to measure the edge cutter.
Re: Automatic tool length measurement
Tom hello.
Please help solve the problem.
Sincerely, Alexander.
Re: Automatic tool length measurement
Hi Alexander,
We have added functionality for Get/Set Tool Diameter and Tool XY offsets.
Code:
// Request a Tool Diameter, answer will be placed at persist offset
int GetToolDiameter(int index, double *Diameter)
// Change a Tool Diameter, value to be passed up is at specified persist offset
int SetToolDiameter(int index, double Diameter)
// Request a Tool X offset, answer will be placed at persist offset
int GetToolOffsetX(int index, double *OffsetX)
// Change a Tool X offset, value to be passed up is at specified persist offset
int SetToolOffsetX(int index, double OffsetX)
// Request a Tool Y offset, answer will be placed at persist offset
int GetToolOffsetY(int index, double *OffsetY)
// Change a Tool Y offset, value to be passed up is at specified persist offset
int SetToolOffsetY(int index, double OffsetY)
Here is an example of how to use them:
Code:
GetToolDiameter(TWORD,&ToolDiameter);
GetToolOffsetX(TWORD,&ToolOffsetX);
GetToolOffsetY(TWORD,&ToolOffsetY);
printf("Original Tool #%d Diameter=%.17g OffsetX=%.17g OffsetY=%.17g\n",
TWORD,ToolDiameter,ToolOffsetX,ToolOffsetY);
SetToolDiameter(TWORD,0.1);
SetToolOffsetX(TWORD,0.2);
SetToolOffsetY(TWORD,0.3);
GetToolDiameter(TWORD,&NewToolDiameter);
GetToolOffsetX(TWORD,&NewToolOffsetX);
GetToolOffsetY(TWORD,&NewToolOffsetY);
printf("New Tool #%d Diameter=%.17g OffsetX=%.17g OffsetY=%.17g\n",
TWORD,NewToolDiameter,NewToolOffsetX,NewToolOffsetY);
That prints:
Original Tool #0 Diameter=0 OffsetX=0 OffsetY=0
New Tool #0 Diameter=0.1 OffsetX=0.2 OffsetY=0.3
Can you do the rest yourself?
To make use of this functionality add and patch the following files in Test Version V4.33c
http://dynomotion.com/Software/KMotion433cc.exe
Files are located here:
Index of /Software/Patch/AddKMotionCNC_GetSetToolDiamXYOff_V433c
Copy KMotionCNC.exe to the KMotion/Release Directory
Copy PC-DSP.h to the DSP_KFLOP directory
Copy KflopToKMotionCNCFunctions.c to the C Programs Directory
Copy ToolTableSetDebug.c to the C Programs Directory
Please provide feedback if problems are encountered.
Regards
Re: Automatic tool length measurement
Thank you very much Tom!
When I conducted an experiment, it will unsubscribe here.
Sincerely, Alexander.
Re: Automatic tool length measurement
Hello everyone.
Tom, thank you.
Everything works. The result was the following code:
Code:
#include "KMotionDef.h"
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"
#define Zaxis 2
#define Xaxis 0
#define Yaxis 1
#define XaxisCNTS_mm 3937.0078740157
#define ToolSensorPin 0
#define ToolSensorX 992000
#define ToolSensorY 400000
int DoPC(int cmd);
int DoPCFloat(int cmd, float f);
int DoPCInt(int cmd, int i);
int MsgBox(char *s, int Flags);
int SetVars(int poff, int varoff, int n);
int GetVars(int varoff, int n, int poff);
main()
{
int FixtureIndex,Units, TWORD, HWORD, DWORD;
double NewToolLength,Length,OriginOffsetZ,AxisOffsetZ,ToolOffsetX,ToolDiameter;
double Machinex,Machiney,Machinez,Machinea,Machineb,Machinec;
double P0,P1,A0,A1;
int GetToolOffsetX(int index, double *OffsetX);
int GetToolDiameter(int index, double *Diameter);
GetMiscSettings(&Units, &TWORD, &HWORD, &DWORD);
SetBitDirection(ToolSensorPin,0); // sensor input - вход датчика
// Stop the spindle and lift tool - Останавливаем шпиндель и поднимаем инструмент
ClearBit(153); // Stop spindle
ClearBit(154); // Stop spindle
Delay_sec(0.5);
MoveAtVel(Zaxis,1300000, 40000);
while (ch2->Dest < 1300000) ;
//Ansver "ToolChange"
GetToolDiameter(TWORD,&ToolDiameter);
printf("Original Tool #%d Diameter=%.17g\n",
TWORD,ToolDiameter);
int Answer;
//int tool = persist.UserData[9]; // value stored is actually a float
char s[100];
sprintf(s,"Change to Tool diameter D=%.17g\n",ToolDiameter); //sprintf(s,"Change to Tool diameter D=%d",ToolDiameter);
Answer = MsgBox(s,MB_ICONEXCLAMATION);
//if (Answer != IDOK)
//{
DoPC(PC_COMM_HALT);
//}
// Offset X - перемещаем инструмент к датчику и делаем смещение по Х
GetToolOffsetX(TWORD,&ToolOffsetX);
printf("Original Tool #%d OffsetX=%.17g\n",
TWORD,ToolOffsetX);
MoveAtVel(Xaxis,ToolSensorX-ToolOffsetX*XaxisCNTS_mm,40000);
MoveAtVel(Yaxis,ToolSensorY,40000);
while (ch0->Dest != ToolSensorX-ToolOffsetX*XaxisCNTS_mm) ; // ПРОВЕРИТЬ УСЛОВИЕ!!!!
while (ch1->Dest != ToolSensorY) ; // ПРОВЕРИТЬ УСЛОВИЕ!!!!
//omit the Z-axis of sensor - опускаем инструмент на датчик
Jog(Zaxis,-10000);
while (!ReadBit(ToolSensorPin)) ;
Jog(Zaxis,0);
P0 = chan[Zaxis].Dest;
P1=P0+100000;
MoveAtVel(Zaxis,P1,20000);
while (ch2->Dest < P1) ;
Jog(Zaxis,-1000);
while (!ReadBit(ToolSensorPin)) ;
Jog(Zaxis,0);
// calculate the length of the instrument and record in the table
// вычисляем длину инструмента и записываем в таблицу
GetFixtureIndex(&FixtureIndex);
GetOriginOffset(&OriginOffsetZ, FixtureIndex, Zaxis);
GetAxisOffset(&AxisOffsetZ, Zaxis);
GetMachine(&Machinex,&Machiney,&Machinez,&Machinea,&Machineb,&Machinec);
// Compute Tool Offset to make DRO zero when Tool Length selected and enabled
//
// Since Machine = DRO + OriginOffset + AxisOffset + ToolOffset
//
// Set DRO = 0 and solve for ToolOffset
//
NewToolLength = RoundToReasonable(Machinez - OriginOffsetZ - AxisOffsetZ,Units);
// Change Currently Selected Tool Length
SetToolLength(TWORD,NewToolLength);
// Lift tool - Останавливаем шпиндель и поднимаем инструмент
MoveAtVel(Zaxis,1300000, 40000);
while (ch2->Dest < 1300000) ;
printf("Units=%d T=%d H=%d D=%d\n",Units, TWORD, HWORD, DWORD);
printf("Current Tool Length is %g\n",Length);
printf("Fixture Index = %d\n",FixtureIndex);
printf("Origin Offset Z = %g\n",OriginOffsetZ);
printf("Axis Offset Z = %g\n",AxisOffsetZ);
printf("Machine Coordinates %.17g %.17g %.17g %.17g %.17g %.17g\n",Machinex,Machiney,Machinez,Machinea,Machineb,Machinec);
}
int SetVars(int varoff, int n, int poff)
{
persist.UserData[PC_COMM_PERSIST+2] = n; // number of elements
persist.UserData[PC_COMM_PERSIST+3] = poff; // persist offset (doubles)
return DoPCInt(PC_COMM_SET_VARS,varoff); // Var index and Cmd
}
int GetVars(int varoff, int n, int poff)
{
persist.UserData[PC_COMM_PERSIST+2] = n; // number of elements
persist.UserData[PC_COMM_PERSIST+3] = poff; // persist offset (doubles)
return DoPCInt(PC_COMM_GET_VARS,varoff); // Var index and Cmd
}
#define GATH_OFF 0 // define the offset into the Gather buffer where strings are passed
// Trigger a message box on the PC to be displayed
// defines for MS Windows message box styles and Operator
// response IDs are defined in the KMotionDef.h file
int MsgBox(char *s, int Flags)
{
char *p=(char *)gather_buffer+GATH_OFF*sizeof(int);
int i;
do // copy to gather buffer w offset 0
{
*p++ = *s++;
}while (s[-1]);
persist.UserData[PC_COMM_PERSIST+2] = Flags; // set options
DoPCInt(PC_COMM_MSG,GATH_OFF);
return persist.UserData[PC_COMM_PERSIST+3];
}
// put the MDI string (Manual Data Input - GCode) in the
// gather buffer and tell the App where it is
int MDI(char *s)
{
char *p=(char *)gather_buffer+GATH_OFF*sizeof(int);
int i;
do // copy to gather buffer w offset 0
{
*p++ = *s++;
}while (s[-1]);
// issue the command an wait till it is complete
// (or an error - such as busy)
return DoPCInt(PC_COMM_MDI,GATH_OFF);
}
// Put a Float as a parameter and pass the command to the App
int DoPCFloat(int cmd, float f)
{
int result;
persist.UserData[PC_COMM_PERSIST+1] = *(int*)&f;
return DoPC(cmd);
}
// Put an integer as a parameter and pass the command to the App
int DoPCInt(int cmd, int i)
{
int result;
persist.UserData[PC_COMM_PERSIST+1] = i;
return DoPC(cmd);
}
// Pass a command to the PC and wait for it to handshake
// that it was received by either clearing the command
// or changing it to a negative error code
int DoPC(int cmd)
{
int result;
persist.UserData[PC_COMM_PERSIST]=cmd;
do
{
WaitNextTimeSlice();
}while (result=persist.UserData[PC_COMM_PERSIST]>0);
//printf("Result = %d\n",result);
return result;
}
Sometimes the program KmotionCNC 4.33cc itself is paused, she can completely shut down, the axis sometimes not go to the right place. This version is not stable.
Re: Automatic tool length measurement
Hi Alexander,
Very nice and thanks for sharing.
There is a simpler and better way to check if a motion has completed using ChecDone(). Comparing floating point numbers exactly can sometime cause problems because of small round off errors. So you might replace:
while (ch2->Dest < 1300000) ;
with
while (!CheckDone(2)) ;
and
while (ch0->Dest != ToolSensorX-ToolOffsetX*XaxisCNTS_mm) ; // ПРОВЕРИТЬ УСЛОВИЕ!!!!
while (ch1->Dest != ToolSensorY) ; // ПРОВЕРИТЬ УСЛОВИЕ!!!!
with
while (!CheckDone(0) || !CheckDone(1)) ;
and
while (ch2->Dest < P1) ;
with
while (!CheckDone(2)) ;
and
while (ch2->Dest < 1300000) ;
with
while (!CheckDone(2)) ;
I don't know why V4.33cc would be unstable. Can you provide any information about when it happens and under what conditions. We will be making a new Test Version 4.33d with all these patches. You might try that to see if it helps.
Regards
Re: Automatic tool length measurement
KMotion/KFlop Test Version 4.33d Available
Several new commands and bug fixes.
For details see:
http://www.dynomotion.com/Software/K...%20Changes.pdf
Download here:
http://www.dynomotion.com/Software/KMotion433d.exe
Regards,
1 Attachment(s)
Re: Automatic tool length measurement
Thanks Tom, I'll try.
The program version 4,33сс itself shut down if you do what any team through MDI. Not every time, and sometimes. But often.\
Here are my settings and C files.
Can help find the problem?
Regards, Alexander.
Re: Automatic tool length measurement
Hi Tom
4.33d is not stable. It crashed 3 times in a row. Then I went back to 33c everything was fine again.
The crashing was once after saving my offsets (G54) and returning to the main screen ->crash
Three times after setting up my offsets, then manually change tool on main screen ->crash
But because at one point my MPG behaved strange before the crash (one axis was not possible to jog the other was fine) I suspect the error in the Kflop software. MPG is hard wired to Kflop.
Regards
Leo
Re: Automatic tool length measurement
Hi Leo and Alexander,
You are correct that test version had a significant bug in KMotionCNC introduced when adding the Run Time Interpreter Log. Turns out MDI, Tool Changes, and such invoke the Interpreter that then tried to log invalid data.
Please see the new Test Release V 4.33f described here to see if it resolves your issues:
https://groups.yahoo.com/neo/groups/...messages/10180
Regards