Cheers Tom,
Removed the wait and changed to exec program which solved the issue of the GUI.
Your right the KmotionCNC spindle speed is actually showing the surface speed in CSS mode. The spindle is slow to respond, but I'd only be using CSS mode occasionally, in turn operations and at slow feed rates.
For trial purposes I've implemented the gear change code in to my init.c serviceCS() routine without the state machine timer. I understand what you mean, as I've used a similar method of delay by measuring current time and interval duration on the Arduino without pausing the loop.
I decided to run CSS in high gear only:
Although I had to add an additional if (*css_mode != 2) { 'gear change' } statement into my OnCWJog.c and OnCCWJog.c as when the G96 M04 D2500 S300 was called in the program my jog scripts were interpreting S as spindle speed and executing a gear change to low before the change to high by the ServiceCSS(). This extra if solved the issue.Code:// Safety circuit for (;;) { WaitNextTimeSlice(); ServiceCSS(); intTurretActive = persist.UserData[89]; intHomeActive = persist.UserData[83]; //Monitor for E-stop, mains pwr, drive error signals if (ReadBit(136) == 0 || ReadBit(137) == 0 || ReadBit(139) == 0) { if (ch0->Enable) DisableAxis(0); if (ch1->Enable) DisableAxis(1); if (ch2->Enable) DisableAxis(2); ClearBit(159); ClearBit(152); ClearBit(153); ClearBit(154); ClearBit(145); ClearBit(146); //Monitor for limit switches (unless during tool turret rotation) } else if (ReadBit(138) == 0) { if ((intTurretActive == 1) || (intHomeActive == 1)) { //printf("Limit switches disabled for turret change or homing\n"); //Limit switches in-operable } else { if (ch0->Enable) DisableAxis(0); if (ch1->Enable) DisableAxis(1); if (ch2->Enable) DisableAxis(2); ClearBit(159); if (intZpost == 0) printf("Z axis limit triggered\n"); intZpost = 1; } } else if (ReadBit(142) == 0) { if ((intTurretActive == 1) || (intHomeActive == 1)) { //printf("Limit switches disabled for turret change or homing\n"); //Limit switches in-operable } else { if (ch0->Enable) DisableAxis(0); if (ch1->Enable) DisableAxis(1); if (ch2->Enable) DisableAxis(2); ClearBit(159); if (intXpost == 0) printf("X axis limit triggered\n"); intXpost = 1; } } } } #include "C:\KMotion434j\C Programs\SpindleUsingJogs\CSS\MySpindleDefs.h" #include "C:\KMotion434j\C Programs\SpindleUsingJogs\CSS\CSSJog.c" int *css_mode = &persist.UserData[PC_COMM_CSS_MODE]; // Mode 1=Normal RPM mode. 2=CSS float *css_xoff = &persist.UserData[PC_COMM_CSS_X_OFFSET]; // X axis counts for Radius zero float *css_xfactor = &persist.UserData[PC_COMM_CSS_X_FACTOR]; // X axis factor to convert counts to inches float *css_s = &persist.UserData[PC_COMM_CSS_S]; // S speed setting in inches/sec float *css_max_rpm = &persist.UserData[PC_COMM_CSS_MAX_RPM]; // Limit max RPM to this value as Radius approaches zero double css_T=0; // update only every so often int intIsLow; int intIsHigh; #define CSS_UPDATE_DT 0.05 void ServiceCSS(void) { intIsLow = ReadBit(IS_GLOW); intIsHigh = ReadBit(IS_GHIGH); float rpm; double T=Time_sec(); if (*css_mode == 2 && T > css_T) // check if we are in CSS mode and it is time to update { css_T=T+CSS_UPDATE_DT; // determine next time to update // convert axis position to distance from center in inches float radius = fast_fabs((chan[CS0_axis_x].Dest - *css_xoff) * *css_xfactor); if (radius > 0.0f) rpm = *css_s / (radius * (TWO_PI_F/60.0f)); else rpm = *css_max_rpm; if (rpm > *css_max_rpm) rpm = *css_max_rpm; // Select high gear only for CSS if (intIsLow == 1) { Jog(SPINDLEAXIS,0); while (!CheckDone(SPINDLEAXIS)) ; Delay_sec(3.0); //while(intIsHigh != 1) { SetBit(SET_GHIGH); Delay_sec(2.5); intIsHigh = ReadBit(IS_GHIGH); //} ClearBit(SET_GHIGH); printf("Spindle in high gear\n"); Delay_sec(3.0); } if (persist.UserData[STATEVAR]!=0) // if spindle is already on, ramp to new speed { if (USE_POS_NEG_VOLTAGE) Jog(SPINDLEAXIS,rpm * FACTOR * persist.UserData[STATEVAR]); else Jog(SPINDLEAXIS,rpm * FACTOR); } // printf("xoff=%f radius= %f xfactor=%f s=%f(ips) maxrpm=%f rpm=%f\n",*css_xoff,radius,*css_xfactor,*css_s,*css_max_rpm,rpm); } }
What I'm finding now is that when the G96 code is executed the axis start moving before the spindle has changed to high. I've solved this by adding a 10 second delay to the jog scripts (see attached). Whether this is right way of having the axis wait until the spindle has started I don't know.... but it works. As the serviceCSS() is in my init.c running continuously I cannot add a wait.
I'm now going to program in the machine state current time and duration delays as you've suggested, then move on to making sure threading works next week. After this, it's just a case of finishing the post processor and a few wiring issues... hopefully.
Thanks Tom!