0
votes

I have a dock as an static resource and I want to move the current ship in the dock to a waiting area when a ship of higher priority arrives (the dock can only attend one ship at a time. Ships are the agent in the flowchart). To do this, I allowed preemption in the seize block (the one that seizes the dock) and on it's "On task suspended" box I wrote the code:

agent.moveTo(waitingArea);

When the ship of higher priority arrives and suspends the task of the current ship, the current ship remains without movement in the dock, the new ships gets to the dock (on top of the current ship), and only after a few seconds (hours in the model), the current ship jumps to the waitingArea like if the code was jumpTo instead of moveTo.

Not only the movement is not being shown in the animation (just jumps) and the movement (jump) is being executed with an extrage delay, but also, later in the model run I get the error "Can't set arrival callback during movement".

If I remove the code described above from the "On task suspended" box, the error doesn't appear, but of course the animations of the ships would overlap like if there were two ships in the dock one on top of the other and that's what I don't want to happen.

Any idea on what is happening and how to fix it?

More detail of my model just in case

2

2 Answers

0
votes

Try not writing the code in the pre-emption section.

Instead, continue the flow chart out of the pre-emption port and use a MoveTo block to do what you need: enter image description here

Always make sure you understand all ports of your blocks so you can use them when needed.

Seize-block help is here.

0
votes

I solved all the points as follow:

To allow the animation to occur instead of jump, I had to remove the delay block location propertie and leave it empty. Apparently the moveTo code doesn't override the location entered in the block properties, but the destination of the moveTo code does (unintuitive behaviour in my opinion).

The strange delay before the jump occurred was the time of the "invisible" movement the ship was doing, so when the ship "arrived" to the waiting area the jump was executed by the animation. With the above this point was understood and solved.

Finally, the error occurred because while the ship was returning to the dock from the waiting area, the delay time ended and the next block was a moveTo block, so the ship received two moveTo instructions at the same time (the one from the "When task resumed" and the one from the moveTo block after the delay). To solved this, I had to enter a code that paused the delay countdown until the ship was in the dock again, and then resume it.