starting my C program, any guidance would be appreciated. - Page 11


Page 11 of 11 FirstFirst ... 891011
Results 201 to 208 of 208

Thread: starting my C program, any guidance would be appreciated.

  1. #201
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    3773
    Downloads
    0
    Uploads
    0

    Default Re: starting my C program, any guidance would be appreciated.

    Hi,

    If you want the system to home when you push a button then assign the program to a button.

    Regards
    TK http://dynomotion.com


  2. #202
    Member Gunmachinist's Avatar
    Join Date
    May 2020
    Posts
    231
    Downloads
    0
    Uploads
    0

    Default

    Quote Originally Posted by TomKerekes View Post
    Hi,

    If you want the system to home when you push a button then assign the program to a button.
    That is how I want the system to home which is how my machine at work is homed and what I did, but when I press the button it moves very little (.05+/-). In my code where it tells the machine to move (0,100) 0 being the axis, what is the 100; speed, inches or counts? I assume that the location of the limit switch would be my G53 and can home and soft be set manually?



  3. #203
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    3773
    Downloads
    0
    Uploads
    0

    Default Re: starting my C program, any guidance would be appreciated.

    The 100 would be counts.

    Regards
    TK http://dynomotion.com


  4. #204
    Member Gunmachinist's Avatar
    Join Date
    May 2020
    Posts
    231
    Downloads
    0
    Uploads
    0

    Default Re: starting my C program, any guidance would be appreciated.

    I am having a hard time getting code for my MPG to compile. I keep getting a MPGServiceSmoothHardwareEncFilteredRev3 undeclared error on the last line of this code, and Google won't answer me. If I remove the last line it compiles.
    Code:
    #include "KMotionDef.h"
    #include "MPGServiceSmoothHardwareEncFilteredRev3.c"
    #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(;;)
    	{
    		MPGServiceSmoothHardwareEncFilteredRev3.c();
    	}
    }




  5. #205
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    3773
    Downloads
    0
    Uploads
    0

    Default Re: starting my C program, any guidance would be appreciated.

    I think you put the filename instead of the function name. C doesn't call files. But it can call functions that are defined in a file. Open the file and see exactly what the name of the function in that file that you want to call and use that name. It won't likely have a .c in it.

    Regards
    TK http://dynomotion.com


  6. #206
    Member Gunmachinist's Avatar
    Join Date
    May 2020
    Posts
    231
    Downloads
    0
    Uploads
    0

    Default Re: starting my C program, any guidance would be appreciated.

    Quote Originally Posted by TomKerekes View Post
    I think you put the filename instead of the function name. C doesn't call files. But it can call functions that are defined in a file. Open the file and see exactly what the name of the function in that file that you want to call and use that name. It won't likely have a .c in it.
    I'm not sure what you mean, #include "KMotionDef.h", and #include "MySpindleDefs.h" at the top of the program are files that the Init. program calls? #include "MPGServiceSmoothHardwareEncFilteredRev3.c" is the code which may make my MPG work, haven't been able to get it working yet. If I remove the .c at the end it gives me an undefined symbol error on the MPGServiceSmoothHardwareEncFilteredRev3(); line.

    here is a screen shot with the file open, maybe you can point me in right direction.

    Attached Thumbnails Attached Thumbnails starting my C program, any guidance would be appreciated.-screenshot-1-jpg  


  7. #207
    Member Gunmachinist's Avatar
    Join Date
    May 2020
    Posts
    231
    Downloads
    0
    Uploads
    0

    Default Re: starting my C program, any guidance would be appreciated.

    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);
    	}
    }




  8. #208
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    3773
    Downloads
    0
    Uploads
    0

    Default Re: starting my C program, any guidance would be appreciated.

    You might think of a C Function definition as a list of instructions that has been given a name. Imagine a list of 10 steps to inflate a tire called "InflateATire". Now from a different list one of the instructions might be to go do list InflateATire. Functions can be useful when similar things need to be performed multiple times. For example servicing all 4 tires of a car. Instead of duplicating the10 instructions 4 times for 40 instructions by copying and pasting, 4 instructions (in a different list) can be to perform the list. But even if a list of instructions is only needed once it can still make sense to make a separate list and give it a name for purposes of organization and clarity.

    Putting the list (function) in a separate file makes it easy to include that list in any program that might need it. Its also possible to put multiple functions in a file so its easy to include a bunch of functions. The names of any functions in a file and the name of the file itself are normally different.

    If you decide to not use a function and just paste in the instructions instead then you would not define a function or include a call to the function. Its an either or situation.

    In C there is a special function called main where the program begins executing instructions. Any C Program must have exactly one main function. It also doesn't make sense to call the main function to be executed as the program automatically does this when it starts.

    I think the example you started with had a function called ServiceMPG but it was changed to main.

    There is a ton of info on the Internet. Such as this. Also our wiki.

    HTH

    Regards
    TK http://dynomotion.com


Page 11 of 11 FirstFirst ... 891011

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


About CNCzone.com

    We are the largest and most active discussion forum for manufacturing industry. The site is 100% free to join and use, so join today!

Follow us on


Our Brands

starting my C program, any guidance would be appreciated.

starting my C program, any guidance would be appreciated.

starting my C program, any guidance would be appreciated.