lua中位置数组与JBI交互

例如机器人在lua中通过socket接收到一段轨迹点位并保存数组,则lua和jbi可以通过交互,在jbi中使用lua中的点位数组

相关lua代码如下:

sleep(0.3)

Pose_arr = {{400,12.543,25.9139,2.30554,-0.00000,-3.14159},
{400,25.9819,36.2783,2.48465,-0.00000,-3.14159},
{400,40.0492,43.015,2.69498,-0.00000,-3.14159},
{400,55.475,46.1574,2.94063,-0.00000,-3.14159},
{400,72.1395,45.5849,-3.10724,-0.00000,3.14159},
{400,92.1442,41.2421,-2.92782,-0.00000,3.14159},
{400,131.193,28.7256,-2.83139,-0.00000,3.14159},
{400,158.247,21.5695,-2.88300,-0.00000,3.14159},
{400,179.531,18.4946,-2.99811,-0.00000,3.14159},
{400,200,18.3181,-3.13297,-0.00000,3.14159},
{400,220.469,18.4946,3.13297,-0.00000,-3.14159},
{400,241.753,21.5695,2.99811,-0.00000,-3.14159},
{400,268.807,28.7256,2.88300,-0.00000,-3.14159},
{400,307.856,41.2421,2.83139,-0.00000,-3.14159},
{400,327.86,45.5849,2.92782,-0.00000,-3.14159},
{400,344.525,46.1574,3.10724,-0.00000,-3.14159},
{400,359.951,43.015,-2.94063,-0.00000,3.14159},
{400,374.018,36.2783,-2.69498,-0.00000,3.14159},
{400,387.457,25.9139,-2.48465,-0.00000,3.14159},
{400,400,12.0313,-2.30554,-0.00000,3.14159}}
-- 路径轨迹一共20个笛卡尔点

function WaitUntil(var, value)
    -- 等待满足条件
    while get_global_variable(var) ~= value do
        sleep(0.005)
    end
end

function PoseMove()
    -- 将点位数组Pose_arr中所有点位赋值给V002
    for i = 1, #Pose_arr, 1 do
        WaitUntil('B003',1)
        -- 等待前台将B003置1
        set_global_variable('V002',Pose_arr[i][1],Pose_arr[i][2],Pose_arr[i][3],Pose_arr[i][4],Pose_arr[i][5],Pose_arr[i][6])
        set_global_variable('B003',0)
        -- 将B003置0,JBI等待B003=0往下走
    end   
end

set_global_variable('B005',0)
while true do
    B005 = get_global_variable('B005')
    if B005 ==1 then
        set_global_variable('B005',2)
        PoseMove()
        set_global_variable('B005',0)
    end
    sleep(0.1)
end

前台JBI代码如下:

NOP
SETPOSE V000 0,0,100,0.0,0.0,0.0
SETTOOLFRAME TOOL#(1) V000
SETPOSE V000 -70,-140,130,0.0,0.0,0.0
SETUSERFRAME USER #(1) V000
MOVEJ V=100.0DEG/S CR=0.0MM ACC=20 DEC=20 ConstP=[-54.169,-68.726,81.686,-61.057,115.744,25.829]

SET B003 0
TIMER T=0.5 S
SET B005 1
WAIT B005=2
LABEL *start
SET B003 1
WAIT B003=0
MOVEL V=100.0MM/S CR=20.0MM ACC=10 DEC=10 TOOL#(1) USER#(1) V002
// 使用CR达到圆滑效果
JUMP *start IF B005=2
END
点击显示全文
赞同0
发表评论
分享

手机扫码分享
0
687
收藏
举报
收起
登录
  • 密码登录
  • 验证码登录
还没有账号,立即注册
还没有账号,立即注册
注册
已有账号,立即登录
选择发帖板块
上传文件
举报
请选择举报理由
举报
举报说明