Visual Servoing Platform  version 3.4.0
testVirtuoseWithGlove.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 http://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  * Author:
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 
46 #include <stdlib.h>
47 
48 #include <iostream>
49 #include <sstream>
50 #include <vector>
51 
52 #include <visp3/robot/vpVirtuose.h>
53 #include <visp3/core/vpImage.h>
54 #include <visp3/core/vpCameraParameters.h>
55 #include <visp3/core/vpMeterPixelConversion.h>
56 #include <visp3/gui/vpDisplayX.h>
57 #include <visp3/gui/vpDisplayGDI.h>
58 
59 #if defined(VISP_HAVE_VIRTUOSE) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
60 
61 int main()
62 {
63  int port = 53210;
64  std::string ip = "localhost";
65 
66  std::vector<vpVirtuose> virtuose(4); // 0: virtuose, 1: thumb, 2: index, 3: middle
67  std::vector<vpHomogeneousMatrix> wMd(4);
68 
69  // Position of the external camera with respect of the virtuose world frame
70  vpHomogeneousMatrix wMc(0.3, 0, 1.2, vpMath::rad(180), 0, 0);
71 
72  // Open device
73  for (size_t device=0; device < virtuose.size(); device ++) {
74  std::cout << "Try to connect to " << ip << " port " << (port + device) << std::endl;
75  virtuose[device].setIpAddressAndPort(ip, port + static_cast<int>(device));
76  virtuose[device].init();
77  }
78 
79  std::cout << "After init" << std::endl;
80 #if 0
81  // Get joint position
82  for (size_t device=0; device < virtuose.size(); device ++) {
83  std::cout << "Number of joints: " << virtuose[device].getJointsNumber()
84  << " Joint position: " << virtuose[device].getArticularPosition().t() << std::endl
85  << " Cartesian position: " << virtuose[device].getAvatarPosition().t() << std::endl;
86  // std::cout << "Joint velocity: " << virtuose.getArticularVelocity().t() << std::endl;
87  }
88 #endif
89  bool end = false;
90  vpImage<unsigned char> I(480, 640, 0);
92 
93 #if defined(VISP_HAVE_X11)
94  vpDisplayX d(I);
95 #elif defined(VISP_HAVE_GDI)
96  vpDisplayGDI d(I);
97 #endif
98 
99  while(!end) {
101  // Get joint position
102  for (size_t device=0; device < virtuose.size(); device ++) {
103  vpPoseVector wpd = virtuose[device].getAvatarPosition();
104  std::cout << "Device #" << device << " has position: " << wpd.t() << std::endl;
105  wMd[device].buildFrom(wpd);
106 
107  vpHomogeneousMatrix cMd = wMc.inverse() * wMd[device];
108  vpDisplay::displayFrame(I, cMd, cam, 0.1);
109 
110  std::stringstream ss;
111  ss << device;
112  double X = cMd[0][3];
113  double Y = cMd[1][3];
114  double Z = cMd[2][3];
115  vpImagePoint pos;
116  vpMeterPixelConversion::convertPoint(cam, X/Z, Y/Z, pos);
117  vpDisplay::displayText(I, pos + vpImagePoint(10, 10), ss.str(), vpColor::white);
118  vpDisplay::displayText(I, 10, 10, "Click to quit...", vpColor::red);
119  }
120  if(vpDisplay::getClick(I, false)) {
121  end = true;
122  }
123  vpDisplay::flush(I);
124 
125  }
126 
127  // Close device
128  for (size_t device=0; device < virtuose.size(); device ++) {
129  virtuose[device].close();
130  }
131  std::cout << "The end" << std::endl;
132 }
133 
134 #else
135 int main() { std::cout << "You should install Virtuose API to use this binary..." << std::endl; }
136 #endif
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Implementation of an homogeneous matrix and operations on such kind of matrices.
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:150
static void flush(const vpImage< unsigned char > &I)
static const vpColor red
Definition: vpColor.h:217
static void display(const vpImage< unsigned char > &I)
Generic class defining intrinsic camera parameters.
static double rad(double deg)
Definition: vpMath.h:110
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))
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:151
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:87
static const vpColor white
Definition: vpColor.h:212
vpRowVector t() const