# Pick and Place Example

**HMI Panel File**

<figure><img src="https://175138337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fvxlh3prlGsBGF30oqbYW%2Fuploads%2FGIFlHZV1xjgApM3FL1Ts%2Fhmi-pick-place-example.png?alt=media&#x26;token=fb762e7e-8f98-49e5-bb89-8c46ad6db406" alt=""><figcaption></figcaption></figure>

{% file src="<https://175138337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fvxlh3prlGsBGF30oqbYW%2Fuploads%2FQreABDlNHX6LcDiBJovE%2Fpick_place.hmi?alt=media&token=837a870a-71cb-49a7-b70c-f75919745589>" %}

**Robot Program File**

```python
# variables
global velocity = 200
global loop_forever = False
global repetitions = 2
global gripper_status = "ACTIVATED"
global counter = 0
global aborted = False
global completed = False
global status = "READY"

# positions (can be defined also as installation variables to store their value)
global pick_pose = p[0, 0, 0, 0, 0, 0]
global place_pose = p[0, 0, 0, 0, 0, 0]

# functions
def open_gripper():
    if gripper_status == "ACTIVATED":
        textmsg("open")
        #rq_open()
    end
end

def close_gripper():
    if gripper_status == "ACTIVATED":
        textmsg("close")
        #rq_close()
    end
end

def pick(pose):
    if not aborted:
        status = "PICKING"
        approach = pose_trans(pose, p[0, 0, -0.1, 0, 0, 0])
        movel(approach, a=0.1, v=velocity/1000)
        movel(pick_pose, a=0.1, v=velocity/1000)
        close_gripper()
        movel(approach, a=0.1, v=velocity/1000)
    end
end

def place(pose):
    if not aborted:
        status = "PLACING"
        approach = pose_trans(pose, p[0, 0, -0.1, 0, 0, 0])
        movel(approach, a=0.1, v=velocity/1000)
        movel(pick_pose, a=0.1, v=velocity/1000)
        open_gripper()
        movel(approach, a=0.1, v=velocity/1000)
    end
end

def start_task():
    global counter = 0
    global aborted = False
    global completed = False
    while (not aborted) and (loop_forever or counter < repetitions):
        pick(pick_pose)
        place(place_pose)
        pick(place_pose)
        place(pick_pose)
        counter = counter + 1
    end
    completed = True
    status = "READY"
end

def stop_task():
    global aborted = True
    status = "STOPPING..."
    while not completed:
        sleep(0.1)
    end
end
```

{% file src="<https://175138337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fvxlh3prlGsBGF30oqbYW%2Fuploads%2FuuIGCrkdyuN59BfCkDPc%2Fpick_place.script?alt=media&token=a132e6b4-75be-4a5e-8881-fd9006266574>" %}
