Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
testComedi.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 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*****************************************************************************/
35
43#include <iostream>
44#include <sstream>
45
46#include <visp3/gui/vpPlot.h>
47#include <visp3/sensor/vpComedi.h>
48
49int main()
50{
51#ifdef VISP_HAVE_COMEDI
52 vpComedi comedi;
53 comedi.setDevice("/dev/comedi0");
54 comedi.setChannelNumbers(6); // to read a F/T tensor
55 comedi.open();
56
57#ifdef VISP_HAVE_DISPLAY
58 vpPlot scope(1, 700, 700, 100, 200,
59 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" + ((std::ostringstream() << i)).str());
63 }
64#endif
65
66 std::string file("recorded-physical-data-sync.txt");
67 std::ofstream f(file.c_str());
68
69 double start_time = vpTime::measureTimeMs();
70#ifdef VISP_HAVE_DISPLAY
71 while (!vpDisplay::getClick(scope.I, false)) // Stop recording by a user click
72#else
73 std::cout << "Data recording during 20 seconds in progress..." << std::endl;
74 while (vpTime::measureTimeMs() - start_time < 20000) // Stop recording after 20 seconds
75#endif
76 {
77 double loop_time = vpTime::measureTimeMs();
78 vpColVector phydata = comedi.getPhyData();
79 double timestamp = loop_time - start_time;
80
81 f << timestamp << " " << phydata.t() << std::endl;
82
83#ifdef VISP_HAVE_DISPLAY
84 scope.plot(0, timestamp, phydata);
85#endif
86 vpTime::wait(loop_time, 10);
87 }
88
89 f.close();
90
91#else
92 std::cout << "You should install comedi to enable this test..." << std::endl;
93#endif
94}
Implementation of column vector and the associated operations.
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: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:113
VISP_EXPORT double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)