Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
testForceTorqueIitSensor.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
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 https://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 IIT sensor.
32  */
33 
40 #include <iostream>
41 
42 #include <visp3/gui/vpPlot.h>
43 #include <visp3/sensor/vpForceTorqueIitSensor.h>
44 
45 int main(int argc, char **argv)
46 {
47 #ifdef ENABLE_VISP_NAMESPACE
48  using namespace VISP_NAMESPACE_NAME;
49 #endif
50 #ifdef VISP_HAVE_FT_IIT_SDK
51  bool opt_no_display = false;
52  bool opt_filtered = false;
53 
54  for (int i = 0; i < argc; i++) {
55  if (std::string(argv[i]) == "--no-display" || std::string(argv[i]) == "-d")
56  opt_no_display = true;
57  if (std::string(argv[i]) == "--filtered" || std::string(argv[i]) == "-f")
58  opt_filtered = true;
59  else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
60  std::cout << "\nUsage: " << argv[0] << " [--no-display] [--filtered] [--help] [-d] [-f] [-h]\n" << std::endl;
61  return 0;
62  }
63  }
64 
65  std::cout << "Disable display: " << opt_no_display << std::endl;
66 
68 
69 #if defined(VISP_HAVE_DISPLAY)
70  vpPlot *plotter = nullptr;
71  if (!opt_no_display) {
72  plotter = new vpPlot(2, 700, 700, 100, 200, "Curves...");
73  plotter->initGraph(0, 3);
74  plotter->setTitle(0, "Force measurements");
75  plotter->setLegend(0, 0, "Fx");
76  plotter->setLegend(0, 1, "Fy");
77  plotter->setLegend(0, 2, "Fz");
78  plotter->initGraph(1, 3);
79  plotter->setTitle(1, "Torque measurements");
80  plotter->setLegend(1, 0, "Tx");
81  plotter->setLegend(1, 1, "Ty");
82  plotter->setLegend(1, 2, "Tz");
83  }
84 #endif
85 
86  if (!iit_ft.connected()) {
87  std::cout << "Unable to connect to IIT force-torque sensor" << std::endl;
88  return EXIT_SUCCESS;
89  }
90 
91  iit_ft.bias();
92  iit_ft.startStreaming();
93 
94  vpColVector ft;
95  bool end = false;
96  unsigned long nbacq = 0;
97  double t_start = vpTime::measureTimeMs();
98  while (!end) {
99  double t = vpTime::measureTimeMs();
100 
101  ft = iit_ft.getForceTorque(opt_filtered);
102 #if defined(VISP_HAVE_DISPLAY)
103  if (!opt_no_display) {
104  vpColVector force = ft.extract(0, 3);
105  vpColVector torque = ft.extract(3, 3);
106  plotter->plot(0, nbacq, force);
107  plotter->plot(1, nbacq, torque);
108  vpDisplay::displayText(plotter->I, 20, 80, "Left click to quit", vpColor::red);
110 
111  if (vpDisplay::getClick(plotter->I, button, false)) {
112  if (button == vpMouseButton::button1) {
113  end = true;
114  }
115  }
116  vpDisplay::flush(plotter->I);
117  }
118  else {
119  std::cout << "F/T: " << ft.t() << std::endl;
120  if (nbacq > 30) {
121  end = true;
122  }
123  }
124 #else
125  std::cout << "F/T: " << ft.t() << std::endl;
126  if (nbacq > 30) {
127  end = true;
128  }
129 #endif
130  vpTime::wait(t, 1);
131  nbacq++;
132  }
133 
134  iit_ft.stopStreaming();
135  double fps = 1000. * nbacq / (vpTime::measureTimeMs() - t_start);
136  std::cout << "Mean acquisition frequency: " << fps << " Hz" << std::endl;
137 
138 #if defined(VISP_HAVE_DISPLAY)
139  if (plotter) {
140  delete plotter;
141  }
142 #endif
143 
144  std::cout << "Test succeed" << std::endl;
145 
146 #else
147  (void)argc;
148  (void)argv;
149  std::cout << "ViSP is not build with IIT force-torque SDK support" << std::endl;
150 #endif
151  return EXIT_SUCCESS;
152 }
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
vpColVector extract(unsigned int r, unsigned int colsize) const
Definition: vpColVector.h:405
vpRowVector t() const
static const vpColor red
Definition: vpColor.h:217
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
bool connected(int timeout_ms=0) const
vpColVector getForceTorque(bool filtered=false)
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Definition: vpPlot.h:112
void initGraph(unsigned int graphNum, unsigned int curveNbr)
Definition: vpPlot.cpp:203
vpImage< unsigned char > I
Definition: vpPlot.h:114
void setLegend(unsigned int graphNum, unsigned int curveNum, const std::string &legend)
Definition: vpPlot.cpp:552
void plot(unsigned int graphNum, unsigned int curveNum, double x, double y)
Definition: vpPlot.cpp:270
void setTitle(unsigned int graphNum, const std::string &title)
Definition: vpPlot.cpp:510
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()