【CSEN029】Obtain CS Robots Real MDH parameter (Forward Kinematics Calculation Sample Included)
  • MDH
  • 30001
  • parameter
  • forward
  • kinematics
Yu Lin
我要的是机器人?我要的是机器猫!

CS Robot use MDH parameters to create models, the MDH parameter for each model can be found at: https://bbs.elibot.cn/forum/detail/topic/376.html

Users can use TCP/IP communication to obtain data from port 30001, the data contains MDH parameter for current robot.

To analysis the data from port 30001, please use the Robot State Message Chat that attached with the User manual, which can be download from the the following link:

https://drive.google.com/drive/folders/1ImbQzU5DomuCiMznPaauQsyDpmYew2_t

The following are some sample code. The robot comunicates with itself to obtain the MDH parameters. 

It also uses the data to perfrom a forward kinematic calculation.

import socket
import struct
import time

HOST = "127.0.0.1"  # The server's hostname or IP address
PORT = 30001  # The port used by the server

global a
global d
global alpha
global theta
a = [0, 0, 0, 0, 0, 0]
d = [0, 0, 0, 0, 0, 0]
alpha = [0, 0, 0, 0, 0, 0]
theta = [0, 0, 0, 0, 0, 0]

# CS Obtains MDH parameter
bFinish = False
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))

    while bFinish == False:
        __buf = s.recv(4096)
        #print(len(__buf))
        if len(__buf) <= 0:
            time.sleep(0.01)

        while(len(__buf) > 0):
            data_length = struct.unpack(">i", __buf[0:4])[0]
            data_type = struct.unpack("B", __buf[4:5])[0]
            #print(data_length, data_type)
            data, __buf = __buf[0:data_length], __buf[data_length:]

            if data_type == 16:
                # MESSAGE_TYPE_ROBOT_STATE = 16
                bFinish = True
                sub_type = 0
                
                data = data[5:data_length]
                # Remove the head of the message at the first 5 bytes
                while sub_type != 6:
                    #ROBOT_STATE_PACKAGE_TYPE_CONFIGURATION_DATA = 6
                    sub_length = struct.unpack(">i", data[0:4])[0]
                    sub_type = struct.unpack("B", data[4:5])[0]
                    data1, data = data[0:sub_length], data[sub_length:]

                curr_data_add = 5+32*6+40
				
                for i in range(0, 6):
                        a[i] = struct.unpack(
                                ">d", data1[curr_data_add:curr_data_add+8])[0]
                        curr_data_add = curr_data_add+8

                for i in range(0, 6):
                        d[i] = struct.unpack(
                                ">d", data1[curr_data_add:curr_data_add+8])[0]
                        curr_data_add = curr_data_add+8

                for i in range(0, 6):
                        alpha[i] = struct.unpack(
                                ">d", data1[curr_data_add:curr_data_add+8])[0]
                        curr_data_add = curr_data_add+8

                for i in range(0, 6):
                        theta[i] = struct.unpack(
                                ">d", data1[curr_data_add:curr_data_add+8])[0]
                        curr_data_add = curr_data_add+8


def mdh2pose(a,alpha,d,theta):
    # Rx(alpha) * Dx(a) * Rz(theta) * Dz(d)
    pose = [0, 0, 0, 0, 0, 0]
    pose[0] = a
    pose[3] = alpha

    pose = pose_trans(pose, [0, 0, 0, 0, 0, theta])
    pose = pose_trans(pose, [0, 0, d, 0, 0, 0])
    return pose
end

def ForwardKinCal(c_joint):
    # Input angle to calculate Position in Cartesian Coordinate refer to base of the robot by forward kinematics
    out = [0,0,0,0,0,0]
    for i in range(0,6):
        out = pose_trans(out,mdh2pose(a[i], alpha[i], d[i], theta[i]+c_joint[i]))
    return out
	# Returns the pose of the flange

global c_pose
# Unit for xyz are in m,Unit for rpy are in radian

global c_pose1
# Unit for xyz are in mm,Unit for rpy are in degrees

joint = get_actual_joint_positions()
c_pose = ForwardKinCal(joint)
c_pose1=[c_pose[0]*1000,c_pose[1]*1000,c_pose[2]*1000,c_pose[3]/3.14159*180,c_pose[4]/3.14159*180,c_pose[5]/3.14159*180]

    The calculated result for c_pose1 matches with the actual result displaying in Tool Position




点击显示全文
赞同0
发表评论
分享

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