RobotStudio event

RAPID recursion - strange results

Options

Hi,

I am getting some strange RAPID behaviour when running a test program involving recursively called routines (while running on a virtual robot):

MODULE MainModule
  PROC main()
    TPErase;
    RecRoutine 2;
  ENDPROC
  PROC RecRoutine(num nInput)
    TPWrite "Called with: "Num:=nInput;
    WaitTime 0.05;
    IF nInput < 5 THEN
      RecRoutine nInput + 1;
    ENDIF
  ENDPROC
ENDMODULE

I get different (and random) results depending on the length of the "WaitTime" instruction, for example:

Called with: 3
Called with: 2
Called with: 4
Called with: 5
  OR
Called with: 2
Called with: 4
Called with: 3
Called with: 5
  etc...

The longer the wait time, the more chance of the result being correct (in the correct numerical order). A wait time of 0.1 sec usually produces the correct result, but NOT if the program is executed in "continuous mode". Whereas if the wait time is removed completely, the result is never correct.

Does RAPID formally support recursion? Is this a bug of some sort?

Thanks,

Michael Siminski

Michael Siminski
Technical Support Engineer
Robotics Product & Systems Service
Manufacturing Automation, Automation Technologies (ATMA)
ABB Australia
Email: michael.siminski @ au.abb.com

Comments

  • lemster68
    Options

    Greetings,

    I am not sure why you want to run a program like that, but anyway you might get the desired result with this:

    PROC main()
        TPErase;
        RecRoutine nInput;
      ENDPROC

    Good Luck,

    LJ
     

    Lee Justice
  • Hi again,

    Recursion is a fairly standard feature in programming languages (where you can call a routine from within itself), though not all languages support it. I cannot find any reference to it in any rapid manual - whether rapid supports it or not. However the fact that the code executes but in a bad way is not a good sign. There is a concern that there is something seriously wrong with the way in which the robot system handles its stacks. I'm hoping for a reply from the robotware department.

    Michael Siminski

     

    Michael Siminski
    Technical Support Engineer
    Robotics Product & Systems Service
    Manufacturing Automation, Automation Technologies (ATMA)
    ABB Australia
    Email: michael.siminski @ au.abb.com
  • j_proulx
    Options

    Hello, The error in your display is not due to recurrsion. It is due to the fact that you are not giving enough time for the TPWrite to display on the Teach pendant before Erasing it and displaying the next TPWrite. You must give a time delay to get a proper display. If you don't give the delay the display on the teach pendant will be unpredictable.

    A programmer can get into trouble by calling a routine from itself. I am not sure how many times you call a program from itself but there is a limit that will fault out the computer. To stop recurssion use the ExitCycle command.

    Best Regards,

    Jim Proulx

  • Hi,

    Yes, you are correct, thanks. I ran a test:

    MODULE MainModule
      PROC main()
        TPErase;
        FOR i FROM 1 TO 10 DO
          TPWrite "i = "Num:=i;
        ENDFOR
      ENDPROC
    ENDMODULE

    and this also gives random display results. Is this due to the messaging between the controller and the flexpendant?

    Regs,

    Michael Siminski

    Michael Siminski
    Technical Support Engineer
    Robotics Product & Systems Service
    Manufacturing Automation, Automation Technologies (ATMA)
    ABB Australia
    Email: michael.siminski @ au.abb.com