Skip to main content
Glama

nUR MCP Server

by nonead
realTimeClient.cpython-312.pyc14.7 kB
� #0h 2��z�dZdZdZdZddlZddlZddlZddlZddlZddl Z ddl Z dZ Gd�d�Z Gd �d e�Zy) aw Python 3.x library to control an UR robot through its TCP/IP interfaces Copyright (C) 2017 Martin Huus Bjerge, Rope Robotics ApS, Denmark Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL "Rope Robotics ApS" BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the name of "Rope Robotics ApS" shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from "Rope Robotics ApS". zMartin Huus Bjergez*Copyright 2017, Rope Robotics ApS, Denmarkz MIT License�Ng�?c� �eZdZdZdZdZdZdZy)�ConnectionStater����N)�__name__� __module__� __qualname__�ERROR� DISCONNECTED� CONNECTED�PAUSED�STARTED���XD:\mcp\Nonead-Universal-Robots-MCP\Nonead-Universal-Robots-MCP\URBasic\realTimeClient.pyrr&s�� �E��L��I� �F��Grrc�J�eZdZdZd�Zd�Zd�Zd�Zd d�Zd d�Z d�Z d �Z d �Z y ) �RealTimeClienta� Interface to UR robot Real Time Client interface. For more detailes see this site: http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/remote-control-via-tcpip-16496/ The Real Time Client in this version is only used to send program and script commands to the robot, not to read data from the robot, all data reading is done via the RTDE interface. The constructor takes a UR robot hostname as input, and a RTDE configuration file. Input parameters: host (string): hostname or IP of UR Robot (RT CLient server) conf_filename (string): Path to xml file describing what channels to activate Example: rob = URBasic.realTimeClient.RT_CLient('192.168.56.101') self.close_rtc() c�|� ||_t j |j_d|_d|_ d|_ y)zB Constructor see class description for more info. �<N) � isinstance�URBasic� robotModel� RobotModel�_RealTimeClient__robotModelrr �rtcConnectionState�!_RealTimeClient__reconnectTimeout�_RealTimeClient__sock�_RealTimeClient__thread)�selfrs r�__init__zRealTimeClient.__init__Cs9�� �&���/>�/K�/K����,�"$����� ��� rc�<�|jrytj�}tj�|z |jk�rW|jjt j k�r/ tjtjtj�|_|jjtjtjd�|jjtjtjd�|jjt �|jj#|jj$df�t j |j_tj&d�yy#tj(tj*f$r d|_YnwxYwtj�|z |jks�V|jjt j kr�����)z� Initialize RT Client connection to host . Return value: success (boolean) Example: rob = URBasic.realTimeClient.RT_CLient('192.168.56.101') rob.connect() Tri3ug�?NF)r�timerrrrr�socket�AF_INET� SOCK_STREAM� setsockopt� IPPROTO_TCP� TCP_NODELAY� SOL_SOCKET� SO_REUSEADDR� settimeout�DEFAULT_TIMEOUT�connect� ipAddress�sleep�timeout�error)r!�t0s r� __connectzRealTimeClient.__connectPsf�� �;�;�� �Y�Y�[���y�y�{�2�~�d�5�5�5�4�;L�;L�;_�;_�bq�b{�b{�;{� #�$�m�m�F�N�N�F�<N�<N�O�� �� � �&�&�v�'9�'9�6�;M�;M�q�Q�� � �&�&�v�'8�'8�&�:M�:M�q�Q�� � �&�&��7�� � �#�#�T�%6�%6�%@�%@�%�$H�I�7F�7P�7P��!�!�4�� � �3��� �� �N�N�F�L�L�1� #�"�� � #���y�y�{�2�~�d�5�5�5�4�;L�;L�;_�;_�bq�b{�b{�;{�s�0D-F�*G � G c��|jr!|jj�d|_tj|j_y)z6 Disconnect the RT Client connection. NT)r�closerr rr�r!s r� DisconnectzRealTimeClient.Disconnectqs9�� �;�;� �K�K� � � ��D�K�/>�/K�/K����,�rc�P�|jjtjkDS)a< Returns True if the connection is open. Return value: status (boolean): True if connected and False of not connected. Example: rob = URBasic.realTimeClient.RT_CLient('192.168.56.101') rob.connect() print(rob.is_connected()) rob.disconnect() )rrrr r8s r�IsRtcConnectedzRealTimeClient.IsRtcConnected}s!��� � �3�3�o�6R�6R�R�Rrc���|j�s|j�s td�|jjry|j ��|jj rdd|j_|jj r,tjd�|jj r�,d|j_|j j�d|j_d|j_ |j|j|��tj|jd|i��|_|j j!�y)a Send a new command or program (string) to the UR controller. The command or program will be executed as soon as it's received by the UR controller. Sending a new command or program while stop and existing running command or program and start the new one. The program or command will also bee modified to include some control signals to be used for monitoring if a program execution is successful and finished. Input parameters: prg (string): A string containing a single command or a whole program. Example: rob = URBasic.realTimeClient.RT_CLient('192.168.56.101',logger=logger) rob.connect() rob.send_srt('set_digital_out(0, True)') rob.disconnect() �#SendProgram: Not connected to robotNT皙�����?F�prg)�target�kwargs)r;�_RealTimeClient__connect�printr�stopRunningFlagr �rtcProgramRunningr$r1�join�rtcProgramExecutionError�_RealTimeClient__sendPrg�"_RealTimeClient__AddStatusBit2Prog� threading�Thread�&_RealTimeClient__waitForProgram2Finish�start�r!r?s r� SendProgramzRealTimeClient.SendProgram�s ��"�"�"�$��>�>�#��;�<� � � � ,� ,� � �=�=� $�� � �2�2�48��!�!�1��'�'�9�9�4�:�:�c�?�d�'�'�9�9�49��!�!�1� �M�M� � � �/3����+�5:����2� ���t�/�/��4�5�!�(�(��0L�0L�V[�]`�Ua�b�� � � � ���rc��|j�s|j�s td�|jjryd|j_d|j_|j|�d|j_y)a� Send a new command (string) to the UR controller. The command or program will be executed as soon as it's received by the UR controller. Sending a new command or program while stop and existing running command or program and start the new one. The program or command will also bee modified to include some control signals to be used for monitoring if a program execution is successful and finished. Input parameters: prg (string): A string containing a single command or a whole program. Example: rob = URBasic.realTimeClient.RT_CLient('192.168.56.101',logger=logger) rob.connect() rob.send_srt('set_digital_out(0, True)') rob.disconnect() r=NTF)r;rBrCrrDrErGrHrNs r�SendzRealTimeClient.Send�so��$�"�"�$��>�>�#��;�<� � � � ,� ,� �/3����+�5:����2� ���s��.3����+rc�$�|jd�}|dk\r�t|�}|jddd�}t|�|k(ryttjd|��dkDrs|d||dzdjd�|zdz}t j |jd �|jd �g�}|j|d||d|d zd�}|S|jd �}|j|d||d|d zd�}|Sd |zdz}|S)z[ Modifying program to include status bit's in beginning and end of program zdef rz): z,): write_output_boolean_register(0, True) rFrNzend zend z* write_output_boolean_register(1, True) �endz9def script(): write_output_boolean_register(0, True) z. write_output_boolean_register(1, True) end )�find�len�replace�re�findall�np�max�rfind)r!r?�def1�prglen�mainprg� mainPrgEnds r�__AddStatusBit2Progz"RealTimeClient.__AddStatusBit2Prog�s9���x�x���� ��7���X�F��+�+�f�&V�WX�Y�C��3�x�6�!���B�J�J�v�s�+�,�a�/��a��D��F�G� � 1� 1�&� 9�$� >�q� @�A�� �f�f�g�m�m�F�&;�W�]�]�7�=S�%T�U� ��k�k�#�a� �"3�S��:�5F�Iw�5w�xy�z��� � !�Y�Y�u�-� ��k�k�#�a� �"3�S��:�5F�Iw�5w�xy�z��� �P�RU�U�YL�L�C�� rc��d}d|j_|jjs}|s{ tjg|jggt �\}}}t |�r+|jj|j��d}|jjs|s�{|sd|j_ tjd�y#d|_tj|j_ |j�Y�|xYw)z0 Sending program str via socket FTNr>)r�forceRemoteActiveFlagrD�selectrr.rU�send�encoderr rrBrEr$r1)r!r?� programSend�_�writables r� __sendPrgzRealTimeClient.__sendPrg�s���� �27����/��#�#�3�3�K� !�#)�=�=��d�k�k�]�B��#X� ��H�a��x�=��K�K�$�$�S�Z�Z�\�2�"&�K� �#�#�3�3�K��27�D� � � /� � � �3��� !�"�� �7F�7L�7L��!�!�4���� �s �A!C�8D c��t|�dz }d}d}|jj�s�|jj�r�|jj �j r$d|j_d|j_�n|jj�ddk(r|dz }||kDr�d|j_n�|jj�ddk(r2|jj�ddk(rd|j_n�|jj�ddk(rT|jj�jrd}n>|dz }|dkDr4d|j_d|j_nd|j_tjd�|jjs|jjr���|j|�d|j_y ) z/ waiting for program to finish �2rzmdef resetRegister(): write_output_boolean_register(0, False) write_output_boolean_register(1, False) end FTr� g�������?N) rUrrDrE� SafetyStatus�StoppedDueToSafetyrG�OutputBitRegister� RobotStatus�ProgramRunningr$r1rH)r!r?�waitForProgramStart�notrun�prgRests r�__waitForProgram2Finishz&RealTimeClient.__waitForProgram2Finish s���"�#�h�r�k����F���#�#�3�3��8I�8I�8[�8[�� � �-�-�/�B�B�6;��!�!�3�=A��!�!�:��"�"�4�4�6�q�9�U�B��!� ���/�/�:?�D�%�%�7��"�"�4�4�6�q�9�T�A�d�FW�FW�Fi�Fi�Fk�lm�Fn�rv�Fv�6;��!�!�3��"�"�4�4�6�q�9�T�A��$�$�0�0�2�A�A��F��a�K�F��b�y�>C��)�)�;�EI��)�)�B�7<��!�!�3� �J�J�t� �7�#�#�3�3��8I�8I�8[�8[�8 ���w��.3����+rN)�) r r r �__doc__r"rBr9r;rOrQrIrHrLrrrrr-s8���* ��B � S�*�Z 4�D�0�0$4rr)rw� __author__� __copyright__� __license__rr%rJrcrW�numpyrYr$r.r�objectrrrr�<module>r}sM���."� �<� �� �� �� � �� �����B4�V�B4r

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nonead/nUR-MCP-SERVER'

If you have feedback or need assistance with the MCP directory API, please join our Discord server