Visual Servoing Platform  version 3.6.1 under development (2024-12-17)
testVirtuoseWithGlove.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 for Virtuose + Glove SDK wrapper.
32  */
33 
41 #include <stdlib.h>
42 
43 #include <iostream>
44 #include <sstream>
45 #include <vector>
46 
47 #include <visp3/core/vpCameraParameters.h>
48 #include <visp3/core/vpImage.h>
49 #include <visp3/core/vpMeterPixelConversion.h>
50 #include <visp3/gui/vpDisplayGDI.h>
51 #include <visp3/gui/vpDisplayX.h>
52 #include <visp3/robot/vpVirtuose.h>
53 
54 #if defined(VISP_HAVE_VIRTUOSE) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
55 
56 int main()
57 {
58 #ifdef ENABLE_VISP_NAMESPACE
59  using namespace VISP_NAMESPACE_NAME;
60 #endif
61  int port = 53210;
62  std::string ip = "localhost";
63 
64  std::vector<vpVirtuose> virtuose(4); // 0: virtuose, 1: thumb, 2: index, 3: middle
65  std::vector<vpHomogeneousMatrix> wMd(4);
66 
67  // Position of the external camera with respect of the virtuose world frame
68  vpHomogeneousMatrix wMc(0.3, 0, 1.2, vpMath::rad(180), 0, 0);
69 
70  // Open device
71  for (size_t device = 0; device < virtuose.size(); device++) {
72  std::cout << "Try to connect to " << ip << " port " << (port + device) << std::endl;
73  virtuose[device].setIpAddressAndPort(ip, port + static_cast<int>(device));
74  virtuose[device].init();
75  }
76 
77  std::cout << "After init" << std::endl;
78 #if 0
79  // Get joint position
80  for (size_t device = 0; device < virtuose.size(); device++) {
81  std::cout << "Number of joints: " << virtuose[device].getJointsNumber()
82  << " Joint position: " << virtuose[device].getArticularPosition().t() << std::endl
83  << " Cartesian position: " << virtuose[device].getAvatarPosition().t() << std::endl;
84 // std::cout << "Joint velocity: " << virtuose.getArticularVelocity().t() << std::endl;
85  }
86 #endif
87  bool end = false;
88  vpImage<unsigned char> I(480, 640, 0);
90 
91 #if defined(VISP_HAVE_X11)
92  vpDisplayX d(I);
93 #elif defined(VISP_HAVE_GDI)
94  vpDisplayGDI d(I);
95 #endif
96 
97  while (!end) {
99  // Get joint position
100  for (size_t device = 0; device < virtuose.size(); device++) {
101  vpPoseVector wpd = virtuose[device].getAvatarPosition();
102  std::cout << "Device #" << device << " has position: " << wpd.t() << std::endl;
103  wMd[device].buildFrom(wpd);
104 
105  vpHomogeneousMatrix cMd = wMc.inverse() * wMd[device];
106  vpDisplay::displayFrame(I, cMd, cam, 0.1);
107 
108  std::stringstream ss;
109  ss << device;
110  double X = cMd[0][3];
111  double Y = cMd[1][3];
112  double Z = cMd[2][3];
113  vpImagePoint pos;
114  vpMeterPixelConversion::convertPoint(cam, X / Z, Y / Z, pos);
115  vpDisplay::displayText(I, pos + vpImagePoint(10, 10), ss.str(), vpColor::white);
116  vpDisplay::displayText(I, 10, 10, "Click to quit...", vpColor::red);
117  }
118  if (vpDisplay::getClick(I, false)) {
119  end = true;
120  }
121  vpDisplay::flush(I);
122  }
123 
124  // Close device
125  for (size_t device = 0; device < virtuose.size(); device++) {
126  virtuose[device].close();
127  }
128  std::cout << "The end" << std::endl;
129 }
130 
131 #else
132 int main() { std::cout << "You should install Virtuose API to use this binary..." << std::endl; }
133 #endif
Generic class defining intrinsic camera parameters.
static const vpColor white
Definition: vpColor.h:212
static const vpColor red
Definition: vpColor.h:217
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:130
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1, const vpImagePoint &offset=vpImagePoint(0, 0), const std::string &frameName="", const vpColor &textColor=vpColor::black, const vpImagePoint &textOffset=vpImagePoint(15, 15))
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)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
static double rad(double deg)
Definition: vpMath.h:129
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:203
vpRowVector t() const