Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
testVirtuoseAfma6.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 SDK wrapper.
32 */
33
41
42#include <visp3/core/vpTime.h>
43#include <visp3/robot/vpRobotAfma6.h>
44#include <visp3/robot/vpVirtuose.h>
45
46int main()
47{
48#ifdef ENABLE_VISP_NAMESPACE
49 using namespace VISP_NAMESPACE_NAME;
50#endif
51#if defined(VISP_HAVE_VIRTUOSE) && defined(VISP_HAVE_AFMA6)
52 vpRobotAfma6 robot;
53 try {
54 vpVirtuose virtuose;
55 virtuose.setVerbose(true);
56 virtuose.setCommandType(COMMAND_TYPE_IMPEDANCE);
57 virtuose.setPowerOn();
58 // virtuose.setSaturation(1.0f,0.0f);
59
60 vpColVector virt_velocity;
61 vpColVector robot_velocity;
62 vpColVector robot_joint_position;
63 vpColVector robot_cart_position;
64 vpColVector robot_cart_position_init;
65 vpColVector force_feedback_robot(3);
66 float force_limit = 15;
67 int force_increase_rate = 500;
68
69 double cube_size = 0.15;
70
72 rMv[0][0] = rMv[0][2] = 0;
73 rMv[1][1] = rMv[1][2] = 0;
74 rMv[2][0] = rMv[2][1] = 0;
75 rMv[0][1] = rMv[1][0] = rMv[2][2] = -1;
76 std::cout << "rMv:\n" << rMv << std::endl;
77 vpVelocityTwistMatrix rVv(rMv);
78
79 // Set the extrinsic camera parameters obtained with a perspective
80 // projection model including a distortion parameter
82 // Initialize the controller to position control
83 robot.setRobotState(vpRobot::STATE_POSITION_CONTROL);
84 // Moves the robot in the joint space
85 vpColVector q(6, 0);
86 robot.setPositioningVelocity(10);
87 robot.setPosition(vpRobot::ARTICULAR_FRAME, q);
88
89 robot.getPosition(vpRobot::REFERENCE_FRAME, robot_cart_position_init);
90 vpColVector min(3), max(3);
91 for (unsigned int i = 0; i < 3; i++) {
92 min[i] = robot_cart_position_init[i] - cube_size / 2;
93 max[i] = robot_cart_position_init[i] + cube_size / 2;
94 }
95 std::cout << "min: " << min.t() << std::endl;
96 std::cout << "max: " << max.t() << std::endl;
97
98 // Initialize the controller to position control
99 robot.setRobotState(vpRobot::STATE_VELOCITY_CONTROL);
100
101 for (unsigned int iter = 0; iter < 10000; iter++) {
102 virt_velocity = virtuose.getVelocity();
103 std::cout << "Virtuose velocity: " << virt_velocity.t() << std::endl;
104
105 robot.getPosition(vpRobot::REFERENCE_FRAME, robot_cart_position);
106
107 for (int i = 0; i < 3; i++) {
108 if (robot_cart_position[i] >= max[i]) {
109 force_feedback_robot[i] = (max[i] - robot_cart_position[i]) * force_increase_rate;
110 if (force_feedback_robot[i] <= -force_limit)
111 force_feedback_robot[i] = -force_limit;
112 }
113 else if (robot_cart_position[i] <= min[i]) {
114 force_feedback_robot[i] = (min[i] - robot_cart_position[i]) * force_increase_rate;
115 if (force_feedback_robot[i] >= force_limit)
116 force_feedback_robot[i] = force_limit;
117 }
118 else
119 force_feedback_robot[i] = 0;
120 }
121 vpColVector force_feedback_virt = rMv.getRotationMatrix().inverse() * force_feedback_robot;
122
123 // Printing force feedback
124 std::cout << "Force feedback: " << force_feedback_virt.t() << std::endl;
125
126 robot_velocity = rVv * virt_velocity;
127 robot.setVelocity(vpRobot::CAMERA_FRAME, robot_velocity);
128
129 // Set force feedback
130 vpColVector force_feedback(6, 0);
131 force_feedback.insert(0, force_feedback_virt);
132
133 virtuose.setForce(force_feedback);
134
135 vpTime::wait(10);
136 }
137 robot.stopMotion();
138 virtuose.setPowerOff();
139 std::cout << "The end" << std::endl;
140 }
141 catch (const vpException &e) {
142 robot.stopMotion();
143 std::cout << "Catch an exception: " << e.getStringMessage() << std::endl;
144 }
145#else
146 std::cout << "You should install Virtuose SDK to use this binary..." << std::endl;
147#endif
148}
@ TOOL_CCMOP
Definition vpAfma6.h:125
@ perspectiveProjWithDistortion
Perspective projection with distortion model.
Implementation of column vector and the associated operations.
vpRowVector t() const
error that can be emitted by ViSP classes.
Definition vpException.h:60
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpRotationMatrix getRotationMatrix() const
Control of Irisa's gantry robot named Afma6.
@ REFERENCE_FRAME
Definition vpRobot.h:75
@ ARTICULAR_FRAME
Definition vpRobot.h:77
@ CAMERA_FRAME
Definition vpRobot.h:81
@ STATE_POSITION_CONTROL
Initialize the position controller.
Definition vpRobot.h:65
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
Definition vpRobot.h:64
vpRotationMatrix inverse() const
vpColVector getVelocity() const
void setPowerOff()
void setForce(const vpColVector &force)
void setCommandType(const VirtCommandType &type)
void setPowerOn()
void setVerbose(bool mode)
Definition vpVirtuose.h:194
VISP_EXPORT int wait(double t0, double t)