Discord
@hash/rack
Simulation
1
0
Public

Racks

Racks act like shelves, allowing you to store items on them. This library also provides behaviors for picking and placing items. You can find further information about the Material Handling Libraries in the HASH docs.

The Rack Library is part of the Material Handling Libraries. You can find further information about them in the HASH docs.


A Rack represents one compartment of storage space on a set of shelves, typically used in warehouses or fulfillment centers. The Rack Library will allow you to easily add such storage spaces into your models, and provide you with behaviors that other agents can use to interact with Racks by adding or removing objects. Forklifts are an excellent example of agents that you could create using the "pick.js" and "place.js" behaviors located in this library.

Defining a Rack

To define a rack you'll have to include certain behaviors, parameters, and fields on your agent.

Behaviors

Racks need to run the @hash/rack/rack.js behavior on their agent. This behavior will handle "pick" and "place" messages that other agents send to it, and respond accordingly.

Agents who want to interact with a Rack must have the @hash/rack/pick.js or @hash/rack/place.js behaviors. This will cause them to attempt the corresponding action when they are adjacent to their target Rack. If a rack is full when another agent attempts to place something, or empty when trying to pick, then the agent will receive "failed_" messages.

Parameters

Rack-related parameters must be defined in state.rack_parameters. The only parameter on a Rack controls the depth (number of items that can be stored), while the parameters on agents interacting with a Rack tell it what object it needs to place or pick.

// Parameters for the Rack
"rack_parameters": {
  "depth": number // The number of objects the rack can store at a time
}

All interacting agents must have waiting and target_rack_id in their state. If an agent is running @hash/rack/pick.js it must have pick_item. The agent will ask the Rack to give it the item whose "field" matches the "value". Agents running @hash/rack/place.js must have place_item, and will send the matching item instead.

// Parameters for agent interacting with a Rack
"rack_parameters": {
  "pick_item": {
    "field": string, // Field to match on the item you want to pick
    "value": string // Required value of that field
  },
  "place_item": {
    "field": string, // Field to match the item you want to place
    "value": string // Required value of that field
  }
  "waiting": boolean, // Used by the logic of the behaviors, must be set to false on initialization
  "target_rack_id": string // agent_id of the rack to interact with 
}

Storage Logic

When an agent picks something up from a Rack it is placed into the state.carrying array on the agent. This is also the array from which an agent will place objects into a Rack. The corresponding field on the Rack itself is the state.stock array.

Initializing those arrays on your agents is the best practice, but the behaviors do have checks in them that will create those fields if they are not present.