simple 2 axis lathe initial lathe set up

Moderators: TomKerekes, dynomotion

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: simple 2 axis lathe initial lathe set up

Post by turbothis » Mon Dec 11, 2023 9:26 pm

ok, i got the spindle servo mounted and ready to test run in jog mode. i just need the 5v and ground to the encoder
spindle encoder A/B to ch2
spindle Z to A4+ and A4- ( bits 8 and 9? )

i dont really under stand the SpindleOnJog examples as the 3 of them all seem to do something with ClearBit(154); ClearBit(155);
with using DAC output there is no need for any FET bit toggling right?

Image

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: simple 2 axis lathe initial lathe set up

Post by turbothis » Mon Dec 11, 2023 9:41 pm

i think this is the old code for my lathe with spindle servo

Code: Select all

 
#include "KMotionDef.h"

#include "MySpindleDefs.h"

int   *css_mode = &persist.UserData[PC_COMM_CSS_MODE];			// Mode 1=Normal RPM mode. 2=CSS

// desired speed is passed from KMotionCNC in variable KMVAR
// save in user variable STATEVAR whether it was off, CW, or CCW (0,1,-1)
// save in user variable SPEEDVAR the last desired speed

main()
{
	float speed = *(float *)&persist.UserData[KMVAR];  // value stored is actually a float 
	float LastState = persist.UserData[STATEVAR];  // get last state 
	
	persist.UserData[SPEEDVAR] = persist.UserData[KMVAR];  // Always save the last desired speed 
	
	if (LastState==0 || *css_mode == 2)  
	{
		// if spindle is off (or CSS mode) and User Changes the speed 
		// just save the desired speed
		
		return 0;
	}
	
	// spindle is already on, so ramp to new speed
	if (USE_POS_NEG_VOLTAGE)
		Jog(SPINDLEAXIS,speed * FACTOR * LastState);
	else
		Jog(SPINDLEAXIS,speed * FACTOR);
		
	printf("Jogging Spindle %f counts/sec\n",speed * FACTOR);
}

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: simple 2 axis lathe initial lathe set up

Post by turbothis » Mon Dec 11, 2023 9:47 pm

i had 2 buttons
one for turning and one for indexing
the old servo was a 3 phase AC though so it had some phase finding in the main init
now with the brushed DC none of that is needed

turning

Code: Select all

#include "KMotionDef.h"

void main()
{
	    // A  axis / spindle

	ch2->InputMode=ENCODER_MODE;
	ch2->OutputMode=DAC_SERVO_MODE;
	ch2->Vel=300000;
	ch2->Accel=80000;
	ch2->Jerk=150000;
	ch2->P=10;
	ch2->I=0;
	ch2->D=10;
	ch2->FFAccel=0;
	ch2->FFVel=0;
	ch2->MaxI=200;
	ch2->MaxErr=1e+06;
	ch2->MaxOutput=2000;
	ch2->DeadBandGain=1;
	ch2->DeadBandRange=0;
	ch2->InputChan0=2;
	ch2->InputChan1=2;
	ch2->OutputChan0=7;
	ch2->OutputChan1=4;
	ch2->MasterAxis=-1;
	ch2->LimitSwitchOptions=0x100;
	ch2->LimitSwitchNegBit=0;
	ch2->LimitSwitchPosBit=0;
	ch2->SoftLimitPos=1e+30;
	ch2->SoftLimitNeg=-1e+30;
	ch2->InputGain0=-1;
	ch2->InputGain1=1;
	ch2->InputOffset0=0;
	ch2->InputOffset1=0;
	ch2->OutputGain=1;
	ch2->OutputOffset=0;
	ch2->SlaveGain=1;
	ch2->BacklashMode=BACKLASH_OFF;
	ch2->BacklashAmount=0;
	ch2->BacklashRate=0;
	ch2->invDistPerCycle=1;
	ch2->Lead=0;
	ch2->MaxFollowingError=1000000;
	ch2->StepperAmplitude=20;

	ch2->iir[0].B0=1;
	ch2->iir[0].B1=0;
	ch2->iir[0].B2=0;
	ch2->iir[0].A1=0;
	ch2->iir[0].A2=0;

	ch2->iir[1].B0=1;
	ch2->iir[1].B1=0;
	ch2->iir[1].B2=0;
	ch2->iir[1].A1=0;
	ch2->iir[1].A2=0;

	ch2->iir[2].B0=1;
	ch2->iir[2].B1=0;
	ch2->iir[2].B2=0;
	ch2->iir[2].A1=0;
	ch2->iir[2].A2=0;

	DefineCoordSystem(1,-1,0,-1);  // define the coordinate system
}
indexing

Code: Select all

#include "KMotionDef.h"

void main()
{
	     // A  axis / spindle
	   
	ch2->InputMode=ENCODER_MODE;
	ch2->OutputMode=DAC_SERVO_MODE;
	ch2->Vel=100000;
	ch2->Accel=300000;
	ch2->Jerk=3e+06;
	ch2->P=30;
	ch2->I=0.001;
	ch2->D=20;
	ch2->FFAccel=0;
	ch2->FFVel=0;
	ch2->MaxI=200;
	ch2->MaxErr=1e+06;
	ch2->MaxOutput=2000;
	ch2->DeadBandGain=1;
	ch2->DeadBandRange=0;
	ch2->InputChan0=2;
	ch2->InputChan1=2;
	ch2->OutputChan0=7;
	ch2->OutputChan1=4;
	ch2->MasterAxis=-1;
	ch2->LimitSwitchOptions=0x100;
	ch2->LimitSwitchNegBit=0;
	ch2->LimitSwitchPosBit=0;
	ch2->SoftLimitPos=1e+30;
	ch2->SoftLimitNeg=-1e+30;
	ch2->InputGain0=-1;
	ch2->InputGain1=1;
	ch2->InputOffset0=0;
	ch2->InputOffset1=0;
	ch2->OutputGain=1;
	ch2->OutputOffset=0;
	ch2->SlaveGain=1;
	ch2->BacklashMode=BACKLASH_OFF;
	ch2->BacklashAmount=0;
	ch2->BacklashRate=0;
	ch2->invDistPerCycle=1;
	ch2->Lead=0;
	ch2->MaxFollowingError=1000000;
	ch2->StepperAmplitude=20;

	ch2->iir[0].B0=1;
	ch2->iir[0].B1=0;
	ch2->iir[0].B2=0;
	ch2->iir[0].A1=0;
	ch2->iir[0].A2=0;

	ch2->iir[1].B0=1;
	ch2->iir[1].B1=0;
	ch2->iir[1].B2=0;
	ch2->iir[1].A1=0;
	ch2->iir[1].A2=0;

	ch2->iir[2].B0=1;
	ch2->iir[2].B1=0;
	ch2->iir[2].B2=0;
	ch2->iir[2].A1=0;
	ch2->iir[2].A2=0;
	
	    EnableAxis(2);
	 	DefineCoordSystem(1,-1,0,2);  // define the coordinate system
        
}

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: simple 2 axis lathe initial lathe set up

Post by turbothis » Mon Dec 11, 2023 10:16 pm

likely jumping the gun but wondering why i can "init" and have encoders read position zero and then when i push either turn or index button i get a new encoder position?
i mean neither index or turn have a set position type command in there right?
Attachments
Capture.JPG

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: simple 2 axis lathe initial lathe set up

Post by turbothis » Mon Dec 11, 2023 10:29 pm

jeez i had another code for defs?

Code: Select all

#define SPINDLEAXIS 2			// Axis Channel to Jog to rotate Spindle
#define FACTOR (2000/60.0)  	// to convert RPM to counts/sec (counts/rev / 60.0sec)
#define SPINDLECW_BIT 154   	// bit to activate to cause CW rotation
#define SPINDLECCW_BIT 155		// 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 1 	// 0 = output Magnitude, 1 = output positive and negative speed 

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

Re: simple 2 axis lathe initial lathe set up

Post by TomKerekes » Tue Dec 12, 2023 1:08 am

spindle Z to A4+ and A4- ( bits 8 and 9? )
No. Its only one bit going into KFLOP JP7 Bit 36

i dont really under stand the SpindleOnJog examples as the 3 of them all seem to do something with ClearBit(154); ClearBit(155);
with using DAC output there is no need for any FET bit toggling right?
That depends on how your Spindles have an on/off input and +/- 10V to control speed and direction. Some have 2 inputs: on-forward and on-reverse to control direction and 0-10V to control speed

likely jumping the gun but wondering why i can "init" and have encoders read position zero and then when i push either turn or index button i get a new encoder position?
i mean neither index or turn have a set position type command in there right?
idk what is your Init Program doing? Post it. What are the Position values on the KMotion.exe Axis Screen?
Regards,

Tom Kerekes
Dynomotion, Inc.

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: simple 2 axis lathe initial lathe set up

Post by turbothis » Tue Dec 12, 2023 5:10 pm

ok,
spindle control
i have a 2000 count encoder with Z pulse
i use a +/- 10V to the drive
1-1 ratio pulley so there is no dirty little numbers there
no relays or on/off required
i want cw and ccw jog and also an A axis indexing

Image

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

Re: simple 2 axis lathe initial lathe set up

Post by TomKerekes » Tue Dec 12, 2023 6:58 pm

Start here.
Regards,

Tom Kerekes
Dynomotion, Inc.

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: simple 2 axis lathe initial lathe set up

Post by turbothis » Tue Dec 12, 2023 10:28 pm

well after hours, again i am no closer to understanding where to put C codes or which to use in what configuration with VARS and thread numbers
sadly most of what i search on here just brings up MY previous threads on the same topic on here. lol

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

Re: simple 2 axis lathe initial lathe set up

Post by TomKerekes » Tue Dec 12, 2023 11:01 pm

So we can help you please put more effort into your responses. Explain what you understand and don't understand, what you have done, and what happened.

I don't think you need any C Code at this point.

Did you do the 3 steps in the link? If so, what happened?
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply