Visual Servoing Platform  version 3.6.1 under development (2024-05-03)
testVirtuoseWithGlove.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 for Virtuose + Glove SDK wrapper.
33  *
34  *
35 *****************************************************************************/
36 
44 #include <stdlib.h>
45 
46 #include <iostream>
47 #include <sstream>
48 #include <vector>
49 
50 #include <visp3/core/vpCameraParameters.h>
51 #include <visp3/core/vpImage.h>
52 #include <visp3/core/vpMeterPixelConversion.h>
53 #include <visp3/gui/vpDisplayGDI.h>
54 #include <visp3/gui/vpDisplayX.h>
55 #include <visp3/robot/vpVirtuose.h>
56 
57 #if defined(VISP_HAVE_VIRTUOSE) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
58 
59 int main()
60 {
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:206
static const vpColor red
Definition: vpColor.h:211
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:128
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:127
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:189
vpRowVector t() const