Originally Posted by
TomKerekes
Hi vektor_z,
Support of metric Tool Table values was corrected in Version 4.34k (1/13/2018). Please try Release Version 4.34 or later.
Hi Tom
Yes, you were right, updated the version to the latest and the length of the tool from the table works in mm.
I edited the C program a little, I need the axis to physically rotate 90 degrees when the tool is changed, and then the axis A is reset.
Code:
#include "KMotionDef.h"#define TMP 10 // which spare persist to use to transfer data
#include "C:\KMotion434\C Programs\KflopToKMotionCNCFunctions.c"
//-----------------------------------------
// Rotary TOOL CHANGING
//-----------------------------------------
#define AXISA 3
#define TOOL_VAR 9 // Tool changer desired new tool Var
// Tool changer Last tool loaded is saved globally in this Var
#define LAST_TOOL_VAR 8 // -1=Spindle empty, 0=unknown, 1-4 Tool Slot loaded into Spindle
#define TOOL_DISK_FILE "c:\\Temp\\ToolChangerData.txt"
//#define TOOL_DISK_FILE "C:\\KMotion434\\C Programs\\ToolChangerData.txt"
#define CNT_PER_DEGREE_A 1125.25
// function prototypes
int DoToolChange(int ToolSlot);
int GetCurrentTool(int *tool);
int SaveCurrentTool(int tool);
BOOL ToolNumberValid(int tool);
int UnloadTool(int CurrentTool);
int LoadNewTool(int CurrentTool, int Tool);
main()
{
int ToolSlot = persist.UserData[TOOL_VAR]; // Requested tool to load (value stored an integer)
if (DoToolChange(ToolSlot)) // perform Tool Change
{
// error, Halt Job
DoPC(PC_COMM_HALT);
}
}
// Perform Tool Change. Return 0=Success, 1=Failure
int DoToolChange(int ToolSlot)
{
int CurrentTool;
if (GetCurrentTool(&CurrentTool))
return 1; // -1=Spindle empty, 0=unknown, 1-4 Tool Slot loaded into Spindle
printf("Load Tool Slot %d requested, Current Tool %d\n", ToolSlot, CurrentTool);
if (!ToolNumberValid(ToolSlot)) // check if invalid
{
char s[80];
sprintf(s, "Invalid Tool Change Number %d\n", ToolSlot);
printf(s);
MsgBox(s, MB_ICONHAND | MB_OK);
return 1;
}
// load requested tool
if (LoadNewTool(CurrentTool, ToolSlot))
return 1;
SaveCurrentTool(ToolSlot); // save the one that has been loaded
return 0; // success
}
// - Load new Tool by adjusting A Axis machine coordinate appropriately
int LoadNewTool(int CurrentTool, int Tool)
{
if (CurrentTool != Tool)
{
double Adjustment = (Tool - CurrentTool) * -90.0 * CNT_PER_DEGREE_A;
//DisableAxis(AXISA);
WaitNextTimeSlice(); // make sure we don't get interrupted
//chan[AXISA].Position -= Adjustment; // Adjust machine coordinates
//EnableAxisDest(AXISA, chan[AXISA].Position); // re-enable where we now are
MoveAtVel(3,Adjustment, 100000); // ??????????? ??? Y ? ??????? ? ??????? 819 ??? (??? ???????? 1?? ??? ??????? ????) ?? ???????? 20480???/???
while (!CheckDone(3)) ; // ???????? ????????? ???????? ??? b
Zero(3);
//????????? 1-2 ???????? ? ??????????? ?? ????? ???????????
}
if (Tool == 1)
{
ClearBit(23);
ClearBit(24);
}
if (Tool == 2)
{
SetBit(24);
SetBit(23);
}
if (Tool == 3)
{
ClearBit(23);
SetBit(24);
}
if (Tool == 4)
{
SetBit(23);
ClearBit(24);
}
return 0; //success
}
// Get the last loaded tool. Parameter points to where to return tool
// First try to get from KFLOP memory
// if memory is invalid, try to read from disk
// if can't read disk then ask Operator
// returns 0 on success, 1 on fail or Operator asked to abort
int GetCurrentTool(int *ptool)
{
int success, Answer, result, tool;
float value;
tool = persist.UserData[LAST_TOOL_VAR];
success = ToolNumberValid(tool); // check if valid
if (!success) // invalid after power up, try to read from PC Disk File
{
// Try to open file
FILE *f = fopen(TOOL_DISK_FILE, "rt");
if (f) // did file open?
{
// read a line and convert it
result = fscanf(f, "%d", &tool);
fclose(f);
if (result == 1 && ToolNumberValid(tool))
{
printf("Read Disk File Value of %d\n", tool);
success = TRUE; // success if one value converted
}
}
if (!success)
printf("Unable to open/read file:%s\n", TOOL_DISK_FILE);
}
if (!success) // if still no success ask Operator
{
//???? ????????? ?? ???????? ?? ????? ???? ?? A ? ????????? 1 ??????????
ch1->LimitSwitchOptions=0x100; // ?????????? ????????? ????????? ??????? ?? ??? b, ????? ?? ????????????? ???
Jog(3,20000); // ??????????? ??? Y ? ????????????? ??????????? ?? ???????? 10% ?? ???????????? 204800 ???/???
while (ReadBit(15)) ; // ???????? ???????????? ??????? ?? b- ??? 139
Zero(3); // ????????? ?????????? ??? b
Jog(3,0); // ????????? ??? Y
MoveAtVel(3,-300, 1000); // ??????????? ??? Y ? ??????? ? ??????? 819 ??? (??? ???????? 1?? ??? ??????? ????) ?? ???????? 20480???/???
while (!CheckDone(3)) ; // ???????? ????????? ???????? ??? b
Jog(3,300); // ????????? ??????????? ??? Y ? ????????????? ??????????? ?? ???????? 5% ?? ???????????? 204800 ???/???
while (ReadBit(15)) ; // ???????? ???????????? ??????? ?? b- ??? 139
Zero(3); // ????????? ?????????? ??? b
Jog(3,0); // ????????? ??? Y
MoveAtVel(3,-5380, 30000); // ??????????? ??? Y ? ??????? ? ??????? 819 ??? (??? ???????? 1?? ??? ??????? ????) ?? ???????? 20480???/???
while (!CheckDone(3)) ; // ???????? ????????? ???????? ??? b
Zero(3);
tool = 1;
// Answer = InputBox("Tool in Spindle or -1", &value);
// if (Answer)
// {
// printf("Operator Canceled\n");
// return 1;
// }
// else
// {
// tool = value;
// printf("Operator Entered Value of %d\n", tool);
// }
//}
//if (!ToolNumberValid(tool)) // check if invalid
//{
// char s[80];
// sprintf(s, "Invalid Current Tool Number %d\n", tool);
// printf(s);
// MsgBox(s, MB_ICONHAND | MB_OK);
// return 1;
}
printf("Current tool = %d\n", tool);
*ptool = tool; // return result to caller
return 0; //success
}
// save the tool number to KFLOP global Variable and to PC Disk file in case we loose power
int SaveCurrentTool(int tool)
{
persist.UserData[LAST_TOOL_VAR] = tool;
FILE *f = fopen(TOOL_DISK_FILE, "wt");
fprintf(f, "%d\n", tool);
fclose(f);
return 0;
}
// check if Current Tool number Valid
// -1 = no tool loaded
// 1-4 = valid tool
BOOL ToolNumberValid(int tool)
{
return tool == -1 || (tool >= 1 && tool <= 4);
}
But I still need to with each Homing axis A, the tool is dropped to the number 1.
I have on the main screen a button home axis A,
she executes this code
Code:
ch1->LimitSwitchOptions=0x100;
Jog(3,20000);
while (ReadBit(15)) ;
Zero(3);
Jog(3,0);
MoveAtVel(3,-300, 1000);
while (!CheckDone(3)) ;
Jog(3,300);
while (ReadBit(15)) ;
Zero(3);
Jog(3,0);
MoveAtVel(3,-5380, 30000);
while (!CheckDone(3)) ;
Zero(3);
I need to install tool # 1 while executing this code.
thank.