Welcome, Guest. Please login or register.
Did you miss your activation email?
May 23, 2012, 07:46:28 PM
Home Help Login Register
News: Any Problems or Experience with Industrial Robots ?
Register and place your Question / Answer to worldwide Robotexperts right here !

+  Robotforum | Support for Robotprogrammer and Users
|-+  Industrial Robot Help and Discussion Center
| |-+  KUKA Robot Forum (Moderators: Werner Hampel, Martin H, SkyeFire)
| | |-+  Nested loops
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: Nested loops  (Read 713 times)
gouch
Newbie
*
Offline Offline

Posts: 37


« on: October 27, 2009, 10:35:02 AM »

Hi There,

Below is the structure of some code I am writing. I have a Main program which initialises everything and then waits for the correct conditions before entering the program AUTOMATIC_MODE ( ). The main robot functions are carried out using this code. I want the robot to leave this program when the signal automatic mode goes false and return to the main program and await the signals again to enter AUTOMATIC_MODE ( ). I want to know the correct method to exit the loop as I believe I am only entering another loop with the code below. Should I use the exit command instead of "Main ()" to exit the loop when  AUTOMATIC_MODE==FALSE.

Thanks for any assistance.


DEF Main( )
INI

LOOP
WAIT FOR ROBOT1_AT_HOME
WAIT FOR AUTOMATIC_MODE
WAIT Time= 1 sec
WAIT FOR ROBOT1_AT_HOME
AUTOMATIC_MODE ( )
ENDLOOP
END

DEF AUTOMATIC_MODE ( )
PTP HOME  Vel= 100 % DEFAULT
Loop
WAIT FOR AUTOMATIC_MODE
WAIT FOR EMERGENCY_STOP_HEALTHY
‘’’’’’’’’’’’
‘’’’’’’’’’’’
‘’’’’’’’’’’’
IF AUTOMATIC_MODE==FALSE THEN ;This condition ends the robot cycle.
Main ()
ENDIF
ENDIF
 
ENDLOOP
END
Logged
potis
Sr. Member
****
Offline Offline

Gender: Male
Posts: 307



« Reply #1 on: October 27, 2009, 10:50:18 AM »

you must use exit loop because you are always open programs and that will make an overflow
Logged
SkyeFire
Global Moderator
*****
Offline Offline

Posts: 1784



« Reply #2 on: October 27, 2009, 08:05:56 PM »

What Potis said.  You can't call A_M() from Main(), then call Main() from A_M(), and so on.  Every call would (assuming the interpreter let you do recursive calls) just add another program to the call stack until it overflowed.  You could have a stack of umpteen copies of Main() and A_M() running on top of each other like a multi-decker sandwich.  You want to keep the sandwich small enough to fit in your mouth (so to speak). 

You could use an EXIT command at the bottom of A_M(), or do something like:
Code:
DEF AUTOMATIC_MODE()
PTP HOME
WHILE AUTOMATIC_MODE
  ;stuff
ENDWHILE
END
This way, A_M() will hit its END statement at the end of the cycle during which AUTOMATIC_MODE goes False.  But to go back to a higher-level program from a sub-program that it called, don't use a call, use a RETURN or, better, simply let the sub-program reach its natural end.
Logged
optimus_prime
Full Member
***
Offline Offline

Posts: 168


« Reply #3 on: October 31, 2009, 07:13:21 PM »

I agree with Skyfire.
Since already stack is a limited section reserved in memory during runtime, better not to overload it.
Logged
SkyeFire
Global Moderator
*****
Offline Offline

Posts: 1784



« Reply #4 on: October 31, 2009, 07:35:33 PM »

PS:  as a general rule, avoid giving variables the same names as subroutines.  Even if you can get away with it (which you generally can't in KRL), it just leads to confusion.  Some programmers I know insist on giving variable names prefixes that indicate variable type and scope, and giving programs&functions prefixes related to their type and module.  It's a pain, but on large complex programs, it can really save you a lot of work later.

Logged
Pages: [1] Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!