Need Help! Kmotion Control Issues on K2CNC machine - Page 2


Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28

Thread: Kmotion Control Issues on K2CNC machine

  1. #21
    Registered
    Join Date
    Jul 2012
    Location
    USA
    Posts
    18
    Downloads
    0
    Uploads
    0

    Default Re: Kmotion Control Issues on K2CNC machine

    I have included the K2_Home file as well as a file named HOMING-ZXY (c:\KFLOP\Driver\homing_ZXY.c) which is loaded in thread #5 according to the kmotion

    K2_HOME.c

    #include "KMotionDef.h"
    #define HomingStart 1026
    #define HOMING_PERSIST 13

    int main()
    {
    ClearBit(HomingStart);
    Delay_sec(0.5);
    SetBit(HomingStart);
    return 0;
    }




    Also, in thread 5 is HOMING_ZXY



    //----------------------------------------------------------------
    // KFLOP Homing routine
    // K2CNC - Copyright 2013
    // Version: 2.0.4
    //
    // - Homing.c -> Thread 5
    //----------------------------------------------------------------
    // Last Modified: 10-02-2013
    //
    //
    //----------------------------------------------------------------

    #include "KMotionDef.h"
    #include "defines.h"
    #include "pthread.h"
    #include "util.h"

    #define HM_DUAL_DEBUG

    //---------------------------------------------------------
    #define ST_DUAL_BOTH_TO_SW 0
    #define ST_DUAL_BOTH_BACK_OFF 1
    #define ST_DUAL_SLAVE_TO_SW 2
    #define ST_DUAL_SLAVE_BACK_OFF 4

    //---------------------------------------------------------
    //---------------------------------------------------------
    void ReadPersist();
    void WritePersist();

    int ChkOnSwitch(int Axis);
    int ChkOffSwitch(int Axis);

    static int myHomeThread(int axis, int hmSw, int inxSw);
    static int myHomeThreadDual(int axis0, int hmSw0, int inxSw0, int axis1, int hmSw1, int inxSw1);

    void PRINT(char *str, float val, float val2)
    {
    #ifdef HM_DUAL_DEBUG
    printf(str, val, val2);
    #endif
    }

    void PRINT_DEC(char *str, int val)
    {
    #ifdef HM_DUAL_DEBUG
    printf(str, val);
    #endif
    }

    //---------------------------------------------------------
    //---------------------------------------------------------
    main()
    {
    int i;

    SetBit(vbThread5Started);

    if (ReadBit(vbHomeRunning))
    {
    ClearBit(vbAbortHome);

    ReadPersist();

    // Skip homing for these axis if not enabled
    fHomeDone[X] = !homeAxisEn[X];
    fHomeDone[Y] = !homeAxisEn[Y];
    fHomeDone[Z] = !homeAxisEn[Z];
    fHomeDone[A] = !homeAxisEn[A];

    //fHomeDone[X] = 1;
    //fHomeDone[Y] = 1;
    fHomeDone[A] = 1;
    //fHomeDone[Z] = 1;

    #ifdef HM_DEBUG
    printf("HomeRunning:%d fHomeDone[z]%d\n", ReadBit(vbHomeRunning), fHomeDone[Z]);
    #endif

    myHomeThread(Z, vbHomeSwZ, vbIndexSwZ);
    //myHomeThreadDual(Y, vbHomeSwY, vbIndexSwY, A, vbHomeSwA, vbIndexSwA);
    myHomeThread(X, vbHomeSwX, vbIndexSwX);
    myHomeThread(Y, vbHomeSwY, vbIndexSwY);

    if (fHomeDone[X] && fHomeDone[Y] && fHomeDone[Z] && fHomeDone[A])
    {
    // Homing Completed successfully
    Zero(X);
    Zero(Y);
    Zero(Z);
    Zero(A);
    Zero(B);
    Zero(C);

    SetBit(vbMachineHomed);
    SetBit(vbSoftlimitEn);
    }
    }

    ClearBit(vbHomeRunning);
    ClearBit(vbHomeStarted);

    ClearBit(vbThread5Started);
    }
    //---------------------------------------------------------
    //---------------------------------------------------------

    //-------
    int ReadBitDebounce(pin)
    {
    int i, j;

    i = 0;
    for (j = 0; j < 10; j++)
    i += ReadBit(pin);

    if (i >= 5)
    return 1;
    else
    return 0;
    }

    //-------
    #define StopOnPinChange(axis, pin, state) \
    while (ReadBitDebounce(pin) != state)\
    {\
    if (!ReadBit(vbHomeRunning))\
    break;\
    }\
    Jog(axis, 0);\
    if (!ReadBit(vbHomeRunning))\
    break;

    //-------
    #define StopOnEitherPinChange(axis, pin, state, pin1, state1) \
    while ((ReadBit(pin) != state) && (ReadBit(pin1) != state1))\
    {\
    if (!ReadBit(vbHomeRunning))\
    break;\
    }\
    Jog(axis, 0);\
    if (!ReadBit(vbHomeRunning))\
    break;

    //-------
    #define WaitDone(axis) \
    while (!CheckDone(axis))\
    ;



    //----------------------------------------------------------------
    int ChkOnSwitch(int Axis)
    {
    return !(ReadBit(vbHomeSwX + Axis) == homeActiveLow[Axis]);
    }

    //----------------------------------------------------------------
    int ChkOffSwitch(int Axis)
    {
    return (ReadBit(vbHomeSwX + Axis) == homeActiveLow[Axis]);
    }


    //----------------------------------------------------------------
    static int myHomeThread(int axis, int hmSw, int inxSw)
    {
    static int index_this[6];
    static double velSav[6];
    static int moveSpeed;
    static double homePos;

    if (!ReadBit(vbHomeRunning))
    return;

    while(!fHomeDone[axis])
    {
    if (ReadBit(vbHomeRunning) && !fHomeDone[axis])
    {
    Jog(axis, homeSpeed[axis] * revHome[axis]); // Move Toward Switch
    StopOnPinChange(axis, hmSw, homeActiveLow[axis]);

    WaitDone(axis);
    //Delay_sec(0.5);

    Jog(axis, -(homeSpeed[axis] * revHome[axis] / BACKOFF_SPEED_SCALE)); // Backoff
    //Delay_sec(0.5);
    StopOnPinChange(axis, hmSw, !homeActiveLow[axis]);

    WaitDone(axis);

    //Delay_sec(0.5);

    if (homeIndexOn[axis])
    {
    // Save index state
    index_this[axis] = ReadBit(inxSw);

    // Continue to Back off until Find Index
    Jog(axis, -(homeSpeed[axis] * revHome[axis] / INDEX_SPEED_SCALE));
    StopOnPinChange(axis, inxSw, !index_this[axis]);

    // Save and move to index position
    hmIndexPos[axis] = GetPos(axis);

    // Move To Index Position + HomeOffset
    velSav[axis] = chan[axis].Vel;
    moveSpeed = abs(homeSpeed[axis] * revHome[axis]);
    chan[axis].Vel = moveSpeed;
    homePos = hmIndexPos[axis] + (homeOffset[axis] * stepsPerIn[axis]);
    //homePos = hmIndexPos[axis];
    Move(axis, homePos);
    WaitDone(axis);
    chan[axis].Vel = velSav[axis];
    }

    WaitDone(axis);
    Delay_sec(0.1);

    fHomeDone[axis] = 1;
    }
    }
    }

    //----------------------------------------------------------------
    static int myHomeThreadDual(int axis0, int hmSw0, int inxSw0, int axis1, int hmSw1, int inxSw1)
    {
    static int index_this0, index_this1;
    static int moveSpeed;
    static double velSav0, velSav1;
    static int hitSw0;
    static int indexHit0, indexHit1;
    static double homePos0, homePos1;
    static int homeState;
    static double savPos;

    moveSpeed = abs(homeSpeed[axis1] * revHome[axis1]);
    //Debug
    //#define HM_DEBUG

    #ifdef HM_DEBUG
    printf("HomeMode:%d\n", homeMode);
    #endif

    if (!ReadBit(vbHomeRunning))
    return;

    while(!fHomeDone[axis0] || !fHomeDone[axis1])
    {
    if (ReadBit(vbHomeRunning) && !fHomeDone[axis0])
    {
    homeState = 1;
    while (homeState == 1)
    {
    Jog(axis0, homeSpeed[axis0] * revHome[axis0]); // Move Toward Switches
    StopOnEitherPinChange(axis0, hmSw0, homeActiveLow[axis0], hmSw1, homeActiveLow[axis1]);

    if( ReadBit(hmSw0) == !homeActiveLow[axis0])
    hitSw0 = 0;
    else
    hitSw0 = 1;

    //WaitDone(axis0);

    if (hitSw0) // Master Sw hit first
    {
    // Jog until slave hit Sw also
    Jog(axis1, homeSpeed[axis1] * revHome[axis1]); // Move Toward Switches
    StopOnPinChange( axis1, hmSw1, homeActiveLow[axis1]);
    WaitDone(axis1);

    // Jog Both back off Sw
    Jog(axis0, -(homeSpeed[axis0] * revHome[axis0] / BACKOFF_SPEED_SCALE)); // Backoff
    StopOnPinChange( axis0, hmSw0, !homeActiveLow[axis0]);
    WaitDone(axis0);

    homeState = 2;
    }
    else // Slave Sw hit first
    {
    //Back-off and repeat Home Process
    Jog(axis1, -(homeSpeed[axis1] * revHome[axis1] / BACKOFF_SPEED_SCALE)); // Backoff
    StopOnPinChange( axis1, hmSw1, !homeActiveLow[axis1]);
    WaitDone(axis0);

    }
    }

    WaitDone(axis0);

    if (homeIndexOn[axis0])
    {
    index_this0 = ReadBit(inxSw0);
    index_this1 = ReadBit(inxSw1);
    savPos = GetPos(axis0);

    // Continue to Back off until Find Index
    Jog(axis0, -(homeSpeed[axis0] * revHome[axis0] / INDEX_SPEED_SCALE));

    while (index_this0 == ReadBit(inxSw0))
    ;
    hmIndexPos[axis0] = GetPos(axis0);

    Jog(axis0, 0);
    WaitDone(axis0);

    Move(axis0, savPos);
    WaitDone(axis0);

    Jog(axis0, -(homeSpeed[axis0] * revHome[axis0] / INDEX_SPEED_SCALE));

    while (index_this1 == ReadBit(inxSw1))
    ;
    hmIndexPos[axis1] = GetPos(axis1);

    Jog(axis0, 0);
    WaitDone(axis0);

    // Move To Index Postion + HomeOffset
    velSav0 = chan[axis0].Vel;
    velSav1 = chan[axis1].Vel;
    chan[axis0].Vel = moveSpeed;
    chan[axis1].Vel = moveSpeed;
    homePos0 = hmIndexPos[axis0] + (homeOffset[axis0] * stepsPerIn[axis0]);
    Move(axis0, homePos0);
    WaitDone(axis0);
    homePos1 = hmIndexPos[axis1] + (homeOffset[axis1] * stepsPerIn[axis1]);
    Move(axis1, homePos1);
    WaitDone(axis1);
    //WaitDoneDual(this, axis0, axis1);
    chan[axis0].Vel = velSav0;
    chan[axis1].Vel = velSav1;

    }

    WaitDone(axis0);
    WaitDone(axis1);
    Delay_sec(0.1);

    fHomeDone[axis0] = 1;
    fHomeDone[axis1] = 1;
    }
    }
    }



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

    Default Re: Kmotion Control Issues on K2CNC machine

    Hi Chris,

    I'm thinking HOMING_ZXY is or should be Flashed into Thread #5 in KFLOP so it is there on power up. It contains the logic to do the homing.

    K2_HOME.c just sets a flag to tell the K2 Driver? Program to run Thread #5. If you load/run K2_HOME.c in Thread #5 you will have overwritten and erased the HOMING_ZXY.c program. So the homing program will be lost until the next power cycle to reload it from Flash.

    Try running K2_HOME.c in some other unused Thread. Maybe #3?

    Regards

    Regards
    TK http://dynomotion.com


  3. #23
    Registered
    Join Date
    Jul 2012
    Location
    USA
    Posts
    18
    Downloads
    0
    Uploads
    0

    Default Re: Kmotion Control Issues on K2CNC machine

    Tom,

    Thank you. All working just fine now. Have screen shots of all screens to document where I am now!

    Appreciate all the help and feedback!

    Chris



  4. #24
    Registered
    Join Date
    Jul 2012
    Location
    USA
    Posts
    18
    Downloads
    0
    Uploads
    0

    Default Re: Kmotion Control Issues on K2CNC machine

    Tom -

    We have had an issue last two days on initial start-up. With PC off, and Delta Spindle control off, only the K@cnc control box on with the kflop board, etc. the axis take off immediately when I enable the drives (green button on e-stop). Once I reset the axis again, they behave normally, but the initial start-up of the kflop controller is erratic. Have you seen this before?

    Thanks,

    Chris



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

    Default Re: Kmotion Control Issues on K2CNC machine

    Hi Chris,

    Did anything change? You would need to look at the K2CNC Driver program to see what it normally does.

    Is this a servo system? Does it appear to be moving in a controlled manner? Or like there is no feedback and a runaway? Which axes?

    Does pushing EStop first before enabling solve the problem?

    Regards

    Regards
    TK http://dynomotion.com


  6. #26
    Registered
    Join Date
    Jul 2012
    Location
    USA
    Posts
    18
    Downloads
    0
    Uploads
    0

    Default Re: Kmotion Control Issues on K2CNC machine

    Hi Tom,

    Nothing changed, but I can't say that the problem didn't exist before. We had so much noise from the unshielded cables, that we saw similar issues much more frequently. That being said, the computer was off, so it is not getting a signal from the computer to go anywhere, more like a latent signal or built up charge which turns some of the axis on.

    It has happened where only the Z-axis moved. Or in the case yesterday, all three axis moved simultaneously. the move rapidly (think G0) and would go until they reach end of travel and trigger a fault or someone hits the e-stop.

    When we were fighting the noise form the spindle drive, this would happen while the machine was sitting idle. Now it seems to be something that only happens at start up.

    When shutting down, I have been homing the axis prior to shut-down, then turning everything off (PC, Kflop, Delta Controller, in that order).

    This morning the machine did not act erratic upon start up, but after some thought on this, we did not turn on the spindle power at all yesterday and wonder if there is still some noise coming from the spindle cabling into the axiz com cables??

    We may hook up an O-scope today to see if we see any noise on the lines as we run the machine.

    Thanks!



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

    Default Re: Kmotion Control Issues on K2CNC machine

    Hi Chris,

    One thought I had was that K2CNC might assume that on power up the Encoder Position is zero (which is what it is initialized to) and therefore enabling the axis to move to a commanded Destination of zero would not move. However it might be that encoder noise is causing the Encoder Position to count up to a large non-zero number while sitting disabled. So then when commanded to a Destination of zero the axis would make a large move.

    To test this idea you might power up the system (including the PC) then before enabling the system run KMotion.exe, open the Axis Screen, and check if the Encoder Positions are either holding small numbers near zero or counting continuously due to noise.

    HTH
    Regards

    Regards
    TK http://dynomotion.com


  8. #28
    Registered
    Join Date
    Jul 2012
    Location
    USA
    Posts
    18
    Downloads
    0
    Uploads
    0

    Default Re: Kmotion Control Issues on K2CNC machine

    Tom,

    Thanks - We will see if we can get it to react as described. One thing we noticed, is that the encoder cables are not shielded cables. The cables supplying the power to the motors are shielded and drained properly, but not the encoder cables. We are planning at this time to replace the encoder cables with shielded wiring with a drain at one end. Does this sound like a potential root cause/solution?

    Thanks,
    Chris



Page 2 of 2 FirstFirst 12

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

Kmotion Control Issues on K2CNC machine

Kmotion Control Issues on K2CNC machine