机器人手眼标定原理与python实现

这篇具有很好参考价值的文章主要介绍了机器人手眼标定原理与python实现。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、标定原理

机器人手眼标定分为eye in hand与eye to hand两种。介绍之前进行变量定义说明:

{b}: base基坐标系

{g}: gripper夹具坐标系

{t}: target标定板坐标系

{c}: camera相机坐标系

1、眼在手上(eye in hand)

眼在手上,相机固定在机器人上。

手眼标定程序 python,AI,人工智能,计算机视觉,python,Powered by 金山文档

图1. eye in hand示意图

手眼标定程序 python,AI,人工智能,计算机视觉,python,Powered by 金山文档

由以上两公式得:

手眼标定程序 python,AI,人工智能,计算机视觉,python,Powered by 金山文档

经变换得:

手眼标定程序 python,AI,人工智能,计算机视觉,python,Powered by 金山文档

可得:

手眼标定程序 python,AI,人工智能,计算机视觉,python,Powered by 金山文档

求解X即标定 :

手眼标定程序 python,AI,人工智能,计算机视觉,python,Powered by 金山文档

2、眼在手外(eye to hand)

眼在在手外,相机固定在机器人外。

手眼标定程序 python,AI,人工智能,计算机视觉,python,Powered by 金山文档

图2. eye to hand示意图

手眼标定程序 python,AI,人工智能,计算机视觉,python,Powered by 金山文档

由以上两公式可得:

手眼标定程序 python,AI,人工智能,计算机视觉,python,Powered by 金山文档

经变换得:

手眼标定程序 python,AI,人工智能,计算机视觉,python,Powered by 金山文档

可得:

手眼标定程序 python,AI,人工智能,计算机视觉,python,Powered by 金山文档

求解X即标定:

手眼标定程序 python,AI,人工智能,计算机视觉,python,Powered by 金山文档

二 、标定步骤

  1. 将标定板固定至机械臂末端;

  1. 在位置1采集标定板图像,并记录机械臂在位置1下的位置与姿态;

  1. 在位置2采集标定板图像,并记录机械臂在位置2下的位置与姿态;

  1. 移动机械臂更换不同位置,采集25-40张图像,并记录机械臂在每个位置下的位姿;

  1. 相机标定,获取25-40组Tt_c ;

  1. 位姿读取,获取25-40组Tb_g ;

  1. 根据5,6调用标定接口,获取Tc_b 。文章来源地址https://www.toymoban.com/news/detail-785843.html

三、标定代码

import os
import cv2
import xlrd2
from math import *
import numpy as np


class Calibration:
    def __init__(self):
        self.K = np.array([[2.54565632e+03, 0.00000000e+00, 9.68119560e+02],
                           [0.00000000e+00, 2.54565632e+03, 5.31897821e+02],
                           [0.00000000e+00, 0.00000000e+00, 1.00000000e+00]], dtype=np.float64)
        self.distortion = np.array([[-0.2557898, 0.81056366, 0.0, 0.0, -8.39153683]])
        self.target_x_number = 12
        self.target_y_number = 8
        self.target_cell_size = 40

    def angle2rotation(self, x, y, z):
        Rx = np.array([[1, 0, 0], [0, cos(x), -sin(x)], [0, sin(x), cos(x)]])
        Ry = np.array([[cos(y), 0, sin(y)], [0, 1, 0], [-sin(y), 0, cos(y)]])
        Rz = np.array([[cos(z), -sin(z), 0], [sin(z), cos(z), 0], [0, 0, 1]])
        R = Rz @ Ry @ Rx
        return R

    def gripper2base(self, x, y, z, tx, ty, tz):
        thetaX = x / 180 * pi
        thetaY = y / 180 * pi
        thetaZ = z / 180 * pi
        R_gripper2base = self.angle2rotation(thetaX, thetaY, thetaZ)
        T_gripper2base = np.array([[tx], [ty], [tz]])
        Matrix_gripper2base = np.column_stack([R_gripper2base, T_gripper2base])
        Matrix_gripper2base = np.row_stack((Matrix_gripper2base, np.array([0, 0, 0, 1])))
        R_gripper2base = Matrix_gripper2base[:3, :3]
        T_gripper2base = Matrix_gripper2base[:3, 3].reshape((3, 1))
        return R_gripper2base, T_gripper2base

    def target2camera(self, img):
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        ret, corners = cv2.findChessboardCorners(gray, (self.target_x_number, self.target_y_number), None)
        corner_points = np.zeros((2, corners.shape[0]), dtype=np.float64)
        for i in range(corners.shape[0]):
            corner_points[:, i] = corners[i, 0, :]
        object_points = np.zeros((3, self.target_x_number * self.target_y_number), dtype=np.float64)
        count = 0
        for i in range(self.target_y_number):
            for j in range(self.target_x_number):
                object_points[:2, count] = np.array(
                    [(self.target_x_number - j - 1) * self.target_cell_size,
                     (self.target_y_number - i - 1) * self.target_cell_size])
                count += 1
        retval, rvec, tvec = cv2.solvePnP(object_points.T, corner_points.T, self.K, distCoeffs=distortion)
        Matrix_target2camera = np.column_stack(((cv2.Rodrigues(rvec))[0], tvec))
        Matrix_target2camera = np.row_stack((Matrix_target2camera, np.array([0, 0, 0, 1])))
        R_target2camera = Matrix_target2camera[:3, :3]
        T_target2camera = Matrix_target2camera[:3, 3].reshape((3, 1))
        return R_target2camera, T_target2camera

    def process(self, img_path, pose_path):
        image_list = []
        for root, dirs, files in os.walk(img_path):
            if files:
                for file in files:
                    image_name = os.path.join(root, file)
                    image_list.append(image_name)
        R_target2camera_list = []
        T_target2camera_list = []
        for img_path in image_list:
            img = cv2.imread(img_path)
            R_target2camera, T_target2camera = self.target2camera(img)
            R_target2camera_list.append(R_target2camera)
            T_target2camera_list.append(T_target2camera)
        R_gripper2base_list = []
        T_gripper2base_list = []
        data = xlrd2.open_workbook(pose_path)
        table = data.sheets()[0]
        for row in range(table.nrows):
            x = table.cell_value(row, 0)
            y = table.cell_value(row, 1)
            z = table.cell_value(row, 2)
            tx = table.cell_value(row, 3)
            ty = table.cell_value(row, 4)
            tz = table.cell_value(row, 5)
            R_gripper2base, T_gripper2base = self.gripper2base(x, y, z, tx, ty, tz)
            R_gripper2base_list.append(R_gripper2base)
            T_gripper2base_list.append(T_gripper2base)
        R_camera2base, T_camera2base = cv2.calibrateHandEye(R_gripper2base_list, T_gripper2base_list,
                                                            R_target2camera_list, T_target2camera_list)
        return R_camera2base, T_camera2base, R_gripper2base_list, T_gripper2base_list, R_target2camera_list, T_target2camera_list

    def check_result(self, R_cb, T_cb, R_gb, T_gb, R_tc, T_tc):
        for i in range(len(R_gb)):
            RT_gripper2base = np.column_stack((R_gb[i], T_gb[i]))
            RT_gripper2base = np.row_stack((RT_gripper2base, np.array([0, 0, 0, 1])))
            RT_base2gripper = np.linalg.inv(RT_gripper2base)
            print(RT_base2gripper)

            RT_camera_to_base = np.column_stack((R_cb, T_cb))
            RT_camera_to_base = np.row_stack((RT_camera_to_base, np.array([0, 0, 0, 1])))
            print(RT_camera_to_base)

            RT_target_to_camera = np.column_stack((R_tc[i], T_tc[i]))
            RT_target_to_camera = np.row_stack((RT_target_to_camera, np.array([0, 0, 0, 1])))
            RT_camera2target = np.linalg.inv(RT_target_to_camera)
            print(RT_camera2target)

            RT_target_to_gripper = RT_base2gripper @ RT_camera_to_base @ RT_camera2target
            print("第{}次验证结果为:".format(i))
            print(RT_target_to_gripper)
            print('')


if __name__ == "__main__":
    image_path = r"D\code\img"
    pose_path = r"D\code\pose.xlsx"
    calibrator = Calibration()
    R_cb, T_cb, R_gb, T_gb, R_tc, T_tc = calibrator.process(image_path, pose_path)
    calibrator.check_result(R_cb, T_cb, R_gb, T_gb, R_tc, T_tc)

到了这里,关于机器人手眼标定原理与python实现的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 汇川机器人+五点法标定常规托盘码垛

            个人观点,码垛和拆垛本质上是一样,把流水线上的产品按规律整齐堆叠到托盘里叫码垛,从整齐排列有物料的托盘取料然后放到流水线上叫拆垛。取放料操作一般由机器人完成,我习惯按物料流向将设备分为码盘机(码垛)和上料机(拆垛),以下程序实例中的机器人为

    2024年03月27日
    浏览(42)
  • 手机拍照转机器人末端坐标(九点标定法)

    在图示位置读取九个点的X,Y坐标 测试可以随机拍一张,实用的话需要固定手机的拍照位置,得到的图片如下:  实用如下代码显示这个图片,用鼠标悬停取抄写坐标 效果如下: 鼠标悬停在P1上,在左下角就可以读取这个像素坐标值了。 验证算法如下: 运行后结果分析:

    2024年02月06日
    浏览(37)
  • 机器人运动学标定:基于DH建模方法

    作者:桂凯 链接:https://www.zhihu.com/question/401957723/answer/1298513878 来源:知乎 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 当然,运动学标定这种很基础的问题,理论已非常成熟了,基于激光或拉线编码器的标定系统也已经商业化了。我们在接

    2024年02月12日
    浏览(36)
  • 发那科机器人:MOTN-049 零点标定结果未更新

    现象如图: 原因:机器人在进行零位标定相关操作后出现 解决方法:MENU---系统---变量---$DMR_GRP--回车---回车 选择有效后查看一下机器人点位 然后重启机器人,开机后查看机器人点位和关机前对比,点位一致则表示成功,上使能机器人就可以手动运动。

    2024年02月01日
    浏览(29)
  • (视觉人机器视觉培训)康耐视3DA5000标定详细流程(相机安装于机器人上)

    (Q有答疑)visionman基本脚本培训-康耐视Visionpro之Visual Studio -调试快速方法 1、打开,运行A5000Viewer 2、修改相应参数,确认图像效果,并在Fifo取像工具自定义属性中添加。 1、本次应用为相机安装在机器人六轴前段,标定块位于相机视野内静止不动,对于相机固定安装稍有差异。

    2023年04月26日
    浏览(51)
  • 确保发那科机器人零点标定(零点复归)精度的3种方法

    最近接触了库卡的机器人,在上电的过程中,本想着需要确认一下机器人各轴零点是否对齐,深入查看后才发现库卡机器人并没有各轴零点标牌对齐一说,而是有一套专门的零点标定工具叫做EMD。 理解下来,大致原理就是如果机器人机械零点丢失,客户需要使用EMD标定工具,

    2024年02月09日
    浏览(55)
  • python机器人编程——用python实现一个写字机器人

    本篇我们构建一个可以跟人一样写字的机器人python软件。实现如下功能:打开一个写字板,人类在屏幕上写或画出任意形状,机器人同步在纸面上画出和人类一样的形状,就好像人类在远程操控机械臂,又或是机械臂是人的另一只手。这个软件是可以扩展的,如果连上互联网

    2024年02月05日
    浏览(31)
  • 深度揭秘:返利机器人的自动赚佣金原理与实现方法

    大家好,我是免费搭建查券返利机器人赚佣金就用微赚淘客系统3.0的小编,也是冬天不穿秋裤,天冷也要风度的程序猿!今天,我将为大家揭示返利机器人的核心秘密——自动赚佣金的原理及实现方法。 在电商时代,返利机器人已经成为许多消费者追求实惠的得力助手。它们

    2024年02月02日
    浏览(28)
  • 返利机器人的实现原理:从技术到收益的全面解析

    返利机器人的实现原理:从技术到收益的全面解析 大家好,我是免费搭建查券返利机器人赚佣金就用微赚淘客系统3.0的小编,也是冬天不穿秋裤,天冷也要风度的程序猿!在电商时代,许多消费者对返利机器人并不陌生。这种自动化的工具能帮助用户在购物时获取额外的优惠

    2024年02月03日
    浏览(29)
  • 【NLP开发】Python实现聊天机器人(微软Azure机器人服务)

    🍺NLP开发系列相关文章编写如下🍺: 1 🎈【小沐学NLP】Python实现词云图🎈 2 🎈【小沐学NLP】Python实现图片文字识别🎈 3 🎈【小沐学NLP】Python实现中文、英文分词🎈 4 🎈【小沐学NLP】Python实现聊天机器人(ELIZA))🎈 5 🎈【小沐学NLP】Python实现聊天机器人(ALICE)🎈 6

    2024年02月04日
    浏览(37)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包