Is it possible to have the robot time out when waiting for a digital input? What I am wanting is for the robot to wait for a digital input, but if it doesn't receive the input in say 10 seconds to halt and display an error message. In ABB that is a feature of the WAIT statement.
Timeout when waiting for an input
-
bellm -
September 29, 2014 at 6:07 PM -
Thread is marked as Resolved.
-
-
You can use a timer.
$TIMER[1]=0
$TIMER_STOP[1]=FALSE
wait for ($TIMER[1] == 10 )
if not $in[input] thenMSG_SHOW("****","****","***")
else
Continue
endif -
You can use a timer.
$TIMER[1]=0
$TIMER_STOP[1]=FALSE
wait for ($TIMER[1] == 10 )
if not $in[input] thenMSG_SHOW("****","****","***")
else
Continue
endifI'm not familiar with timers. Wouldn't that just time for 10s and then check to see if its not true?
-
I think foliagelx was close, but I'm not so sure it would work the way you would like it. In KRL, Timers are simply system variables with an index number. I don't remember off the top of my head, but I think there are 20 of them by default, thus the index number.
First of all, KRL timers operate in milliseconds. Second, yes, his/her code would wait for the specified period to expire and then check your input.
All of that being said I think you could adjust that code and get it to do what you want it to do. I might try something like this:
Code
Display More$TIMER[1] = 0 ;resets the initial value of the timer to zero $TIMER_STOP[1] = FALSE ;starts the timer WHILE $TIMER[1] < 10000 ;Cyclically evaluates the timer until 10 seconds has passed IF $IN[YOUR_INPUT] == TRUE THEN;If the value of your input becomes true, jumps out of the while evaluation GOTO ACTION ENDIF ENDWHILE MSG_NOTIFY("Enter your message here.") ;If the timer expires before the input comes true, this line will generate a message. HALT ;stops the running program ACTION: ;If the Input comes true before the timer expires, the GOTO statement will jump to this line. ;Enter code here for whatever you want to do when your input becomes true.
This was something I just threw together without testing, so your mileage may vary. Give a try and see how it works. Let us know.
Edited to include the proper syntax for the IF statement.
-
Thanks that looks like it would do what I am wanting, as soon as I get a chance to test the code I will let you know what happens
-
I know it has been a while but I finally got a chance to implement this and it worked perfectly. now my next task when I have a chance is to write a function out of it.
-
Rip_2:
$TIMER_STOP[1]=TRUE
$TIMER_FLAG[1]=FALSE
$TIMER[1]=-10000
$TIMER_STOP[1]=FALSE
WAIT FOR ($IN[1] OR $TIMER_FLAG[1])
$TIMER_STOP[1]=TRUE
CONTINUE
IF $TIMER_FLAG[1]== TRUE THEN
mAllarme(7)
GOTO Rip_2
ENDIFRETURN
-
devilrouse - perfect - this is the genius KUKA way of doing it. why have a timeout implementet in wait when you can use 10 lines of high sophisticated code instead
sorry my sarcasm. and many thanks to you for the topic and the 2 solutions. I ran into the same question right now and I will choose the suggestion from devilrouse for my implementation.
something like this
Code
Display MoreDEFFCT BOOL WAIT_TIMEOUT(nCycFlagNum:IN,nTimeout:IN ) DECL INT nTimeout DECL INT nCycFlagNum $TIMER_STOP[2]=TRUE $TIMER_FLAG[2]=FALSE $TIMER[2]=-nTimeout $TIMER_STOP[2]=FALSE WAIT FOR ($CYCFLAG[nCycFlagNum] OR $TIMER_FLAG[2]) $TIMER_STOP[2]=TRUE RETURN NOT $TIMER_FLAG[2] ENDFCT
and use like
-
devilrouse - perfect - this is the genius KUKA way of doing it. why have a timeout implementet in wait when you can use 10 lines of high sophisticated code instead
sorry my sarcasm. and many thanks to you for the topic and the 2 solutions. I ran into the same question right now and I will choose the suggestion from devilrouse for my implementation.
Check this thread and TIMER_LIMIT() function
PostRE: How to write a wait function
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
ENDpanic modeJune 1, 2020 at 1:22 PM -
Ok. Thank you. I see it was discussed there aswell and I didn't think about the option to pass the CYCFLAG to an OUT parameter and get the access to the passed flag instead of the snapshot at calling the function.
It becomes a little handier with using it then like
AND of course the TIMER_LIMIT - thanks for mention this. I wasn't aware of this function till now.
so I would write the Code like this?
Code$CYCFLAG[2] = $IN[1] AND NOT $IN[2] WAIT FOR $CYCFLAG[2] OR TIMER_LIMIT(5.0) IF $CYCFLAG[2] THEN ;OK ELSE ;TIMEOUT ENDIF
that nails it then down to a very simple and strait forward implementation.