Return operator in motion program actions

I am writing a motion program with a _MAIN program that calls an action named HARVEST.
There is a conditional in the HARVEST action that if true I’d like to return back to the _MAIN program before finishing the action. In 8f5752f3-5c65-4eb6-bb10-3fccb69bc785, it mentions that the “RETURN statement in an action does not exit the POU; it only exits the action”. However, when I call RETURN, it exits the entire program. Am I interpreting this wrong, and if so are there any other ways to return from an action prematurely?

Relevant code:

ACTION HARVEST:
    // Action begins (commands retracted for clarity)
	IF trimVars.fingersActualPos > typeCfg.trimStationCfg.stemSizeDiscardLimit THEN
		RETURN;
	END_IF
    // Action continues (commands retracted for clarity)...
END_ACTION

PROGRAM _MAIN
	Absolute();
	WHILE TRUE DO
		IF trimVars.executeHarvest THEN
			HARVEST;
		ELSE
			EXIT;
		END_IF
	END_WHILE
END_PROGRAM

i tried this:

VAR
	var : USINT;
END_VAR
PROGRAM _CYCLIC
	var := 1;
	Action1;
	var := 3; 
END_PROGRAM
ACTION Action1:
	var := 2;
	RETURN;
END_ACTION

and this ends up in

image

=> the RETURN instruction really only ends the ACTION.
did i miss anything ?

2 Likes

Hello,

I am not familiar with ACTIONS in ST-MotionSyntax. But to test the RETURN statement, i would recoment a very simple application like this. Were you can see the Sequence taken by the comments (Program monitor) and lines due to the wait time.

“Hint: Christoph Hilchenbach was faster wrinting :slight_smile: he had also a good idea …”

ACTION HARVEST:
   WaitTime(5); // Wait 3
   RETURN;
   WaitTime(5); // Wait 4
END_ACTION

PROGRAM _MAIN
  WaitTime(5); // Wait 1 
  HARVEST;
  WaitTime(5); // Wait 2
END_PROGRAM

About your inital Program…
It looks like you try to program some cyclic routine to wait for some conditions…
Please be a ware that in the CNC, code behave a little bit different than in normal ST. Because you have a lookaheadpointer and a pathpointer. So you should consider how every statment is processed - interpreter or path synchron.

Currently i do not see any path synchonous statements in the loop. I think they are all interpreter synchronous. Which makes me wonder if it is your intend to do it like this. Because the PathPlaner runs through the loop very fast and fills the Buffer in advance. You can currently not predict how fast he runs throught the loop and how far ahead.

I wonder of using a CYCLIC would be better than a WHILE at this code construction.
But i do not fully understand the intend of the codes purpose.

Cyclic Execution

Greetings
Michael Bertsch

2 Likes

Hmm… when I do the same in a motion program in my environment, it exits the program. I also can’t run the program if Action1 is defined after Program _MAIN as it doesn’t recognize the identifier. Maybe it’s specific to my interpreter setup. I’ll do some more digging.

ACTION Action1:
	trimVars.trimLength := 2;
	RETURN;
END_ACTION

PROGRAM _MAIN
	trimVars.trimLength := 1;
	Action1;
	trimVars.trimLength := 3; 
END_PROGRAM

image

Good point Michael, thanks for suggesting cyclic execution. That will be much better :slight_smile:

Hello,

Currently i have no access to my laptop, so i can’t provide a third test on the RETURN case at the monent.

Having the Action before the Main is, what i would expect. In G-Code we have the same requirement for local Sub-Programs. The interpreter reads from top to bottom, and he has to first find the Action, to know the declaration of it. I think Christoph may have switched it while posting into separate code sections. He may respond to this.

Going forward… I would recommend to first check that you both had used the same version of mapp Motion. In General checking if you are using the newest version could be also a step forward.

Greetings
Michael