AnswerHub Upload Issue
Our AnswerHub community currently has a bug that prevents you from attaching your model or other files to your questions. AnswerHub is aware of this issue and they are working on a fix. Until we receive their patch, you can upload your models and other files to FlexSim's file share site. Include the file name in your question so that we know which upload to reference.


anthony.johnson avatar image
anthony.johnson posted Felix Möhlmann commented

Example Kiva System Model

Attached is an example model that simulates a Kiva system.


See Dev Talk: Kiva System Modeling for the steps I took in building the model.

astarkivatemplatesdynamic barriers
kivasystem.fsm (205.6 KiB)
· 19
5 |100000

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

Hey everyone,

Here's the slot assignment code:

Storage.Object current = ownerobject(c);
Object item = param(1);
Storage.Item storageItem = Storage.Item(item);
/**Random Bay, Level, and Slot with Space*/

while (true) {
    int bayNum = duniform(1, current.bays.length);
    Storage.Bay bay = current.bays[bayNum];
    int levelNum = duniform(1, bay.levels.length);
    Storage.Level level = bay.levels[levelNum];
    int slotNum = duniform(1, level.slots.length);
    Storage.Slot slot = level.slots[slotNum];
    if (slot.isStorable && slot.slotItems.length == 0) {
        storageItem.assignedSlot = slot;
        return 0;

Note that I've changed it from the model in the video. As some of you have noticed, it causes an infinite loop if you run the model too fast. Unfortunately I myself fell victim to the rotational peculiarities that may come up when using slot.hasSpace(). When you run the model fast, the rotation of the item is dependent on the last window refresh, which may end up being non-zero. This causes slot.hasSpace() to return false always, so you get into an infinite loop. So to solve, I just don't use slot.hasSpace() but just say the slot must be empty.

1 Like 1 ·

Thank you for the KIVA system model. Can you post the code for the floor storage slot assignment? line 13 is difficult to read not sure what's after 1aStorable. Thank you.

0 Likes 0 ·


I'm new to Flexsim and these tutorials are great and very informative. Once again thank you for a great simulation and instructions. My apologies, I was looking at the code on a small screen and it made it difficult to read some of the code which I have now after looking at it on a larger screen. 1aStorable is actual IsStorable and what is after is &&. Best regards and please keep making these tutorials.

** May I suggest a tutorial on AGVs with crabbing capabilities, 90 degree movement without turning. Thank you.

0 Likes 0 ·

Thanks for the very nice Kiva model (did you know that kiva means nice in Finnish?:) ). Good demonstration of the new features as well as using the lists.

I run the model and noticed that sometimes FlexSim freezes and I have to kill the process. It seems to be connected to the run speed - if the run speed is less than ~50 you can run the model without problems.It also runs with FastForward. Do you know the source of the freezing?

0 Likes 0 ·
Tomi, sorry for the delayed response. I guess this comment slipped through my watch. See my comment below.
0 Likes 0 ·


I want to get any other idea or ways to control the AGVs battery level (moving and charging) in KIVA model layout.

A-Star module has not the feature to control the battery level in the AGVs.

For example...

ex1) Replacing A* with AGV path line control using AGV module?

ex2) Using 'total travel distance limit' replacing with Battery level?

ex3) Aor any other way modeling?


0 Likes 0 ·

There isn't anything really special about the AGV's battery level tracking, and in some cases it can be more restrictive than doing it yourself. I would suggest tracking battery level on your own using a tracked variable label on the AGV, along with using the process flow to change the discharge rate.

  1. Click on the AGV in the model, and go to the labels pane in properties
  2. Add a Tracked Variable label. Then click on the label and press Edit in the top right.
  3. From the drop-down, choose Kinetic (e.g. Battery Level). Set the start value (either in amp hours or as a percentage, whichever you decide to use).

Once you've added the tracked variable, you can set its discharge or recharge rate in the process flow. When the rate of change for the battery level changes, (e.g. when you start a travel operation):

  1. Add a custom code activity
  2. In that activity, add a code snippet
  3. For the code snippet, add code to change the rate:
    current.labels["BatteryLevel"].as(TrackedVariable).rate = -1;

A value of -1 would mean the discharge rate, in units per model time unit. If you're representing the tracked variable in amp hours and your model time unit is seconds, then -1 means you're discharging at 1 amp hour per model second, i.e. 3600 amps. If you're simulating battery level as a percentage, then -1 means one percent battery per second.

1 Like 1 ·
David Seo avatar image David Seo anthony.johnson ♦♦ ·

Thanks a lot, @anthony.johnson

I will try to do using Tracked Variables for solve my real issues.

Yes. I have the hard project about picking-up the items to the rack-cart and then picking-off to the gravity flow racks by oprators but transporting between them is done using Kiva robot system.

The layout is also some irregular and the AGV robots are self-spinning and there are battery charge points in it.

I will try to do as your guide and then If I will have some questions and issues, I will post it as other independent subject.

Thanks again very much.

0 Likes 0 ·
Show more comments

我想知道這個模型是否可以在 2020 版本中做同樣的事情

"I wonder if this model can do the same in the 2020 version"

0 Likes 0 ·

No, it requires functionality that was added to FlexSim version 21.2 in August 2021.

0 Likes 0 ·
立洲 avatar image 立洲 Jason Lightfoot ♦ ·

這部分是否僅在版本 21.2 中可用?有沒有辦法使用自定義代碼來完成同樣的事情?


-1 Like -1 ·
1652762606261.png (76.3 KiB)
Show more comments



anthony.johnson contributed to this article