How to Prevent AGV Deadlock on a Single Bidirectional Path(2)?

How to Prevent AGV Deadlock on a Single Bidirectional Path(2)?

hbg485
Contributor Contributor
211 Views
10 Replies
Message 1 of 11

How to Prevent AGV Deadlock on a Single Bidirectional Path(2)?

hbg485
Contributor
Contributor

I searched through several community posts at first, but as a beginner it was difficult to understand them, so I’d like to ask for help here.

I am working on an AGV model with a single bidirectional path, and I am trying to handle a potential deadlock situation between two AGVs. The situation looks like this (see the diagram):

 

  1. Initial positions:

    • AGV is moving downward from Area 1.

    • OtherAGV is moving upward from Area 2.

  2. Conflict detected:

    • When AGV is inside Area 1 and OtherAGV is inside Area 2, both AGVs are approaching each other on the same path.

    • To avoid deadlock, I want to temporarily deallocate their current tasks.

  3. Redirection logic:

    • AGV should stop and wait at a predefined AGV wait CP.

    • OtherAGV should move to a predefined OtherAGV void CP (a side control point for avoidance).

  4. Resuming tasks:

    • After AGV continues its original task and enters Area 2,

    • OtherAGV should then also resume its original task and move forward.

  5. Special case:

    • If AGV’s original task is to deliver to a Processor located between Area 1 and Area 2, then AGV should proceed with the task directly without redirection.

hbg485_0-1756792917243.png

 

0 Likes
Accepted solutions (1)
212 Views
10 Replies
Replies (10)
Message 2 of 11

hbg485
Contributor
Contributor

@moehlmann_fe Could you please help me?

0 Likes
Message 3 of 11

moehlmann_fe
Enthusiast
Enthusiast

What you show here is only one of the cases that need to be handled. Another one would for example be an AGV wanting to turn onto the main path from a spur while another one is approaching from the direction it wants to travel to.

I would recommend you first build a foundation of data: Knowing which area is occupied and into what direction the AGV that occupies it is currently travelling. You could track this in a global table for example (one row per area) with values of 0 (empty), positive (travel up) and negative (travel down). In the On Allocation triggers of the areas, increment or decrement the respective value depending on the destination of the allocating AGV. You can read the destination either from the AGV class or from the travel task (te.currentTask.involved1).

 

https://docs.flexsim.com/en/25.2/Reference/CodingInFlexSim/FlexScriptAPIReference/AGV/AGV.html#Prope...

https://docs.flexsim.com/en/25.2/Reference/CodingInFlexSim/FlexScriptAPIReference/TaskExecuter/TaskS...

 

With the necessary information available, you can then listen for the pre-arrival event of the CPs around the intersections and check whether a redirection is needed or not. Labels on the areas and CPs can be helpful to identify which intersection the AGV is at. And with which area status would be relevant.

Message 4 of 11

hbg485
Contributor
Contributor

First of all, thank you for your advice. As I understand it, the logic works as follows:

  1. In the Global Table, I created rows corresponding to each area (e.g., Area 1 → Row 1, Area 2 → Row 2, Area 3 → Row 3).

  2. When the OnAllocated event is triggered, the logic finds a row whose current value is 0. If the AGV’s destination is Control Point 1, it records an upward movement (1), otherwise it records a downward movement (-1).

  3. When the OnDeallocated event is triggered, the row value is reset back to 0 (empty).

  4. Later, when Row 1 has a value of 1 or -1 and Row 2 has the opposite sign (-1 or 1), the system should recognize this as a conflict and trigger an avoidance logic.

Additional Question:
I wrote a Custom Code in the CA (Control Area) Process to insert information into the Global Table, but it throws an error and the values are not being written. Could you please advise me on this issue?

0 Likes
Message 5 of 11

moehlmann_fe
Enthusiast
Enthusiast

You are making wrong assumptions about the parameters passed in the activities code. The default header tells you that param(1) is the instance object and param(2) is the activity itself.

moehlmann_fe_0-1756883199094.png

You should never change the header. Additional variables should be added below it.

moehlmann_fe_1-1756883282316.png

 

0 Likes
Message 6 of 11

hbg485
Contributor
Contributor

I am currently working on a CP Process logic, and I would greatly appreciate your advice. My understanding and implementation are as follows:

In the CP Process, I built a logic that determines whether avoidance is necessary (return 2) or not (return 1), and this result is stored in a label. After making this judgment, I also store the current AGV’s movement direction (upward or downward) in a label.

 

Question 1: If avoidance is required, I intend to create a Task Sequence (TS) immediately. After the Create TS step, I save the AGV’s currentCP value into a label and then instruct the AGV to move to the centerobject[1] of the current CP. Could you advise on the correct way to implement this logic?

 

Question 2: If a downward-moving AGV’s destination lies within a process located between two occupied sections, how can I configure the logic so that the AGV continues with its original task sequence rather than executing the avoidance logic?

0 Likes
Message 7 of 11

moehlmann_fe
Enthusiast
Enthusiast
Accepted solution

Building a routing logic that prevents deadlocks from occuring is a complex task, even in a relatively simple network. Solving this is outside the scope of support I can offer on the forum, so I instead offered some general tips on how I would approach it. 

I can suggest a different approach though that is easier to implement in this case, because the cases in which deadlocks can occur is limited (after adding/changing some control areas). Instead of preventing deadlocks from occuring you can react to them and reroute one of the involved AGVs to solve it.

The "On Allocation Failed" event has a parameter that denotes whether the failure constitutes a deadlock or not (this can have false positives if one of the involved AGVs is still travelling, but these shouldn't matter in this model). You can thus create a token only when a deadlock occurs, implement logic to solve it and then return a 1 as the return value of the event to suppress the error message that would normally pop up.

Assuming that there are never more than 2 AGVs at an intersection at a time, solving the deadlock only requires choosing which AGV to redirect to the third intersection-CP. By using labels on the CPs we can know from which direction each AGV is approaching the intersection and base the choice on this information.

I changed the model a bit to make more deadlocks happen to better test the logic (entry queue can take two items at a time and multiple concurrent transports to the same processor are possible).

While this solution is a bit less efficient (the AGVs react later than they could with logic that detects potential deadlocks ahead of time) but, as I said, overall much simpler to implement.

0 Likes
Message 8 of 11

hbg485
Contributor
Contributor

"Thank you for providing this new example. For the future, I would still like to study a more practical approach. Would it be okay if I refer to your post about intersection vehicles as a reference?"

 

https://forums.autodesk.com/t5/flexsim-knowledge-base/traffic-lights-in-agv-network-custom-control-o...

0 Likes
Message 9 of 11

moehlmann_fe
Enthusiast
Enthusiast

Sure, people learning from it is the main goal of that article.

0 Likes
Message 10 of 11

gjm504
Participant
Participant

Thank you very much. I hope you have a wonderful day!

0 Likes
Message 11 of 11

hbg4857MXY4
New Member
New Member

By mistake, I replied without logging in, and the comment was posted under another colleague’s account. This seems to be a bug. Wishing you a wonderful day, and thank you!

0 Likes