So now iam opening a new can of worms on my lathe. And trying to configure for constant surface speed. I have looked at the example...https://dynomotion.com/Help/KMotionCNC/ ... ontrol.htm.
Altered and added the MySpindleDefs.h to directories DSP_KFLOP and DSP_Kmotion. Below is the altered MySpindleDefs.h...
Code: Select all
#define SPINDLEAXIS 3 // Axis Channel to Jog to rotate Spindle
#define FACTOR (1.0/4000) // to convert RPM to counts/sec (counts/rev / 60.0sec)
#define SPINDLECW_BIT 147 // bit to activate to cause CW rotation
#define SPINDLECCW_BIT 148 // bit to activate to cause CCW rotation
#define SPEEDVAR 99 // global persistant variable to store latest speed
#define STATEVAR 98 // global persistant variable to store latest state (-1=CCW,0=off,1=CW)
#define KMVAR PC_COMM_CSS_S // variable KMotionCNC will pass speed parameter (113)
#define USE_POS_NEG_VOLTAGE 0 // 0 = output Magnitude, 1 = output positive and negative speed
Added the CSSJog.c unchanged to my C programs folder.Below is the CSSjog.c
Code: Select all
// Handle CSS (Constant Surface Speed) messages from KMotionCNC)
//
// This code assumes you have an Axis Channel Configured to control
// Spindle speed and Jog Calls can be made to control speed
//
// Include this function into your main Init Thead code and call it
// continuously from a forever loop similar to that shown here
//#include "KMotionDef.h"
//#include "MySpindleDefs.h"
//#include "CSSJog.c"
//main()
//{
// for (;;)
// {
// WaitNextTimeSlice();
// ServiceCSS();
// }
//}
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);
}
}
Iam using this gcode to test...
Code: Select all
(1001)
(1UPPERROLLERFACE_TURNOP2)
N1 G18
N2 G90
N3 G20
(FACE1)
N4 G53 G0 X0.
G97m3s400
N5 T1 M6
N6 G43 H1
N7 G54
N9 G96 D800 S650 M3
N10 G95
N11 G0 X5.175 Z0.35
G01X2F.05
G0X5.175
M05
G53X0Z0
M30
Can you put some light on this for me?
Troy