Hi Tom,
Thanks for the reply. Yes velocity seems to make a big difference. Too high and misses the first index pulse. Reduced homing velocity, setting the correct index input bits and polarity has fixed the issue My only minor issue now is KmotionCNC gives me a pop-up box saying "GUI button waiting on C program taking a long time complete. Continue waiting?" during the home process. Is this a simple fix?
I'm currently setting up the CSS feature. I appreciate having a spindle gear change @ 500rpm isnt ideal, but I'm hoping when I do run CSS on turning operations that the min rpm is above 500rpm anyway. I've incorporated the ServiceCSS() function into my init program forever loop (see below).
Code:
#include "KMotionDef.h"
int intTurretActive;
int intHomeActive;
int intXpost;
int intZpost;
main()
{
int BitA,Change1=0,Change2=0, DiffX2;
int PosNoWrap, NewPos, Pos=0, wraps;
double Factor=0;
ch0->InputMode=ENCODER_MODE;
ch0->
........................................................
DefineCoordSystem(1,-1,2,-1);
EnableAxis(0);
EnableAxis(1);
EnableAxis(2);
SetBit(159);
intXpost = 0;
intZpost = 0;
// 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);
//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
#define CSS_UPDATE_DT 0.05
void ServiceCSS(void)
{
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;
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);
}
}
Using the G96 example program on the dynomotion spindle control page I can sucessfully vary the spindle speed according to X radius, but I have two problems:
1. The spindle controller in KmotionCNC shows CSS mode, but the spindle RPM display is wrong. As the actual RPM increases with smaller radius, the display shows the RPM reducing in speed. As the actual RPM decreases, Kmotion shows it as increasing.
2. The spindle doesnt change to the high gear (+500rpm), before starting. It just runs flat out in low gear (see below), varying its speed in corrolation with X.
http://81.138.85.180/~jim_cliff11/css.mp4
When using CSS, would I be right in saying the surface speed (passed in S code - eg. G96 M04 D2500 S159.6), does NOT go through the OnCCWJog.C / OnCWJog.C scripts? The CSSJog.c (incorporated into init.c) solely deals with the S code? If so, could I use the rpm float variable within the ServiceCSS() function to take the required spindle speed, and depending if <500 or >500 implement my gear change code? Basically as I've done in SpindleJog.C (see attached). Tell me if I'm way off track here Tom!
Thanks,
Jim