This example shows how to retrieve data from an ATI F/T sensor connected to a DAQ board. He we have 2 threads:
#include <iostream>
#include <visp3/core/vpIoTools.h>
#include <visp3/core/vpMutex.h>
#include <visp3/core/vpTime.h>
#include <visp3/core/vpThread.h>
#include <visp3/sensor/vpForceTorqueAtiSensor.h>
#include <visp3/gui/vpPlot.h>
#if defined(VISP_HAVE_PTHREAD)
typedef enum {
BIAS_DONE,
UNBIAS_DONE,
TO_BIAS,
TO_UNBIAS
} BiasState;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef struct {
double timestamp;
BiasState bias_state;
} t_shared_data;
#endif
t_shared_data s_shared_data;
bool s_state_stop = false;
{
(void)args;
#ifdef VISP_HAVE_DISPLAY
vpPlot scope(2, 700, 700, 100, 200,
"ATI F/T sensor data");
scope.initGraph(0,3);
scope.initGraph(1,3);
scope.setTitle(0, "Forces (N)");
scope.setTitle(1, "Torques (Nm)");
scope.setLegend(0, 0, "x");
scope.setLegend(0, 1, "y");
scope.setLegend(0, 2, "z");
scope.setLegend(1, 0, "x");
scope.setLegend(1, 1, "y");
scope.setLegend(1, 2, "z");
#endif
t_shared_data shared_data;
#ifdef VISP_HAVE_DISPLAY
bool click = false;
#else
#endif
do {
#ifdef VISP_HAVE_DISPLAY
{
shared_data.ft = s_shared_data.ft;
shared_data.timestamp = s_shared_data.timestamp;
shared_data.bias_state = s_shared_data.bias_state;
}
scope.plot(0, shared_data.timestamp, force);
scope.plot(1, shared_data.timestamp, torque);
if (shared_data.bias_state == BIAS_DONE)
else if (shared_data.bias_state == UNBIAS_DONE)
else if (shared_data.bias_state == TO_BIAS)
else if (shared_data.bias_state == TO_UNBIAS)
if (shared_data.bias_state == BIAS_DONE) shared_data.bias_state = TO_UNBIAS;
else if (shared_data.bias_state == UNBIAS_DONE) shared_data.bias_state = TO_BIAS;
{
s_shared_data.bias_state = shared_data.bias_state;
}
}
#endif
}
#ifdef VISP_HAVE_DISPLAY
#else
#endif
{
s_state_stop = true;
}
std::cout << "End of scope thread" << std::endl;
return 0;
}
int main(int argc, char** argv)
{
#if defined(VISP_HAVE_ATIDAQ) && defined(VISP_HAVE_COMEDI)
#ifdef VISP_HAVE_VIPER850_DATA
(void)argc;
(void)argv;
std::string calibfile = std::string(VISP_VIPER850_DATA_PATH) + std::string("/ati/FT17824.cal");
std::cout << "ATI F/T calib file \"" << calibfile << "\" doesn't exist";
return 0;
}
#else
if(argc != 2) {
std::cout << "Usage: " << argv[0] << " <ATI calibration file FT*.cal]>" << std::endl;
return -1;
}
std::string calibfile(argv[1]);
#endif
std::cout << "ATI F/T sensor characteristics: \n" << ati << std::endl;
std::cout << "Data recording in progress..." << std::endl;
std::string file("recorded-ft-sync.txt");
std::ofstream f(file.c_str());
bool state_stop;
t_shared_data shared_data;
do {
double timestamp = loop_time - start_time;
{
shared_data.bias_state = s_shared_data.bias_state;
}
if (shared_data.bias_state == TO_BIAS) {
std::cout << "Bias sensor" << std::endl;
std::cout << "Unbias sensor" << std::endl;
shared_data.bias_state = BIAS_DONE;
}
else if (shared_data.bias_state == TO_UNBIAS) {
shared_data.bias_state = UNBIAS_DONE;
}
{
s_shared_data.ft = ft;
s_shared_data.timestamp = timestamp;
s_shared_data.bias_state = shared_data.bias_state;
}
{
state_stop = s_state_stop;
}
f << timestamp <<
" " << ft.
t() << std::endl;
}
while(! state_stop);
thread_scope.join();
f.close();
std::cout << "Data recorded in " << file << std::endl;
#else
(void)argc;
(void)argv;
std::cout << "You should install comedi and build atidaq to enable this test..." << std::endl;
#endif
}
#else
int main()
{
std::cout << "You should build this test with threading capabilities..." << std::endl;
}
#endif