ABB机器人与Halcon通讯——ABB机器人配件
声明:本媒体部分图片、文章来源于网络
版权归原作者所有,如有侵权,请与我联系删除。
1. HALCON 为现在主流工业视觉处理软件,提供各类视觉识别算子,提供不同软件接口,也可通过HALCON HDevelop进行编程处理,如下图
2. 在视觉处理前后,通常都需要和外设(例如机器人)进行通讯,此处举例socket通讯
3. 在HALCON的HELP中,提供了详细的示例代码。
4. 此处举例HALCON作为socket通讯的server,机器人作为socket通讯的client
5. 在HALCON创建如下代码
Protocol := 'TCP4'
Timeout := 10.0
*
* 创建一个监听,设置端口为4660,超时为10s
open_socket_accept (4660, ['protocol','timeout'], [Protocol,Timeout], AcceptingSocket)
* Strip AddressFamily from Protocl
tuple_regexp_match (Protocol, 'TCP|HALCON', BaseProtocol)
if (BaseProtocol == 'TCP' or BaseProtocol == 'HALCON')
* Wait for an incoming connection, use the timeout of the
* AcceptingSocket
dev_error_var (Error, 1)
dev_set_check ('~give_error')
OpenStatus := 5
while (OpenStatus != 2)
socket_accept_connect (AcceptingSocket, 'auto', Socket)
OpenStatus := Error
endwhile
dev_set_check ('give_error')
* Set the same timeout on the newly created socket
set_socket_param (Socket, 'timeout', Timeout)
else
* UDP sockets do not need an accept()
Socket := AcceptingSocket
endif
get_socket_param (Socket, 'address_info', Address)
*
Answer := []
while (Answer != 'End')
receive_data (Socket, 'z', Answer, From)
To:=[]
Data:='received '+Answer
Format := 'z'
send_data (Socket, Format, Data, To)
endwhile
stop ()
close_socket (Socket)
close_socket (AcceptingSocket)
6. 在机器人端创建如下代码
PROC main1()
VAR robtarget ptmp;
VAR string send_string;
SocketClose socket1;
SocketCreate socket1;
SocketConnect socket1,"127.0.0.1",4660\Time:=WAIT_MAX;
SocketSend socket1\Str:="Hello Halcon"+" "+CTime();
SocketReceive socket1\Str:=received_string\Time:=WAIT_MAX;
TPWrite "Server wrote - "+received_string;
SocketSend socket1\Str:="End";
SocketReceive socket1\Str:=received_string\Time:=WAIT_MAX;
TPWrite "Server wrote - "+received_string;
received_string:="";
ERROR
SocketClose socket1;
7. 先运行HALCON的server,再运行机器人端的client程序。
8. HALCON会先接受机器人发来的Hello Halcon,再将接受到的数据发送回机器人
更多资讯:ABB机器人配件