Visual Servoing Platform version 3.5.0
testComedi.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2019 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 http://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 * Authors:
35 * Fabien Spindler
36 *
37 *****************************************************************************/
38
46#include <iostream>
47#include <sstream>
48
49#include <visp3/gui/vpPlot.h>
50#include <visp3/sensor/vpComedi.h>
51
52int main()
53{
54#ifdef VISP_HAVE_COMEDI
55 vpComedi comedi;
56 comedi.setDevice("/dev/comedi0");
57 comedi.setChannelNumbers(6); // to read a F/T tensor
58 comedi.open();
59
60#ifdef VISP_HAVE_DISPLAY
61 vpPlot scope(1, 700, 700, 100, 200,
62 std::string("ATI physical sensor data (") + comedi.getPhyDataUnits() + std::string(")"));
63 scope.initGraph(0, comedi.getNChannel());
64 for (unsigned int i = 0; i < comedi.getNChannel(); i++)
65 scope.setLegend(0, i, "G" + dynamic_cast<std::ostringstream &>((std::ostringstream() << i)).str());
66#endif
67
68 std::string file("recorded-physical-data-sync.txt");
69 std::ofstream f(file.c_str());
70
71 double start_time = vpTime::measureTimeMs();
72#ifdef VISP_HAVE_DISPLAY
73 while (!vpDisplay::getClick(scope.I, false)) // Stop recording by a user click
74#else
75 std::cout << "Data recording during 20 seconds in progress..." << std::endl;
76 while (vpTime::measureTimeMs() - start_time < 20000) // Stop recording after 20 seconds
77#endif
78 {
79 double loop_time = vpTime::measureTimeMs();
80 vpColVector phydata = comedi.getPhyData();
81 double timestamp = loop_time - start_time;
82
83 f << timestamp << " " << phydata.t() << std::endl;
84
85#ifdef VISP_HAVE_DISPLAY
86 scope.plot(0, timestamp, phydata);
87#endif
88 vpTime::wait(loop_time, 10);
89 }
90
91 f.close();
92
93#else
94 std::cout << "You should install comedi to enable this test..." << std::endl;
95#endif
96}
Implementation of column vector and the associated operations.
Definition: vpColVector.h:131
vpRowVector t() const
void setChannelNumbers(const unsigned int &nchannel)
Definition: vpComedi.h:148
void setDevice(const std::string &device)
Set comedi device name. Default value is /dev/comedi0.
Definition: vpComedi.h:151
unsigned int getNChannel() const
Get number of channels.
Definition: vpComedi.h:124
vpColVector getPhyData() const
Definition: vpComedi.cpp:136
void open()
Definition: vpComedi.cpp:66
std::string getPhyDataUnits() const
Definition: vpComedi.cpp:158
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:116
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()