In this blog post, we will detail a simulation model of battery recharging for automated guided vehicles (AGVs).
We recommend that you download the source file and open the example model in AnyLogic to follow along with the example.
The model was developed in AnyLogic 8.7.12 featuring new Material Handling Library functionality, such as new storage racks and respective logic blocks Store and StorageSystem, that aids warehouse operations modeling.
The model describes a truck unloading process and SKU placement according to the available storage slots in a warehouse. On top of that, the model is comprised of the discrete-event and agent-based simulation modeling approaches.
For discrete-event modeling, AnyLogic offers built-in libraries. In this model, one of them – Fluid Library – was used to simulate the battery life cycle. Another one – Material Handling Library – is especially useful for manufacturing and warehousing modeling and in this case it helped with AGVs (transporters) and racks.
AGV charging model description
The model’s layout is quite simple yet serves as a good example of the interconnection between the agent’s nature and its discrete-event behavior modeled with the Fluid Library.
In the lower left corner, there’s an AGV base and a charging station. On the right side of the warehouse, there’s an unloading gate where the tasks for transporters appear. The most important part of the model’s logic is the charging-related processes inside an AGV agent.
As you can see in the picture, the first flowchart makes the SKUs appear. Then transporters seize them for a “to-rack” delivery. Meanwhile, the second flowchart has more actions and starts with the Enter block, which simulates a manually created query – “СhargeTask”.
This query is supposed to interrupt the truck unloading process since the “task may preempt” policy is chosen in the properties of the chargetask block. The “task priority” parameter value equals 1000 which makes it more important than the unloading task. According to the logic described in the flowchart, once the charging task is complete, the AGV gets back to its routine.
One more step to making the model work correctly is to change the mode (type) of the Delay block to “Until stopDelay() is called”. Later, you can call this stopDelay() function from the AGV’s statechart using Java code.
Battery flowchart inside an AGV agent type
Another simple flowchart is used to describe the battery life cycle. The Fluid Library helps to simulate the storing and transfer of large amounts of discrete items, for example, liquid, grain, and energy.
The battery’s capacity is set to 1000 liters. We’ve chosen liters as the most appropriate unit from the list in the Fluid Library. The initial battery level – when a transporter is initiated for the first time – is stochastic and assigned according to the triangular probability distribution and parameters (min, max, mode).
What is more interesting to note, the “Actions” section of the Battery’s properties shows the conjunction of the agent’s statechart and SKU’s flowchart in Main. When the battery is full, the message “GoOperate” is sent to the AGV agent, so it could finish charging and proceed with the unloading task.
When the battery level falls below 350 (35%), a respective action triggers the creation of the ChargeTask object instance and sends it to the SKU’s flowchart in Main, to the Enter block. An AGV agent stops performing the unloading task and goes to the charging station.
But how does the Enter flowchart block know which AGV the charging task was created for? In other words, which AGV should go to the charging station?
The code, which executes in the Battery block (inside the AGV agent):
currentChargeTask = new ChargeTask(this); main.enter.take(currentChargeTask);
Line 1 creates an agent type ChargeTask which is related to a specific AGV.
Line 2 adds this ChargeTask agent type to the SKU’s flowchart in Main.
The ChargeTask agent has a “transporter” parameter of type “AGV”. When you run the code (inside the AGV agent), “this” identifies that the ChargeTask agent belongs to the parent object.
That is how you get a new ChargeTask agent in the flowchart. The agent remembers which transporter needs to go to the charging station.
Going through the second flowchart, the ChargeTask agent should seize the correct AGV. And in the MoveByTransporter of the chargetask block, the “transporter choice condition” guarantees that the required AGV will stop performing the routine task of SKU delivering to the racks. Instead, a new charging query will make the AGV go to the charging station.
An agent’s statechart and its connection with the battery level
We have discussed the battery logic and the AGV movement logic (when an AGV needs to be charged). However, the model is missing a high-level management component that will control the AGV behavior and this is the Statechart.
As you might’ve guessed, the most popular means of communication between agents is messaging and it could trigger the changing of states for an agent. A change of states is called a transition and during the transition, an action can be performed, for example, opening and closing of energy flow valves.
A set of AGV’s states is called a composite state – within the black frame. It consists of smaller states which define the AGV’s behavior.
For instance, each AGV agent can have “Operate”, “Charging”, and other states. A state change depends on the message that has been received by the agent. So, the transition from one state to another, which happens because an AGV receives a “start” message, makes the AGV agent close the outflow valve and open the inflow one to fill the battery with energy.
It also works the other way round – the “GoOperate” message closes the inflow valve which means the charging is over.
- Transporters have a certain initial battery level at the start.
- When the level drops below 35%, the Battery block initializes the charging task creation – a new ChargeTask agent.
- The chargeTask block prioritizes the charging task over the AGV’s routine tasks and seizes the AGV.
- When the ChargeTask seizes the AGV in MoveByTransporter, the message “GoCharging” is sent to the AGV.
- This message makes the AGV’s statechart change the state from “Operate” to “MovingToChargingStation”.
- In MoveByTransporter, in the “Actions” tab there’s an “on loading finished” field. This field contains a function that sends a “start” message. The code calls this function when an AGV arrives at the charging station.
- This message triggers the transition to the state “Charging” and opens and closes the respective Battery valves.
- The Battery starts to accumulate energy and when it is full, it sends the message “GoOperate” to the AGV.
- This message opens and closes respective valves. The Battery’s discharging process begins and the AGV’s state changes to “ReadyToWork”.
- With the given timeout (1 sec), the automatic transition occurs and the AGV’s state is “Operate” again.
- The transition from “ReadyToWork” to “Operate” frees the AGV from the Delay block, so it could return to the main task until the next charging session.
This AGV charging model description will help you learn how the model was built in AnyLogic. However, instead of just reading along, start practicing. Feel free to check out the AGV charging model with source files in AnyLogic Cloud and implement it in your own project.