586,080 active members*
3,782 visitors online*
Register for free
Login
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2004
    Posts
    235

    If (Check) {Do Something}... ?

    Greetings,

    Working of a program with Home Limit Input Bit 1034, Peddle for Go which is Input 1033, and Lower limit which is Input 1035.

    This is for a simple punch machine control. Using Konnect board for I/O and three inputs.

    When I push the peddle I want axis 2 to go down. When I let off the peddle it should stop.
    This code below works... for this.
    ______________________________

    #include "KMotionDef.h"

    main()
    {
    for(;
    {
    if (!ReadBit(1033))
    {
    while (!ReadBit(1033));
    Jog(2,-100);
    }
    if (ReadBit(1033))
    {
    while (ReadBit(1033));
    Jog(2,0);
    }

    }
    }
    _________________________________________

    Now I need to to stop this motion also if the lower input (1034) comes on. Then home to the upper input (1034).

    I have tried to do this, but have had little luck with the code... and trying to add the other monitoring... Think I am just missing something?

    Thanks in advance for any help?

    - Jeff
    Robot & Machine Design - BLUECNC4, GreenCNC3, RedCNC2L, SilverCNC2; CNC Software!
    www.truemachinedesign.com - - - - - - - - - - - - - www.truemachineautomation.com

  2. #2
    Join Date
    May 2006
    Posts
    4045

    Re: If (Check) {Do Something}... ?

    Hi Jeff,

    Now I need to to stop this motion also if the lower input (1034) comes on. The home to the upper input (1034).
    Is that a typo? Can you explain more clearly?
    TK
    http://dynomotion.com

  3. #3
    Join Date
    Jul 2004
    Posts
    235

    Re: If (Check) {Do Something}... ?

    Tom,

    Yes that was a typo! Go figure!!

    See here for what I want to accomplish to start. This will get more complicated later, with a fast and slow speed input. Not worried about that yet!


    Attachment 502902
    Robot & Machine Design - BLUECNC4, GreenCNC3, RedCNC2L, SilverCNC2; CNC Software!
    www.truemachinedesign.com - - - - - - - - - - - - - www.truemachineautomation.com

  4. #4
    Join Date
    May 2006
    Posts
    4045

    Re: If (Check) {Do Something}... ?

    Hi Jeff,

    A general way to handle multiple events using a single Thread is to use a State Machine, See the untested example below:

    Code:
    #include "KMotionDef.h"
    
    // Press Brake control 
    
    enum { IDLE, JOG_DOWN, DELAY, HOME };  // states
    
    #define BIT_PEDAL 1033
    #define BIT_NEG_LIMIT 1035
    #define BIT_TOP_LIMIT 1034
    #define BIT_AUTO 46
    
    #define ZAXIS 0
    
    #define DWELL 2.0 // delay at bottom seconds
    
    void main()
    {
        int state=IDLE;
        double DelayTime;
        
        for (;;)
        {
            switch (state)
            {
            case IDLE:
            if (ReadBit(BIT_PEDAL))
            {
                Jog(ZAXIS, -100);  // Jog down
                state = JOG_DOWN;
            }
            break;
    
            case JOG_DOWN:
            // stop Jogging down if pedal released and not Auto mode
            if (!ReadBit(BIT_PEDAL) && !ReadBit(BIT_AUTO)) 
            {
                Jog(ZAXIS, 0);  // Stop
                state = IDLE;
            }
            else
            {
                // hit negative limit?
                if (ReadBit(BIT_NEG_LIMIT))
                {
                    Jog(ZAXIS, 0);  // Stop
                    DelayTime = Time_sec() + DWELL;
                    state = DELAY;
                }
            }
            break;
    
            case DELAY:
            if (Time_sec() > DelayTime)  // Dwell finished?
            {
                Jog(ZAXIS, 400);  // Begin Homing
                state = HOME;
            }
            break;
    
            case HOME:
            if (ReadBit(BIT_TOP_LIMIT))  // Homed?
            {
                Jog(ZAXIS, 0);  // Stop
                state = IDLE;
            }
            break;
            }
        }
    }
    TK
    http://dynomotion.com

  5. #5
    Join Date
    Jul 2004
    Posts
    235

    Re: If (Check) {Do Something}... ?

    Thanks so much!

    I am getting something accomplished now! This is working!! Of course I will modify to the specifics according to the machine.
    I will be using the the Kflop and Kanalog control boards to do this.
    The program will have a couple of more inputs, for different modes or ways of operating the code sequencing.
    The State Machine idea is a good thing. I like that.

    Thanks - Jeff
    Robot & Machine Design - BLUECNC4, GreenCNC3, RedCNC2L, SilverCNC2; CNC Software!
    www.truemachinedesign.com - - - - - - - - - - - - - www.truemachineautomation.com

Similar Threads

  1. Replies: 5
    Last Post: 01-27-2018, 03:23 PM
  2. Check It Out
    By Journey_Man in forum Syil Products
    Replies: 4
    Last Post: 11-02-2009, 05:15 PM
  3. Check this out !!
    By weirdharold in forum UG NX
    Replies: 1
    Last Post: 07-06-2009, 12:13 AM
  4. Replies: 3
    Last Post: 01-19-2007, 02:59 PM

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
  •