钧舵夹爪一对多艾利特适配手册
一、驱动脚本导入
U盘导入方法
- 将JDgeneral-1to2.lua 文件放到rbctrl/luadir 文件夹目录下,然后把文件夹放到U盘里。
- U盘插入机器人控制器
- 在机器人示教器上左上角选择系统->U盘到本地->脚本升级
- 在机器人示教器右上角选择用户工艺->脚本,打开JDgeneral-1to2。
SSH登录导入方法
elite 控制器支持sftp传输,所以我们可以通过sftp传输方式,将JDgeneral-1to2.lua 文件放到机器人系统中的/rbctrl/luadir/ 文件夹下
我们可以使用sftp的软件,例如:secure_FX, moba_xterm, ftpSurf软件也可以使用VScode或者notepad++等IDE自带的sftp插件实现
二、驱动使用说明
D0,控制脚本的运行,1:开启
初始化成功会打印显示connect success-8(9),slave set success-8(9)
D1-D10为ID9(默认ID)夹爪参数
D1用于夹爪控制,0:无 1:使夹爪运动 2:设置夹爪参数3:清除故障报警
D2夹爪的状态,0:手指正向指定位置移动1:手指到达指定位置并且接触到物体2:手指到达指定位置为检测到物体或者脱落
D3夹爪实时位置,范围0-255mm。0为完全打开,255完全闭合。
D4夹爪故障:0:无1:故障
D5显示当前的设定速度,最低速度:0最高速度:255
D6力状态:该值为当前电机的电流值,该值为标幺值
D7温度
D8动态位置设置参数,范围0-255mm。0为完全打开,255完全闭合。
D9动态速度设置,最低速度:0最高速度:255
D10动态力的设置,最小力:0最大力:255
D11-D20为修改ID为8夹爪的参数
D11用于夹爪控制,0:无 1:使夹爪运动 2:设置夹爪参数3:清除故障报警
D12夹爪的状态,0:手指正向指定位置移动1:手指到达指定位置并且接触到物体2:手指到达指定位置为检测到物体或者脱落
D13夹爪实时位置,范围0-255mm。0为完全打开,255完全闭合。
D14夹爪故障:0:无1:故障
D15显示当前的设定速度,最低速度:0最高速度:255
D16力状态:该值为当前电机的电流值,该值为标幺值
D17温度
D18动态位置设置参数,范围0-255mm。0为完全打开,255完全闭合。
D19动态速度设置,最低速度:0最高速度:255
D20动态力的设置,最小力:0最大力:255
三、夹爪ID修改
EPG 系列模块电动夹爪可通过设备 ID 寄存器修改与查看 ID,该寄存器地址为 0x138D,EPG 系列模块电动夹爪设备 ID 可配置范围为 1-247,出厂时默认为 0x09,具体修改 ID 命
令如下:
发送:09 10 13 8D 00 01 02 00 08 FC 4A
回复:09 10 13 8D 00 01 94 2E
这时 ID 号就变成了 0x08,如果要修改回原来的 0x09,命令如下:
发送:08 10 13 8D 00 01 02 00 09 30 1A
回复:08 10 13 8D 00 01 95 FF
如图下
控制单个夹爪脚本.Lua
--此脚本用于钧舵RG产品系列的夹爪,使用前请仔细阅读使用说明
sleep(0.2)
local Script_control = "D0"--用于控制脚本的运行
local Claw_mode = "D1"--用于夹爪控制0:无 1:使夹爪运动 2:设置夹爪参数3:清除故障报警
local State = "D2" --夹爪的状态,0:手指正向指定位置移动1:手指到达指定位置并且接触到物体2:手指到达指定位置为检测到物体或者脱落
local Position = "D3"--夹爪实时位置
local Failure = "D4" --夹爪故障:0:无1:故障
local Speed = "D5" -- 显示当前的设定速度
local Force = "D6" --力状态:该值为当前电机的电流值,该值为标幺值
local Temperature = "D7"--温度
local Dynamicposition = "D8" --动态位置设置参数
local SetSpeed = "D9" --动态速度设置
local SetForce = "D10" --动态力的设置
--初始化参数
function InitData()
set_global_variable(Script_control,0)
set_global_variable(Claw_mode,0)
set_global_variable(Dynamicposition,0)
set_global_variable(SetSpeed,100)
set_global_variable(SetForce,100)
end
function RepeatVar(var)
repeat
elite_print("Waiting "..var.." == 1!")
sleep(1)
until (get_global_variable(var) == 1)
end
--通讯参数设置
choose = 2
baud = 115200
parity = 78
data_bit = 8
stop_bit = 1
ID = 9--夹爪从站地址
Stroke = 75 --夹爪的行程
Proportion = Stroke//255
SetProportion = 255//Stroke
CTX = modbus_new_rtu(choose,baud,parity,data_bit,stop_bit)--设置modbus rtu句柄
--通讯连接
function connect(set1)
local ctx = set1
repeat
local con = modbus_connect(ctx)--modbus发起连接
if con == -1 then
elite_print("connect error")
end
until(con ~= -1)
elite_print("connect success")
end
--设置从站地址
function set_slave(set2,id)
local ctx = set2
local Id = "0x"..string.format("%X",id)
repeat
local ret= modbus_set_slave(ctx,Id)--设置从站地址
if ret == -1 then
elite_print("slave set error")
end
until(ret ~= -1)
elite_print ("slave set success")
end
--夹爪控制函数
--10进制转2进制
function byte2bin(n,start,dend)--n整数,start截取的开始地址,dend截取的结束地址
local t = {}
for i=15,0,-1 do
t[#t+1] = math.floor(n / 2^i)
n = n % 2^i
end
ObjectDetection = string.sub(table.concat(t),start,dend)
return ObjectDetection
end
--10进制转2进制转number
function byte2binNum(n,start,dend)
local t = {}
for i=15,0,-1 do
t[#t+1] = math.floor(n / 2^i)
n = n % 2^i
end
ObjectDetection = string.sub(table.concat(t),start,dend)
local num = tonumber(ObjectDetection, 2)
return num
end
--读取夹爪状态反馈
function ReadGripper(ctx)
--电动夹爪状态
local ret0,state = modbus_read_register(ctx,0x07D0)
state = byte2bin(state,9,10)
if state == "00" then --夹爪正在运动
set_global_variable(State,0)
elseif state == "01" or state == "10" then
set_global_variable(State,1)
elseif state == "11" then
set_global_variable(State,2)
end
--故障和位置寄存器
local ret1,PositionFailure = modbus_read_register(ctx,0x07D1)
local failure = byte2binNum(PositionFailure,9,16)
local position = byte2binNum(PositionFailure,1,8)
set_global_variable(Position,position)
if failure == 0 then
set_global_variable(Failure,0)
else
set_global_variable(Failure,1)
end
--速度和力状态寄存器
local ret2,ForceSpeed = modbus_read_register(ctx,0x07D2)
local speed = byte2binNum(PositionFailure,9,16)
local force = byte2binNum(PositionFailure,1,8)
set_global_variable(Speed,speed)
set_global_variable(Force,force)
--环境温度寄存器
local ret2,temperature = modbus_read_register(ctx,0x07D3)
local Temper = byte2binNum(temperature,1,8)
set_global_variable(Temperature,Temper)
--elite_print(pos)
end
--夹爪使能并清除故障
function enable(ctx)
local ena = modbus_write_register(ctx,0x03E8,0x0001)
end
--夹爪运动
function RunGripper(ctx)
modbus_write_register(ctx,0x03E8,0x0009)
--sleep(0.1)
--local state1 = get_global_variable(State)
--if state1 == 1 then
-- modbus_write_register(ctx,0x03E8,0x0001)
--elseif state1 == 2 then
-- elite_print("Finger reaches specified position, object is not detected or object falls off")
-- modbus_write_register(ctx,0x03E8,0x0001)
--end
end
-- 参数限制
function ThresholdLimit(value, max, min)
if value > max then
value = max
elseif value < min then
value = min
end
return value
end
function restriction(value)
if value >= 255 then
value = 255
elseif value == 6 then
value = 0
end
return value
end
--设置夹爪基本参数
function SetGripper(ctx)
--夹爪动态位置设置
local DynamicPosition = get_global_variable(Dynamicposition) + 6
local dp = restriction(DynamicPosition)
local setdp = "0x"..string.format("%02X",dp).."00"
ret3 = modbus_write_register(ctx,0x03E9,setdp)
--elite_print("ret3:"..ret3)
--夹爪动态速度和力的设置
local DynamicSpeed = get_global_variable(SetSpeed)
local ds = ThresholdLimit(DynamicSpeed,255,0)
local DynamicForc = get_global_variable(SetForce)
local df = ThresholdLimit(DynamicForc,255,0)
local FS = "0x"..string.format("%02X",df)..string.format("%02X",ds)
ret4 = modbus_write_register(ctx,0x03EA,FS)
--elite_print("ret4:"..ret4)
end
--main
InitData()
RepeatVar(Script_control)
connect(CTX)
set_slave(CTX,ID)
enable(CTX)
repeat
sleep(0.01)
D1=get_global_variable (Claw_mode)
if D1 == 1 then
RunGripper(CTX)
set_global_variable(Claw_mode,0)
elseif D1 == 2 then
SetGripper(CTX)
set_global_variable(Claw_mode,0)
elseif D1 == 3 then
enable(CTX)
set_global_variable(Claw_mode,0)
end
ReadGripper(CTX)
until(get_global_variable("D0") == 0)
elite_print("Disconnect")
modbus_close (CTX)
机器人控制两个个夹爪脚本.Lua
--此脚本用于钧舵RG产品系列的夹爪,使用前请仔细阅读使用说明
sleep(0.2)
local Script_control = "D0"--用于控制脚本的运行
local Claw_mode = "D1"--用于夹爪控制0:无 1:使夹爪运动 2:设置夹爪参数3:清除故障报警
local State = "D2" --夹爪的状态,0:手指正向指定位置移动1:手指到达指定位置并且接触到物体2:手指到达指定位置为检测到物体或者脱落
local Position = "D3"--夹爪实时位置
local Failure = "D4" --夹爪故障:0:无1:故障
local Speed = "D5" -- 显示当前的设定速度
local Force = "D6" --力状态:该值为当前电机的电流值,该值为标幺值
local Temperature = "D7"--温度
local Dynamicposition = "D8" --动态位置设置参数
local SetSpeed = "D9" --动态速度设置
local SetForce = "D10" --动态力的设置
local Claw_mode_8 = "D11"--用于夹爪控制0:无 1:使夹爪运动 2:设置夹爪参数3:清除故障报警
local State_8 = "D12" --夹爪的状态,0:手指正向指定位置移动1:手指到达指定位置并且接触到物体2:手指到达指定位置为检测到物体或者脱落
local Position_8 = "D13"--夹爪实时位置
local Failure_8 = "D14" --夹爪故障:0:无1:故障
local Speed_8 = "D15" -- 显示当前的设定速度
local Force_8 = "D16" --力状态:该值为当前电机的电流值,该值为标幺值
local Temperature_8 = "D17"--温度
local DynamicPosition_8 = "D18" --动态位置设置参数
local SetSpeed_8 = "D19" --动态速度设置
local SetForce_8 = "D20" --动态力的设置
--ID9初始化参数
function InitData()
set_global_variable(Script_control,0)
set_global_variable(Claw_mode,0)
set_global_variable(Dynamicposition,0)
set_global_variable(SetSpeed,100)
set_global_variable(SetForce,100)
end
function RepeatVar(var)
repeat
elite_print("Waiting "..var.." == 1!")
sleep(1)
until (get_global_variable(var) == 1)
end
--ID9通讯参数设置
choose = 2
baud = 115200
parity = 78
data_bit = 8
stop_bit = 1
ID = 9--夹爪从站地址
Stroke = 75 --夹爪的行程
Proportion = Stroke//255
SetProportion = 255//Stroke
CTX = modbus_new_rtu(choose,baud,parity,data_bit,stop_bit)--设置modbus rtu句柄
--ID9通讯连接
function connect(set1)
local ctx = set1
repeat
local con = modbus_connect(ctx)--modbus发起连接
if con == -1 then
elite_print("connect error-9")
end
until(con ~= -1)
elite_print("connect success-9")
end
--ID9设置从站地址
function set_slave(set2,id)
local ctx = set2
local Id = "0x"..string.format("%X",id)
repeat
local ret= modbus_set_slave(ctx,Id)--设置从站地址
if ret == -1 then
elite_print("slave set error-9")
end
until(ret ~= -1)
elite_print ("slave set success-9")
end
--9夹爪控制函数
--10进制转2进制
function byte2bin(n,start,dend)--n整数,start截取的开始地址,dend截取的结束地址
local t = {}
for i=15,0,-1 do
t[#t+1] = math.floor(n / 2^i)
n = n % 2^i
end
ObjectDetection = string.sub(table.concat(t),start,dend)
return ObjectDetection
end
--10进制转2进制转number
function byte2binNum(n,start,dend)
local t = {}
for i=15,0,-1 do
t[#t+1] = math.floor(n / 2^i)
n = n % 2^i
end
ObjectDetection = string.sub(table.concat(t),start,dend)
local num = tonumber(ObjectDetection, 2)
return num
end
--ID9读取夹爪状态反馈
function ReadGripper(ctx)
--电动夹爪状态
local ret0,state = modbus_read_register(ctx,0x07D0)
state = byte2bin(state,9,10)
if state == "00" then --夹爪正在运动
set_global_variable(State,0)
elseif state == "01" or state == "10" then
set_global_variable(State,1)
elseif state == "11" then
set_global_variable(State,2)
end
--故障和位置寄存器
local ret1,PositionFailure = modbus_read_register(ctx,0x07D1)
local failure = byte2binNum(PositionFailure,9,16)
local position = byte2binNum(PositionFailure,1,8)
set_global_variable(Position,position)
if failure == 0 then
set_global_variable(Failure,0)
else
set_global_variable(Failure,1)
end
--速度和力状态寄存器
local ret2,ForceSpeed = modbus_read_register(ctx,0x07D2)
local speed = byte2binNum(PositionFailure,9,16)
local force = byte2binNum(PositionFailure,1,8)
set_global_variable(Speed,speed)
set_global_variable(Force,force)
--环境温度寄存器
local ret2,temperature = modbus_read_register(ctx,0x07D3)
local Temper = byte2binNum(temperature,1,8)
set_global_variable(Temperature,Temper)
--elite_print(pos)
end
--ID9夹爪使能并清除故障
function enable(ctx)
local ena = modbus_write_register(ctx,0x03E8,0x0001)
end
--ID9夹爪运动
function RunGripper(ctx)
modbus_write_register(ctx,0x03E8,0x0009)
--sleep(0.1)
--local state1 = get_global_variable(State)
--if state1 == 1 then
-- modbus_write_register(ctx,0x03E8,0x0001)
--elseif state1 == 2 then
-- elite_print("Finger reaches specified position, object is not detected or object falls off")
-- modbus_write_register(ctx,0x03E8,0x0001)
--end
end
--ID9参数限制
function ThresholdLimit(value, max, min)
if value > max then
value = max
elseif value < min then
value = min
end
return value
end
function restriction(value)
if value >= 255 then
value = 255
elseif value == 6 then
value = 0
end
return value
end
--ID9设置夹爪基本参数
function SetGripper(ctx)
--夹爪动态位置设置
local DynamicPosition = get_global_variable(Dynamicposition) + 6
local dp = restriction(DynamicPosition)
local setdp = "0x"..string.format("%02X",dp).."00"
ret3 = modbus_write_register(ctx,0x03E9,setdp)
--elite_print("ret3:"..ret3)
--夹爪动态速度和力的设置
local DynamicSpeed = get_global_variable(SetSpeed)
local ds = ThresholdLimit(DynamicSpeed,255,0)
local DynamicForc = get_global_variable(SetForce)
local df = ThresholdLimit(DynamicForc,255,0)
local FS = "0x"..string.format("%02X",df)..string.format("%02X",ds)
ret4 = modbus_write_register(ctx,0x03EA,FS)
--elite_print("ret4:"..ret4)
end
--ID8初始化参数
function InitData_8()
--set_global_variable(Script_control,0)
set_global_variable(Claw_mode_8,0)
set_global_variable(DynamicPosition_8,0)
set_global_variable(SetSpeed_8,100)
set_global_variable(SetForce_8,100)
--elite_print("初始化完成")
end
--ID8通讯参数设置
choose = 2
baud = 115200
parity = 78
data_bit = 8
stop_bit = 1
ID_8 = 8--夹爪从站地址
Stroke = 75 --夹爪的行程
Proportion = Stroke//255
SetProportion = 255//Stroke
CTX_8 = modbus_new_rtu(choose,baud,parity,data_bit,stop_bit)--设置modbus rtu句柄
--ID8通讯连接
function connect_8(set1)
local ctx = set1
repeat
local con = modbus_connect(ctx)--modbus发起连接
if con == -1 then
elite_print("connect error-8")
end
until(con ~= -1)
elite_print("connect success-8")
end
--ID8设置从站地址
function set_slave_8(set2,id)
local ctx = set2
local Id = "0x"..string.format("%X",id)
repeat
local ret= modbus_set_slave(ctx,Id)--设置从站地址
if ret == -1 then
elite_print("slave set error-8")
end
until(ret ~= -1)
elite_print ("slave set success-8")
end
--ID8读取夹爪状态反馈
function ReadGripper_8(ctx)
--ID8电动夹爪状态
local ret0,State = modbus_read_register(ctx,0x07D0)
State = byte2bin(State,9,10)
if State == "00" then --夹爪正在运动
set_global_variable(State_8,0)
elseif State == "01" or State_8 == "10" then
set_global_variable(State_8,1)
elseif State == "11" then
set_global_variable(State_8,2)
end
--ID8故障和位置寄存器-------------------------------------------
local ret1,Position_8Failure = modbus_read_register(ctx,0x07D1)
local Failure = byte2binNum(Position_8Failure,9,16)
local position = byte2binNum(Position_8Failure,1,8)
set_global_variable(Position_8,position)
if Failure == 0 then
set_global_variable(Failure_8,0)
else
set_global_variable(Failure_8,1)
end
--ID8速度和力状态寄存器
local ret2,Force_8Speed_8 = modbus_read_register(ctx,0x07D2)
local speed = byte2binNum(Force_8Speed_8,9,16)
local force = byte2binNum(Force_8Speed_8,1,8)
set_global_variable(Speed_8,speed)
set_global_variable(Force_8,force)
--ID8环境温度寄存器
local ret2,Temperature = modbus_read_register(ctx,0x07D3)
local Temper = byte2binNum(Temperature,1,8)
set_global_variable(Temperature_8,Temper)
--elite_print("134")
--elite_print(pos)
end
--ID8夹爪使能并清除故障
function enable_8(ctx)
local ena = modbus_write_register(ctx,0x03E8,0x0001)
-- elite_print("11")
end
--ID8夹爪运动
function RunGripper_8(ctx)
modbus_write_register(ctx,0x03E8,0x0009)
--sleep(0.1)
--local State_81 = get_global_variable(State_8)
--if State_81 == 1 then
-- modbus_write_register(ctx,0x03E8,0x0001)
--elseif State_81 == 2 then
-- elite_print("Finger reaches specified Position_8, object is not detected or object falls off")
-- modbus_write_register(ctx,0x03E8,0x0001)
--end
end
--ID8参数限制
function ThresholdLimit(value, max, min)
if value > max then
value = max
elseif value < min then
value = min
end
return value
end
function restriction(value)
if value >= 255 then
value = 255
elseif value == 6 then
value = 0
end
return value
end
--设置ID8夹爪基本参数
function SetGripper_8(ctx)
--夹爪动态位置设置
local DynamicPosition_8 = get_global_variable(DynamicPosition_8) + 6
local dp = restriction(DynamicPosition_8)
local setdp = "0x"..string.format("%02X",dp).."00"
ret3 = modbus_write_register(ctx,0x03E9,setdp)
--elite_print("ret3:"..ret3)
--夹爪动态速度和力的设置
local DynamicSpeed_8 = get_global_variable(SetSpeed_8)
local ds = ThresholdLimit(DynamicSpeed_8,255,0)
local DynamicForc = get_global_variable(SetForce_8)
local df = ThresholdLimit(DynamicForc,255,0)
local FS = "0x"..string.format("%02X",df)..string.format("%02X",ds)
ret4 = modbus_write_register(ctx,0x03EA,FS)
--elite_print("ret4:"..ret4)
end
--main9
InitData()
RepeatVar(Script_control)
connect(CTX)
set_slave(CTX,ID)
enable(CTX)
--main8
InitData_8()
connect_8(CTX_8)
set_slave_8(CTX_8,ID_8)
enable_8(CTX_8)
repeat
sleep(0.01)
D1=get_global_variable (Claw_mode)
D11=get_global_variable (Claw_mode_8)
--9
if D1 == 1 then
RunGripper(CTX)
set_global_variable(Claw_mode,0)
elseif D1 == 2 then
SetGripper(CTX)
set_global_variable(Claw_mode,0)
elseif D1 == 3 then
enable(CTX)
set_global_variable(Claw_mode,0)
end
--8
if D11 == 1 then
RunGripper_8(CTX_8)
set_global_variable(Claw_mode_8,0)
elseif D11 == 2 then
SetGripper_8(CTX_8)
set_global_variable(Claw_mode_8,0)
elseif D11 == 3 then
enable_8(CTX_8)
set_global_variable(Claw_mode_8,0)
end
ReadGripper(CTX)
ReadGripper_8(CTX_8)
until(get_global_variable("D0") == 0)
elite_print("Disconnect")
modbus_close (CTX_8)
modbus_close (CTX)
机器人控制程序示例.jbi
NOP
SET D000 1
//#SET D020 1
//9号夹爪
//D8动态位置设置参数0最大255最小
SET D008 0
//D9速度
SET D009 100
//D8力
SET D010 50
//10号夹爪
SET D028 0
//D9速度
SET D029 100
//D8力
SET D030 50
LABEL *3
//夹爪1
SET D008 0
TIMER T=0.2 S
SET D001 2
TIMER T=0.2 S
MOVJ VJ=1% CR=0.000MM
SET D001 1
WAIT D002 = 1
MOVJ VJ=1% CR=0.000MM
MOVJ VJ=1% CR=0.000MM
SET D008 255
TIMER T=0.2 S
SET D001 2
TIMER T=0.2 S
SET D001 1
WAIT D002 = 2
MOVJ VJ=1% CR=0.000MM
//夹爪2
SET D018 0
TIMER T=0.2 S
SET D011 2
TIMER T=0.2 S
MOVJ VJ=1% CR=0.000MM
SET D011 1
WAIT D002 = 1
MOVJ VJ=1% CR=0.000MM
MOVJ VJ=1% CR=0.000MM
SET D018 255
TIMER T=0.2 S
SET D011 2
TIMER T=0.2 S
SET D011 1
WAIT D002 = 2
MOVJ VJ=1% CR=0.000MM
JUMP *3
END