{"id":2788,"date":"2021-08-22T08:08:13","date_gmt":"2021-08-22T08:08:13","guid":{"rendered":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/?page_id=2788"},"modified":"2023-01-21T05:27:35","modified_gmt":"2023-01-21T05:27:35","slug":"matlab-client-interface","status":"publish","type":"page","link":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/matlab-client-interface\/","title":{"rendered":"Matlab &#8211; Client interface."},"content":{"rendered":"\n<p><a title=\"Visit Zacobria &amp; Webshop &amp; Universal-Robots solutions.\" href=\"https:\/\/www.zacobria.com\/automation\/webshop\/\">Visit Zacobria Webshop<\/a><\/p>\n\n\n\n<p><strong>Client-Interfaces &#8211; reading the cartesian coordinates (sometimes reffered to as matlab data).<\/strong><\/p>\n\n\n\n<p><strong>Application Description:<\/strong><br>This example shows the use of client-Interfaces (Also sometimes reffered to as Matlab data) on the Universal-Robots to read the robot position from external device.<\/p>\n\n\n\n<p>The application uses the port 30003 on the Universal-Robots which is streaming data out containing informations about the robot status. These data might look like random unreadable data similar to data in a binary file, but thats because the way the data are formatted.<\/p>\n\n\n\n<p>Below is a screen shoot of the dataflow streamed out from port 30003.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips\/wp-content\/uploads\/2017\/01\/universal-robots-zacobria-client-interfaces-port-30003-matlab-data-1.jpg\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips\/wp-content\/uploads\/2017\/01\/universal-robots-zacobria-client-interfaces-port-30003-matlab-data-1.jpg\" alt=\"universal-robots-zacobria-client-interfaces-port-30003-matlab-data-1\" class=\"wp-image-1912\"\/><\/a><\/figure>\n\n\n\n<p>Port 30003 is part of the Client-Interfaces and an overview can be found at this link. <a href=\"https:\/\/www.universal-robots.com\/how-tos-and-faqs\/how-to\/ur-how-tos\/overview-of-client-interfaces-21744\/\">Client-Interfaces document<\/a><\/p>\n\n\n\n<p>A file containing more informations about these data called Client-Interface.xls can be found at this link <a href=\"https:\/\/www.universal-robots.com\/how-tos-and-faqs\/how-to\/ur-how-tos\/remote-control-via-tcpip-16496\/\">Client-Interfaces document<\/a><\/p>\n\n\n\n<p>In the file Client-Interface.xls at the tab RealTime_3.2 and overview of the data streamed out can be found and where each data can be found in the data stream.<\/p>\n\n\n\n<p>Notice the data for cartesian coordinates shown in line 14 is of type double and has a size of 48 bytes.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips\/wp-content\/uploads\/2017\/01\/universal-robots-zacobria-client-interfaces-cartesian-matlab-data-1.jpg\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips\/wp-content\/uploads\/2017\/01\/universal-robots-zacobria-client-interfaces-cartesian-matlab-data-1.jpg\" alt=\"universal-robots-zacobria-client-interfaces-cartesian-matlab-data-1\" class=\"wp-image-1913\"\/><\/a><\/figure>\n\n\n\n<p><strong>Function description:<\/strong><\/p>\n\n\n\n<p>The aim is to read the Cartiseian coordinates of the tool (X, Y, Z, Rx, Ry, Rz).<\/p>\n\n\n\n<p>(This is similar to reading these data from the MODBUS registers as described in this article <a href=\"http:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips\/knowledge-base\/modbus-registers-read-position\/\">MODBUS example of reading the Cartesian position data<\/a>.)<\/p>\n\n\n\n<p>In this case the cartesian coordinate data are read from a external host with Python code.<\/p>\n\n\n\n<p><strong>Program description:<\/strong><br>The external host connects to port 30003 on the UR and continually reads the dataflow which the robot stream out and convert the raw data to readable data in mm.<\/p>\n\n\n\n<p>Since the desired data is located some way down the list as shown in client-interfaces.xls document &#8211; therefore the previous data are read first, but not converted and shown.<\/p>\n\n\n\n<p>This means blocks of 4 + 8 + 48 + 48 + 48 + 48 + 48 + 48 + 48 + 48 + 48 are read first, but not converted and not shown.<\/p>\n\n\n\n<p>The next block of 48 bytes contain the data desired &#8211; and since the data consists of 6 values (each value therefore contain 8 bytes) then each value of 8 bytes are read one by one and printed out to the screen.<\/p>\n\n\n\n<p>The data are formatted as double and therefore they are converted in human readable data. Some more informations about double can be found at this link <a href=\"https:\/\/en.wikipedia.org\/wiki\/Double-precision_floating-point_format\">Double-precision floating-point format<\/a>.<\/p>\n\n\n\n<p><strong>Program code:<\/strong><\/p>\n\n\n\n<p><strong>No program on UR.<\/strong><\/p>\n\n\n\n<p><strong>Host program in Python code.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Echo client program\nimport socket\nimport time\nimport struct\n\nHOST = \"192.168.0.9\" # The remote host\nPORT_30003 = 30003\n\nprint \"Starting Program\"\n\ncount = 0\nhome_status = 0\nprogram_run = 0\n\nwhile (True):\n if program_run == 0:\n try:\n s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n s.settimeout(10)\n s.connect((HOST, PORT_30003))\n time.sleep(1.00)\n print \"\"\n packet_1 = s.recv(4)\n packet_2 = s.recv(8)\n packet_3 = s.recv(48)\n packet_4 = s.recv(48)\n packet_5 = s.recv(48)\n packet_6 = s.recv(48)\n packet_7 = s.recv(48) \n packet_8 = s.recv(48)\n packet_9 = s.recv(48)\n packet_10 = s.recv(48)\n packet_11 = s.recv(48)\n\n packet_12 = s.recv(8)\n packet_12 = packet_12.encode(\"hex\") #convert the data from \\x hex notation to plain hex\n x = str(packet_12)\n x = struct.unpack('!d', packet_12.decode('hex'))[0]\n print \"X = \", x * 1000\n\n packet_13 = s.recv(8)\n packet_13 = packet_13.encode(\"hex\") #convert the data from \\x hex notation to plain hex\n y = str(packet_13)\n y = struct.unpack('!d', packet_13.decode('hex'))[0]\n print \"Y = \", y * 1000\n\n packet_14 = s.recv(8)\n packet_14 = packet_14.encode(\"hex\") #convert the data from \\x hex notation to plain hex\n z = str(packet_14)\n z = struct.unpack('!d', packet_14.decode('hex'))[0]\n print \"Z = \", z * 1000\n\n packet_15 = s.recv(8)\n packet_15 = packet_15.encode(\"hex\") #convert the data from \\x hex notation to plain hex\n Rx = str(packet_15)\n Rx = struct.unpack('!d', packet_15.decode('hex'))[0]\n print \"Rx = \", Rx\n\n packet_16 = s.recv(8)\n packet_16 = packet_16.encode(\"hex\") #convert the data from \\x hex notation to plain hex\n Ry = str(packet_16)\n Ry = struct.unpack('!d', packet_16.decode('hex'))[0]\n print \"Ry = \", Ry\n\n packet_17 = s.recv(8)\n packet_17 = packet_17.encode(\"hex\") #convert the data from \\x hex notation to plain hex\n Rz = str(packet_17)\n Rz = struct.unpack('!d', packet_17.decode('hex'))[0]\n print \"Rz = \", Rz\n\n home_status = 1\n program_run = 0\n s.close()\n except socket.error as socketerror:\n print(\"Error: \", socketerror)\nprint \"Program finish\"\n\n<\/pre>\n\n\n\n<p><strong>Program run:<\/strong><\/p>\n\n\n\n<p>The robot is in this position &#8211; Notice the X, Y, Z, Rx, Ry, Rz values in the Move screen.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips\/wp-content\/uploads\/2017\/01\/universal-robots-zacobria-client-interfaces-port-30003-matlab-data-2.jpg\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips\/wp-content\/uploads\/2017\/01\/universal-robots-zacobria-client-interfaces-port-30003-matlab-data-2.jpg\" alt=\"universal-robots-zacobria-client-interfaces-port-30003-matlab-data-2\" class=\"wp-image-1918\"\/><\/a><\/figure>\n\n\n\n<p>Below is the printout on the screen with the X, Y, Z, Rx, Ry, Rz values when the Python program is executed. The values are collected from port 30003 and correspond with the actual values of the robot position. The X, Y, Z are in mm and Rx, Ry, Rz are in radians.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips\/wp-content\/uploads\/2017\/01\/universal-robots-zacobria-client-interfaces-port-30003-matlab-data-3.jpg\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips\/wp-content\/uploads\/2017\/01\/universal-robots-zacobria-client-interfaces-port-30003-matlab-data-3.jpg\" alt=\"universal-robots-zacobria-client-interfaces-port-30003-matlab-data-3\" class=\"wp-image-1920\"\/><\/a><\/figure>\n\n\n\n<p>And this is also the position of the robot.<\/p>\n\n\n\n<p>Notice: Data of a very small value is written as exponent of 10 \u2013 and a value of 10-05 is very small \u2013 and is virtual 0.<\/p>\n\n\n\n<p>X = 0.0<br>Y = 300.0<br>Z = 300.0<br>Rx = 0.0<br>Ry = 3.14<br>Rz = 0.0<\/p>\n\n\n\n<p><strong>Disclaimer:<\/strong> While the Zacobria Pte. Ltd. believes that information and guidance provided is correct, parties must rely upon their skill and judgement when making use of them. Zacobria Pte. Ltd. assumes no liability for loss or damage caused by error or omission, whether such an error or omission is the result of negligence or any other cause. Where reference is made to legislation it is not to be considered as legal advice. Any and all such liability is disclaimed.<\/p>\n\n\n\n<p>If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.<\/p>\n\n\n\n<p>Author:<br><a href=\"https:\/\/plus.google.com\/u\/0\/116832821661215606670?rel=author\">By Zacobria Lars Skovsgaard<\/a><br>Accredited 2015-2018 Universal Robots support Centre and Forum.<br><br><\/p>\n\n\n\n<p><a href=\"https:\/\/twitter.com\/share\">Tweet<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/twitter.com\/zacobria\">Follow @zacobria<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visit Zacobria Webshop Client-Interfaces &#8211; reading the cartesian coordinates (sometimes reffered to as matlab data). Application Description:This example shows the use of client-Interfaces (Also sometimes reffered to as Matlab data) on the Universal-Robots to read the robot position from external&#8230; <\/p>\n<div class=\"more-link-container\"><a class=\"more-link\" href=\"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/matlab-client-interface\/\">Read More<\/a><\/div>\n","protected":false},"author":1,"featured_media":2481,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"templates\/full-width-page.php","meta":{"footnotes":""},"class_list":["post-2788","page","type-page","status-publish","has-post-thumbnail","hentry"],"_links":{"self":[{"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/pages\/2788","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/comments?post=2788"}],"version-history":[{"count":4,"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/pages\/2788\/revisions"}],"predecessor-version":[{"id":3097,"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/pages\/2788\/revisions\/3097"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/media\/2481"}],"wp:attachment":[{"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/media?parent=2788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}