Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
takktile2-control.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 * Interface for the Reflex Takktile 2 hand from Right Hand Robotics.
32 */
33
40
41#include <iostream>
42#include <string>
43
44#include <visp3/core/vpConfig.h>
45#include <visp3/robot/vpReflexTakktile2.h>
46
47int main(int argc, char *argv[])
48{
49#ifdef ENABLE_VISP_NAMESPACE
50 using namespace VISP_NAMESPACE_NAME;
51#endif
52
53 std::string opt_network_interface = "eth0";
54 std::string opt_finger_file_name = "yaml/finger_calibrate.yaml";
55 std::string opt_tactile_file_name = "yaml/tactile_calibrate.yaml";
56 std::string opt_motor_file_name = "yaml/motor_constants.yaml";
57
58 for (int i = 1; i < argc; i++) {
59 if (std::string(argv[i]) == "--network" && i + 1 < argc) {
60 opt_network_interface = std::string(argv[++i]);
61 }
62 else if (std::string(argv[i]) == "--finger" && i + 1 < argc) {
63 opt_finger_file_name = std::string(argv[++i]);
64 }
65 else if (std::string(argv[i]) == "--tactile" && i + 1 < argc) {
66 opt_tactile_file_name = atoi(argv[++i]);
67 }
68 else if (std::string(argv[i]) == "--motor" && i + 1 < argc) {
69 opt_motor_file_name = atoi(argv[++i]);
70 }
71 else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
72 std::cout << "\nUsage: " << argv[0]
73 << " [--network <interface name>] "
74 << " [--finger <calib file name>]"
75 << " [--tactile <calib file name>]"
76 << " [--motor <constants file name>]"
77 << " [--help] [-h]\n"
78 << std::endl;
79 std::cout << "Options:" << std::endl;
80 std::cout << " --network <interface name>" << std::endl;
81 std::cout << "\tNetwork interface name. Default: " << opt_network_interface << std::endl << std::endl;
82 std::cout << " --finger <calib file name>" << std::endl;
83 std::cout << "\tFinger calibration file name. Default: " << opt_finger_file_name << std::endl << std::endl;
84 std::cout << " --tactile <calib file name>" << std::endl;
85 std::cout << "\tTactile calibration file name. Default: " << opt_tactile_file_name << std::endl << std::endl;
86 std::cout << " --motor <constants file name>" << std::endl;
87 std::cout << "\tMotor constants file name. Default: " << opt_motor_file_name << std::endl << std::endl;
88 std::cout << " --help, -h" << std::endl;
89 std::cout << "\tPrint this helper." << std::endl;
90
91 return EXIT_SUCCESS;
92 }
93 }
94#ifdef VISP_HAVE_TAKKTILE2
95 vpReflexTakktile2 reflex;
96 reflex.setNetworkInterface(opt_network_interface);
97 reflex.setFingerConfigFile(opt_finger_file_name);
98 reflex.setTactileConfigFile(opt_tactile_file_name);
99 reflex.setMotorConfigFile(opt_motor_file_name);
100
101 reflex.open();
102
103 /****************************************************/
104 reflex.calibrate();
105 reflex.wait(100);
106
107 std::cout << "Calibration complete" << std::endl;
108 reflex.wait(500);
109
110 /****************************************************/
111 // Demonstration of position control
112
113 std::cout << "Moving fingers..." << std::endl;
114
115 std::vector<vpColVector> finger_positions = {
116 {0.0, 0.0, 0.0, 0.0}, {0.5, 0.5, 0.5, 0.0}, {1.0, 1.0, 1.0, 0.0}, {0.5, 0.5, 0.5, 0.0}, {0.0, 0.0, 0.0, 0.0} };
117
118 for (size_t i = 0; i < finger_positions.size(); i++) {
119 reflex.setPosition(finger_positions[i]);
120 reflex.wait(500);
121 }
122
123 std::cout << "Finger movement complete" << std::endl;
124 reflex.wait(500);
125
126 /****************************************************/
127 // Demonstration of preshape joint
128
129 std::cout << "Moving preshape joint..." << std::endl;
130
131 std::vector<vpColVector> preshape_positions = {
132 {0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.5}, {0.0, 0.0, 0.0, 1.5}, {0.0, 0.0, 0.0, 0.5}, {0.0, 0.0, 0.0, 0.0} };
133
134 for (size_t i = 0; i < preshape_positions.size(); i++) {
135 reflex.setPosition(preshape_positions[i]);
136 reflex.wait(500);
137 }
138
139 std::cout << "Preshape movement complete" << std::endl;
140 reflex.wait(500);
141
142 /****************************************************/
143 // Demonstration of changing velocity
144
145 std::cout << "Changing to faster speed..." << std::endl;
146 vpColVector faster_velocities = { 7.0, 7.0, 7.0, 7.0 };
147 reflex.setPositioningVelocity(faster_velocities);
148
149 for (size_t i = 0; i < finger_positions.size(); i++) {
150 reflex.setPosition(finger_positions[i]);
151 reflex.wait(500);
152 }
153
154 std::cout << "Changing to slower speed..." << std::endl;
155 vpColVector slower_velocities = { 0.5, 0.5, 0.5, 0.5 };
156 reflex.setPositioningVelocity(slower_velocities);
157
158 for (size_t i = 0; i < finger_positions.size(); i++) {
159 reflex.setPosition(finger_positions[i]);
160 reflex.wait(500);
161 }
162
163 std::cout << "Done changing speeds" << std::endl;
164 reflex.wait(500);
165
166 /****************************************************/
167 // Demonstration of blended control
168
169 std::cout << "Starting blended control..." << std::endl;
170 vpColVector mixed_speeds = { 0.5, 1.0, 1.5, 0.0 };
171 reflex.setPositioningVelocity(mixed_speeds);
172
173 for (int i = 0; i < 5; i++) {
174 reflex.setPosition(finger_positions[i]);
175 reflex.wait(500);
176 }
177
178 reflex.setPositioningVelocity(slower_velocities);
179
180 std::cout << "Blended control complete" << std::endl;
181 reflex.wait(500);
182
183 /****************************************************/
184 // Demonstration of tactile feedback and setting sensor thresholds
185
186 std::cout << "Starting tactile feedback..." << std::endl
187 << "All fingers will stop moving when any one makes contact" << std::endl;
188 vpColVector move_speeds = { 1.25, 1.25, 1.25, 0 };
189
190 reflex.setTactileThreshold(15);
191
192 reflex.setVelocityUntilAnyContact(move_speeds);
193 reflex.wait(1000);
194
195 reflex.setPosition(finger_positions[0]);
196 reflex.wait(500);
197
198 /****************************************************/
199 std::cout << "Now each finger will only stop moving once it makes contact" << std::endl;
200
201 std::vector<int> thresholds = { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 20, 20,
202 20, 20, 20, 20, 20, 20, 20, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 };
203
204 reflex.setTactileThreshold(thresholds);
205
206 reflex.setVelocityUntilEachContact(move_speeds);
207 reflex.wait(1000);
208
209 reflex.setPosition(finger_positions[0]);
210 reflex.wait(500);
211
212 /****************************************************/
213 reflex.disableTorque();
214 std::cout << "All torques disabled" << std::endl;
215
216 std::cout << "The end" << std::endl;
217
218#else
219 std::cout << "ViSP is not built to support Right Hand Reflex Takktile2 hand" << std::endl;
220#endif
221
222 return EXIT_SUCCESS;
223}
Implementation of column vector and the associated operations.
void setVelocityUntilAnyContact(const vpColVector &targets)
void setVelocityUntilEachContact(const vpColVector &targets)
void setTactileThreshold(int threshold)
void setMotorConfigFile(const std::string &motor_file_name)
void setPosition(const vpColVector &targets)
void setTactileConfigFile(const std::string &tactile_file_name)
void setPositioningVelocity(const vpColVector &targets)
void setNetworkInterface(const std::string &network_interface="eth0")
void setFingerConfigFile(const std::string &finger_file_name)
void wait(int milliseconds)