您好!欢迎光临工博士商城

ABB工业beplay网站入口 服务商

产品:110
联系我们
您当前的位置: 首页? 新闻中心? ABB机器人socket做server示例程序
beplay新网址
新闻中心
ABB机器人socket做server示例程序
发布时间:2023-01-30 浏览次数:56 返回列表
1. ABB机器人进行socket通讯,支持机器人做socket的client连接其他设备,也支持机器人作为socket的server,被其他设备进行连接。
2.作为server时,需要考虑其他客户端连接机器人时断开后的机器人异常处理。同时,机器人作为socket 的server,通常编写测试完成后,对应的task会被设为semi static(即开机自启动,且前台无法停止程序,除非程序出错或者再次进入controller的task设定,将task类型设为normal)
3.此处推荐Ros编写的机器人作为socket server的代码,以供参考。相关代码可以从https://github.com/ros-industrial/abb_driver/tree/kinetic-devel/rapid 下载
主程序如下:
MODULE ROS_stateServer
!程序运行模式设定为循环
LOCAL CONST num server_port := 11002;
LOCAL CONST num update_rate := 0.10; ! broadcast rate (sec)
LOCAL VAR socketdev server_socket;
LOCAL VAR socketdev client_socket;
PROC main()
TPWrite "StateServer: Waiting for connection.";
ROS_init_socket server_socket, server_port;
ROS_wait_for_client server_socket, client_socket;
WHILE (TRUE) DO
send_joints;
send_status;
WaitTime update_rate;
ENDWHILE
ERROR (ERR_SOCK_TIMEOUT, ERR_SOCK_CLOSED)
IF (ERRNO=ERR_SOCK_TIMEOUT) OR (ERRNO=ERR_SOCK_CLOSED) THEN
SkipWarn; ! TBD: include this error data in the message logged below?
ErrWrite \W, "ROS StateServer disconnect", "Connection lost. Waiting for new connection.";
ExitCycle; ! restart program
!程序运行模式设定为循环,这样ExitCycle可以重新从main***行开始运行
ELSE
TRYNEXT;
ENDIF
UNDO
ENDPROC
ENDMODULE
MODULE ROS_socket(SYSMODULE)
PROC ROS_init_socket(VAR socketdev server_socket, num port)
IF (SocketGetStatus(server_socket) = SOCKET_CLOSED) SocketCreate server_socket;
IF (SocketGetStatus(server_socket) = SOCKET_CREATED) SocketBind server_socket, GetSysInfo(\LanIp), port;
IF (SocketGetStatus(server_socket) = SOCKET_BOUND) SocketListen server_socket;
ERROR
RAISE; ! raise errors to calling code
ENDPROC
PROC ROS_wait_for_client(VAR socketdev server_socket, VAR socketdev client_socket, \num wait_time)
VAR string client_ip;
VAR num time_val := WAIT_MAX; ! default to wait-forever
IF Present(wait_time) time_val := wait_time;
IF (SocketGetStatus(client_socket) <> SOCKET_CLOSED) SocketClose client_socket;
WaitUntil (SocketGetStatus(client_socket) = SOCKET_CLOSED);
SocketAccept server_socket, client_socket, \ClientAddress:=client_ip, \Time:=time_val;
TPWrite "Client at "+client_ip+" connected.";
ERROR
RAISE; ! raise errors to calling code
! 所有的错误处理使用Raise,即调用上层统一进行错误处理
ENDPROC
ENDMODULE



联系热线:18717873382 联系人:郑经理 联系地址:上海市宝山区富联一路98弄6号

技术和报价服务:星期一至星期六8:00-22:00ABB工业beplay网站入口 服务商

Baidu
map