question

shanice.c avatar image
0 Likes"
shanice.c asked Felix Möhlmann commented

How to wait for event until conditional is true?

In my AGV process flow, AGV is waiting in standby point in the beginning, so I use wait for event activity to control. I have a table used to record all tasks for AGVs, I want to check if AGV still has any tasks to do after completing one. I'd like to use a condition like:

int getTaskID = query("SELECT MAX(TaskID)FROM TaskTable WHERE AGVID = tempAGV AND Done = 0");

if(getTaskID>0){

AGV will execute a new task.

}else

stay in standbypoint.

1631095078234.png

I would like to know which event I should use? The object field is token.agv. I want to fill in the if statement above for the event field. Also, for the if statement, how could I let AGV leave/stay in wait for event activity if that statement is true/false. I think I'd like to use "return", but I still couldn't find a suitable event to use.

1631094532617.png



0907.fsm

FlexSim 21.2.2
process flowwait for eventflexsim 21.2.2
1631094532617.png (25.3 KiB)
1631095078234.png (55.2 KiB)
0907.fsm (586.0 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Felix Möhlmann commented

As the name of the activity suggest, "Wait for Event" reacts to a distinct event triggering and can decide whether to send the token onwards based on parameters of that event. It can not directly be used to continuously check for a condition.

What you might do instead, is use a "Decide" activity in the place of the "Wait for Event". In there you can use you code to return which connection the token should be send to next. If no task is available, the token can then enter into a "Wait for Event" that reacts to a new entry being added to the table and routes the token back to the "Decide" activity to reevaluate the condition.

As there is (to my knowledge) no event for a row being added to a global table, you will have to listen to something else. If I'm not mistaken, rows currently get added by a custom code activity in another process flow. You could have the "Wait for Event" listen for a token exiting that activity, because if that happens, a new row will have been added to the table. Or you listen to a token entering that activity (as it currently doesn't lead anywhere). In that case put a 0-second delay after the "Wait for Event" to be sure the code of the other activity has finished before the token is send to the "Decide".

Another alternative would be to send a message to the process flow (or some other object) in the same place where the table rows are added and listen for that message.

1631101504537.png


1631101504537.png (30.1 KiB)
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

shanice.c avatar image shanice.c commented ·

@Felix Möhlmann Thanks for the method of using decide and wait for event.

As there are many kind of Tasktypes, I think I would like to change a little bit, as the wait for event activity cannot deal with listening to several activities at the same time or maybe it can do that way, but become complicated.

My condition to release token form wait for event is any task exists, but doesn't mind which kind of tasks they are. So I would like to add a new label on token.agv or a global variable to record the number of an AGV has. The expression would be SELECT COUNT FROM TaskTable WHERE Done=0 AND AGVID = token.agv. And I would wait for event until this label value > 0. I hope this way could work. I'm having problem with how to declare the variable, could I assign a sql query count to an integer?

0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann shanice.c commented ·

@Fiona C

I understand what you want and yes, you could listen to a tracked variable label, however you can't have a label be both a tracked variable and a flexscript label. So either you would have to continuously update the label value (in a fixed interval or by reacting to events) or evaluate the query contiuously, which is what my solution above does.

Having a larger number of events to listen to shouldn't be an issue. You can simply add all activities you want to react to into a group and have the "Wait for Event" listen to that group as a whole.

Sample Model: WaitForGroup.fsm

Another alternative would be to use a list to determine tasks for the AGVs. Each time you create a row in the task table, you could push the row number and AGV that is assigned to the task to a list and pull those entries with the AGV-tokens. Then you use the pulled row number to reference the details of the task.

0 Likes 0 ·
waitforgroup.fsm (32.2 KiB)

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.