Did some more tests and found some Ccode issues.
1. After i run my machine/ToolChanger reference Ccode.Then do a MDI tool change, the tool change sequence faults out at the point where the tool changer should move out to spindle. After i run my main INIT code to reset fault, the tool change sequence works fine.
2. I did a simple Gcode test like this....
G53G0Z0.
M6T5
G53G0Z-2.
G53G0Z0.
M30
And after tool change i get a Following error on z axis when the G53G0Z-2. trys to execute. So i did a test by commenting out the Z axis position move in my M6ToolChange Ccode. And G code ran fine. Of course Z axis did not position for tool change.
This is the Z axis move in the M6ToolChange code that i commented out....
Code:
// 4. Move to toolchange position Z-1.01inches from Reference Position
{
Move(Z, -20528);
while (!CheckDone(2))
WaitNextTimeSlice(); // wait until we are stopped
}
Also tried using the below command to move Z axis but still had same issue of Following Error on Z axis.
Code:
MoveAtVel(2, -20528, 20000);
while (!CheckDone(2)) WaitNextTimeSlice(); // wait until we are stopped
Any ideas what am i missing in my M6Tool change code?
Code:
#include "KMotionDef.h"
#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"
//#define Z 2
main()
{
if (!ReadBit(137))
return 0; // if in Estop, Exit program
// 1. Determine how many pockets to rotate
int pockets = persist.UserData[6] - persist.UserData[157]; // pockets = requested tool - current tool
if (pockets == 0)
return 0; // No toolchange needed, End
if (pockets >= 8)
pockets = -16 + pockets; // If more then halfway CW, reverse
if (pockets <= -8)
pockets = 16 + pockets; // If more then halfway CCW, reverse
persist.UserData[161] = 1; // Toolchanger active disable feedhold button
ResumeCoordinatedMotion(); // Clear feedhold
// 3. Turn off spindle
if (ReadBit(147) || ReadBit(148)) //check if spindle is running forward or reverse
{
SetBit(147); // turn off spindle clockwise
SetBit(148); // turn off spindle counterclockwise
while(fast_fabs(Spindle.TrueSpeedRPS)*60.0>5.0);//wait untiless than 5RPM
Delay_sec(.2);
ClearBit(147);
ClearBit(148);
}
// 4. Move to toolchange position Z-1.01inches from Reference Position
{
MoveAtVel(2, -20528, 20000);
while (!CheckDone(2))
WaitNextTimeSlice(); // wait until we are stopped
//Move(Z, -20528);
//while (!CheckDone(2))
//WaitNextTimeSlice(); // wait until we are stopped
}
// 5. Orientate
if (!ReadBit(1035) || !ReadBit(1037)) // if toolchanger slide is not home estop
{
MsgBox("E-Stop TC not Home",MB_OK|MB_ICONEXCLAMATION);
printf("E-stop Toolchanger not Home");
DoPC(PC_COMM_ESTOP); // E-stop
}
{
persist.UserData[155] = 1; // Enable orientate speed override
SetBit(156); // Kanalog Switch4 to turn on SpindleOrientateProxSensor
Delay_sec(0.1); // Delay 0.1s
DAC(7, -16); // set motor rpm approx 30
SetBit(147); // spindle on CW
Delay_sec(0.2); // wait for spindle to reach speed
while (!ReadBit(1038))
WaitNextTimeSlice(); // wait for SpindleOrientateProx signal
SetBit(48); // Signal to VFD, set VFD to ZeroServoCommand
Delay_sec(0.90); // Delay for spindle to stop at orientation that is set in VFD parameter
}
{
persist.UserData[155] = 0; // Spindle speed normal
Delay_sec(0.75); // wait before checking if successfull
}
while (!ReadBit(1035) || !ReadBit(1037))
WaitNextTimeSlice(); // Check TC is at home position.
// 6. Tool Chnager OUT
SetBit(63); // TC_OUT solenoid
Delay_sec(1.1);
ClearBit(63); //TC_OUT solenoid
double TF = Time_sec() + 2; // timeout in 2 seconds
while (!ReadBit(1034)) // Wait for TC_OUT limit switch
{
WaitNextTimeSlice();
if (Time_sec() > TF) // Timed out?
{
if (MsgBox("E-Stop TC Not OUT", MB_OK | MB_ICONEXCLAMATION))
{
DoPC(PC_COMM_ESTOP);//Estop
persist.UserData[161] = 0; // toolchanger finished
return 0; //exit program
}
else
{
TF = Time_sec() + 3; // continue and timeout after 3 seconds
}
}
}
// 7. Unclamp Tool
SetBit(59); //Tool Release Solenoid
Delay_sec(.6);
double TF = Time_sec() + 2; // timeout in 2 seconds
while (!ReadBit(1039)) // Wait for ToolReleaseProxSensor
{
WaitNextTimeSlice();
if (Time_sec() > TF) // Timed out?
{
if (MsgBox("E-Stop Tool Unclamp Failed",MB_OK|MB_ICONEXCLAMATION))
{
DoPC(PC_COMM_HALT);
persist.UserData[161] = 0; // toolchanger finished
DoPC(PC_COMM_ESTOP);//Estop
return 0; //exit program
}
else
{
TF = Time_sec() + 3; // continue and timeout after 3 seconds
}
}
}
// 8. Move Tool Changer DOWN
SetBit(61); // TC_DOWN Solenoid
Delay_sec(0.9);
ClearBit(61); //TC_DOWN solenoid
double TF = Time_sec() + 2; // timeout in 2 seconds
while (!ReadBit(1036)) // Wait for TC_DOWN Limit Switch
{
WaitNextTimeSlice();
if (Time_sec() > TF) // Timed out?
{
if (MsgBox("E-Stop TC not DOWN",MB_OK|MB_ICONEXCLAMATION))
{
DoPC(PC_COMM_HALT);
persist.UserData[161] = 0; // toolchanger finished
DoPC(PC_COMM_ESTOP); //Estop
return 0; //exit program
}
else
{
TF = Time_sec() + 3; // continue and timeout after 3 seconds
}
}
}
// 9. Rotate Carousel
while (pockets >= 1) // Rotate Turret CW whatever number of pockets
{
SetBit(49); // TC Carousel Motor On CW
while (!ReadBit(1033))
WaitNextTimeSlice(); // Wait for CarouselMotorProxSensor
Delay_sec(.4);
ClearBit(49); // TC_Carousel CW Motor Off
pockets = pockets - 1;
}
while (pockets <= -1) // Rotate Turret CCW whatever number of pockets
{
SetBit(50); // TC Carousel Motor On CCW
while (!ReadBit(1033))
WaitNextTimeSlice(); // Wait for CarouselMotorProxSensor
Delay_sec(.4);
ClearBit(50); // TC_Carousel CCW Motor Off
pockets = pockets + 1;
}
// 10. Move Tool Changer UP
SetBit(60); // TC_UP Solenoid
Delay_sec(0.9);
ClearBit(60); //TC_UP solenoid
double TF = Time_sec() + 2; // timeout in 2 seconds
while (!ReadBit(1037)) // Wait for TC_UP Limit Switch
{
WaitNextTimeSlice();
if (Time_sec() > TF) // Timed out?
{
if (MsgBox("E-Stop TC not UP",MB_OK|MB_ICONEXCLAMATION))
{
DoPC(PC_COMM_HALT);
persist.UserData[161] = 0; // toolchanger finished
DoPC(PC_COMM_ESTOP);//Estop
return 0; //exit program
}
else
{
TF = Time_sec() + 3; // continue and timeout after 3 seconds
}
}
}
// 11. Clamp tool
ClearBit(59); //Tool Release Solenoid
double TF = Time_sec() + 2; // timeout in 2 seconds
while (ReadBit(1039)) // Wait for Tool Release Proximity Sensor
{
WaitNextTimeSlice();
if (Time_sec() > TF) // Timed out?
{
if (MsgBox("E-Stop Tool Clamp Failed",MB_OK|MB_ICONEXCLAMATION))
{
DoPC(PC_COMM_HALT);
persist.UserData[161] = 0; // toolchanger finished
DoPC(PC_COMM_ESTOP);//Estop
return 0; //exit program
}
else
{
TF = Time_sec() + 3; // continue and timeout after 3 seconds
}
}
}
// 12. Tool Changer IN
SetBit(62); // TC_IN solenoid
Delay_sec(0.7);
ClearBit(62); // TC_IN solenoid
double TF = Time_sec() + 2; // timeout in 2 seconds
while (!ReadBit(1035)) // Check TC_IN limit switch
{
WaitNextTimeSlice();
if (Time_sec() > TF) // Timed out?
{
if (MsgBox("E-Stop TC not IN",MB_OK|MB_ICONEXCLAMATION))
{
DoPC(PC_COMM_HALT);
persist.UserData[161] = 0; // toolchanger finished
DoPC(PC_COMM_ESTOP);//Estop
return 0; //exit program
}
else
{
TF = Time_sec() + 3; // continue and timeout after 3 seconds
}
}
}
// 13. Set Variables
persist.UserData[157] = persist.UserData[6]; // Update current tool number
persist.UserData[161] = 0; // toolchanger finished
printf("Tool changed to T%d\n", persist.UserData[157]); // send message to console
// 14. Write current tool # disk
FILE *f;
char s[256];
float CTool = persist.UserData[157]; // s value from g code
f=fopen("c:\\KMotionFiles\\KFlopData.txt","wt");
fprintf(s,"%f\n",CTool);
fclose(f);
//15.
ClearBit(156);
ClearBit(48);
ClearBit(147);
ClearBit(148);
//SetBit(147);
//SetBit(148);
Delay_sec(.3);
}
Thanks,
Troy