Skip to content

Commit 78875f5

Browse files
committed
Add documentation for all examples
* Move ur_driver example docs to examples subfolder * Update example documentation for ur_driver example * Add dashboard_client example documentation * Add documentation for force_mode example * Add documentation for freedrive mode example * Add instruction_executor example doc * Add example documentation for primary_pipeline * Add example documentation for primary_pipeline_calibration * Add example documentation for RTDE client * Add documentation for script sender example * Add example documentation for tool contact * Add example documentation for spline example * Add example documentation for trajectory_point_interface
1 parent f4a563e commit 78875f5

27 files changed

+1027
-195
lines changed

doc/architecture/instruction_executor.rst

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _instruction_executor:
2+
13
Instruction Executor
24
====================
35

@@ -21,12 +23,4 @@ for sending motion instructions to the robot. Hence, it requires a :ref:`ur_driv
2123
Therefore, all parameters and restrictions of these functions apply. For example, velocity and
2224
acceleration parameters will be ignored if there is a time > 0 given.
2325

24-
As a minimal working example, please see ``examples/instruction_executor.cpp`` example:
25-
26-
.. literalinclude:: ../../examples/instruction_executor.cpp
27-
:language: c++
28-
:caption: examples/instruction_executor.cpp
29-
:linenos:
30-
:lineno-match:
31-
:start-at: g_my_driver.reset
32-
:end-at: g_my_driver->stopControl();
26+
As a minimal working example, please see the :ref:`instruction_executor_example`.

doc/architecture/script_sender.rst

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,7 @@ corresponding request when starting a program on the robot that contains the **E
1313
program node. In order to work properly, make sure that the IP address and script sender port are
1414
configured correctly on the robot.
1515

16-
The following example creates a ``ScriptSender`` listening on port ``12345`` and sends the script
17-
``textmsg("Hello, World!")`` when requested. A fully compilable example can be found in `script_sender.cpp <https://github.com/UniversalRobots/Universal_Robots_Client_Library/blob/master/examples/script_sender.cpp>`_
18-
19-
.. literalinclude:: ../../examples/script_sender.cpp
20-
:language: c++
21-
:caption: examples/script_sender.cpp
22-
:linenos:
23-
:lineno-match:
24-
:start-at: constexpr uint32_t PORT
16+
An example of how to use the ``ScriptSender`` class can be found in the :ref:`script_sender_example`.
2517

2618
.. note::
2719
PolyScope X users cannot use the URCap linked above. There is a development version of a URCapX

doc/example.rst

Lines changed: 0 additions & 12 deletions
This file was deleted.

doc/examples.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Usage examples
2+
==============
3+
4+
This library contains a number of examples how this library can be used. You can use them as a
5+
starting point for your own applications.
6+
7+
All examples take a robot's IP address as a first argument and some of them take a maximum run
8+
duration (in seconds) as second argument. If the second argument is omitted, some of the examples
9+
may be running forever until manually stopped.
10+
11+
.. note:: Most of these examples use the driver's headless mode. Therefore, on an e-Series (PolyScope 5) robot, the robot has to be
12+
in *remote control mode* to work.
13+
14+
.. toctree::
15+
:maxdepth: 1
16+
17+
examples/dashboard_client
18+
examples/force_mode
19+
examples/freedrive
20+
examples/instruction_executor
21+
examples/primary_pipeline
22+
examples/primary_pipeline_calibration
23+
examples/rtde_client
24+
examples/script_sender
25+
examples/spline_example
26+
examples/tool_contact_example
27+
examples/trajectory_point_interface
28+
examples/ur_driver

doc/examples/dashboard_client.rst

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+

doc/examples/force_mode.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
:github_url: https://github.com/UniversalRobots/Universal_Robots_Client_Library/blob/master/doc/examples/force_mode.rst
2+
3+
Force Mode example
4+
==================
5+
6+
The ``ur_client_library`` supports leveraging the robot's force mode directly. An example on how to
7+
use it can be found in `force_mode_example.cpp <https://github.com/UniversalRobots/Universal_Robots_Client_Library/blob/master/examples/force_mode_example.cpp>`_.
8+
9+
In order to utilize force mode, we'll have to create and initialize a full ``UrDriver`` object
10+
first:
11+
12+
.. literalinclude:: ../../examples/force_mode_example.cpp
13+
:language: c++
14+
:caption: examples/force_mode_example.cpp
15+
:linenos:
16+
:lineno-match:
17+
:start-at: // Now the robot is ready to receive a program
18+
:end-at: // End of initialization
19+
20+
Start force mode
21+
----------------
22+
23+
After that, we can start force mode by calling the ``startForceMode()`` function:
24+
25+
.. literalinclude:: ../../examples/force_mode_example.cpp
26+
:language: c++
27+
:caption: examples/force_mode_example.cpp
28+
:linenos:
29+
:lineno-match:
30+
:start-at: // Start force mode
31+
:end-at: if (!success)
32+
33+
All parameters for the force mode are included into the ``startForceMode()`` function call. If you
34+
want to change the parameters, e.g. change the forces applied, you can simply call
35+
``startForceMode()`` again with the new parameters.
36+
37+
.. note::
38+
CB3 robots don't support specifying force_mode's ``gain_scaling``, so there are two different
39+
functions available.
40+
41+
Once force mode is started successfully, we'll have to send keepalive messages to the robot in
42+
order to keep the communication active:
43+
44+
.. literalinclude:: ../../examples/force_mode_example.cpp
45+
:language: c++
46+
:caption: examples/force_mode_example.cpp
47+
:linenos:
48+
:lineno-match:
49+
:start-at: std::chrono::duration<double> time_done(0);
50+
:end-at: URCL_LOG_INFO("Timeout reached.");
51+
52+
Stop force mode
53+
---------------
54+
55+
Once finished, force_mode can be stopped by calling ``endForceMode()``.
56+
57+
.. literalinclude:: ../../examples/force_mode_example.cpp
58+
:language: c++
59+
:caption: examples/force_mode_example.cpp
60+
:linenos:
61+
:lineno-match:
62+
:start-at: endForceMode()
63+
:end-at: endForceMode()

doc/examples/freedrive.rst

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
:github_url: https://github.com/UniversalRobots/Universal_Robots_Client_Library/blob/master/doc/examples/freedrive.rst
2+
3+
Freedrive Mode example
4+
======================
5+
6+
`Freedrive
7+
<https://www.universal-robots.com/manuals/EN/HTML/SW5_20/Content/prod-scriptmanual/G5/freedrive_mode.htm>`_
8+
allows the robot arm to be manually pulled into desired positions and/or poses. The joints move
9+
with little resistance because the brakes are released.
10+
11+
An example to utilize the freedrive mode can be found in the `freedrive_example.cpp <https://github.com/UniversalRobots/Universal_Robots_Client_Library/blob/master/examples/freedrive_example.cpp>`_.
12+
13+
.. note:: For the following example to work on an e-Series (PolyScope 5) robot, the robot has to be
14+
in *remote control mode*.
15+
16+
At first, we create a ``ExampleRobotWrapper`` object in order to initialize communication with the
17+
robot.
18+
19+
.. literalinclude:: ../../examples/freedrive_example.cpp
20+
:language: c++
21+
:caption: examples/freedrive_example.cpp
22+
:linenos:
23+
:lineno-match:
24+
:start-at: bool headless_mode = true;
25+
:end-before: URCL_LOG_INFO("Starting freedrive mode");
26+
27+
28+
Start freedrive mode
29+
--------------------
30+
31+
The ``UrDriver`` provides a method to start freedrive mode directly:
32+
33+
.. literalinclude:: ../../examples/freedrive_example.cpp
34+
:language: c++
35+
:caption: examples/freedrive_example.cpp
36+
:linenos:
37+
:lineno-match:
38+
:start-at: URCL_LOG_INFO("Starting freedrive mode");
39+
:end-at: sendFreedriveMessageOrDie(control::FreedriveControlMessage::FREEDRIVE_START);
40+
41+
As it is potentially dangerous to leave the robot in freedrive mode, the robot program expect
42+
frequent keepalive messages to verify that the remote connection is still available and freedrive
43+
mode is being expected to be active.
44+
45+
Freedrive mode will be active from this point on until it is either stopped, or no keepalive
46+
message is received by the robot anymore.
47+
48+
Therefore, we have to make sure to send regular keepalive messages to the robot. The following
49+
section will keep freedrive mode active for a period of time defined in ``seconds_to_run``.
50+
51+
.. literalinclude:: ../../examples/freedrive_example.cpp
52+
:language: c++
53+
:caption: examples/freedrive_example.cpp
54+
:linenos:
55+
:lineno-match:
56+
:start-at: std::chrono::duration<double> time_done(0);
57+
:end-before: sendFreedriveMessageOrDie(control::FreedriveControlMessage::FREEDRIVE_STOP);
58+
59+
Stop force Mode
60+
---------------
61+
62+
To stop force mode either stop sending keepalive signals or request deactivating it explicitly:
63+
64+
.. literalinclude:: ../../examples/freedrive_example.cpp
65+
:language: c++
66+
:caption: examples/freedrive_example.cpp
67+
:linenos:
68+
:lineno-match:
69+
:start-at: sendFreedriveMessageOrDie(control::FreedriveControlMessage::FREEDRIVE_STOP);
70+
:end-at: sendFreedriveMessageOrDie(control::FreedriveControlMessage::FREEDRIVE_STOP);
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
:github_url: https://github.com/UniversalRobots/Universal_Robots_Client_Library/blob/master/doc/examples/instruction_executor.rst
2+
3+
.. _instruction_executor_example:
4+
5+
Instruction Executor example
6+
============================
7+
8+
This example shows how to use the :ref:`instruction_executor` class. It can be used for easily
9+
executing a sequence of instructions such as motions on the robot using the built-in URScript functions.
10+
11+
The `instruction_executor.cpp <https://github.com/UniversalRobots/Universal_Robots_Client_Library/blob/master/examples/instruction_executor.cpp>`_ shows how to use this class:
12+
13+
.. note:: For the instruciton executor to work there has to be an established connection to the
14+
:ref:`reverse_interface`. That means, the respective program has to be running on the robot. The
15+
example below will do that automatically, if the connected robot is in *remote_control* mode.
16+
17+
18+
.. literalinclude:: ../../examples/instruction_executor.cpp
19+
:language: c++
20+
:caption: examples/instruction_executor.cpp
21+
:linenos:
22+
:lineno-match:
23+
:start-at: std::unique_ptr<urcl::ToolCommSetup> tool_comm_setup;
24+
:end-at: auto instruction_executor = std::make_shared<urcl::InstructionExecutor>(g_my_driver);
25+
26+
At first, a ``InstructionExecutor`` object is created with the URDriver object as it needs that
27+
for communication with the robot.
28+
29+
Currently, the ``InstructionExecutor`` can either be used to run sequences of motions or single motions.
30+
31+
Execute a sequence of motions
32+
-----------------------------
33+
34+
To run a sequence of motions, create an
35+
``std::vector<std::shared_ptr<urcl::cointrol::MotionPrimitive>>`` and pass it to the
36+
``executeMotion`` function:
37+
38+
.. literalinclude:: ../../examples/instruction_executor.cpp
39+
:language: c++
40+
:caption: examples/instruction_executor.cpp
41+
:linenos:
42+
:lineno-match:
43+
:start-at: // Trajectory definition
44+
:end-at: instruction_executor->executeMotion(motion_sequence);
45+
46+
Each element in the motion sequence can be a different motion type. In the example, there are two
47+
``MoveJ`` motions and two ``MoveL`` motion. The primitives' parameters are directly forwarded to
48+
the underlying script functions, so the parameter descriptions for them apply, as well.
49+
Particularly, you may want to choose between either a time-based execution speed or an acceleration
50+
/ velocity parametrization. The latter will be ignored if a time > 0 is given.
51+
52+
Execute a single motion
53+
-----------------------
54+
55+
To run a single motion, the ``InstructionExecutor`` provides the methods ``moveJ(...)`` and
56+
``moveL(...)``:
57+
58+
.. literalinclude:: ../../examples/instruction_executor.cpp
59+
:language: c++
60+
:caption: examples/instruction_executor.cpp
61+
:linenos:
62+
:lineno-match:
63+
:start-at: double goal_time_sec = 2.0;
64+
:end-before: g_my_driver->stopControl();
65+
66+
Again, time parametrization has priority over acceleration / velocity parameters.

0 commit comments

Comments
 (0)