背景需求
需要仿真fanuc的姿态。
解决方法
- 下载并安装robodk;
- 导入fanuc r2000ib的机器人文件,robodk官网可以下载;
- 新建py程序,安装mqtt包;
- 新建py程序,并运行py程序,通过mqtt协议将机器人的姿态发出。
python 代码如下:
from robodk.robolink import * # RoboDK API
from robodk.robomath import * # 数学函数
import json
# 初始化 RoboDK 接口
RDK = Robolink()
# 获取机器人对象
robot = RDK.Item('Fanuc R-2000iB/165F', ITEM_TYPE_ROBOT)
# 检查机器人是否存在
if not robot.Valid():
raise Exception('无法找到指定的机器人')
# 获取当前的关节坐标
# 打印关节坐标
#print('当前关节坐标:', joints.tolist())
import paho.mqtt.client as mqtt
client = mqtt.Client()
client.username_pw_set('xxxxxxxxxxx', 'xxxxxxxxx')
client.connect("192.168.1.1", 1883, 60)
while True:
joints = robot.Joints().tolist()
jointJson = json.dumps({
'E1':0,
'J1':joints[0],
'J2':joints[1],
'J3':joints[2],
'J4':joints[3],
'J5':joints[4],
'J6':joints[5],
})
client.publish("/fanuc/robot/r1/joint_coordinates", jointJson)
time.sleep(0.05)
使用案例
修正误差前视频如下:
修正误差后的视频如下效果如下,通过仿真发现了J2和J3轴之间存在联动,计算校准后解决。