CSS on Lathe

Moderators: TomKerekes, dynomotion

Post Reply
tmday7
Posts: 50
Joined: Fri May 11, 2018 10:17 pm

CSS on Lathe

Post by tmday7 » Sat Jun 01, 2019 11:50 pm

Hay Tom,
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);
	}
}
And added the ServiceCSS(); to my main Init code.

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
When the CSS starts the spindle RPM drops to about 380rpms (checking with a laser Tach) and when Xaxis starts to move, SpindleRPM drops to about 122RPMs and stays there. The X axis continues to feed but actual spindle RPM never changes(on laser Tach) from 122RPM but in KMCNC the display RPM is following the X axis but instead of it getting faster as tool reaches center of part,the KMCNC rpm display is displaying slower. Not sure if i have my spindle axis configured correctly in my main init code. Attached is init ccode.
Can you put some light on this for me? :)

Troy
Attachments
KMCNC2AxisAnalogM6 V5,3.c.txt
(17.05 KiB) Downloaded 18 times

tmday7
Posts: 50
Joined: Fri May 11, 2018 10:17 pm

Re: CSS on Lathe

Post by tmday7 » Sun Jun 02, 2019 12:12 pm

I found one issue, in the MySpindleDefs header file. I had the wrong axis. Had 3 because i was thinking of the spindle encoder is connected to axis 3 inputs. :roll: I changed it to 7 which is the output for spindle, but nothing has changed, still does same thing i described in previous post.

Troy

User avatar
TomKerekes
Posts: 617
Joined: Mon Dec 04, 2017 1:49 am

Re: CSS on Lathe

Post by TomKerekes » Sun Jun 02, 2019 6:10 pm

Hi Troy,

All that you posted and described looks ok to me.
but in KMCNC the display RPM is following the X axis but instead of it getting faster as tool reaches center of part,the KMCNC rpm display is displaying slower.
In CSS mode KMotionCNC displays the cutting rate in linear feet/min not RPM. So it makes sense that if the RPM does change but the radius gets smaller then the cutting rate would decrease.

It seems the basic problem is the RPM is not changing for some reason.

The CSS code doesn't change the speed if the Spindle is off. It determines if the Spindle is off by checking the STATEVAR. So it is a requirement that your M3/M4/M5 C programs to set the STATEVAR properly with something like:

persist.UserData[STATEVAR] = 1; // remember we are CW

Also the actual value of STATEVAR is needs to be defined the same consistently everywhere. To assure that this is true it is best to include MySpindleDefs.h rather than duplicating definitions in each program. I suspect you are not doing this or your basic Spindle programs wouldn't have worked before you fixed MySpindleDefs.h referencing the wrong axis.

In order to troubleshoot what is wrong you might temporarily change the update time in CSSJogs.c to something like 2 seconds and enable the print statement.

If you still cant get it to work properly, post all your M3,M4,M5,S Spindle Programs and the Tool Setup Screens (M0 - M30 and Trajectory Planner Pages).

Also Single step through the GCode and tell us which line is executed and what the Console shows.

With S=650 ft/min and X=5.175 inch radius the RPM should be 239.9 RPM

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

tmday7
Posts: 50
Joined: Fri May 11, 2018 10:17 pm

Re: CSS on Lathe

Post by tmday7 » Fri Jun 07, 2019 10:24 pm

Hi Tom,
Been trying to get this to work with no change in issue of spindle RPM not changing. So i opened the CSSjogs.c program and enabled the print out. Then did a compile to check it and i got a "CSSJog.c:22: 'persist' undeclared". I get the same persist undeclared when i disable the print out. I dont remember changing anything in the CSSJogs program.
Attached are c programs.

Thanks,
Troy
Attachments
TrajectoryPlanner.jpg
M0-M30.jpg
CSSJog.zip
(3.06 KiB) Downloaded 14 times

User avatar
TomKerekes
Posts: 617
Joined: Mon Dec 04, 2017 1:49 am

Re: CSS on Lathe

Post by TomKerekes » Sat Jun 08, 2019 1:56 am

Hi Troy,

The code inside the file CSSJog.c is basically only a function that is meant to be included in another program (your KMCNC2AxisAnalogM6 V5,3.c). It can not be compiled as a program on its own as there would be no main function and other header files aren't included to define things. To compile it and check for errors compile the program that includes it.

On a note unrelated to your problem I believe the KMotionCNC | Tool Setup | Trajectory Planner | Threading | Spindle axis is incorrectly set to 3 instead of 7.
Regards,

Tom Kerekes
Dynomotion, Inc.

tmday7
Posts: 50
Joined: Fri May 11, 2018 10:17 pm

Re: CSS on Lathe

Post by tmday7 » Sat Jun 08, 2019 2:30 am

Hi Tom,
On a note unrelated to your problem I believe the KMotionCNC | Tool Setup | Trajectory Planner | Threading | Spindle axis is incorrectly set to 3 instead of 7.
So its not were i have the encoder connected to on the Kanalog board?

Troy

User avatar
TomKerekes
Posts: 617
Joined: Mon Dec 04, 2017 1:49 am

Re: CSS on Lathe

Post by TomKerekes » Sat Jun 08, 2019 7:09 am

It is the KFLOP axis that is configured to read the encoder channel it is connected to.
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply