从UR5机器人的TCP/IP端口读取数据出现问题

问题描述 投票:0回答:2

我编写了下面的 MATLAB 代码,从 UR5 的 TCP/IP 30003 端口读取一些数据流。我得到的结果与我的机器人上的结果不同(我使用的是 URSim 3.5.3 Virtual环境)但它应该是相同的。尽管看起来很接近,因为有 6 个数据,正如预期的那样。

我相信这是可能的,因为有人使用Python来实现它http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/client-interfaces -cartesian-matlab-data/,但我被指示使用 MATLAB。

MATLAB 代码

clear all

HOST = '192.168.56.101';
PORT_30003 = 30003;

while (true)
s = tcpclient(HOST, PORT_30003);
disp('connected and starting program');
disp('data received:');

data = read(s, 80, 'double');

disp(data(56:61));

pause(1);
end

获得的结果:

>> ur5
connected and starting program
data received:
1.0e-15 *

-0.4406    0.0000   -0.0000    0.0000    0.0000   -0.0000


connected and starting program
data received:
1.0e-15 *

-0.4406    0.0000   -0.0000    0.0000    0.0000   -0.0000

连续相同,因为机器人没有移动,但与我的机器人中的值有很大不同。第一行用于笛卡尔坐标(X,Y,Z,RX,RY,RZ),但运行程序时我的机器人上的值是:-120.11mm,-431.76mm,146.07mm,0.0012,- 3.1664、-0.0395,第二个用于夹具状态(X、Y、Z、RX、RY、RZ)。有谁知道这是否是转换问题?我该如何纠正它?

matlab robotics
2个回答
0
投票

Universal Robots Matlab 接口(实时客户端/端口 30003)发送数据包结构的数据:

int LENGTH
double PAYLOAD_0
double PAYLOAD_1
double ...
double PAYLOAD_n

由于软件版本不同,长度可能会有所不同,因此建议先读取长度,然后再读取剩余的 double 值。如果你没有读取包的完整长度,那么你的输入缓冲区中可能会有一些“上一个包的剩余部分”,那么你读取的下一个包将是无意义的。

因此我建议读取长度,缓冲剩余的包,然后提取感兴趣的包。

length = read(s, 1, 'int64')
payload = read(s, length, 'double')
disp(payload(x:y))

您可以在此处找到 UR TCP 接口的官方文档。 请注意,端口 30003 接口有时会扩展,并在末尾添加新变量。双打的完整长度应该是 139 个双打左右。


0
投票

我们也遇到了和你一样的问题。 我们找到的解决方案是。 Matlab代码

clear all
HOST = '192.168.56.101';
PORT_30003 = 30003;
s = tcpclient(HOST, PORT_30003);
disp('connected and starting program');
s.flush;
data = read(s, 1220, 'uint8');
disp('data received:');
% use flip to get the right bight order
% read the actual joint position
q_joint_1 = typecast(flip(data(253:260),'double');
% or typecast(uint8 ([data(260), data(259), data(258) ,data(257), data(256), data(255), data(254), data(253)]),'double');
disp(q_joint_1);
pause(1);
© www.soinside.com 2019 - 2024. All rights reserved.