EC机器人只支持 通过sdk 打开/关闭机器人碰撞检测功能。 sdk相关语句见sdk 手册的2.2.2.32 设置安全参数。该指令支持机器人在remote和自动模式下设置!!
该指令可以在机器人 自动模式下修改机器人 碰撞检测功能,即用户可以在lua中编写socket指令,发送相关字符串,打开关闭碰撞检测。
发送该指令时,需要计算 机器人密码的md5值。可以在lua中实现相关计算。
ret , str1 , id = sendCMD(sock, ”get_remote_sys_password”) word = hashlib .md5() str2 = ”123456” // str2为机器人远程模式的密码,默认为123456 word.update( str1 .encode(”utf8”) ) word.update( str2 .encode(”utf8”) ) password = word. hexdigest () ret , result , id = sendCMD(sock, ”setSafetyParams”, {”password”: password, ”enable”: 1, ” mode”: 1, ”power”: 400, ”momentum”: 90, ”tool_force”: 400, ”elbow_force”: 400, ”speed”: 0.5, ” collision_enable ”: 0, ” collision_sensitivity ”: 10})
用户将以下的2个lua文件导入机器人控制器,并运行SetCollision.lua程序。机器人处于自动或者remote模式,用户可以通过改变B012变量来打开/关闭 碰撞检测(B012为1,打开碰撞检测,B012为2,关闭碰撞检测),可以通过B013设置灵敏度(10-100)
-- SetCollision.lua local md5 = require("./md5") local json = require("json") local ret local recv -- IPAdd = "127.0.0.1" IPAdd = "192.168.1.200" local cmd = "" local para1 = {} local ret1 local recv1 local id1 function NumToStr(data, num) local s = "%." .. num .. "f" return string.format(s, data) end function WaitUntil(var, value) --local vtmp = while get_global_variable(var) ~= value do sleep(0.1) end end function Connect1(IPAdd) ret = connect_tcp_server(IPAdd, 8055) end function SendCMD(IPAdd, cmd, params) local out_tmp if params == nil then out_tmp = json.encode({jsonrpc = "2.0", method = cmd, id = 1}) .. "\n" else out_tmp = json.encode({jsonrpc = "2.0", method = cmd, params = params, id = 1}) .. "\n" end ret = client_send_data(IPAdd, out_tmp, 0, 8055) ret, recv = client_recv_data(IPAdd, 1, 0, 8055) if ret < 0 then elite_print("接受8055数据失败") return false, nil, nil else local recv_json = json.decode(recv) return true, recv_json.result, recv_json.id end end function String2Table(str_t) local tmp = string.sub(str_t, 2, -2) local tmp1 = string.split(tmp, ",") local out = {} for i = 1, #tmp1, 1 do out[i] = tonumber(tmp1[i]) --out[i] = tonumber(tmp1[i]) end return out end function SetCollision(en,sensitivity) cmd = "get_remote_sys_password" local str1 ret1, str1, id1 = SendCMD(IPAdd, cmd) str1 = string.sub(str1,2,-2) -- 返回值带有前后引号,需要删除前后引号 local str2_pwd = '123456' -- 此处为远程机器人的密码!!! local pwd = md5.sumhexa(str1..str2_pwd) cmd = 'setSafetyParams' if sensitivity ==nil then para1 = {password= pwd, enable= 1, mode=0, power=400, momentum= 90,tool_force= 400, elbow_force= 400, speed= 0.5, collision_enable= en} else para1 = {password= pwd, enable= 1, mode=0, power=400, momentum= 90,tool_force= 400, elbow_force= 400, speed= 0.5, collision_enable= en,collision_sensitivity = sensitivity} end ret1, recv1, id1 = SendCMD(IPAdd, cmd,para1) end sleep(0.3) Connect1(IPAdd) --建立连接 while true do local mc = get_global_variable("B012") local mc_sense = get_global_variable("B013") if mc == 1 then -- 打开碰撞检测 if mc_sense <100 and mc_sense>10 then SetCollision(1,mc_sense) elite_print('碰撞检测设置完成') else elite_print('碰撞灵敏度只能设置在10-100之间!') end set_global_variable('B012',0) end if mc == 2 then -- 关闭碰撞检测 SetCollision(0) set_global_variable('B012',0) elite_print('碰撞检测设置完成') end sleep(0.2) end
https://blog.csdn.net/xiaoxiaohan130/article/details/123573730 获取md5.lua