Hello,
I've put together this small program that counts down from a given amount of seconds and I would like it to display on the FlexPendant while the robot is running to let the operator know when the program will end. Because the cycle time is the same, this solution works as I can simply input the cycle time in seconds and have it count down from there. I am trying to get this program to run in the background because when you put in in the main program it always hangs on "WaitTime currentTimeStep" which makes sense, because it is an instruction telling the robot to wait. How can I get this program to run in the background so it doesn't get in the way of the main program?
Code
MODULE WaitTimeModule
CONST num timeStep:=1;
PROC RemainingTime(num waitingTime)
VAR num currentTimeStep;
VAR num timeLeft:=0;
VAR string displayString;
timeLeft:=waitingTime;
WHILE timeLeft>0 DO
IF timeLeft<timeStep THEN
currentTimeStep:=timeLeft;
timeLeft:=0;
ELSE
Add timeLeft,-timeStep;
currentTimeStep:=timeStep;
ENDIF
TPErase;
TPWrite "Time Remaining is:" + SecondstoTime(timeLeft);
WaitTime currentTimeStep;
ENDWHILE
ENDPROC
FUNC string SecondstoTime(num s)
VAR num seconds:=0;
VAR num minutes:=0;
VAR num hours:=0;
s:=Round(s);
seconds:=0;
minutes:=0;
hours:=0;
IF s>=60 THEN
minutes:= s DIV 60;
seconds:= s MOD 60;
ELSE
seconds:=s;
ENDIF
minutes:=Trunc(minutes);
IF minutes >= 60 THEN
hours:= minutes DIV 60;
minutes:= minutes MOD 60;
ELSE
minutes:=minutes;
ENDIF
RETURN NumToStr(hours,0) + "hr" + NumToStr(minutes,0) + "m" + NumToStr(seconds,0) + "s";
ENDFUNC
PROC main()
RemainingTime 11400;
ENDPROC
ENDMODULE
Display More