This example shows how to retrieve data from a sensor connected to a DAQ board. He we have 1 signe main threads that acquires physical values at 100 Hz (10 ms) and records data in recorded-physical-data-sync.txt file.
#include <iostream>
#include <sstream>
#include <visp3/gui/vpPlot.h>
#include <visp3/sensor/vpComedi.h>
int main()
{
#ifdef VISP_HAVE_COMEDI
#ifdef VISP_HAVE_DISPLAY
vpPlot scope(1, 700, 700, 100, 200,
std::string(
"ATI physical sensor data (") + comedi.
getPhyDataUnits() + std::string(
")"));
for (
unsigned int i = 0; i < comedi.
getNChannel(); i++)
scope.setLegend(0, i, "G" + dynamic_cast<std::ostringstream &>((std::ostringstream() << i)).str());
#endif
std::string file("recorded-physical-data-sync.txt");
std::ofstream f(file.c_str());
#ifdef VISP_HAVE_DISPLAY
#else
std::cout << "Data recording during 20 seconds in progress..." << std::endl;
#endif
{
double timestamp = loop_time - start_time;
f << timestamp <<
" " << phydata.
t() << std::endl;
#ifdef VISP_HAVE_DISPLAY
scope.plot(0, timestamp, phydata);
#endif
}
f.close();
#else
std::cout << "You should install comedi to enable this test..." << std::endl;
#endif
}