Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
testQbSoftHand.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 qbdevice.
32  */
33 
40 #include <iostream>
41 
42 #include <visp3/core/vpTime.h>
43 #include <visp3/robot/vpQbSoftHand.h>
44 
45 int main()
46 {
47 #ifdef ENABLE_VISP_NAMESPACE
48  using namespace VISP_NAMESPACE_NAME;
49 #endif
50 #if defined(VISP_HAVE_QBDEVICE) && defined(VISP_HAVE_THREADS)
51  std::cout << "Test qbSoftHand device" << std::endl;
52  try {
53  vpQbSoftHand qbsofthand;
54 
55  {
56  // Call blocking functions to close and open the hand
57  vpColVector q(1), q_mes, current;
58 
59  double speed_factor = 0.5; // half speed
60  double stiffness = 0.7;
61  std::cout << "** Close the hand with blocking positioning function" << std::endl;
62  q[0] = 1;
63  qbsofthand.setPosition(q, speed_factor, stiffness);
64 
65  std::cout << "** Open the hand with blocking positioning function" << std::endl;
66  q[0] = 0;
67  qbsofthand.setPosition(q, speed_factor, stiffness);
68  }
69 
70  {
71  // Call non-blocking positioning functions
72  vpColVector q(1), q_mes, current;
73  double max_current = qbsofthand.getCurrentMax();
74  int i_max = 0;
75  std::cout << "** Close the hand with non-blocking positioning function" << std::endl;
76  for (int i = 1; i <= 10; i++) {
77  qbsofthand.getPosition(q_mes);
78  qbsofthand.getCurrent(current);
79  if (std::fabs(current[0]) > max_current / 2) {
80  std::cout << "Stop closure, current > " << max_current / 2 << std::endl;
81  i_max = i;
82  break;
83  }
84  q[0] = i / 10.0;
85  qbsofthand.setPosition(q);
86  vpTime::sleepMs(500);
87  }
88  std::cout << "** Open the hand with non-blocking positioning function" << std::endl;
89  for (int i = i_max; i >= 0; i--) {
90  qbsofthand.getPosition(q_mes);
91  qbsofthand.getCurrent(current);
92  q[0] = i / 10.0;
93  qbsofthand.setPosition(q);
94  vpTime::sleepMs(500);
95  }
96  }
97  std::cout << "The end" << std::endl;
98  }
99  catch (const vpException &e) {
100  std::cout << "Catch exception: " << e.getStringMessage() << std::endl;
101  }
102 #else
103  std::cout << "ViSP is not build with qbdevice 3rd party" << std::endl;
104 #endif
105  return EXIT_SUCCESS;
106 }
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
error that can be emitted by ViSP classes.
Definition: vpException.h:60
const std::string & getStringMessage() const
Definition: vpException.cpp:67
double getCurrentMax() const
Definition: vpQbDevice.cpp:529
void getCurrent(vpColVector &current, const int &id=1)
void setPosition(const vpColVector &position, const int &id=1)
void getPosition(vpColVector &position, const int &id=1)
VISP_EXPORT void sleepMs(double t)