Skip to content

Commit aa97110

Browse files
committed
Add example documentation for primary_pipeline_calibration
1 parent 3b8c2fe commit aa97110

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

doc/examples.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Usage examples
44
This library contains a number of examples how this library can be used. You can use them as a
55
starting point for your own applications.
66

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+
711
.. note:: Most of these examples use the driver's headless mode. Therefore, on an e-Series (PolyScope 5) robot, the robot has to be
812
in *remote control mode* to work.
913

@@ -15,4 +19,5 @@ starting point for your own applications.
1519
examples/freedrive
1620
examples/instruction_executor
1721
examples/primary_pipeline
22+
examples/primary_pipeline_calibration
1823
examples/ur_driver
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
:github_url: https://github.com/UniversalRobots/Universal_Robots_Client_Library/blob/master/doc/examples/primary_pipeline_calibration.rst
2+
3+
.. _primary_pipeline_calibration_example:
4+
5+
Primary Pipeline Calibration example
6+
====================================
7+
8+
This example is very similar to the :ref:`primary_pipeline_example`. However, it uses a
9+
specialized consumer that will analyze the calibration data sent from the robot instead of the
10+
``ShellConsumer``.
11+
12+
Consumer setup
13+
--------------
14+
15+
This example uses a specialized type of consumer that stores data about the received robot
16+
calibration.
17+
18+
.. literalinclude:: ../../examples/primary_pipeline_calibration.cpp
19+
:language: c++
20+
:caption: examples/primary_pipeline_calibration.cpp
21+
:linenos:
22+
:lineno-match:
23+
:start-at: class CalibrationConsumer
24+
:end-at: };
25+
26+
Since the producer is reading every package from the primary interface, the consumer has to be able
27+
to consume any primary package.
28+
29+
Assemble the pipeline
30+
---------------------
31+
32+
The rest of the pipeline setup is the same as in the other pipeline example, just that we create a
33+
``CalibrationConsumer`` instead of a ``ShellConsumer``:
34+
35+
.. literalinclude:: ../../examples/primary_pipeline_calibration.cpp
36+
:language: c++
37+
:caption: examples/primary_pipeline_calibration.cpp
38+
:linenos:
39+
:lineno-match:
40+
:start-at: // The calibration consumer
41+
:end-at: calib_pipeline.run()
42+
43+
Again, product handling will be happening in the background, so in the rest of the program we wait
44+
until the calibration consumer received and processed data and then print information about that:
45+
46+
.. literalinclude:: ../../examples/primary_pipeline_calibration.cpp
47+
:language: c++
48+
:caption: examples/primary_pipeline_calibration.cpp
49+
:linenos:
50+
:lineno-match:
51+
:start-at: while (!calib_consumer
52+
:end-at: return 0

examples/primary_pipeline_calibration.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ class CalibrationConsumer : public urcl::comm::IConsumer<urcl::primary_interface
3131
}
3232
virtual ~CalibrationConsumer() = default;
3333

34+
// This will consume any primary package
3435
virtual bool consume(std::shared_ptr<urcl::primary_interface::PrimaryPackage> product)
3536
{
37+
// Try to cast the product to a KinematicsInfo package. If that succeeds, we handle the
38+
// calibration information.
3639
auto kin_info = std::dynamic_pointer_cast<urcl::primary_interface::KinematicsInfo>(product);
3740
if (kin_info != nullptr)
3841
{
@@ -105,11 +108,11 @@ int main(int argc, char* argv[])
105108

106109
if (calib_consumer.isCalibrated())
107110
{
108-
printf("The robot on IP: %s is calibrated\n", robot_ip.c_str());
111+
printf("The robot on IP: %s is calibrated.\n", robot_ip.c_str());
109112
}
110113
else
111114
{
112-
printf("The robot controller on IP: %s do not have a valid calibration\n", robot_ip.c_str());
115+
printf("The robot controller on IP: %s does not have a valid calibration.\n", robot_ip.c_str());
113116
printf("Remeber to turn on the robot to get calibration stored on the robot!\n");
114117
}
115118

0 commit comments

Comments
 (0)