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