Need Help! Problem jig grinding machine. - Page 2


Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 55

Thread: Problem jig grinding machine.

  1. #21
    Registered
    Join Date
    Nov 2016
    Posts
    28
    Downloads
    0
    Uploads
    0

    Default Re: Problem jig grinding machine.

    Hi Tom!
    Thank you so much for the video, this is that's what I need.

    Best Regards.



  2. #22
    Registered
    Join Date
    Nov 2016
    Posts
    28
    Downloads
    0
    Uploads
    0

    Default Re: Problem jig grinding machine.

    Hi Tom!
    We trying to quote hydraulic cylinder to axis (for using it in basic main dialog screen), in this regard, there is a question: may I know which direction of the axis (bit or something else, displaying this state)?
    It is associated with the specifics of control hydraulic cylinder: voltage from 0 to 10 volts determines speed of cylinder (flow of oil) and one bit determines direction of cylinder. Is it possible to receive this bit?

    Best regards!




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

    Default Re: Problem jig grinding machine.

    Hi vadim_cnc,

    It isn't clear to me what you are asking. But you can display the state of an input bit with the Label Controls. Just assign two bitmaps to the label and assign the Input Bit Number as the Var parameter and KMotionCNC will automatically toggle between the two bitmaps based on the state of the input. The previous video had examples above each of the Momentary and Toggle Butons.

    If you interface the speed voltage to a Kanalog ADC then you could also display the speed in a DROLabel similar to what is shown here:



    and/or also as a VertBar Graph control. Such as shown here:

    Problem jig grinding machine.-vertbar-jpg

    HTH
    Regards

    Regards
    TK http://dynomotion.com


  4. #24
    Registered
    Join Date
    Nov 2016
    Posts
    28
    Downloads
    0
    Uploads
    0

    Default Re: Problem jig grinding machine.

    Hi, Tom!
    I try to explain what I meant. Cylinder's drive have only 0...10 V control of speed and driving direction of cylinder is switching of two valves, which controls by high or low signal. Could it be implemented diagram on following picture?


    Thanks!

    Attached Thumbnails Attached Thumbnails Problem jig grinding machine.-hydraulic-cylinder-jpg  


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

    Default Re: Problem jig grinding machine.

    Hi vadim_cnc,

    Sorry for completely miss understanding. That should be possible. It will require a bit of C Code to Output in that Sign+Magnitude format instead of the normal +/-10V format.

    You might look at the "Setup Gcode 4 axis PWM signMag.c" example. Change the OutputSignMag() function to output to a DAC instead of a PWM. So for example change:

    FPGA(IO_PWMS+pwm*2) = chan[ch].Output;

    to

    DAC(pwm, chan[ch].Output);

    Set the Output Mode to No Output as you will be doing the Output with the C Program.

    I assume you will have encoder feedback?

    I believe this Gentleman did something similar using a hydraulic proportional valve:



    HTH
    Regards

    Regards
    TK http://dynomotion.com


  6. #26
    Registered
    Join Date
    Nov 2016
    Posts
    28
    Downloads
    0
    Uploads
    0

    Default Re: Problem jig grinding machine.

    Hi, Tom!
    Thanks a lot for Your supporting and patience! But we have some issues (again). There is problem while compiling (after changes in example, see picture). Our knowledges in C programming not very good)), maybe You can prompt us what we doing wrong?

    P.S. our cylinder has optical linear encoder.

    Attached Thumbnails Attached Thumbnails Problem jig grinding machine.-jpg  


  7. #27
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4043
    Downloads
    0
    Uploads
    0

    Default Re: Problem jig grinding machine.

    Opps the DAC value needs to be an integer. Try changing:

    DAC(pwm, chan[ch].Output);

    to

    DAC(pwm, (int)chan[ch].Output);

    You must also change the other 3 places where fixed data is written to the FPGA to write to the DAC instead

    MAXPWM will probably need to be increased to 2047 if you require the full 0-10V output.

    Regards

    Regards
    TK http://dynomotion.com


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

    Default Re: Problem jig grinding machine.

    Also I now see you missed a negative sign on the second instance. The idea is that when the output is negative then we output the negative of it which would be a positive value:

    DAC(pwm, (int)-chan[ch].Output);

    Regards

    Regards
    TK http://dynomotion.com


  9. #29
    Registered
    Join Date
    Nov 2016
    Posts
    28
    Downloads
    0
    Uploads
    0

    Default Re: Problem jig grinding machine.

    Hi, Tom!
    We try to change this strings and program really compiles, but "dir_bit" wont set correctly. We need to set one bit, when voltage is negative and set another one bit and reset first bit, when voltage is positive and in reverse order.
    For example, we need to determine sign of voltage on ch3 and switch bit accordingly to sign of measured voltage.



    Attached Thumbnails Attached Thumbnails Problem jig grinding machine.-png  


  10. #30
    Member
    Join Date
    Jun 2004
    Location
    Scotland
    Posts
    355
    Downloads
    0
    Uploads
    0

    Default Re: Problem jig grinding machine.

    Can you post the actual c file, or copy and paste it into code tags, rather than a screenshot?

    What you want is easily doable, but I'd rather not re-type the whole file, for what is a only a couple lines of extra code.



  11. #31
    Registered
    Join Date
    Nov 2016
    Posts
    28
    Downloads
    0
    Uploads
    0

    Default Re: Problem jig grinding machine.

    No problem, there is the file.
    Code:
    #include "KMotionDef.h"
    
    
    // Defines axis as Servos with output as PWM Sign and Magnitude
    // enables them
    // sets them as an xy coordinate system for GCode
    
    
    #define MAXPWM 242
    #define DIR_BIT0 30
    #define DIR_BIT1 31
    #define DIR_BIT2 32
    #define DIR_BIT3 33
    
    
    void OutputSignMag(int ch, int pwm, int dir_bit);
    
    
    int main() 
    {
        ch0->InputMode=ENCODER_MODE;
        ch0->OutputMode=NO_OUTPUT_MODE;
        ch0->Vel=100.000000;
        ch0->Accel=1000.000000;
        ch0->Jerk=10000.000000;
        ch0->P=1.000000;
        ch0->I=0.000000;
        ch0->D=0.000000;
        ch0->FFAccel=0.000000;
        ch0->FFVel=0.000000;
        ch0->MaxI=200.000000;
        ch0->MaxErr=200.000000;
        ch0->MaxOutput=200.000000;
        ch0->DeadBandGain=1.000000;
        ch0->DeadBandRange=0.000000;
        ch0->InputChan0=0;
        ch0->InputChan1=1;
        ch0->OutputChan0=0;
        ch0->OutputChan1=1;
        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=250.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=1.000000;
        ch0->iir[2].B1=0.000000;
        ch0->iir[2].B2=0.000000;
        ch0->iir[2].A1=0.000000;
        ch0->iir[2].A2=0.000000;
    
    
        ch1->InputMode=ENCODER_MODE;
        ch1->OutputMode=NO_OUTPUT_MODE;
        ch1->Vel=100.000000;
        ch1->Accel=1000.000000;
        ch1->Jerk=10000.000000;
        ch1->P=1.000000;
        ch1->I=0.000000;
        ch1->D=0.000000;
        ch1->FFAccel=0.000000;
        ch1->FFVel=0.000000;
        ch1->MaxI=200.000000;
        ch1->MaxErr=200.000000;
        ch1->MaxOutput=200.000000;
        ch1->DeadBandGain=1.000000;
        ch1->DeadBandRange=0.000000;
        ch1->InputChan0=1;
        ch1->InputChan1=2;
        ch1->OutputChan0=3;
        ch1->OutputChan1=2;
        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=250.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=1.000000;
        ch1->iir[2].B1=0.000000;
        ch1->iir[2].B2=0.000000;
        ch1->iir[2].A1=0.000000;
        ch1->iir[2].A2=0.000000;
    
    
        ch2->InputMode=ENCODER_MODE;
        ch2->OutputMode=NO_OUTPUT_MODE;
        ch2->Vel=100.000000;
        ch2->Accel=1000.000000;
        ch2->Jerk=10000.000000;
        ch2->P=1.000000;
        ch2->I=0.000000;
        ch2->D=0.000000;
        ch2->FFAccel=0.000000;
        ch2->FFVel=0.000000;
        ch2->MaxI=200.000000;
        ch2->MaxErr=200.000000;
        ch2->MaxOutput=200.000000;
        ch2->DeadBandGain=1.000000;
        ch2->DeadBandRange=0.000000;
        ch2->InputChan0=2;
        ch2->InputChan1=3;
        ch2->OutputChan0=4;
        ch2->OutputChan1=5;
        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=250.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=1.000000;
        ch2->iir[2].B1=0.000000;
        ch2->iir[2].B2=0.000000;
        ch2->iir[2].A1=0.000000;
        ch2->iir[2].A2=0.000000;
    
    
        ch3->InputMode=ENCODER_MODE;
        ch3->OutputMode=NO_OUTPUT_MODE;
        ch3->Vel=100.000000;
        ch3->Accel=1000.000000;
        ch3->Jerk=10000.000000;
        ch3->P=1.000000;
        ch3->I=0.000000;
        ch3->D=0.000000;
        ch3->FFAccel=0.000000;
        ch3->FFVel=0.000000;
        ch3->MaxI=200.000000;
        ch3->MaxErr=200.000000;
        ch3->MaxOutput=200.000000;
        ch3->DeadBandGain=1.000000;
        ch3->DeadBandRange=0.000000;
        ch3->InputChan0=3;
        ch3->InputChan1=4;
        ch3->OutputChan0=7;
        ch3->OutputChan1=6;
        ch3->LimitSwitchOptions=0x0;
        ch3->InputGain0=1.000000;
        ch3->InputGain1=1.000000;
        ch3->InputOffset0=0.000000;
        ch3->InputOffset1=0.000000;
        ch3->invDistPerCycle=1.000000;
        ch3->Lead=0.000000;
        ch3->MaxFollowingError=1000000000.000000;
        ch3->StepperAmplitude=250.000000;
    
    
        ch3->iir[0].B0=1.000000;
        ch3->iir[0].B1=0.000000;
        ch3->iir[0].B2=0.000000;
        ch3->iir[0].A1=0.000000;
        ch3->iir[0].A2=0.000000;
    
    
        ch3->iir[1].B0=1.000000;
        ch3->iir[1].B1=0.000000;
        ch3->iir[1].B2=0.000000;
        ch3->iir[1].A1=0.000000;
        ch3->iir[1].A2=0.000000;
    
    
        ch3->iir[2].B0=1.000000;
        ch3->iir[2].B1=0.000000;
        ch3->iir[2].B2=0.000000;
        ch3->iir[2].A1=0.000000;
        ch3->iir[2].A2=0.000000;
        
        EnableAxisDest(0,0);
        EnableAxisDest(1,0);
        EnableAxisDest(2,0);
        EnableAxisDest(3,0);
    
    
        DefineCoordSystem(0,1,2,3);
        SetBitDirection(26,1);          // Set bit 26 (PWM 0 as an output)
        SetBitDirection(27,1);          // Set bit 27 (PWM 1 as an output)
        SetBitDirection(28,1);          // Set bit 28 (PWM 2 as an output)
        SetBitDirection(29,1);          // Set bit 29 (PWM 3 as an output)
        
        SetBitDirection(DIR_BIT0,1);    // Set bit 30 (Direction an output)
        SetBitDirection(DIR_BIT1,1);    // Set bit 31 (Direction an output)
        SetBitDirection(DIR_BIT2,1);    // Set bit 32 (Direction an output)
        SetBitDirection(DIR_BIT3,1);    // Set bit 33 (Direction an output)
        
        FPGA(IO_PWMS_PRESCALE) = 1;      // set pwm period to 30 KHz
        FPGA(IO_PWMS+1) = 1;            // enable the PWM
        FPGA(IO_PWMS+3) = 1;            // enable the PWM
        FPGA(IO_PWMS+5) = 1;            // enable the PWM
        FPGA(IO_PWMS+7) = 1;            // enable the PWM
    
    
        for (;;)  //loop forever
        {
            WaitNextTimeSlice();
            OutputSignMag(0,0,DIR_BIT0);
            OutputSignMag(1,1,DIR_BIT1);
            OutputSignMag(2,2,DIR_BIT2);
            OutputSignMag(3,3,DIR_BIT3);
        }
    }
    
    
    // put the servo Output to a specified PWM channel 
    // and direction bit in signed and magnitude mode
    
    
    void OutputSignMag(int ch, int pwm, int dir_bit)
    {
        if (chan[ch].Enable)
        {
            if (chan[ch].Output >= 0)
            {
                if (chan[ch].Output > MAXPWM) // don't go to 100%
                    FPGA(IO_PWMS+pwm*2) = MAXPWM;  
                else
                    DAC(pwm, (int)-chan[ch].Output);  
                SetBit(dir_bit);
            }
            else
            {
                if (chan[ch].Output < -MAXPWM) // don't go to 100%
                    FPGA(IO_PWMS+pwm*2) = MAXPWM;  
                else
                    DAC(pwm, (int)-chan[ch].Output);  
                ClearBit(dir_bit);
            }
        }
        else
        {
            FPGA(IO_PWMS+pwm*2) = 0;  // whenever not enabled put 0% duty cycle
        }
    }


    Attached Files Attached Files


  12. #32
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4043
    Downloads
    0
    Uploads
    0

    Default Re: Problem jig grinding machine.

    Hi vadim_cnc,

    I'd prefer that you learn to modify the program yourself. Its like:

    Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime

    We need to set one bit, when voltage is negative and set another one bit and reset first bit, when voltage is positive and in reverse order.
    So if I understand this correctly you require two outputs that must be always driven opposite polarity? If so what two Output bits are they wired to?

    Please answer each of the following questions:

    #1 Have you read through the code?

    #2 Can you understand any parts of it?

    #3 Can you see that blocks of code are identified with curly brackets { } that mark a beginning and end?
    You might read this.

    #4 Do you understand the programming concept of "if" and "else" ?

    #5 Do you understand what SetBit and ClearBit do?

    #6 Do you understand the concept of a function (subroutine)

    Regards

    Regards
    TK http://dynomotion.com


  13. #33
    Registered
    Join Date
    Nov 2016
    Posts
    28
    Downloads
    0
    Uploads
    0

    Default Re: Problem jig grinding machine.

    Hi Tom!
    You understand us correctly. This bits are 144 and 145.
    About this questions:
    #1 Yes, of course
    #2 Partially
    #3 We read it. We understand that
    #4 In a general sense, we understand, but the problems with syntax
    #5 Yes, setbit sets some bit to '1' and clearbit sets to '0'
    #6 Probably, yes

    Code:
    DefineCoordSystem(0,1,2,3);
        SetBitDirection(26,1);          // Set bit 26 (PWM 0 as an output)
        SetBitDirection(27,1);          // Set bit 27 (PWM 1 as an output)
        SetBitDirection(28,1);          // Set bit 28 (PWM 2 as an output)
        SetBitDirection(29,1);          // Set bit 29 (PWM 3 as an output)
        
        SetBitDirection(DIR_BIT0,1);    // Set bit 30 (Direction an output)
        SetBitDirection(DIR_BIT1,1);    // Set bit 31 (Direction an output)
        SetBitDirection(DIR_BIT2,1);    // Set bit 32 (Direction an output)
        SetBitDirection(DIR_BIT3,1);    // Set bit 33 (Direction an output)
        
        FPGA(IO_PWMS_PRESCALE) = 1;      // set pwm period to 30 KHz             (this is a multiplier for PWM)
        FPGA(IO_PWMS+1) = 1;            // enable the PWM                         (i am not fully understand, what digit is added to IO_PWMS)
        FPGA(IO_PWMS+3) = 1;            // enable the PWM                        -//-
        FPGA(IO_PWMS+5) = 1;            // enable the PWM                        -//-
        FPGA(IO_PWMS+7) = 1;            // enable the PWM                        -//-
    
    
        for (;;)  //loop forever
        {
            WaitNextTimeSlice();
            OutputSignMag(0,0,DIR_BIT0);                                        // (now i don`t understand this string )
            OutputSignMag(1,1,DIR_BIT1);                                        //  -//-
            OutputSignMag(2,2,DIR_BIT2);                                        //  -//-
            OutputSignMag(3,3,DIR_BIT3);                                        //  -//-
        }
    }
    
    
    // put the servo Output to a specified PWM channel 
    // and direction bit in signed and magnitude mode
    
    
    void OutputSignMag(int ch, int pwm, int dir_bit) (function and args)
    {
        if (chan[ch].Enable)
        {
            if (chan[ch].Output >= 0)                                             //(if output channel above or equally zero value, then run next actions)
            {
                if (chan[ch].Output > MAXPWM) // don't go to 100%
                    FPGA(IO_PWMS+pwm*2) = MAXPWM;                                  //(i don`t understand value for FPGA, i mean 'IO_PWMS+pwm*2')
                else
                    DAC(pwm, (int)-chan[ch].Output);  
                SetBit(dir_bit);                                                //(set value '1' to 'dirbit' )
            }
            else
            {
                if (chan[ch].Output < -MAXPWM) // don't go to 100%                // (same, as previous)
                    FPGA(IO_PWMS+pwm*2) = MAXPWM;  
                else
                    DAC(pwm, (int)-chan[ch].Output);  
                ClearBit(dir_bit);
            }
        }
        else
        {
            FPGA(IO_PWMS+pwm*2) = 0;  // whenever not enabled put 0% duty cycle            
            
            
        }
    }

    Best regards!



  14. #34
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4043
    Downloads
    0
    Uploads
    0

    Default Re: Problem jig grinding machine.

    Hi vadim_cnc,

    Here are some things you should fully understand:

    #1 The original example was Outputting to KFLOP PWMs (Pulse Width Modulation) by writing to FPGA Registers. Each PWM has an Output that has to be set to Output Mode. Each PWM has to be enabled. There is a Pre-Scaler for all the PWMs to set the Frequency. To set the value of a PWM an FPGA register is written to. The PWMs are controlled by 8 addresses (2 each) starting at address IO_PWMS. So that is why a digit is added to determine which register to write to.

    In your case you want to use a Kanalog DAC instead. DACs are simpler and don't need to be configured or enabled. Just use the DAC(X,Y); command to set the voltage where X is which DAC to use and Y is a value from -2047 to +2047 which represents +/-10V. But you only want positive magnitude so the value should always be 0-2047.

    Every line that wrote a value to the FPGA should now write a value to a DAC instead. There should be no FPGA commands left in the program at all.

    All the stuff initializing for the PWMs is unnecessary and can be removed (Setting PWMs as Outputs, Prescale, and Enables).

    #2 The original example was for 4 Axes. A function was used, OutputSignMag() and called 4 times for the 4 axes. The function passed 3 parameters. Which Axis, which PWM, and which IO bit to use for the Direction output.

    In your case I believe you only have 1 Axis. So only call the function one time not 4 times. You will need to pass 4 parameters because you have 2 output bits to set based on the direction. Which Axis, Which DAC, the first Direction Bit (144), and the second Direction Bit (145).

    Change the function definition to have 4 appropriate parameters like this:
    void OutputSignMag(int ch, int dac, int dir_bit0, int dir_bit1)


    #3 The "if" statement is used to be able to do different things based on whether the Output is positive or negative. When the value is negative we want to take the negative of it (negative of negative is positive). Your latetest code outputs the negative in both cases regardless of whether the value is negative or positive.

    if (chan[ch].Output >= 0)
    ......
    ...... This code is used when value is positive
    ......
    else
    ......
    ...... This code is used when value is negative
    ......

    #4 change the code to SetBit and ClearBit two bits instead of only one bit.

    #5 because we are controlling a DAC not a PWM change the term MAXPWM to MAXDAC (everywheere in the program) and change the definition to 2047


    Let us know how much of this you understand.

    Regards

    Regards
    TK http://dynomotion.com


  15. #35
    Member
    Join Date
    Jun 2004
    Location
    Scotland
    Posts
    355
    Downloads
    0
    Uploads
    0

    Default Re: Problem jig grinding machine.

    Modified code is below.
    Additional comments are in bold
    Additional code is in green
    As you are only using a single axis, I have also removed extra code.
    I've not tried compiling this code in KMotion, but it should give you an idea of what you need to do, and hopefully my comments will help clarify things.

    Code:
    DefineCoordSystem(0,1,2,3);
    
        // If you're using fixed outputs (I.e. Kanalog output optos/FET relay drivers), you don't need to set bit direction, so the following two lines can be removed, but you will still need to modify the defines at the top of the file
        SetBitDirection(DIR_BIT0_POS,1);    // You will need to rename DIR_BIT0 to DIR_BIT0_POS at the top of the file
        SetBitDirection(DIR_BIT0_NEG,1);    // You will need to add a define for DIR_BIT0_NEG  at the top of the file
    
    
        for (;;)  //loop forever
        {
            WaitNextTimeSlice();
            OutputSignMag(0,DIR_BIT0_POS,DIR_BIT0_NEG);              // This calls, and passes the required values to the function
       }
    }
    
    
    // write the servo output value to the relative DAC, and activate/deactivate direction bits depending on negative/positive output
    
    void OutputSignMag(int ch, int dir_bit_pos, int dir_bit_neg) //(function and args)
    {
        if (chan[ch].Enable)   // if channel is enabled, we need to check the channel output
        {
            if (chan[ch].Output >= 0)                                             //(if output channel above or equally zero value, then run next actions)
            {
                DAC(ch, (int)chan[ch].Output);  // Set DAC output, using channel output
                ClearBit(dir_bit_neg);   // Clear negative direction bit/output
                SetBit(dir_bit_pos);   // Set positive direction bit/output                                             //(set value '1' to 'dirbit' )
    
            }
            else // else our channel output is negative
            {
                DAC(ch, (int)chan[ch].Output*-1);  // As we need an always positive DAC, we multiply by -1
                ClearBit(dir_bit_pos);   // Clear positive direction bit/output
                SetBit(dir_bit_neg);    // Set negative direction bit/output
            }
        }
        else // else the channel is disabled so set DAC to zero, and disable both outputs 
        {
            DAC(ch, 0);          
           ClearBit(dir_bit_pos);
           ClearBit(dir_bit_neg);
            
        }
    }




  16. #36
    Registered
    Join Date
    Nov 2016
    Posts
    28
    Downloads
    0
    Uploads
    0

    Default Re: Problem jig grinding machine.

    Thanks a lot to everyone! Your advices helps us!
    Hydraulic cylider works, but not as we expect(( I will try to explain:
    there is a hydraulic proportional valve, which is controlled by amplifier; amplifier controlled by 0...10 V, but voltage from Kanalog`s DAC won`t exceed appreoximately 2.5 V, what do not allow to work on full speed. To increasing speed we increased feed in G-code, expecting voltage increase, but nothing happend.



    Code:
    #include "KMotionDef.h"
    
    
    //#define MAXPWM 2047
    #define DIR_BIT0_POS 144
    #define DIR_BIT0_NEG 145
    
    
    
    
    main()
    {
        int BitA,Change1=0,Change2=0, DiffX2;
        int PosNoWrap, NewPos, Pos=0, wraps;
        double Factor=0;
        
        SetBit(152);
        SetBit(157);
        SetBit(158);
        
        ch0->InputMode=ENCODER_MODE;
        ch0->OutputMode=DAC_SERVO_MODE;
        ch0->Vel=100000;
        ch0->Accel=2e+006;
        ch0->Jerk=2e+006;
        ch0->P=1;
        ch0->I=0;
        ch0->D=0;
        ch0->FFAccel=0;
        ch0->FFVel=0;
        ch0->MaxI=200;
        ch0->MaxErr=40000;
        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+009;
        ch0->SoftLimitNeg=-1e+009;
        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=0.00025;
        ch0->Lead=0;
        ch0->MaxFollowingError=10000000;
        ch0->StepperAmplitude=100;
    
    
        ch0->iir[0].B0=0.027497;
        ch0->iir[0].B1=0.027497;
        ch0->iir[0].B2=0.000000;
        ch0->iir[0].A1=0.945006;
        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=1.000000;
        ch0->iir[2].B1=0.000000;
        ch0->iir[2].B2=0.000000;
        ch0->iir[2].A1=0.000000;
        ch0->iir[2].A2=0.000000;
    
    
    
    
    
    
    
    
        
        ch1->InputMode=ENCODER_MODE;
        ch1->OutputMode=DAC_SERVO_MODE;
        ch1->Vel=100000;
        ch1->Accel=2e+006;
        ch1->Jerk=2e+006;
        ch1->P=1;
        ch1->I=0;
        ch1->D=0;
        ch1->FFAccel=0;
        ch1->FFVel=0;
        ch1->MaxI=2000;
        ch1->MaxErr=40000;
        ch1->MaxOutput=2000;
        ch1->DeadBandGain=1;
        ch1->DeadBandRange=0;
        ch1->InputChan0=1;
        ch1->InputChan1=1;
        ch1->OutputChan0=1;
        ch1->OutputChan1=1;
        ch1->MasterAxis=-1;
        ch1->LimitSwitchOptions=0x100;
        ch1->LimitSwitchNegBit=0;
        ch1->LimitSwitchPosBit=0;
        ch1->SoftLimitPos=1e+009;
        ch1->SoftLimitNeg=-1e+009;
        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=0.00025;
        ch1->Lead=0;
        ch1->MaxFollowingError=10000000;
        ch1->StepperAmplitude=100;
    
    
    
    
        ch1->iir[0].B0=0.002819;
        ch1->iir[0].B1=0.002819;
        ch1->iir[0].B2=0.000000;
        ch1->iir[0].A1=0.994361;
        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=1.000000;
        ch1->iir[2].B1=0.000000;
        ch1->iir[2].B2=0.000000;
        ch1->iir[2].A1=0.000000;
        ch1->iir[2].A2=0.000000;
    
    
    
    
    
    
    
    
    
    
        
        ch2->InputMode=ENCODER_MODE;
        ch2->OutputMode=DAC_SERVO_MODE;
        ch2->Vel=100000;
        ch2->Accel=1e+006;
        ch2->Jerk=1e+006;
        ch2->P=1;
        ch2->I=0;
        ch2->D=0;
        ch2->FFAccel=0;
        ch2->FFVel=0;
        ch2->MaxI=2000;
        ch2->MaxErr=40000;
        ch2->MaxOutput=2000;
        ch2->DeadBandGain=1;
        ch2->DeadBandRange=0;
        ch2->InputChan0=2;
        ch2->InputChan1=2;
        ch2->OutputChan0=2;
        ch2->OutputChan1=2;
        ch2->MasterAxis=-1;
        ch2->LimitSwitchOptions=0x100;
        ch2->LimitSwitchNegBit=0;
        ch2->LimitSwitchPosBit=0;
        ch2->SoftLimitPos=1e+009;
        ch2->SoftLimitNeg=-1e+009;
        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=0.00025;
        ch2->Lead=0;
        ch2->MaxFollowingError=10000000;
        ch2->StepperAmplitude=100;
        
        
    
    
        ch2->iir[0].B0=0.002819;
        ch2->iir[0].B1=0.002819;
        ch2->iir[0].B2=0.000000;
        ch2->iir[0].A1=0.994361;
        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=1.000000;
        ch2->iir[2].B1=0.000000;
        ch2->iir[2].B2=0.000000;
        ch2->iir[2].A1=0.000000;
        ch2->iir[2].A2=0.000000;
    
    
    
    
    
    
    
    
        ch3->InputMode=ENCODER_MODE;
        ch3->OutputMode=NO_OUTPUT_MODE;
        ch3->Vel=1000;
        ch3->Accel=100000;
        ch3->Jerk=2e+06;
        ch3->P=0.05;
        ch3->I=0.000001;
        ch3->D=5;
        ch3->FFAccel=0;
        ch3->FFVel=0;
        ch3->MaxI=2000;
        ch3->MaxErr=40000;
        ch3->MaxOutput=1000;
        ch3->DeadBandGain=1;
        ch3->DeadBandRange=0;
        ch3->InputChan0=3;
        ch3->InputChan1=0;
        ch3->OutputChan0=3;
        ch3->OutputChan1=0;
        ch3->MasterAxis=-1;
        ch3->LimitSwitchOptions=0x100;
        ch3->LimitSwitchNegBit=0;
        ch3->LimitSwitchPosBit=0;
        ch3->SoftLimitPos=1e+09;
        ch3->SoftLimitNeg=-1e+09;
        ch3->InputGain0=1;
        ch3->InputGain1=1;
        ch3->InputOffset0=0;
        ch3->InputOffset1=0;
        ch3->OutputGain=1;
        ch3->OutputOffset=0;
        ch3->SlaveGain=1;
        ch3->BacklashMode=BACKLASH_OFF;
        ch3->BacklashAmount=0;
        ch3->BacklashRate=0;
        ch3->invDistPerCycle=1;
        ch3->Lead=0;
        ch3->MaxFollowingError=10000000;
        ch3->StepperAmplitude=100;
    
    
        ch3->iir[0].B0=1;
        ch3->iir[0].B1=0;
        ch3->iir[0].B2=0;
        ch3->iir[0].A1=0;
        ch3->iir[0].A2=0;
    
    
        ch3->iir[1].B0=1;
        ch3->iir[1].B1=0;
        ch3->iir[1].B2=0;
        ch3->iir[1].A1=0;
        ch3->iir[1].A2=0;
    
    
        ch3->iir[2].B0=1;
        ch3->iir[2].B1=0;
        ch3->iir[2].B2=0;
        ch3->iir[2].A1=0;
        ch3->iir[2].A2=0;
    
    
    
    
    
    
    
    
        EnableAxis(0);
        EnableAxis(1);
        EnableAxis(2);
        EnableAxis(3);
    
    
        DefineCoordSystem(0,1,2,3);
    
    
    
    
        // If you're using fixed outputs (I.e. Kanalog output optos/FET relay drivers), you don't need to set bit direction, so the following two lines can be removed, but you will still need to modify the defines at the top of the file
        SetBitDirection(DIR_BIT0_POS,1);    // You will need to rename DIR_BIT0 to DIR_BIT0_POS at the top of the file
        SetBitDirection(DIR_BIT0_NEG,1);    // You will need to add a define for DIR_BIT0_NEG  at the top of the file
    
    
    
    
        for (;;)  //loop forever
        {
            WaitNextTimeSlice();
            OutputSignMag(0,DIR_BIT0_POS,DIR_BIT0_NEG);              // This calls, and passes the required values to the function
       }
    }
    
    
    
    
    // write the servo output value to the relative DAC, and activate/deactivate direction bits depending on negative/positive output
    
    
    void OutputSignMag() //(function and args)
    
    
    {
        if (chan[3].Enable)
        {
            if (chan[3].Output >= 0)
            
            {
                DAC(3, (int)chan[3].Output*-3);  // Set DAC output, using channel output
                ClearBit(DIR_BIT0_NEG);   // Clear negative direction bit/output
                SetBit(DIR_BIT0_POS);   // Set positive direction bit/output           //(set value '1' to 'dirbit' )
            }
            else // else our channel output is negative
            
            {   
                DAC(3, (int)chan[3].Output*3);  // As we need an always positive DAC, we multiply by -1
                ClearBit(DIR_BIT0_POS);   // Clear positive direction bit/output
                SetBit(DIR_BIT0_NEG);    // Set negative direction bit/output
            }
    }    
            else // else the channel is disabled so set DAC to zero, and disable both outputs 
            {
                DAC(3, 0);          
                ClearBit(DIR_BIT0_POS);
                ClearBit(DIR_BIT0_NEG);
            }   
        }
    What can be changed to increase voltage?



  17. #37
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4043
    Downloads
    0
    Uploads
    0

    Default Re: Problem jig grinding machine.

    Hi vadim_cnc,

    Before running KMotionCNC please test and tune the Axis with the KMotion.exe Step Response Screen at various Velocities, Accelerations, and Jerks. Verify that your Axis is properly following the commanded trajectory. See:
    Dynomotion

    You should also determine the encoder resolution of your system. See:
    Dynomotion

    Each Axis has Max Limits on Error, Output, and Integrator. Your Max Output is set at 1000 (~5V). Increase to 2047 for a maximum of 10V Output. See:
    Dynomotion

    After you know your Resolution and Max Velocities and Accelerations that work well for your system set them in KMotionCNC | Tool Setup | Trajectory Planner Screen. See:
    Tool Setup Trajectory Planner


    HTH
    Regards

    Regards
    TK http://dynomotion.com


  18. #38
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4043
    Downloads
    0
    Uploads
    0

    Default Re: Problem jig grinding machine.

    Hi vadim_cnc,

    I just noticed your C code has a factor of 3 included. It would be best (more logical) to remove that as any gain can be included in the Axis Parameters PID gains. Having that included would require you to limit the output to 1/3 of 2047 otherwise you might overflow the maximum allowed DAC value.

    Regards

    Regards
    TK http://dynomotion.com


  19. #39
    Registered
    Join Date
    Nov 2016
    Posts
    28
    Downloads
    0
    Uploads
    0

    Default Re: Problem jig grinding machine.

    Hi, Tom!
    Now this axis works good, we tuned it.
    Now we trying to set up MPG like this:

    We trying MPG examples in C programs folder, but nothing succeeded. Last tested is MPGServiceSmoothHardwareEnc. compiles good.

    For testing we changed axis to 4 (MPG connected as on picture)




    Also we changed ENABLE_MPG, HANDWHEEL_EN, SELECT adn FACTOR bits to virtual.
    As well we can see what encoder works after connecting to Kanalog (see picture):





    Code:
    #include "KMotionDef.h"
    
    
    
    
    #define DIR_BIT0_POS 144
    #define DIR_BIT0_NEG 145
    
    
    
    
    #define MPG_INPUT_AXIS 4
    
    
    #define TAU 0.08 // smoothness factor (Low Pass Time constant seconds)
    #define FINAL_TIME 1.0 // Set final dest after this amount of time with no change
    
    
    #define ENABLE_MPG 1056
    
    
    #define SELECTX 1024
    #define SELECTY 1025
    #define SELECTZ 1026
    #define SELECTA 1027
    
    
    #define FACTOR1 1040
    #define FACTOR10 1041
    #define FACTOR100 1042
    #define FACTOR200 1043
    
    
    #define HANDWHEEL_EN    1056
    
    
    
    
    main()
    {
        int BitA,Change1=0,Change2=0, DiffX2;
        int PosNoWrap, NewPos, Pos=0, wraps;
        double Factor=0;
        
        SetBit(152);
        SetBit(157);
        SetBit(158);
        
        ch0->InputMode=ENCODER_MODE;
        ch0->OutputMode=DAC_SERVO_MODE;
        ch0->Vel=100000;
        ch0->Accel=2e+006;
        ch0->Jerk=2e+006;
        ch0->P=1;
        ch0->I=0;
        ch0->D=0;
        ch0->FFAccel=0;
        ch0->FFVel=0;
        ch0->MaxI=200;
        ch0->MaxErr=40000;
        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+009;
        ch0->SoftLimitNeg=-1e+009;
        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=0.00025;
        ch0->Lead=0;
        ch0->MaxFollowingError=10000000;
        ch0->StepperAmplitude=100;
    
    
        ch0->iir[0].B0=0.027497;
        ch0->iir[0].B1=0.027497;
        ch0->iir[0].B2=0.000000;
        ch0->iir[0].A1=0.945006;
        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=1.000000;
        ch0->iir[2].B1=0.000000;
        ch0->iir[2].B2=0.000000;
        ch0->iir[2].A1=0.000000;
        ch0->iir[2].A2=0.000000;
    
    
    
    
    
    
    
    
        
        ch1->InputMode=ENCODER_MODE;
        ch1->OutputMode=DAC_SERVO_MODE;
        ch1->Vel=100000;
        ch1->Accel=2e+006;
        ch1->Jerk=2e+006;
        ch1->P=1;
        ch1->I=0;
        ch1->D=0;
        ch1->FFAccel=0;
        ch1->FFVel=0;
        ch1->MaxI=2000;
        ch1->MaxErr=40000;
        ch1->MaxOutput=2000;
        ch1->DeadBandGain=1;
        ch1->DeadBandRange=0;
        ch1->InputChan0=1;
        ch1->InputChan1=1;
        ch1->OutputChan0=1;
        ch1->OutputChan1=1;
        ch1->MasterAxis=-1;
        ch1->LimitSwitchOptions=0x100;
        ch1->LimitSwitchNegBit=0;
        ch1->LimitSwitchPosBit=0;
        ch1->SoftLimitPos=1e+009;
        ch1->SoftLimitNeg=-1e+009;
        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=0.00025;
        ch1->Lead=0;
        ch1->MaxFollowingError=10000000;
        ch1->StepperAmplitude=100;
    
    
    
    
        ch1->iir[0].B0=0.002819;
        ch1->iir[0].B1=0.002819;
        ch1->iir[0].B2=0.000000;
        ch1->iir[0].A1=0.994361;
        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=1.000000;
        ch1->iir[2].B1=0.000000;
        ch1->iir[2].B2=0.000000;
        ch1->iir[2].A1=0.000000;
        ch1->iir[2].A2=0.000000;
    
    
    
    
    
    
    
    
    
    
        
        ch2->InputMode=ENCODER_MODE;
        ch2->OutputMode=DAC_SERVO_MODE;
        ch2->Vel=100000;
        ch2->Accel=1e+006;
        ch2->Jerk=1e+006;
        ch2->P=1;
        ch2->I=0;
        ch2->D=0;
        ch2->FFAccel=0;
        ch2->FFVel=0;
        ch2->MaxI=2000;
        ch2->MaxErr=40000;
        ch2->MaxOutput=2000;
        ch2->DeadBandGain=1;
        ch2->DeadBandRange=0;
        ch2->InputChan0=2;
        ch2->InputChan1=2;
        ch2->OutputChan0=2;
        ch2->OutputChan1=2;
        ch2->MasterAxis=-1;
        ch2->LimitSwitchOptions=0x100;
        ch2->LimitSwitchNegBit=0;
        ch2->LimitSwitchPosBit=0;
        ch2->SoftLimitPos=1e+009;
        ch2->SoftLimitNeg=-1e+009;
        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=0.00025;
        ch2->Lead=0;
        ch2->MaxFollowingError=10000000;
        ch2->StepperAmplitude=100;
        
        
    
    
        ch2->iir[0].B0=0.002819;
        ch2->iir[0].B1=0.002819;
        ch2->iir[0].B2=0.000000;
        ch2->iir[0].A1=0.994361;
        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=1.000000;
        ch2->iir[2].B1=0.000000;
        ch2->iir[2].B2=0.000000;
        ch2->iir[2].A1=0.000000;
        ch2->iir[2].A2=0.000000;
    
    
    
    
    
    
    
    
        ch3->InputMode=ENCODER_MODE;
        ch3->OutputMode=NO_OUTPUT_MODE;
        ch3->Vel=100000;
        ch3->Accel=100000;
        ch3->Jerk=2e+07;
        ch3->P=0.05;
        ch3->I=0;
        ch3->D=1;
        ch3->FFAccel=0;
        ch3->FFVel=0;
        ch3->MaxI=2000;
        ch3->MaxErr=400000000000;
        ch3->MaxOutput=2000;
        ch3->DeadBandGain=1;
        ch3->DeadBandRange=0;
        ch3->InputChan0=3;
        ch3->InputChan1=0;
        ch3->OutputChan0=3;
        ch3->OutputChan1=0;
        ch3->MasterAxis=-1;
        ch3->LimitSwitchOptions=0x100;
        ch3->LimitSwitchNegBit=0;
        ch3->LimitSwitchPosBit=0;
        ch3->SoftLimitPos=1e+09;
        ch3->SoftLimitNeg=-1e+09;
        ch3->InputGain0=1;
        ch3->InputGain1=1;
        ch3->InputOffset0=0;
        ch3->InputOffset1=0;
        ch3->OutputGain=1;
        ch3->OutputOffset=0;
        ch3->SlaveGain=1;
        ch3->BacklashMode=BACKLASH_OFF;
        ch3->BacklashAmount=0;
        ch3->BacklashRate=0;
        ch3->invDistPerCycle=1;
        ch3->Lead=0;
        ch3->MaxFollowingError=10000000000;
        ch3->StepperAmplitude=100;
    
    
        ch3->iir[0].B0=0.00141172;
        ch3->iir[0].B1=0.00141172;
        ch3->iir[0].B2=0.000000;
        ch3->iir[0].A1=0.997177;
        ch3->iir[0].A2=0.000000;
    
    
        ch3->iir[1].B0=1.000000;
        ch3->iir[1].B1=0.000000;
        ch3->iir[1].B2=0.000000;
        ch3->iir[1].A1=0.000000;
        ch3->iir[1].A2=0.000000;
    
    
        ch3->iir[2].B0=1.000000;
        ch3->iir[2].B1=0.000000;
        ch3->iir[2].B2=0.000000;
        ch3->iir[2].A1=0.000000;
        ch3->iir[2].A2=0.000000;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        EnableAxis(0);
        EnableAxis(1);
        EnableAxis(2);
        EnableAxis(3);
    
    
        DefineCoordSystem(0,1,2,3);
    
    
    
    
        // If you're using fixed outputs (I.e. Kanalog output optos/FET relay drivers), you don't need to set bit direction, so the following two lines can be removed, but you will still need to modify the defines at the top of the file
        SetBitDirection(DIR_BIT0_POS,1);    // You will need to rename DIR_BIT0 to DIR_BIT0_POS at the top of the file
        SetBitDirection(DIR_BIT0_NEG,1);    // You will need to add a define for DIR_BIT0_NEG  at the top of the file
    
    
    
    
        for (;;)  //loop forever
        {
            WaitNextTimeSlice();
            OutputSignMag(0,DIR_BIT0_POS,DIR_BIT0_NEG);              // This calls, and passes the required values to the function
       }
    }
    
    
    
    
    // write the servo output value to the relative DAC, and activate/deactivate direction bits depending on negative/positive output
    
    
    void OutputSignMag() //(function and args)
    
    
    {
        if (chan[3].Enable)
        {
            if (chan[3].Output >= 0)
            
            {
                DAC(3, (int)chan[3].Output*-1);  // Set DAC output, using channel output
                ClearBit(DIR_BIT0_NEG);   // Clear negative direction bit/output
                SetBit(DIR_BIT0_POS);   // Set positive direction bit/output           //(set value '1' to 'dirbit' )
            }
            else // else our channel output is negative
            
            {   
                DAC(3, (int)chan[3].Output);  // As we need an always positive DAC, we multiply by -1
                ClearBit(DIR_BIT0_POS);   // Clear positive direction bit/output
                SetBit(DIR_BIT0_NEG);    // Set negative direction bit/output
            }
    }    
            else // else the channel is disabled so set DAC to zero, and disable both outputs 
            {
                DAC(3, 0);          
                ClearBit(DIR_BIT0_POS);
                ClearBit(DIR_BIT0_NEG);
            }
    }  
     void ServiceMPG()
    {
        static int Pos, FirstTime=TRUE;
        static int InMotion=FALSE,Axis,LastAxis=-1;
        static double LastChangeTime=0,Target,Factor=0;
        int Change1, NewPos;
        
        if (FirstTime)
        {
            Pos = chan[MPG_INPUT_AXIS].Position;
            FirstTime=FALSE;
        }
    
    
        NewPos = chan[MPG_INPUT_AXIS].Position;
        Change1 = NewPos - Pos;
        Pos = NewPos;
    
    
        if (!ReadBit(HANDWHEEL_EN) || JOB_ACTIVE) // if not button pressed or Job Active ignore the encoder.
            Change1 = 0;
        else 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 if (ReadBit(FACTOR200))  // is X200 selected?
            Factor = 400;
        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;
    
    
        // 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,Target);  //finalize any motion
    
    
            LastAxis = Axis;
            InMotion = FALSE;
        }
        
        if (Change1) // did we move?
        {
            if (!InMotion) Target = chan[Axis].Dest;
            Target += Change1 * Factor;
            MoveExp(Axis,Target,TAU);  // note: contains a WaitNextTimeSlice
            LastChangeTime = Time_sec();
            InMotion=TRUE;
        }
        else
        {
            WaitNextTimeSlice();
        }        
        
    }


    Attached Thumbnails Attached Thumbnails Problem jig grinding machine.-s-l1600-jpg   Problem jig grinding machine.-jpg   Problem jig grinding machine.-jpg   Problem jig grinding machine.-jpg  



  20. #40
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4043
    Downloads
    0
    Uploads
    0

    Default Re: Problem jig grinding machine.

    Hi vadim_cnc,

    It seems you created a function ServiceMPG() but never call it anywhere.

    Also you are passing parameters to the function OutputSignMag() that doesn't take any parameters.

    Please read this article to see if you can understand how to use Functions in C correctly
    KFLOP C Programs - Dynomotion

    You should of course remove the MPG from the DefineCoordSystem as the A axis and also in Tool Setup as the Spindle Threading Axis.

    Regards

    Regards
    TK http://dynomotion.com


Page 2 of 3 FirstFirst 123 LastLast

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

Problem jig grinding machine.

Problem jig grinding machine.