Pick and Place LUA script



Can you help me please with the LUA script below?
This is to pick the product from a matrix and place it at P2 place.
P1 is the matrix origin. The matrix size should be 4 by 4 (16 products in total).

There are two for loops to calculate offset of a product within the matrix.
Then by Jump(RelPoint(P1, MOffset), Option1) product at index i and j should be picked from the matrix.
i, j are row and column index.

local Option1={SpeedL=50, AccL=90, Start=10, ZLimit=30, End=10}
local Option2={SpeedL=50, AccL=90, Start=20, ZLimit=50, End=}
local MOffset={0, 0, 0, 0}

while true do
for i = 0, 3 do
for j = 0, 3 do
– Calculate product offset
MOffset[1] = 67j
MOffset[2] = 60
MOffset[3] = 0
MOffset[4] = 0
print(i, j)
– Pick product from matrix P1 + offset
Jump(RelPoint(P1, MOffset), Option1)
– and Place at P2
Jump(P2, Option1)

All goes well when the matrix is 2 by 2 elements. When I am trying to extend it to 3 x 3 elements then during movement robot stops and controller reports the error '5, 23, Plan point during linear motion out of working area.

I know all elements in the matrix are in operating range of the arm as
MG 400 can reach all elements in teaching mode.

How I can get rid of the error?


try to approach the coordinate point using PTP motion


I replaced Jump commands by MovJ and it is working without error.
The thing is I need to use Jump command to avoid mechanical collision. MovJ is not acceptable.
Is there any way to get it working as expected with Jump?


use relative movements (Removal and RelMovJ) and smoothing (CP=100). The result will be no worse than Jump.