发布时间: 2026-01-30

简单码垛(四点法)


简介

该文档适用于艾利特机器人EC/EA系列机械臂,可用于一些机械臂码垛应用场景。该码垛程序包使用时只需要设置码盘的4个对角点的物料位置,以及物料总数,码盘层数,层高即可,操作简单,实用易懂。初始程序包是由陈瞭编写。

1 仅码垛

仅码垛的意思就是该程序只支持码垛,单点取料放入码盘中

1.1 操作步骤及所需变量

(1)使用前需打开以下变量:

打开变量位姿,在 "监视--全局变量--P变量,以及V变量中"。光标选中所需打开的变量,然后点击左下脚的打开即可。变量指示灯变为绿色为打开状态。

V158 //码垛上方位

V159 //码垛位

P150 //码盘第一个点

P151 //码盘第二个点

P152 //码盘第三个点

P153 //码盘第四个点

I 100 //码垛计数

(2)将JBI主程序和子程序导入到机械臂里面,LUA程序导入机械臂并保存设置。

(3)打开JBI子程序,更新P150-153这4个点位,点位设置示意图如下:

(4)设置好子程序里面 I150-153 等参数,参数解析如下:

I150 第一个方向个数(行数)

I151 第二个方向个数(列数)

I152 Z方向层数

I153 单层层高,单位mm

(5)在JBI主程序里面,设置固定抓取点,固定抓取点的位置为第17行

(6)将机械臂程序运行模式设置为 “ 连续循环 “ 模式,运行主程序

1.2 JBI程序

● 主程序

该程序是主运行程序(JBI),无需修改

NOP
CALL JOB:test_pallet_setting
//调用子程序
RESTARTLUA INDEX=1
//B000与后台LUA交互
//1:计算码垛
//2:计算拆垛
SET B000 0
//I100 当前码垛个数
SET I100 1
 
LABEL *startpallet
SET B000 1
TIMER T=0.1 S
WAIT B000 = 0
// 此处需增加固定点抓取程序
 
// V158为当前计算得到的码垛点
// v159 上方偏移30mm
SET V159 V158
CCOOD CART
ADD V159(2) 30
 
//码垛
MOVL V159 V=1000MM/S CR=10.0MM ACC=50 DEC=50
MOVL V158 V=100MM/S CR=0.0MM ACC=50 DEC=50
TIMER T=0.5 S
MOVL V159 V=1000MM/S CR=0.0MM ACC=50 DEC=50
INC I100
JUMP *startpallet IF I100<I159
END

● 子程序

在该程序里面设置码盘4个对角点点位,码垛层数,层高,码垛总个数(JBI)

NOP
// 以下为码垛设置部分
// **************
// 150-159用于码垛
// P150 startpose 第一个点
// P151 rowpose  第一个方向的末端点
// P152 columnpose  第二个方向的末端点
// P153 refpose  远端点
//P150---------->P152
// |  第二个方向    |
// |              |
// |              |
//第一个方向        |
// |              |
//P151  -------- P153
SETJOINT P150 -13.5978,-104.8072,145.8060,-129.0093,134.8434,-180.1184
SETJOINT P151 -47.0715,-104.5984,133.2336,-88.6142,125.0733,-222.4587
SETJOINT P152 -5.5062,-53.8769,86.6584,-128.8164,134.5548,-168.7319
SETJOINT P153 -23.4796,-55.2147,81.2515,-104.4537,133.6682,-193.8322
// I150 第一个方向个数
// I151 第二个方向个数
// I152 Z方向层数
// I153 单层层高,单位mm
SET I150 3
SET I151 4
SET I152 2
SET I153 50
// **************
// 以上为码垛设置部分
 
//以下部分无需设置和修改
JOINTTOPOSE P150 V150
JOINTTOPOSE P151 V151
JOINTTOPOSE P152 V152
JOINTTOPOSE P153 V153
SET I159 I150
MUL I159 I151
MUL I159 I152
INC I159
// I159为码垛总个数
TPWRITE FinishSetting
END

1.3 Lua程序

该lua脚本在机器人后台运行即可,无需修改(LUA)

-- 1st pallet direction:  startpos--->rowpos
-- 2nd pallet direction:  startpos--->columnpos
-- 3rd pallet direction:  startpos--->Z direction
 
-- startpos(1)   ------ columnpos(2)
--    |
--    |
--    |
-- rowpos(3)             refpos(4)
 
-- count:        current pallet number   global variable :I100
-- count_row:    total row number        global variable :I150
-- count_column: total column nubmer     global variable :I151
-- count_layer:  total layer  nubmer     global variable :I152
-- height:       single layer height     global variable :I153
-- startpos                              global variable :V150
-- rowpos                                global variable :V151
-- columnpos                             global variable :V152
-- refpos                                global variable :V153
 
-- outpos  : calculation result          global variable :V160
 
function Interpolate_pose(p_from, p_to, alpha)
    -- Linear interpolation of tool position
    -- When alpha is 0, returns p_from. When alpha is 1, returns p_to. As alpha goes from 0 to 1, returns a
    -- pose going in a straight line from p_from to p_to.
    -- If alpha is less than 0, returns a point before p_from on the line.
    -- If alpha is greater than 1, returns a pose after p_to on the line.
    local p = {}
    p[1] = p_from[1] + (p_to[1] - p_from[1]) * alpha
    p[2] = p_from[2] + (p_to[2] - p_from[2]) * alpha
    p[3] = p_from[3] + (p_to[3] - p_from[3]) * alpha
    p[4] = p_from[4]
    p[5] = p_from[5]
    p[6] = p_from[6]
    return p
end
 
function WaitUntil(var, value)
    --local vtmp =
    while get_global_variable(var) ~= value do
        sleep(0.05)
    end
end
--set_global_variable("B0", 0)
 
function PalletCal(j_count,j_row,j_column,j_height,j_startpos,j_rowpos,j_columnpos,j_refpos)
    local count = get_global_variable(j_count)
    local count_row = get_global_variable(j_row)
    local count_column = get_global_variable(j_column)
    local layer_height = get_global_variable(j_height)
 
 
    local startpos = {get_global_variable(j_startpos)}
    local rowpos = {get_global_variable(j_rowpos)}
    local columnpos = {get_global_variable(j_columnpos)}
    local refpos = {get_global_variable(j_refpos)}
 
    local current_layer = math.floor((count - 1) / (count_row*count_column))
    count = math.fmod(count-1, (count_row*count_column)) +1 --获取在当前层第几个
    local current_row = math.fmod(count - 1, count_row) -- 取余数  get residual
    local current_column = math.floor((count - 1) / count_row) -- 取整数 get integer+1
    if(count_row==1)  then
        count_row =2
    end
    if(count_column==1)  then
        count_column =2
    end
    local outpos1 = Interpolate_pose(startpos, rowpos, current_row / (count_row - 1))
    local outpos2 = Interpolate_pose(columnpos, refpos, current_row / (count_row - 1))
    local outpos3 = Interpolate_pose(outpos1, outpos2, current_column / (count_column - 1))
 
    outpos3[3] = outpos3[3] + layer_height * current_layer
    return outpos3
end
 
while true do
    local state = get_global_variable('B0')
    if state ==1 then
        -- 码垛
        local outpos3 =PalletCal("I100","I150","I151","I153","V150","V151","V152","V153")
        set_global_variable('V158',outpos3[1],outpos3[2],outpos3[3],outpos3[4],outpos3[5],outpos3[6])
        state = 0
        set_global_variable("B0", 0)
 
    elseif state == 2 then
        -- 拆垛
        local outpos3 =PalletCal("I101","I160","I161","I163","V160","V161","V162","V163")
        set_global_variable('V168',outpos3[1],outpos3[2],outpos3[3],outpos3[4],outpos3[5],outpos3[6])
        state = 0
        set_global_variable("B0", 0)
    end
    sleep(0.01)
end

2 拆垛与码垛

拆垛与码垛程序包的意思就是取料垛盘依次取料,依次放入码垛盘中。

2.1 操作步骤及所需变量

(1)使用前需在示教器上打开以下变量:

V158 //码垛上方位

V159 //码垛放料位

V168 //拆垛上方位

V169 //拆垛取料位

P150 //码垛盘第一个点

P151 //码垛盘第二个点

P152 //码垛盘第三个点

P153 //码垛盘第四个点

P160 //拆垛盘第一个点

P161 //拆垛盘第二个点

P162 //拆垛盘第三个点

P163 //拆垛盘第四个点

I 100 //码垛计数

I 101 //拆垛计数

(2)将JBI主程序和子程序导入到机械臂控制柜里面,LUA程序导入机械臂并保存设置。

(3)打开JBI子程序更新P150-153,P160-163这8个点位,点位设置示意图如下。以及设置好I150-153,I160-I163等参数,参数解析如下:

(4)设置好I150-153等参数,参数解析如下:

●  码垛参数:

I150 第一个方向个数

I151 第二个方向个数

I152 Z方向层数

I153 单层层高,单位mm

● 拆垛参数:

I160 第一个方向个数

I161 第二个方向个数

I162 Z方向层数

I163 单层层高,单位mm

(5)将机械臂程序运行模式设置为 “ 连续循环 “ 模式,运行主程序

2.2 JBI程序

该程序是主运行程序,无需修改

NOP
CALL JOB:test_pallet_setting
//调用下面的子程序  
RESTARTLUA INDEX=1
//B000与后台LUA交互
//1:计算码垛
//2:计算拆垛
SET B000 0
//I100 当前码垛个数
SET I100 1
//I101 当前拆垛个数
SET I101 1
 
LABEL *startpallet
SET B000 1
TIMER T=0.1 S
WAIT B000 = 0
SET B000 2
TIMER T=0.1 S
WAIT B000 = 0
 
// V168为当前计算得到的拆垛点
// v169 上方点
SET V169 V168
CCOOD CART
ADD V169(2) 30
 
// V158为当前计算得到的码垛点
// v159 上方点
SET V159 V158
CCOOD CART
ADD V159(2) 30
 
//拆垛
MOVL V169 V=1000MM/S CR=10.0MM ACC=50 DEC=50
MOVL V168 V=100MM/S CR=0.0MM ACC=50 DEC=50
TIMER T=0.5 S
MOVL V169 V=1000MM/S CR=0.0MM ACC=50 DEC=50
INC I101
 
//码垛
MOVL V159 V=1000MM/S CR=10.0MM ACC=50 DEC=50
MOVL V158 V=100MM/S CR=0.0MM ACC=50 DEC=50
TIMER T=0.5 S
MOVL V159 V=1000MM/S CR=0.0MM ACC=50 DEC=50
INC I100
JUMP *startpallet IF I100<I159
END

● 子程序

在该程序里面设置码盘4个对角点点位,码垛层数,层高,码垛总个数(JBI)

NOP
// 以下为码垛设置部分
// **************
// 150-159用于码垛
// P150 startpose 第一个点
// P151 rowpose  第一个方向的末端点
// P152 columnpose  第二个方向的末端点
// P153 refpose  远端点
//P150---------->P152
// |  第二个方向   |
// |               |
// |               |
//第一个方向       |
// |               |
//P151  -------- P153
 
SETJOINT P150 -13.5978,-104.8072,145.8060,-129.0093,134.8434,-180.1184
SETJOINT P151 -47.0715,-104.5984,133.2336,-88.6142,125.0733,-222.4587
SETJOINT P152 -5.5062,-53.8769,86.6584,-128.8164,134.5548,-168.7319
SETJOINT P153 -23.4796,-55.2147,81.2515,-104.4537,133.6682,-193.8322
// I150 第一个方向个数
// I151 第二个方向个数
// I152 Z方向层数
// I153 单层层高,单位mm
SET I150 3
SET I151 4
SET I152 2
SET I153 50
// **************
// 以上为码垛设置部分
 
// 以下为拆垛设置部分
// **************
// 160-169用于拆垛
SETJOINT P160 -46.5353,-94.3171,101.4025,-67.3931,125.3434,-221.8873
SETJOINT P161 -56.9397,-80.2992,84.8697,-59.2620,119.7353,-232.2963
SETJOINT P162 -30.5356,-59.9489,63.1652,-75.3110,131.8696,-203.1308
SETJOINT P163 -40.2939,-46.5040,38.5012,-56.4464,128.2411,-214.9811
// I160 第一个方向个数
// I161 第二个方向个数
// I162 Z方向层数
// I163 单层层高,单位mm
SET I160 3
SET I161 4
SET I162 2
SET I163 -50
// 以上为拆垛设置部分
 
//以下部分无需设置和修改
// **************
JOINTTOPOSE P150 V150
JOINTTOPOSE P151 V151
JOINTTOPOSE P152 V152
JOINTTOPOSE P153 V153
JOINTTOPOSE P160 V160
JOINTTOPOSE P161 V161
JOINTTOPOSE P162 V162
JOINTTOPOSE P163 V163
SET I159 I150
MUL I159 I151
MUL I159 I152
INC I159
// I159为码垛总个数
SET I169 I160
MUL I169 I161
MUL I169 I162
INC I169
// I169为拆垛总个数
TPWRITE FinishSetting
END

2.3 Lua程序

该lua脚本在机器人后台运行即可,无需修改

-- 1st pallet direction:  startpos--->rowpos
-- 2nd pallet direction:  startpos--->columnpos
-- 3rd pallet direction:  startpos--->Z direction
 
-- startpos(1)   ------ columnpos(2)
--    |
--    |
--    |
-- rowpos(3)             refpos(4)
 
-- count:        current pallet number   global variable :I100
-- count_row:    total row number        global variable :I150
-- count_column: total column nubmer     global variable :I151
-- count_layer:  total layer  nubmer     global variable :I152
-- height:       single layer height     global variable :I153
-- startpos                              global variable :V150
-- rowpos                                global variable :V151
-- columnpos                             global variable :V152
-- refpos                                global variable :V153
 
-- outpos  : calculation result          global variable :V160
 
function Interpolate_pose(p_from, p_to, alpha)
    -- Linear interpolation of tool position
    -- When alpha is 0, returns p_from. When alpha is 1, returns p_to. As alpha goes from 0 to 1, returns a
    -- pose going in a straight line from p_from to p_to.
    -- If alpha is less than 0, returns a point before p_from on the line.
    -- If alpha is greater than 1, returns a pose after p_to on the line.
    local p = {}
    p[1] = p_from[1] + (p_to[1] - p_from[1]) * alpha
    p[2] = p_from[2] + (p_to[2] - p_from[2]) * alpha
    p[3] = p_from[3] + (p_to[3] - p_from[3]) * alpha
    p[4] = p_from[4]
    p[5] = p_from[5]
    p[6] = p_from[6]
    return p
end
 
function WaitUntil(var, value)
    --local vtmp =
    while get_global_variable(var) ~= value do
        sleep(0.05)
    end
end
--set_global_variable("B0", 0)
 
function PalletCal(j_count,j_row,j_column,j_height,j_startpos,j_rowpos,j_columnpos,j_refpos)
    local count = get_global_variable(j_count)
    local count_row = get_global_variable(j_row)
    local count_column = get_global_variable(j_column)
    local layer_height = get_global_variable(j_height)
 
 
    local startpos = {get_global_variable(j_startpos)}
    local rowpos = {get_global_variable(j_rowpos)}
    local columnpos = {get_global_variable(j_columnpos)}
    local refpos = {get_global_variable(j_refpos)}
 
    local current_layer = math.floor((count - 1) / (count_row*count_column))
    count = math.fmod(count-1, (count_row*count_column)) +1 --获取在当前层第几个
    local current_row = math.fmod(count - 1, count_row) -- 取余数  get residual
    local current_column = math.floor((count - 1) / count_row) -- 取整数 get integer+1
    if(count_row==1)  then
        count_row =2
    end
    if(count_column==1)  then
        count_column =2
    end
    local outpos1 = Interpolate_pose(startpos, rowpos, current_row / (count_row - 1))
    local outpos2 = Interpolate_pose(columnpos, refpos, current_row / (count_row - 1))
    local outpos3 = Interpolate_pose(outpos1, outpos2, current_column / (count_column - 1))
 
    outpos3[3] = outpos3[3] + layer_height * current_layer
    return outpos3
end
 
while true do
    local state = get_global_variable('B0')
    if state ==1 then
        -- 码垛
        local outpos3 =PalletCal("I100","I150","I151","I153","V150","V151","V152","V153")
        set_global_variable('V158',outpos3[1],outpos3[2],outpos3[3],outpos3[4],outpos3[5],outpos3[6])
        state = 0
        set_global_variable("B0", 0)
 
    elseif state == 2 then
        -- 拆垛
        local outpos3 =PalletCal("I101","I160","I161","I163","V160","V161","V162","V163")
        set_global_variable('V168',outpos3[1],outpos3[2],outpos3[3],outpos3[4],outpos3[5],outpos3[6])
        state = 0
        set_global_variable("B0", 0)
    end
    sleep(0.01)
end

附件

1. 仅码垛

3.1 KB

2. 码垛与拆垛

 

 

 

 

 

 

 

 

提交反馈