To avoid manually turning the C axis on and off,I did this automatically in the M3, M4, and M5 programs.
The Init program turns on the C axis. The M3 and M4 programs first turn off the C axis, then turn on the spindle as a spindle. The M5 program stops the spindle and activates the C axis.
Init.c (executed .out)
Code: Select all
.......
.......
EnableAxis (0);
EnableAxis (1);
EnableAxis (2);
EnableAxis (5); //Spindle
DefineCoordSystem6(0,1,2,-1,-1,5); //Spindle as C axis
.......
.......
M3.c (executed .out)
Code: Select all
#include "KMotionDef.h"
#include "Milling_Machine_24K40_Hardware.h"
/*
//==== All defined in "Milling_Machine_24K40_Hardware.h" ====
#define FACTOR (11468.8/60.0) //1000 counts/sec / 100 counts/rev = 1 RPS = 60 RPM
#define Last_SPEED persist.UserData[2] //save in user variable Last_SPEED the last desired speed
#define Desired_SPEED persist.UserData[3] //desired speed is passed from KMotionCNC in variable Desired_SPEED.
#define Spindle_STATE persist.UserData[4] //save in user variable Spindle_STATE whether it was off, CW, or CCW (0,1,-1)
*/
main()
{
DefineCoordSystem6(0,1,2,-1,-1,-1); //Spindle as Spindle (Off C axis)
printf("M03 start\n");
float speed = *(float *)&Last_SPEED; // value stored is actually a float
float LastState = Spindle_STATE; // get last state
printf("Prewiew spindle state= %f\n",LastState);
if (LastState==-1)
{
Jog(Spindle,0);
while (!CheckDone(Spindle)) StopCoordinatedMotion();
ResumeCoordinatedMotion();
}
printf("Spindle speed= %f\n",speed);
Jog(Spindle,speed * FACTOR);
while ((ch5->last_vel <=(speed * FACTOR/100*95))||(ch5->last_vel >= (speed * FACTOR/100*105))) StopCoordinatedMotion(); //while speed window = 95- 105%
ResumeCoordinatedMotion();
printf("Jogging Spindle %f counts/sec\n",speed * FACTOR);
Spindle_STATE = 1; // remember we are CW
}
M5.c (executed .out)
Code: Select all
#include "KMotionDef.h"
#include "Milling_Machine_24K40_Hardware.h"
/*
//==== All defined in "Milling_Machine_24K40_Hardware.h" ====
#define FACTOR (11468.8/60.0) //1000 counts/sec / 100 counts/rev = 1 RPS = 60 RPM
#define Last_SPEED persist.UserData[2] //save in user variable Last_SPEED the last desired speed
#define Desired_SPEED persist.UserData[3] //desired speed is passed from KMotionCNC in variable Desired_SPEED.
#define Spindle_STATE persist.UserData[4] //save in user variable Spindle_STATE whether it was off, CW, or CCW (0,1,-1)
*/
main()
{
// spin down
Jog(Spindle,0); //Spindle stop
while (!CheckDone(Spindle)) StopCoordinatedMotion(); //Spindle full stop
ResumeCoordinatedMotion();
Spindle_STATE = 0; // remember we are Off
DefineCoordSystem6(0,1,2,-1,-1,5); //Spindle as C axis
printf("Jogging Spindle Stop\n");
}
Everything is working.
But there's a problem: when you first run a G code, even if the code does not contain spindle or C-axis control, a warning appears:
Then everything gets more interesting. Periodically (sometimes), KMotionCNC does not run .C and .Out programs in KFLOP. Variables persist.UserData[] exchange is lost. Sometimes there is a complete loss of Kflop control via KMotionCNC.
However, KMotion.exe continues to control KFLOP. The console sometimes works. The problem can only be solved by restarting both the PC and KFLOP.
When this does not happen, the spindle and C-axis work and switch normally. I'm not sure if the issue is related to the spindle/C-axis switch, but I haven't noticed it before.