File: dinast_grabber.rst

package info (click to toggle)
pcl 1.15.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 143,128 kB
  • sloc: cpp: 520,234; xml: 28,792; ansic: 8,212; python: 334; lisp: 93; sh: 49; makefile: 30
file content (215 lines) | stat: -rw-r--r-- 7,503 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
.. _dinast_grabber:

The PCL Dinast Grabber Framework
--------------------------------

At PCL 1.7 we offer a new driver for Dinast Cameras making use of the generic grabber interface that is present since PCL 1.0. This tutorial shows, in a nutshell, how to set up the pcl grabber to obtain data from the cameras. 

So far it has been currently tested with the `IPA-1110, Cyclopes II <http://dinast.com/ipa-1110-cyclopes-ii/>`_ and the `IPA-1002 ng T-Less NG <http://dinast.com/ipa-1002-ng-t-less-ng-next-generation/>`_ but it is meant to work properly on the rest of the Dinast devices, since manufacturer specifications has been taken into account.

.. image:: images/dinast_cameras.png
    :height: 290px
    :align: center

Small example
-------------

As the Dinast Grabber implements the generic grabber interface you will see high usage similarities with other pcl grabbers. In *applications* you can find a small example that contains the code required to set up a pcl::PointCloud<XYZI> callback to a Dinast camera device.

Here you can see a screenshot of the PCL Cloud Viewer showing the data from a cup laying on a table obtained through the Dinast Grabber interface:

.. image:: images/dinast_cup.png
    :height: 390px
    :align: center

And this is a video of the PCL Cloud Viewer showing the point cloud data corresponding to a face:

.. raw:: html

  <center><iframe title="PCL Dinast Grabber example" width="480" height="390" src="https://www.youtube.com/embed/6hj57RfEMBI?rel=0" frameborder="0" allowfullscreen></iframe></center>
  
Dinast Grabber currently offer this data type, as is the one currently available from Dinast devices:

* `void (const pcl::PointCloud<pcl::PointXYZI>::ConstPtr&)`
  
The code
--------

The code from *apps/src/dinast_grabber_example.cpp* will be used for this tutorial:

.. code-block:: cpp
  :linenos:

  #include <pcl/common/time.h>
  #include <pcl/io/dinast_grabber.h>
  #include <pcl/visualization/cloud_viewer.h>
  #include <pcl/point_types.h>

  #include <chrono>
  #include <thread>

  using namespace std::chrono_literals;

  template <typename PointType>
  class DinastProcessor {
  public:
    using Cloud = pcl::PointCloud<PointType>;
    using CloudConstPtr = typename Cloud::ConstPtr;

    DinastProcessor(pcl::Grabber& grabber)
    : interface(grabber), viewer("Dinast Cloud Viewer")
    {}

    void
    cloud_cb_(CloudConstPtr cloud_cb)
    {
      static unsigned count = 0;
      static double last = pcl::getTime();
      if (++count == 30) {
        double now = pcl::getTime();
        std::cout << "Average framerate: " << double(count) / double(now - last) << " Hz"
                  << std::endl;
        count = 0;
        last = now;
      }
      if (!viewer.wasStopped())
        viewer.showCloud(cloud_cb);
    }

    int
    run()
    {

      std::function<void(const CloudConstPtr&)> f = [this](const CloudConstPtr& cloud) {
        cloud_cb_(cloud);
      };

      boost::signals2::connection c = interface.registerCallback(f);

      interface.start();

      while (!viewer.wasStopped()) {
        std::this_thread::sleep_for(1s);
      }

      interface.stop();

      return 0;
    }

    pcl::Grabber& interface;
    pcl::visualization::CloudViewer viewer;
  };

  int
  main()
  {
    pcl::DinastGrabber grabber;
    DinastProcessor<pcl::PointXYZI> v(grabber);
    v.run();
    return 0;
  }

The explanation
---------------

At first, when the constructor of DinastProcessor gets called, the Grabber and CloudViewer Classes are also initialized:

.. code-block:: cpp

  DinastProcessor(pcl::Grabber& grabber) : interface(grabber), viewer("Dinast Cloud Viewer") {}

At the run function what we first have is actually the callback and its registration:

.. code-block:: cpp    

  std::function<void (const CloudConstPtr&)> f =
    [this] (const CloudConstPtr& cloud) { cloud_cb_ (cloud); };
        
  boost::signals2::connection c = interface.registerCallback (f);

We create a lambda object with the callback *cloud_cb_*, we pass an implicit copy of the DinastProcessor pointer (through *this*).
The lambda then gets casted to a std::function object which is templated on the callback function type, in this case *void (const CloudConstPtr&)*. The resulting function object is then registered with the DinastGrabber interface.

The *registerCallback* call returns a *boost::signals2::connection* object, which we do not use in the this example. However, if you want to interrupt or cancel one or more of the registered data streams, you can call disconnect the callback without stopping the whole grabber:

.. code-block:: cpp

  boost::signals2::connection = interface (registerCallback (f));

  // ...

  if (c.connected ())
    c.disconnect ();

After the callback is set up we start the interface.
Then we loop until the viewer is stopped. Finally interface is stopped although this is not actually needed since the destructor takes care of that.

On the callback function *cloud_cb_* we just do some framerate calculations and we show the obtained point cloud through the CloudViewer.

Testing the code
----------------

We will test the grabber with the previous example. Write down the whole code to a file called *dinast_grabber.cpp* at your preferred location. Then add this as a *CMakeLists.txt* file:
  
.. code-block:: cmake
  :linenos:

  cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

  project(dinast_grabber)

  find_package(PCL 1.7 REQUIRED)

  include_directories(${PCL_INCLUDE_DIRS})
  link_directories(${PCL_LIBRARY_DIRS})
  add_definitions(${PCL_DEFINITIONS})

  add_executable (dinast_grabber dinast_grabber.cpp)
  target_link_libraries (dinast_grabber ${PCL_LIBRARIES})

Then just proceed as a usual cmake compilation::

  $ cd /PATH/TO/DINAST_EXAMPLE
  $ mkdir build
  $ cd build
  $ cmake
  $ make
  
If everything went as expected you should now have a binary to test your Dinast device. 
Go ahead, run it and you should be able to see the point cloud data from the camera::

  $ ./dinast_grabber
  
Troubleshooting
---------------

**Q:** When I run the application I get an error similar to this one::

  $ ./dinast_grabber 
  libusb: 0.000000 error [op_open] libusb couldn't open USB device /dev/bus/usb/002/010: Permission denied.
  libusb: 0.009155 error [op_open] libusb requires write access to USB device nodes.

Where the last numbers of the */dev/bus/usb/...* might vary.

**A:** This means you do not have permission to access the device. You can do a quick fix on the permissions of that specific device::

  $ sudo chmod 666 /dev/bus/usb/002/010

Or you can make this changes permanent for all future Dinast devices writing a rule for udev. 
In debian-like systems it is usually done writing this::

  # make dinast device mount with writing permissions (default is read only for unknown devices)
  SUBSYSTEM=="usb", ATTR{idProduct}=="1402", ATTR{idVendor}=="18d1", MODE:="0666", OWNER:="root", GROUP:="video"

to a file like */etc/udev/rules.d/60-dinast-usb.rules*.

If you still have problems you can always use the users mailing list: *pcl-users@pointclouds.org* to find some extra help.

Conclusions
-----------

With this new grabber a new kind of short-range sensors are available through the PCL Grabber interface. 
It is now a breeze to connect and obtain data from Dinast devices as you do with the rest of devices supported at PCL.

If you have any development suggestions on these or new devices you can contact us through *pcl-developers@pointclouds.org*.