How to write a wait function

  • Hello guys,

    I am rather new to KUKA programming. I want to write a WAIT FOR function so that if it's going to take more than a certain time, an Error be declared. Something like this:

    WaitLoop1:


    $TIMER_STOP[1]=TRUE


    $TIMER_FLAG[1]=FALSE


    $TIMER[1]=-10000


    $TIMER_STOP[1]=FALSE


    WAIT FOR ($IN[7] OR $TIMER_FLAG[1])


    $TIMER_STOP[1]=TRUE


    CONTINUE


    IF $TIMER_FLAG[1]== TRUE THEN


    MyAlarm(7)


    GOTO WaitLoop1


    My problem is that, I want to make it as a function or subprogram so that I could easily use it many times in my program. The inputs of this function should be : the IO number (input or output flag)

    In fact, I don't want the IO value as input, I want the IO number as input. Not just as a number, but also to recognize if its input or output or a flag.


    Can anyone help?

  • AD
  • It should work to pass the Boolean (Input, Flag, CycFlag, Output) as an :OUT argument.


    Code
    WaitForBool ($IN[1])
    WaitForBool ($CYCFLAG[1])
    WaitForBool ($OUT[1])
    
    DEF WaitForBool(FI_bBoolean :OUT)
      DECL BOOL FI_bBoolean
      $TIMER[1] = -10000
      $TIMER_STOP[1] = FALSE
      WAIT FOR FI_bBoolean OR $TIMER_FLAG[1]
    END
  • Why is that?


    DEF WaitForBool(sig:out)

    DECL BOOL sig

    WAIT FOR sig OR TIMER_LIMIT(10.0)

    IF sig THEN

    ; It was completed due signal

    ELSE

    ; it was completed due timer

    ENFIF

    END

    1) read pinned topic: READ FIRST...

    2) if you have an issue with robot, post question in the correct forum section... do NOT contact me directly

    3) read 1 and 2

  • Completely true. I was focusing on the TIMER_LIMIT/$TIMER_FLAG and overlooked the signal itself. I guess that there might be some situation though that the signal is TRUE but goes FALSE before the next instruction is evaluated which will be a nice example of Murphy's law.

  • It should work to pass the Boolean (Input, Flag, CycFlag, Output) as an :OUT argument.


    Code
    WaitForBool ($IN[1])
    WaitForBool ($CYCFLAG[1])
    WaitForBool ($OUT[1])
    
    DEF WaitForBool(FI_bBoolean :OUT)
      DECL BOOL FI_bBoolean
      $TIMER[1] = -10000
      $TIMER_STOP[1] = FALSE
      WAIT FOR FI_bBoolean OR $TIMER_FLAG[1]
    END

    I have used this method. But for negative signals it seems that it is not possible. I mean like: WAIT FOR NOT $IN[1]

    WaitForBool(NOT $IN[1]) , will not take the not value of $IN[1] address.

    Therefore, it seems that the only chance is to define two subprogram or use CYCFLAG like:

    $CYCFLAG[1]=NOT $IN[1]

    WaitForBool() or WaitForBool($CYCFLAG[1])

    I think by using CYCFLAG then it is not the matter to define an input for the subprogram or not because the CYCFLAG is always valid.


    Is this method true?

  • $CYCFLAGs are always handy for this, although most programmers usually save them for when they need complex Boolean equations evaluated as simple BOOLs -- for Triggers and Interrupts, most often.


    A fancier version of WaitForBool in that example could have additional arguments, like so:


    • Helpful

    Therefore, it seems that the only chance is to define two subprogram or use CYCFLAG

    it must be variable when using OUT parameter...

    since using OUT parameter transfer, you cannot just use expression or invert condition like:


    WaitForBool(NOT $IN[25])

    or

    WaitForBool($IN[25]==FALSE)


    but ...


    you can modify sub to simply have additional parameter. that additional parameter can be made optional so when not specified, it defaults to certain value


    Code
    DEF WaitForBool(sig:out, val:in)
        DECL BOOL sig,val
        IF VarState("val")<>#initialized then
           val=TRUE ; assume TRUE
        ENDIF
        WAIT FOR sig==val OR TIMER_LIMIT(10.0)
    END

    1) read pinned topic: READ FIRST...

    2) if you have an issue with robot, post question in the correct forum section... do NOT contact me directly

    3) read 1 and 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account
Sign up for a new account in our community. It's easy!
Register a new account
Sign in
Already have an account? Sign in here.
Sign in Now