> For the complete documentation index, see [llms.txt](https://docs.robpod.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.robpod.cloud/hmi-designer/working-examples/universal-robots/pallettizing-example.md).

# Pallettizing Example

With this palletizing example users can:

* Choose pallet layout (number of layers, rows and columns)
* Define box size
* Choose Left or Right pallet
* Setup starting condition (empty pallet, start from last box, start from specific box)

### **HMI Panel File**

<div><figure><img src="/files/etfWS8hZDm77K7mCL0Ky" alt=""><figcaption></figcaption></figure> <figure><img src="/files/o09EGHfHTn5pxY78zocL" alt=""><figcaption></figcaption></figure></div>

{% file src="/files/GBoHvOJ4bvYjb6xPsyS3" %}

### **Robot Program File**

```python
# PALLET APP - variables

LEFT_PALLET = "LEFT PALLET"
RIGHT_PALLET = "RIGHT PALLET"
pallet_feature = LEFT_PALLET_FEATURE

# start from setup
FIRST_BOX = "FIRST BOX"
CURRENT_BOX = "CURRENT BOX"
BOX_AT = "BOX AT"
start_from = FIRST_BOX

start_row = 0
start_column = 0
start_layer = 0

# PALLET APP - functions
def get_pick_pose():
    x = box_length * 0.0005
    y = box_width * 0.0005
    z = box_height * 0.001
    return pose_trans(PICK_FEATURE, p[x, y, z, 0, 3.1415, 0])
end

def get_place_pose():
    x = box_length * 0.0005 + current_column * box_length * 0.001
    y = box_width * 0.0005 + current_row * box_width * 0.001
    z = box_height * 0.001 + current_layer * box_height * 0.001
    return pose_trans(pallet_feature, p[x, y, z, 0, 3.1415, 0])
end

def get_approach_pose(pose, offset=[0, 0, 0]):
    return pose_add(pose, p[offset[0], offset[1], offset[2], 0, 0, 0])
end

# PALLET APP - tool functions
# implement these functions with logic to operate your gripper
def grasp():

end

def release():

end


# PALLET APP - main function
def start_task():
    # start from condition
    if start_from == FIRST_BOX:
        current_row = 0
        current_column = 0
        current_layer = 0
    elif start_from == BOX_AT:
        current_row = start_row - 1
        current_column = start_column - 1
        current_layer = start_layer - 1
    else:
        current_row = current_row
        current_column = current_column
        current_layer = current_layer
    end

    # selected pallet condition
    if selected_pallet == LEFT_PALLET:
        pallet_feature = LEFT_PALLET_FEATURE
    else:
        pallet_feature = RIGHT_PALLET_FEATURE
    end

    # iteration over layers, columns and rows
    while current_layer < layers:
        while current_column < columns:
            while current_row < rows:
                # pick action
                pick_pose = get_pick_pose()
                approach_pose = get_approach_pose(pick_pose, offset=[0, 0, 0.1])
                current_pose = get_actual_tcp_pose()

                if approach_pose[2] < current_pose[2] + 0.05:
                    approach_pose[2] = current_pose[2] + 0.05
                end

                movej(approach_pose)
                movel(pick_pose)

                grasp()

                place_pose = get_place_pose()
                place_approach_pose = get_approach_pose(place_pose, offset=[0.1, 0.1, box_height * 0.001 + 0.05])

                if place_approach_pose[2] > PICK_FEATURE[2] +  box_height * 0.001 + 0.05:
                    approach_pose[2] = place_approach_pose[2]
                end

                movel(approach_pose)

                # place action
                place_pose = get_place_pose()
                approach_pose = get_approach_pose(place_pose, offset=[0.1, 0.1, box_height * 0.001 + 0.05])
                movej(approach_pose)
                movel(place_pose)

                release()

                approach_pose = get_approach_pose(place_pose, offset=[0, 0, 0.1])
                if approach_pose[2] < PICK_FEATURE[2] +  box_height * 0.001 + 0.05:
                    approach_pose[2] = PICK_FEATURE[2] +  box_height * 0.001 + 0.05
                end

                movel(approach_pose)
                current_row = current_row + 1
            end

            current_row = 0
            current_column = current_column + 1
        end

        current_row = 0
        current_column = 0
        current_layer = current_layer + 1
    end
end

```

{% file src="/files/EHeI9ZUaE5LjeGlrJZHI" %}

{% file src="/files/Xw5E023IIj8YA7dara45" %}

### **Polyscope Setup**

To install this HMI application in a production environment follow these steps:

**1) Features**

Inside installation tab define those reference frames as Plane Features.

| Feature Name               |
| -------------------------- |
| **LEFT\_PALLET\_FEATURE**  |
| **RIGHT\_PALLET\_FEATURE** |
| **PICK\_FEATURE**          |

<figure><img src="/files/DcZ9S71irxhYL1ZPgHbu" alt=""><figcaption></figcaption></figure>

**2) Installation Variables**

Inside installation tab define those variables.

| Variable Name        | Default Value |
| -------------------- | ------------- |
| **rows**             | 2             |
| **columns**          | 4             |
| **layers**           | 8             |
| **selected\_pallet** | "LEFT PALLET" |
| **box\_length**      | 300           |
| **box\_width**       | 400           |
| **box\_height**      | 200           |
| **current\_row**     | 0             |
| **current\_column**  | 0             |
| **current\_layer**   | 0             |
