I just attempted to add the file at the end of my Init. program instead of linking it, it's becoming too much of a headache, but when I copy the file and add it to the end, I get identifier expected on the last line at the }. I really am not getting this.
Code:
#include "KMotionDef.h"
#include "MySpindleDefs.h"
// Note Low Gains, Limited Max Limits, No Limit Options, No Soft Limits,
// Large allowed Following Error, No Feed Forward, No Filters, etc
void main()
{
ClearBit(SPINDLEDOWN_BIT);
ClearBit(SPINDLEUP_BIT);
ch0->InputMode=ENCODER_MODE;
ch0->OutputMode=DAC_SERVO_MODE;
ch0->Vel=40000;
ch0->Accel=40000;
ch0->Jerk=1e+06;
ch0->P=19;
ch0->I=0.0001;
ch0->D=5;
ch0->FFAccel=0.001;
ch0->FFVel=0.0009;
ch0->MaxI=9000;
ch0->MaxErr=100000;
ch0->MaxOutput=2000;
ch0->DeadBandGain=1;
ch0->DeadBandRange=2;
ch0->InputChan0=0;
ch0->InputChan1=1;
ch0->OutputChan0=0;
ch0->OutputChan1=1;
ch0->MasterAxis=0;
ch0->LimitSwitchOptions=0x11f;
ch0->LimitSwitchNegBit=136;
ch0->LimitSwitchPosBit=137;
ch0->SoftLimitPos=1e+09;
ch0->SoftLimitNeg=-1e+08;
ch0->InputGain0=1;
ch0->InputGain1=1;
ch0->InputOffset0=0;
ch0->InputOffset1=0;
ch0->OutputGain=1;
ch0->OutputOffset=0;
ch0->SlaveGain=0;
ch0->BacklashMode=BACKLASH_LINEAR;
ch0->BacklashAmount=1;
ch0->BacklashRate=2;
ch0->invDistPerCycle=0;
ch0->Lead=15;
ch0->MaxFollowingError=100000;
ch0->StepperAmplitude=250;
ch0->iir[0].B0=3.44761;
ch0->iir[0].B1=-6.74051;
ch0->iir[0].B2=3.29464;
ch0->iir[0].A1=1.91668;
ch0->iir[0].A2=-0.918416;
ch0->iir[1].B0=0.123861;
ch0->iir[1].B1=0.123861;
ch0->iir[1].B2=0;
ch0->iir[1].A1=0.752278;
ch0->iir[1].A2=0;
ch0->iir[2].B0=0.0166075;
ch0->iir[2].B1=0.033215;
ch0->iir[2].B2=0.0166075;
ch0->iir[2].A1=1.6066;
ch0->iir[2].A2=-0.673034;
ch1->InputMode=ENCODER_MODE;
ch1->OutputMode=DAC_SERVO_MODE;
ch1->Vel=400000;
ch1->Accel=1e+06;
ch1->Jerk=200000;
ch1->P=29;
ch1->I=0.0001;
ch1->D=5;
ch1->FFAccel=0.002;
ch1->FFVel=0.0006;
ch1->MaxI=5000;
ch1->MaxErr=100000;
ch1->MaxOutput=2000;
ch1->DeadBandGain=0;
ch1->DeadBandRange=1;
ch1->InputChan0=1;
ch1->InputChan1=1;
ch1->OutputChan0=1;
ch1->OutputChan1=1;
ch1->MasterAxis=-1;
ch1->LimitSwitchOptions=0x110;
ch1->LimitSwitchNegBit=140;
ch1->LimitSwitchPosBit=141;
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=0;
ch1->BacklashMode=BACKLASH_LINEAR;
ch1->BacklashAmount=0;
ch1->BacklashRate=0;
ch1->invDistPerCycle=0;
ch1->Lead=10;
ch1->MaxFollowingError=100000;
ch1->StepperAmplitude=250;
ch1->iir[0].B0=3.91172;
ch1->iir[0].B1=-7.64788;
ch1->iir[0].B2=3.73813;
ch1->iir[0].A1=1.91123;
ch1->iir[0].A2=-0.913201;
ch1->iir[1].B0=0.101606;
ch1->iir[1].B1=0.101606;
ch1->iir[1].B2=0;
ch1->iir[1].A1=0.796788;
ch1->iir[1].A2=0;
ch1->iir[2].B0=0.0110084;
ch1->iir[2].B1=0.0220167;
ch1->iir[2].B2=0.0110084;
ch1->iir[2].A1=1.68459;
ch1->iir[2].A2=-0.728624;
ch2->InputMode=ENCODER_MODE;
ch2->OutputMode=DAC_SERVO_MODE;
ch2->Vel=60000;
ch2->Accel=100000;
ch2->Jerk=200000;
ch2->P=26;
ch2->I=0.0001;
ch2->D=8;
ch2->FFAccel=0.0009;
ch2->FFVel=0.001;
ch2->MaxI=5000;
ch2->MaxErr=10000;
ch2->MaxOutput=2000;
ch2->DeadBandGain=0;
ch2->DeadBandRange=1;
ch2->InputChan0=2;
ch2->InputChan1=1;
ch2->OutputChan0=2;
ch2->OutputChan1=1;
ch2->MasterAxis=-1;
ch2->LimitSwitchOptions=0x11f;
ch2->LimitSwitchNegBit=139;
ch2->LimitSwitchPosBit=138;
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_LINEAR;
ch2->BacklashAmount=0.15;
ch2->BacklashRate=0;
ch2->invDistPerCycle=0;
ch2->Lead=12;
ch2->MaxFollowingError=100000;
ch2->StepperAmplitude=250;
ch2->iir[0].B0=0.0900489;
ch2->iir[0].B1=0.0900489;
ch2->iir[0].B2=0;
ch2->iir[0].A1=0.819902;
ch2->iir[0].A2=0;
ch2->iir[1].B0=0.0303998;
ch2->iir[1].B1=0.0607997;
ch2->iir[1].B2=0.0303998;
ch2->iir[1].A1=1.45093;
ch2->iir[1].A2=-0.572529;
ch2->iir[2].B0=8.05937;
ch2->iir[2].B1=-15.204;
ch2->iir[2].B2=7.17064;
ch2->iir[2].A1=1.6778;
ch2->iir[2].A2=-0.703757;
ch7->InputMode=ENCODER_MODE;
ch7->OutputMode=DAC_SERVO_MODE;
ch7->Vel=0.5;
ch7->Accel=1;
ch7->Jerk=5;
ch7->P=0;
ch7->I=0;
ch7->D=0;
ch7->FFAccel=0;
ch7->FFVel=2047;
ch7->MaxI=2047;
ch7->MaxErr=1e+10;
ch7->MaxOutput=2047;
ch7->DeadBandGain=1;
ch7->DeadBandRange=0;
ch7->InputChan0=7;
ch7->InputChan1=1;
ch7->OutputChan0=7;
ch7->OutputChan1=1;
ch7->MasterAxis=-1;
ch7->LimitSwitchOptions=0x100;
ch7->LimitSwitchNegBit=0;
ch7->LimitSwitchPosBit=0;
ch7->SoftLimitPos=1e+09;
ch7->SoftLimitNeg=-1e+09;
ch7->InputGain0=1;
ch7->InputGain1=1;
ch7->InputOffset0=0;
ch7->InputOffset1=0;
ch7->OutputGain=-1;
ch7->OutputOffset=0;
ch7->SlaveGain=1;
ch7->BacklashMode=BACKLASH_OFF;
ch7->BacklashAmount=0;
ch7->BacklashRate=0;
ch7->invDistPerCycle=1;
ch7->Lead=0;
ch7->MaxFollowingError=10000000000;
ch7->StepperAmplitude=250;
ch7->iir[0].B0=1;
ch7->iir[0].B1=0;
ch7->iir[0].B2=0;
ch7->iir[0].A1=0;
ch7->iir[0].A2=0;
ch7->iir[1].B0=1;
ch7->iir[1].B1=0;
ch7->iir[1].B2=0;
ch7->iir[1].A1=0;
ch7->iir[1].A2=0;
ch7->iir[2].B0=1;
ch7->iir[2].B1=0;
ch7->iir[2].B2=0;
ch7->iir[2].A1=0;
ch7->iir[2].A2=0;
EnableAxis(0);
EnableAxis(1);
EnableAxis(2);
DefineCoordSystem(2,1,0,-1); // define XYZU axes
for(;;)
{
#define MPG_INPUT_AXIS 2 // Axis used to read hardware encoder (not necessarily the encoder channel)
#define A 19 // define to which IO bits the AB signals are connected
#define B 20
#define TAU 0.01 // smoothness factor (Low Pass Time constant seconds for MoveExp)
#define TAU1 0.015 // smoothness factor (Low Pass Time constant seconds for pre filter 1)
#define TAU2 0.015 // smoothness factor (Low Pass Time constant seconds for pre filter 2)
#define FINAL_TIME 1.0 // Set final dest after this amount of time with no change
#define FACTOR1 16
#define FACTOR10 17
#define FACTOR100 18
#define SELECTX 21
#define SELECTY 22
#define SELECTZ 23
#define SELECTA 24
#define ENABLE_MPG 25 // Switch/Button used to enable MPG Motion
main();
{
static int Pos, FirstTime = TRUE;
static int InMotion = FALSE, Axis, LastAxis = -1;
static double LastChangeTime = 0, Target, Factor = 0;
static double Target1, Target2, K1, K2, K1M, K2M;
int Change1, NewPos;
if (FirstTime)
{
Pos = chan[MPG_INPUT_AXIS].Position;
K1 = exp(-2 * TIMEBASE / TAU1); // filter coefficients
K2 = exp(-2 * TIMEBASE / TAU2);
K1M = 1.0 - K1;
K2M = 1.0 - K2;
FirstTime = FALSE;
}
NewPos = chan[MPG_INPUT_AXIS].Position;
Change1 = NewPos - Pos;
Pos = NewPos;
if (!ReadBit(ENABLE_MPG) || JOB_ACTIVE) // if not button pressed or Job Active ignore the encoder.
Change1 = 0;
if (ReadBit(FACTOR1)) // is X1 selected?
Factor = 4;
else if (ReadBit(FACTOR10)) // is X10 selected?
Factor = 20;
else if (ReadBit(FACTOR100)) // is X100 selected?
Factor = 40;
else
Factor = 0.0;
if (ReadBit(SELECTX)) // is x selected?
Axis = 0;
else if (ReadBit(SELECTY)) // is y selected?
Axis = 1;
else if (ReadBit(SELECTZ)) // is z selected?
Axis = 2;
else if (ReadBit(SELECTA)) // is A selected?
Axis = 3;
// Feedhold fully stopped ??
if (CS0_StoppingState == 4 && InMotion)
{
Change1 = 0; // ignore any MPG change
Jog(LastAxis, 0);
InMotion = FALSE;
}
// check if the Axis just changed or we have been
// converging to the target for a long time
if (Axis != LastAxis || (InMotion && Time_sec() > LastChangeTime + FINAL_TIME))
{
if (InMotion)
Move(LastAxis, Target1); //finalize any motion
LastAxis = Axis;
InMotion = FALSE;
}
if (Change1) // did we move?
{
if (!InMotion)
Target = Target1 = Target2 = chan[Axis].Dest;
Target1 += Change1 * Factor;
LastChangeTime = Time_sec();
InMotion = TRUE;
}
if (InMotion) // If moving
{
if (Target1 > chan[LastAxis].SoftLimitPos)
Target1 = chan[LastAxis].SoftLimitPos;
if (Target1 < chan[LastAxis].SoftLimitNeg)
Target1 = chan[LastAxis].SoftLimitNeg;
Target2 = Target2 * K1 + Target1 * K1M;
Target = Target * K2 + Target2 * K2M;
MoveExp(Axis, Target, TAU);
}
}