|
| 1 | +:github_url: https://github.com/UniversalRobots/Universal_Robots_Client_Library/blob/master/doc/examples/dashboard_client.rst |
| 2 | + |
| 3 | +Dashboard client example |
| 4 | +======================== |
| 5 | + |
| 6 | +This example shows how to use the builtin `Dashboard server <https://www.universal-robots.com/articles/ur-articles/dashboard-server-e-series-port-29999/>`_ to communicate with a robot. |
| 7 | + |
| 8 | +.. note:: |
| 9 | + |
| 10 | + The Dashboard Server is only available on CB3 and e-Series robots. It is not available on |
| 11 | + PolyScope X. |
| 12 | + |
| 13 | + |
| 14 | +The `dashboard_example.cpp <https://github.com/UniversalRobots/Universal_Robots_Client_Library/blob/master/examples/dashboard_example.cpp>`_ shows how to use this class: |
| 15 | + |
| 16 | +.. note:: For the following example to work on an e-Series (PolyScope 5) robot, the robot has to be |
| 17 | + in *remote control mode*. |
| 18 | + |
| 19 | +.. literalinclude:: ../../examples/dashboard_example.cpp |
| 20 | + :language: c++ |
| 21 | + :caption: examples/dashboard_example.cpp |
| 22 | + :linenos: |
| 23 | + :lineno-match: |
| 24 | + :start-at: std::make_unique<DashboardClient> |
| 25 | + :end-at: my_dashboard->commandCloseSafetyPopup(); |
| 26 | + |
| 27 | +At first, a ``DashboardClient`` object is created with the IP address of the robot. Then, the |
| 28 | +client is connected to the robot. After that, the client sends a command to the robot and receives |
| 29 | +the answer. |
| 30 | + |
| 31 | +Some commands support getting the response from the robot. For example, the |
| 32 | +``commandPolyScopeVersion()`` function: |
| 33 | + |
| 34 | +.. literalinclude:: ../../examples/dashboard_example.cpp |
| 35 | + :language: c++ |
| 36 | + :caption: examples/dashboard_example.cpp |
| 37 | + :linenos: |
| 38 | + :lineno-match: |
| 39 | + :start-at: // Get the PolyScope version |
| 40 | + :end-at: URCL_LOG_INFO(version.c_str()); |
| 41 | + |
| 42 | + |
| 43 | +The ``DashboardClient`` can easily be used to cycle through the robot's states, for example for |
| 44 | +initialization: |
| 45 | + |
| 46 | +.. literalinclude:: ../../examples/dashboard_example.cpp |
| 47 | + :language: c++ |
| 48 | + :caption: examples/dashboard_example.cpp |
| 49 | + :linenos: |
| 50 | + :lineno-match: |
| 51 | + :start-at: // Power it on |
| 52 | + :end-at: // Load existing program |
| 53 | + |
| 54 | +All commands are blocking and will wait for the necessary action being done. The dashboard server's |
| 55 | +response will be compared with an expected response. For example, when calling |
| 56 | +``commandPowerOn(timeout)``, it is checked that the dashboard server is answering ``"Powering on"`` and |
| 57 | +then it is queried until the robot reports ``"Robotmode: IDLE"`` or until the timeout is reached. |
| 58 | +The example contains more commands that follow the same scheme. |
| 59 | + |
| 60 | + |
| 61 | +If you want to send a query / command to the dashboard server and only want to receive the |
| 62 | +response, you can use the ``sendAndReceive()`` function: |
| 63 | + |
| 64 | +.. literalinclude:: ../../examples/dashboard_example.cpp |
| 65 | + :language: c++ |
| 66 | + :caption: examples/dashboard_example.cpp |
| 67 | + :linenos: |
| 68 | + :lineno-match: |
| 69 | + :start-at: // Make a raw request and save the response |
| 70 | + :end-at: URCL_LOG_INFO("Program state: %s", program_state.c_str()); |
| 71 | + |
| 72 | +For checking the response against an expected regular expression use ``sendRequest()``: |
| 73 | + |
| 74 | +.. literalinclude:: ../../examples/dashboard_example.cpp |
| 75 | + :language: c++ |
| 76 | + :caption: examples/dashboard_example.cpp |
| 77 | + :linenos: |
| 78 | + :lineno-match: |
| 79 | + :start-at: // The response can be checked with a regular expression |
| 80 | + :end-at: URCL_LOG_INFO("Power off command success: %d", success); |
| 81 | + |
| 82 | + |
0 commit comments