Visual Servoing Platform  version 3.0.1
testComedi.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Authors:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 
44 #include <iostream>
45 #include <sstream>
46 
47 #include <visp3/sensor/vpComedi.h>
48 #include <visp3/gui/vpPlot.h>
49 
50 int main()
51 {
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, std::string("ATI physical sensor data (") + comedi.getPhyDataUnits() + std::string(")"));
60  scope.initGraph(0, comedi.getNChannel());
61  for(unsigned int i=0; i<comedi.getNChannel(); i++)
62  scope.setLegend(0, i, "G" + dynamic_cast< std::ostringstream & >((std::ostringstream() << i)).str());
63 #endif
64 
65  std::string file("recorded-physical-data-sync.txt");
66  std::ofstream f(file.c_str());
67 
68  double start_time = vpTime::measureTimeMs();
69 #ifdef VISP_HAVE_DISPLAY
70  while(! vpDisplay::getClick(scope.I, false)) // Stop recording by a user click
71 #else
72  std::cout << "Data recording during 20 seconds in progress..." << std::endl;
73  while(vpTime::measureTimeMs() - start_time < 20000) // Stop recording after 20 seconds
74 #endif
75  {
76  double loop_time = vpTime::measureTimeMs();
77  vpColVector phydata = comedi.getPhyData();
78  double timestamp = loop_time - start_time;
79 
80  f << timestamp << " " << phydata.t() << std::endl;
81 
82 #ifdef VISP_HAVE_DISPLAY
83  scope.plot(0, timestamp, phydata);
84 #endif
85  vpTime::wait(loop_time, 10);
86  }
87 
88  f.close();
89 
90 #else
91  std::cout << "You should install comedi to enable this test..." << std::endl;
92 #endif
93 }
VISP_EXPORT int wait(double t0, double t)
Definition: vpTime.cpp:157
void open()
Definition: vpComedi.cpp:68
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
void setChannelNumbers(const unsigned int &nchannel)
Definition: vpComedi.h:156
vpRowVector t() const
vpColVector getPhyData() const
Definition: vpComedi.cpp:133
VISP_EXPORT double measureTimeMs()
Definition: vpTime.cpp:93
void setDevice(const std::string &device)
Set comedi device name. Default value is /dev/comedi0.
Definition: vpComedi.h:161
unsigned int getNChannel() const
Get number of channels.
Definition: vpComedi.h:124
void initGraph(unsigned int graphNum, unsigned int curveNbr)
Definition: vpPlot.cpp:203
std::string getPhyDataUnits() const
Get units (V or mA) of the physical data acquired by getPhyData() or getPhyDataAsync().
Definition: vpComedi.cpp:154
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Definition: vpPlot.h:113