Hi insightmfgsys,
KMotion.exe has a button to auto generate C Code for you.
Select one of your axis channels in KMotion.exe then push "C Code -> Clip Board"
You won't see anything happen but the Windows Clipboard will now contain the C Code representation of all your settings for that axis as something like this:
Code:
ch0->InputMode=NO_INPUT_MODE;
ch0->OutputMode=STEP_DIR_MODE;
ch0->Vel=115000;
ch0->Accel=50000;
ch0->Jerk=100000;
ch0->P=0;
ch0->I=0.01;
ch0->D=0;
ch0->FFAccel=0;
ch0->FFVel=0;
ch0->MaxI=200;
ch0->MaxErr=1e+006;
ch0->MaxOutput=200;
ch0->DeadBandGain=1;
ch0->DeadBandRange=0;
ch0->InputChan0=0;
ch0->InputChan1=0;
ch0->OutputChan0=8;
ch0->OutputChan1=0;
ch0->MasterAxis=-1;
ch0->LimitSwitchOptions=0x100;
ch0->LimitSwitchNegBit=0;
ch0->LimitSwitchPosBit=0;
ch0->SoftLimitPos=1e+030;
ch0->SoftLimitNeg=-1e+030;
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=320;
ch0->BacklashRate=320;
ch0->invDistPerCycle=1;
ch0->Lead=0;
ch0->MaxFollowingError=1000000000;
ch0->StepperAmplitude=20;
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=0.000769;
ch0->iir[2].B1=0.001538;
ch0->iir[2].B2=0.000769;
ch0->iir[2].A1=1.92076;
ch0->iir[2].A2=-0.923833;
Notice all the the ch0-> indicates it is setting parameters for Axis #0. You can then go to the C Programs Screen and open an example Initialization C Program and "Paste" your code over the settings in the example, or if you are initializing more axes than in the example then some of your settings will need to be inserted rather than pasted over.
Here is the example InitStepDir3Axis.c that shows 3 Axes being configured
Code:
#include "KMotionDef.h"
// Defines axis 0, 1, 2 as simple step dir outputs
// enables them
// sets them as an xyz coordinate system for GCode
int main()
{
ch0->InputMode=ENCODER_MODE;
ch0->OutputMode=STEP_DIR_MODE;
ch0->Vel=40000.000000;
ch0->Accel=400000.000000;
ch0->Jerk=4000000.000000;
ch0->P=0.000000;
ch0->I=0.010000;
ch0->D=0.000000;
ch0->FFAccel=0.000000;
ch0->FFVel=0.000000;
ch0->MaxI=200.000000;
ch0->MaxErr=1000000.000000;
ch0->MaxOutput=200.000000;
ch0->DeadBandGain=1.000000;
ch0->DeadBandRange=0.000000;
ch0->InputChan0=0;
ch0->InputChan1=0;
ch0->OutputChan0=0;
ch0->OutputChan1=0;
ch0->LimitSwitchOptions=0x0;
ch0->InputGain0=1.000000;
ch0->InputGain1=1.000000;
ch0->InputOffset0=0.000000;
ch0->InputOffset1=0.000000;
ch0->invDistPerCycle=1.000000;
ch0->Lead=0.000000;
ch0->MaxFollowingError=1000000000.000000;
ch0->StepperAmplitude=20.000000;
ch0->iir[0].B0=1.000000;
ch0->iir[0].B1=0.000000;
ch0->iir[0].B2=0.000000;
ch0->iir[0].A1=0.000000;
ch0->iir[0].A2=0.000000;
ch0->iir[1].B0=1.000000;
ch0->iir[1].B1=0.000000;
ch0->iir[1].B2=0.000000;
ch0->iir[1].A1=0.000000;
ch0->iir[1].A2=0.000000;
ch0->iir[2].B0=0.000769;
ch0->iir[2].B1=0.001538;
ch0->iir[2].B2=0.000769;
ch0->iir[2].A1=1.920810;
ch0->iir[2].A2=-0.923885;
EnableAxisDest(0,0);
ch1->InputMode=ENCODER_MODE;
ch1->OutputMode=STEP_DIR_MODE;
ch1->Vel=40000.000000;
ch1->Accel=400000.000000;
ch1->Jerk=4000000.000000;
ch1->P=0.000000;
ch1->I=0.010000;
ch1->D=0.000000;
ch1->FFAccel=0.000000;
ch1->FFVel=0.000000;
ch1->MaxI=200.000000;
ch1->MaxErr=1000000.000000;
ch1->MaxOutput=200.000000;
ch1->DeadBandGain=1.000000;
ch1->DeadBandRange=0.000000;
ch1->InputChan0=1;
ch1->InputChan1=0;
ch1->OutputChan0=1;
ch1->OutputChan1=0;
ch1->LimitSwitchOptions=0x0;
ch1->InputGain0=1.000000;
ch1->InputGain1=1.000000;
ch1->InputOffset0=0.000000;
ch1->InputOffset1=0.000000;
ch1->invDistPerCycle=1.000000;
ch1->Lead=0.000000;
ch1->MaxFollowingError=1000000000.000000;
ch1->StepperAmplitude=20.000000;
ch1->iir[0].B0=1.000000;
ch1->iir[0].B1=0.000000;
ch1->iir[0].B2=0.000000;
ch1->iir[0].A1=0.000000;
ch1->iir[0].A2=0.000000;
ch1->iir[1].B0=1.000000;
ch1->iir[1].B1=0.000000;
ch1->iir[1].B2=0.000000;
ch1->iir[1].A1=0.000000;
ch1->iir[1].A2=0.000000;
ch1->iir[2].B0=0.000769;
ch1->iir[2].B1=0.001538;
ch1->iir[2].B2=0.000769;
ch1->iir[2].A1=1.920810;
ch1->iir[2].A2=-0.923885;
EnableAxisDest(1,0);
ch2->InputMode=ENCODER_MODE;
ch2->OutputMode=STEP_DIR_MODE;
ch2->Vel=40000.000000;
ch2->Accel=400000.000000;
ch2->Jerk=4000000.000000;
ch2->P=0.000000;
ch2->I=0.010000;
ch2->D=0.000000;
ch2->FFAccel=0.000000;
ch2->FFVel=0.000000;
ch2->MaxI=200.000000;
ch2->MaxErr=1000000.000000;
ch2->MaxOutput=200.000000;
ch2->DeadBandGain=1.000000;
ch2->DeadBandRange=0.000000;
ch2->InputChan0=2;
ch2->InputChan1=0;
ch2->OutputChan0=2;
ch2->OutputChan1=0;
ch2->LimitSwitchOptions=0x0;
ch2->InputGain0=1.000000;
ch2->InputGain1=1.000000;
ch2->InputOffset0=0.000000;
ch2->InputOffset1=0.000000;
ch2->invDistPerCycle=1.000000;
ch2->Lead=0.000000;
ch2->MaxFollowingError=1000000000.000000;
ch2->StepperAmplitude=20.000000;
ch2->iir[0].B0=1.000000;
ch2->iir[0].B1=0.000000;
ch2->iir[0].B2=0.000000;
ch2->iir[0].A1=0.000000;
ch2->iir[0].A2=0.000000;
ch2->iir[1].B0=1.000000;
ch2->iir[1].B1=0.000000;
ch2->iir[1].B2=0.000000;
ch2->iir[1].A1=0.000000;
ch2->iir[1].A2=0.000000;
ch2->iir[2].B0=0.000769;
ch2->iir[2].B1=0.001538;
ch2->iir[2].B2=0.000769;
ch2->iir[2].A1=1.920810;
ch2->iir[2].A2=-0.923885;
EnableAxisDest(2,0);
DefineCoordSystem(0,1,2,-1);
return 0;
}
You can find more information on how to quickly import or export settings between the KMotion Screens and a C Program here:
Besides setting Axis Parameters an Initialization Program can do other things to initialize your system. Typically an Initialization Program will do:
#1 - Set All Axis Parameters
#2 - Enable All Axes ie. EnableAxisDest(0,0);
#3 - Define which axes are to be used in GCode ie DefineCoordSystem(0,1,2,-1);
#4 - Perform a Service Loop to Service/Monitor things like MPGs, EStop, External Buttons, etc...
After creating the C Program, add a button to whatever Application you are using (KmotionCNC, Mach3, etc) to Execute the C Program.
For KMotionCNC in Tool Setup | User Buttons | Define something like:
HTH
Regards