idk why lathe changes
Moderators: TomKerekes, dynomotion
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: idk why lathe changes
No
You've included CSSJog.c and also pasted its contents. Only Include it.
You have 2 main() functions. There must only be one. main() is where the program starts. There can be only one starting place for a program.
Code is incorrectly indented making it hard to understand or read. Use Auto Indent to clean it up.
You've included CSSJog.c and also pasted its contents. Only Include it.
You have 2 main() functions. There must only be one. main() is where the program starts. There can be only one starting place for a program.
Code is incorrectly indented making it hard to understand or read. Use Auto Indent to clean it up.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: idk why lathe changes
gotcha
Can grounding the E stop from the servo amp to the electronics case bring in noise?
getting some nice run off on Z axis in the Z negative direction only
even after the MaxFollowingError=5000 trips
X axis works great
Can grounding the E stop from the servo amp to the electronics case bring in noise?
getting some nice run off on Z axis in the Z negative direction only
even after the MaxFollowingError=5000 trips
X axis works great
Last edited by turbothis on Tue Mar 05, 2024 11:30 pm, edited 4 times in total.
Re: idk why lathe changes
anything else i should do to the init or is it runnable for spindle turning?
Code: Select all
#include "KMotionDef.h"
#include "MySpindleDefs.h"
#include "CSSJog.c"
int main() {
// X axis
ch0->InputMode=ENCODER_MODE;
ch0->OutputMode=DAC_SERVO_MODE;
ch0->Vel=80000;
ch0->Accel=5e+07;
ch0->Jerk=5e+07;
ch0->P=5;
ch0->I=0;
ch0->D=20;
ch0->FFAccel=0;
ch0->FFVel=0;
ch0->MaxI=200;
ch0->MaxErr=200;
ch0->MaxOutput=2000;
ch0->DeadBandGain=1;
ch0->DeadBandRange=0;
ch0->InputChan0=0;
ch0->InputChan1=0;
ch0->OutputChan0=0;
ch0->OutputChan1=0;
ch0->MasterAxis=-1;
ch0->LimitSwitchOptions=0x100;
ch0->LimitSwitchNegBit=0;
ch0->LimitSwitchPosBit=0;
ch0->SoftLimitPos=1e+09;
ch0->SoftLimitNeg=-1e+09;
ch0->InputGain0=1;
ch0->InputGain1=1;
ch0->InputOffset0=0;
ch0->InputOffset1=0;
ch0->OutputGain=1;
ch0->OutputOffset=0;
ch0->SlaveGain=1;
ch0->BacklashMode=BACKLASH_OFF;
ch0->BacklashAmount=0;
ch0->BacklashRate=0;
ch0->invDistPerCycle=1;
ch0->Lead=0;
ch0->MaxFollowingError=1000000000;
ch0->StepperAmplitude=250;
ch0->iir[0].B0=1;
ch0->iir[0].B1=0;
ch0->iir[0].B2=0;
ch0->iir[0].A1=0;
ch0->iir[0].A2=0;
ch0->iir[1].B0=1;
ch0->iir[1].B1=0;
ch0->iir[1].B2=0;
ch0->iir[1].A1=0;
ch0->iir[1].A2=0;
ch0->iir[2].B0=1;
ch0->iir[2].B1=0;
ch0->iir[2].B2=0;
ch0->iir[2].A1=0;
ch0->iir[2].A2=0;
// Z axis
ch1->InputMode=ENCODER_MODE;
ch1->OutputMode=DAC_SERVO_MODE;
ch1->Vel=80000;
ch1->Accel=5e+07;
ch1->Jerk=5e+07;
ch1->P=10;
ch1->I=0;
ch1->D=20;
ch1->FFAccel=0;
ch1->FFVel=0;
ch1->MaxI=200;
ch1->MaxErr=200;
ch1->MaxOutput=2000;
ch1->DeadBandGain=1;
ch1->DeadBandRange=0;
ch1->InputChan0=1;
ch1->InputChan1=0;
ch1->OutputChan0=1;
ch1->OutputChan1=0;
ch1->MasterAxis=-1;
ch1->LimitSwitchOptions=0x114;
ch1->LimitSwitchNegBit=11;
ch1->LimitSwitchPosBit=0;
ch1->SoftLimitPos=1e+09;
ch1->SoftLimitNeg=-1e+09;
ch1->InputGain0=1;
ch1->InputGain1=1;
ch1->InputOffset0=0;
ch1->InputOffset1=0;
ch1->OutputGain=1;
ch1->OutputOffset=0;
ch1->SlaveGain=1;
ch1->BacklashMode=BACKLASH_OFF;
ch1->BacklashAmount=0;
ch1->BacklashRate=0;
ch1->invDistPerCycle=1;
ch1->Lead=0;
ch1->MaxFollowingError=5000;
ch1->StepperAmplitude=250;
ch1->iir[0].B0=1;
ch1->iir[0].B1=0;
ch1->iir[0].B2=0;
ch1->iir[0].A1=0;
ch1->iir[0].A2=0;
ch1->iir[1].B0=1;
ch1->iir[1].B1=0;
ch1->iir[1].B2=0;
ch1->iir[1].A1=0;
ch1->iir[1].A2=0;
ch1->iir[2].B0=1;
ch1->iir[2].B1=0;
ch1->iir[2].B2=0;
ch1->iir[2].A1=0;
ch1->iir[2].A2=0;
// 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=0;
ch2->OutputChan0=2;
ch2->OutputChan1=0;
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(0);
EnableAxis(1);
EnableAxis(2);
DefineCoordSystem(0,-1,1,-1);
}
Re: idk why lathe changes
ok i got the spindle performing well
the only issue is i have to double push the CW/CCW buttons to work
which ever button i push first is the way it will rotate. (first push does nothing but pick which way to rotate)
the second time i push one of the buttons it will turn on spindle. ( this can be either CW or CCW as the first button push locks in which direction to rotate)
my CW
my CCW
my jog
my off
the only issue is i have to double push the CW/CCW buttons to work
which ever button i push first is the way it will rotate. (first push does nothing but pick which way to rotate)
the second time i push one of the buttons it will turn on spindle. ( this can be either CW or CCW as the first button push locks in which direction to rotate)
my CW
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[SPEEDVAR]; // value stored is actually a float
int LastState = persist.UserData[STATEVAR]; // get last state
if (CS0_axis_a == -1 && !ch2->Enable) // is A axis not defined in the Coordinate System and not enabled?
EnableAxis(2); // yes, enable the axis
if (LastState==-1)
{
// if spindle was CCW now we want CW
// spin down
ClearBit(SPINDLECW_BIT);
ClearBit(SPINDLECCW_BIT);
Jog(SPINDLEAXIS,0);
while (!CheckDone(SPINDLEAXIS)) ;
}
// turn spindle on CW and ramp to new speed
SetBit(SPINDLECW_BIT);
LastState = 1; // Add string
if (*css_mode != 2)
{
// 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);
}
persist.UserData[STATEVAR] = 1; // remember we are CW
}
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[SPEEDVAR]; // value stored is actually a float
int LastState = persist.UserData[STATEVAR]; // get last state
if (CS0_axis_a == -1 && !ch2->Enable) // is A axis not defined in the Coordinate System and not enabled?
EnableAxis(2); // yes, enable the axis
if (LastState==1)
{
// if spindle was CW now we want CCW
// spin down
ClearBit(SPINDLECW_BIT);
ClearBit(SPINDLECCW_BIT);
Jog(SPINDLEAXIS,0);
while (!CheckDone(SPINDLEAXIS)) ;
}
// turn spindle on CCW and ramp to new speed
SetBit(SPINDLECCW_BIT);
LastState = -1;
if (*css_mode != 2)
{
// 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);
}
persist.UserData[STATEVAR] = -1; // remember we are CCW
}
my jog
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
int 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);
}
my off
Code: Select all
#include "KMotionDef.h"
#include "MySpindleDefs.h"
// 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()
{
// spin down
ClearBit(SPINDLECW_BIT);
ClearBit(SPINDLECCW_BIT);
Jog(SPINDLEAXIS, 0);
printf("Jogging Spindle Stop\n");
persist.UserData[STATEVAR] = 0; // remember we are Off
while (!CheckDone(SPINDLEAXIS));
if (CS0_axis_a == -1) // is A axis not defined in the Coordinate System?
DisableAxis(2); // yes, disable the axis, otherwise leave it enabled
}
Re: idk why lathe changes
sigh....
so i just tried some other C code examples that did the same double push thing
i re-load my own ones i posted above and now it works perfect
this is what blows my mind.
i am about to get a go pro camera and film what happens
so i just tried some other C code examples that did the same double push thing
i re-load my own ones i posted above and now it works perfect
this is what blows my mind.
i am about to get a go pro camera and film what happens
Re: idk why lathe changes
ok, i got another used AMC drive ( 250$ ebay ) and the Z axis works as it should again!
everything works.
stoked
everything works.
stoked
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: idk why lathe changes
i take pride in completion.