Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testVirtuoseAfma6.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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 SDK wrapper.
32  *
33  * Authors:
34  * Fabien Spindler
35  * Nicolò Pedemonte
36  *
37  *****************************************************************************/
38 
46 #include <visp3/core/vpTime.h>
47 #include <visp3/robot/vpVirtuose.h>
48 #include <visp3/robot/vpRobotAfma6.h>
49 
50 int main()
51 {
52 #if defined(VISP_HAVE_VIRTUOSE) && defined(VISP_HAVE_AFMA6)
53  vpRobotAfma6 robot;
54  try {
55  vpVirtuose virtuose;
56  virtuose.setVerbose(true);
57  virtuose.setCommandType(COMMAND_TYPE_IMPEDANCE);
58  virtuose.setPowerOn();
59 // virtuose.setSaturation(1.0f,0.0f);
60 
61  vpColVector virt_velocity;
62  vpColVector robot_velocity;
63  vpColVector robot_joint_position;
64  vpColVector robot_cart_position;
65  vpColVector robot_cart_position_init;
66  vpColVector force_feedback_robot(3);
67  float force_limit = 15;
68  int force_increase_rate = 500;
69 
70  double cube_size = 0.15;
71 
73  rMv[0][0] = rMv[0][2] = 0;
74  rMv[1][1] = rMv[1][2] = 0;
75  rMv[2][0] = rMv[2][1] = 0;
76  rMv[0][1] = rMv[1][0] = rMv[2][2] = -1;
77  std::cout << "rMv:\n" << rMv << std::endl;
78  vpVelocityTwistMatrix rVv(rMv);
79 
80  // Set the extrinsic camera parameters obtained with a perpective
81  // projection model including a distortion parameter
83  // Initialize the controller to position control
85  // Moves the robot in the joint space
86  vpColVector q(6, 0);
87  robot.setPositioningVelocity(10);
89 
90  robot.getPosition(vpRobot::REFERENCE_FRAME, robot_cart_position_init);
91  vpColVector min(3), max(3);
92  for (unsigned int i=0; i<3; i++) {
93  min[i] = robot_cart_position_init[i] - cube_size/2;
94  max[i] = robot_cart_position_init[i] + cube_size/2;
95  }
96  std::cout << "min: " << min.t() << std::endl;
97  std::cout << "max: " << max.t() << std::endl;
98 
99  // Initialize the controller to position control
101 
102  for(unsigned int iter=0; iter<10000; iter++) {
103  virt_velocity = virtuose.getVelocity();
104  std::cout << "Virtuose velocity: " << virt_velocity.t() << std::endl;
105 
106  robot.getPosition(vpRobot::REFERENCE_FRAME, robot_cart_position);
107 
108  for (int i=0; i < 3; i++) {
109  if (robot_cart_position[i] >= max[i])
110  {
111  force_feedback_robot[i] = (max[i] - robot_cart_position[i]) * force_increase_rate;
112  if (force_feedback_robot[i] <= -force_limit) force_feedback_robot[i] = -force_limit;
113  }
114  else if (robot_cart_position[i] <= min[i])
115  {
116  force_feedback_robot[i] = (min[i] - robot_cart_position[i]) * force_increase_rate;
117  if (force_feedback_robot[i] >= force_limit) force_feedback_robot[i] = force_limit;
118  }
119  else
120  force_feedback_robot[i] = 0;
121  }
122  vpColVector force_feedback_virt = rMv.getRotationMatrix().inverse() * force_feedback_robot;
123 
124  // Printing force feedback
125  std::cout << "Force feedback: " << force_feedback_virt.t() << std::endl;
126 
127  robot_velocity = rVv * virt_velocity;
128  robot.setVelocity(vpRobot::CAMERA_FRAME, robot_velocity);
129 
130  // Set force feedback
131  vpColVector force_feedback(6, 0);
132  force_feedback.insert(0, force_feedback_virt);
133 
134  virtuose.setForce(force_feedback);
135 
136  vpTime::wait(10);
137  }
138  robot.stopMotion();
139  virtuose.setPowerOff();
140  std::cout << "The end" << std::endl;
141  }
142  catch(vpException &e) {
143  robot.stopMotion();
144  std::cout << "Catch an exception: " << e.getStringMessage() << std::endl;
145  }
146 #else
147  std::cout << "You should install Virtuose SDK to use this binary..." << std::endl;
148 #endif
149 }
VISP_EXPORT int wait(double t0, double t)
Definition: vpTime.cpp:157
vpRotationMatrix inverse() const
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setPosition(const vpRobot::vpControlFrameType frame, const vpPoseVector &pose)
Initialize the position controller.
Definition: vpRobot.h:69
error that can be emited by ViSP classes.
Definition: vpException.h:73
void setForce(const vpColVector &force)
Definition: vpVirtuose.cpp:701
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position)
void setPositioningVelocity(const double velocity)
Control of Irisa's gantry robot named Afma6.
Definition: vpRobotAfma6.h:210
void init(void)
Initialize the velocity controller.
Definition: vpRobot.h:68
vpRotationMatrix getRotationMatrix() const
vpColVector t() const
void setPowerOn()
Definition: vpVirtuose.cpp:881
vpRowVector t() const
void setPowerOff()
Definition: vpVirtuose.cpp:867
void setVerbose(bool mode)
Definition: vpVirtuose.h:183
void setCommandType(const VirtCommandType &type)
Definition: vpVirtuose.cpp:681
vpColVector getVelocity() const
Definition: vpVirtuose.cpp:505
vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState)
Implementation of a velocity twist matrix and operations on such kind of matrices.
Perspective projection with distortion model.
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity)
const std::string & getStringMessage(void) const
Send a reference (constant) related the error message (can be empty).