Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
testComedi.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Test force/torque ATI sensor.
32  */
33 
41 #include <iostream>
42 #include <sstream>
43 
44 #include <visp3/gui/vpPlot.h>
45 #include <visp3/sensor/vpComedi.h>
46 
47 int main()
48 {
49 #ifdef ENABLE_VISP_NAMESPACE
50  using namespace VISP_NAMESPACE_NAME;
51 #endif
52 #ifdef VISP_HAVE_COMEDI
53  vpComedi comedi;
54  comedi.setDevice("/dev/comedi0");
55  comedi.setChannelNumbers(6); // to read a F/T tensor
56  comedi.open();
57 
58 #ifdef VISP_HAVE_DISPLAY
59  vpPlot scope(1, 700, 700, 100, 200,
60  std::string("ATI physical sensor data (") + comedi.getPhyDataUnits() + std::string(")"));
61  scope.initGraph(0, comedi.getNChannel());
62 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
63  for (unsigned int i = 0; i < comedi.getNChannel(); i++) {
64  scope.setLegend(0, i, "G" + ((std::ostringstream() << i)).str());
65  }
66 #endif
67 #endif
68 
69  std::string file("recorded-physical-data-sync.txt");
70  std::ofstream f(file.c_str());
71 
72  double start_time = vpTime::measureTimeMs();
73 #ifdef VISP_HAVE_DISPLAY
74  while (!vpDisplay::getClick(scope.I, false)) // Stop recording by a user click
75 #else
76  std::cout << "Data recording during 20 seconds in progress..." << std::endl;
77  while (vpTime::measureTimeMs() - start_time < 20000) // Stop recording after 20 seconds
78 #endif
79  {
80  double loop_time = vpTime::measureTimeMs();
81  vpColVector phydata = comedi.getPhyData();
82  double timestamp = loop_time - start_time;
83 
84  f << timestamp << " " << phydata.t() << std::endl;
85 
86 #ifdef VISP_HAVE_DISPLAY
87  scope.plot(0, timestamp, phydata);
88 #endif
89  vpTime::wait(loop_time, 10);
90  }
91 
92  f.close();
93 
94 #else
95  std::cout << "You should install comedi to enable this test..." << std::endl;
96 #endif
97 }
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
vpRowVector t() const
void setChannelNumbers(const unsigned int &nchannel)
Definition: vpComedi.h:150
void setDevice(const std::string &device)
Set comedi device name. Default value is /dev/comedi0.
Definition: vpComedi.h:153
unsigned int getNChannel() const
Get number of channels.
Definition: vpComedi.h:126
vpColVector getPhyData() const
Definition: vpComedi.cpp:133
void open()
Definition: vpComedi.cpp:63
std::string getPhyDataUnits() const
Definition: vpComedi.cpp:155
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Definition: vpPlot.h:112
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()