Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpReflexTakktile2.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 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
34#include <visp3/core/vpConfig.h>
35
36#ifdef VISP_HAVE_TAKKTILE2
37
38#include <reflex_driver2.h>
39
40#include <visp3/core/vpMath.h>
41#include <visp3/robot/vpReflexTakktile2.h>
42
44#ifndef DOXYGEN_SHOULD_SKIP_THIS
45class vpReflexTakktile2::Impl : public reflex_driver2::ReflexDriver
46{
47public:
48 Impl() { }
49
50 ~Impl() { }
51};
52
53#endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
54
56{
57 proximal.resize(NUM_FINGERS);
58 distal_approx.resize(NUM_FINGERS);
59
60 pressure.resize(NUM_FINGERS);
61 contact.resize(NUM_FINGERS);
62 for (size_t i = 0; i < NUM_FINGERS; i++) {
63 pressure[i].resize(NUM_SENSORS_PER_FINGER);
64 contact[i].resize(NUM_SENSORS_PER_FINGER);
65 }
66
67 joint_angle.resize(NUM_DYNAMIXELS);
68 raw_angle.resize(NUM_DYNAMIXELS);
69 velocity.resize(NUM_DYNAMIXELS);
70 load.resize(NUM_DYNAMIXELS);
71 voltage.resize(NUM_DYNAMIXELS);
72 temperature.resize(NUM_DYNAMIXELS);
73 error_state.resize(NUM_DYNAMIXELS);
74}
75
81VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpReflexTakktile2::HandInfo &hand)
82{
83 for (size_t i = 0; i < NUM_FINGERS; i++) {
84 os << "Finger " << i + 1 << ": " << std::endl;
85
86 os << "\tProximal: " << hand.proximal[i] << std::endl;
87 os << "\tDistal Approx: " << hand.distal_approx[i] << std::endl;
88
89 os << "\tPressures: ";
90 for (size_t j = 0; j < NUM_SENSORS_PER_FINGER; j++) {
91 os << hand.pressure[i][j] << ", ";
92 }
93 os << std::endl;
94
95 os << "\tContact: ";
96 for (size_t j = 0; j < NUM_SENSORS_PER_FINGER; j++) {
97 os << hand.contact[i][j] << ", ";
98 }
99 os << std::endl;
100
101 os << "\tJoint Angle: " << hand.joint_angle[i] << " rad" << std::endl;
102 os << "\tJoint Angle: " << vpMath::deg(static_cast<double>(hand.joint_angle[i])) << " deg" << std::endl;
103 os << "\tVelocity: " << hand.velocity[i] << " rad/s" << std::endl;
104 os << "\tVelocity: " << vpMath::deg(static_cast<double>(hand.velocity[i])) << " deg/s" << std::endl;
105 os << "\tError State: " << hand.error_state[i] << std::endl;
106 }
107
108 os << "Preshape: " << std::endl;
109 os << "\tJoint Angle: " << hand.joint_angle[3] << std::endl;
110 os << "\tVelocity: " << hand.velocity[3] << std::endl;
111 os << "\tError State: " << hand.error_state[3] << std::endl;
112
113 return os;
114}
115
123
128
132void vpReflexTakktile2::calibrate() { m_impl->calibrate(); }
133
137void vpReflexTakktile2::disableTorque() { m_impl->disable_torque(); }
138
143{
144 for (size_t i = 0; i < NUM_FINGERS; i++) {
145 m_hand_info.proximal[i] = m_impl->hand_info.proximal[i];
146 m_hand_info.distal_approx[i] = m_impl->hand_info.distal_approx[i];
147 for (size_t j = 0; j < NUM_SENSORS_PER_FINGER; j++) {
148 m_hand_info.pressure[i][j] = m_impl->hand_info.pressure[i][j];
149 m_hand_info.contact[i][j] = m_impl->hand_info.contact[i][j];
150 }
151 }
152 for (size_t i = 0; i < NUM_DYNAMIXELS; i++) {
153 m_hand_info.joint_angle[i] = m_impl->hand_info.joint_angle[i];
154 m_hand_info.raw_angle[i] = m_impl->hand_info.raw_angle[i];
155 m_hand_info.velocity[i] = m_impl->hand_info.velocity[i];
156 m_hand_info.load[i] = m_impl->hand_info.load[i];
157 m_hand_info.voltage[i] = m_impl->hand_info.voltage[i];
158 m_hand_info.temperature[i] = m_impl->hand_info.temperature[i];
159 m_hand_info.error_state[i] = m_impl->hand_info.error_state[i];
160 }
161
162 return m_hand_info;
163}
164
168int vpReflexTakktile2::getNumServos() const { return static_cast<int>(NUM_SERVOS); }
169
173int vpReflexTakktile2::getNumFingers() const { return static_cast<int>(NUM_FINGERS); }
174
178int vpReflexTakktile2::getNumSensorsPerFinger() const { return static_cast<int>(NUM_SENSORS_PER_FINGER); }
179
185{
186 vpColVector position(NUM_SERVOS);
187 for (unsigned int i = 0; i < NUM_SERVOS; i++) {
188 position[i] = static_cast<double>(m_impl->hand_info.joint_angle[i]);
189 }
190 return position;
191}
192
198{
199 vpColVector velocity(NUM_SERVOS);
200 for (unsigned int i = 0; i < NUM_SERVOS; i++) {
201 velocity[i] = static_cast<double>(m_impl->hand_info.velocity[i]);
202 }
203 return velocity;
204}
205
215{
216 if (targets.size() != NUM_SERVOS) {
217 vpException(vpException::dimensionError, "Wrong Takktile 2 position vector dimension (%d) instead of %d.",
218 targets.size(), NUM_SERVOS);
219 }
220 float targets_[NUM_SERVOS];
221 for (unsigned int i = 0; i < NUM_SERVOS; i++) {
222 targets_[i] = static_cast<float>(targets[i]);
223 }
224 m_impl->set_angle_position(targets_);
225}
226
233void vpReflexTakktile2::setTactileThreshold(int threshold) { m_impl->populate_tactile_thresholds(threshold); }
234
242void vpReflexTakktile2::setTactileThreshold(const std::vector<int> &thresholds)
243{
244 if (thresholds.size() != NUM_FINGERS * NUM_SENSORS_PER_FINGER) {
245 vpException(vpException::dimensionError, "Wrong Takktile threshold vector dimension (%d) instead of %d.",
246 thresholds.size(), NUM_FINGERS * NUM_SENSORS_PER_FINGER);
247 }
248 int thresholds_[NUM_FINGERS * NUM_SENSORS_PER_FINGER];
249 for (size_t i = 0; i < NUM_FINGERS * NUM_SENSORS_PER_FINGER; i++) {
250 thresholds_[i] = thresholds[i];
251 }
252
253 m_impl->set_tactile_thresholds(thresholds_);
254}
255
263{
264 if (targets.size() != NUM_SERVOS) {
265 vpException(vpException::dimensionError, "Wrong Takktile 2 velocity vector dimension (%d) instead of %d.",
266 targets.size(), NUM_SERVOS);
267 }
268 float targets_[NUM_SERVOS];
269 for (unsigned int i = 0; i < NUM_SERVOS; i++) {
270 targets_[i] = static_cast<float>(targets[i]);
271 }
272 m_impl->set_motor_speed(targets_);
273}
274
281{
282 if (targets.size() != NUM_SERVOS) {
283 vpException(vpException::dimensionError, "Wrong Takktile 2 velocity vector dimension (%d) instead of %d.",
284 targets.size(), NUM_SERVOS);
285 }
286 float targets_[NUM_SERVOS];
287 for (unsigned int i = 0; i < NUM_SERVOS; i++) {
288 targets_[i] = static_cast<float>(targets[i]);
289 }
290 m_impl->move_until_any_contact(targets_);
291}
292
299{
300 if (targets.size() != NUM_SERVOS) {
301 vpException(vpException::dimensionError, "Wrong Takktile 2 velocity vector dimension (%d) instead of %d.",
302 targets.size(), NUM_SERVOS);
303 }
304 float targets_[NUM_SERVOS];
305 for (unsigned int i = 0; i < NUM_SERVOS; i++) {
306 targets_[i] = static_cast<float>(targets[i]);
307 }
308 m_impl->move_until_each_contact(targets_);
309}
310
315{
317 reflex_hand2::ReflexHandState *state = &m_impl->rh->rx_state_;
318 m_impl->rh->setStateCallback(std::bind(&reflex_driver2::ReflexDriver::reflex_hand_state_cb, m_impl, state));
319}
320
325void vpReflexTakktile2::wait(int milliseconds) { m_impl->wait(milliseconds); }
326END_VISP_NAMESPACE
327#endif
unsigned int size() const
Return the number of elements of the 2D array.
Definition vpArray2D.h:435
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ dimensionError
Bad dimension.
Definition vpException.h:71
static double deg(double rad)
Definition vpMath.h:119
std::vector< uint32_t > temperature
std::vector< float > joint_angle
std::vector< std::vector< bool > > contact
std::vector< std::vector< int > > pressure
std::vector< std::string > error_state
std::vector< float > raw_angle
std::vector< float > proximal
std::vector< float > voltage
std::vector< float > distal_approx
std::vector< float > velocity
friend VISP_EXPORT std::ostream & operator<<(std::ostream &os, const HandInfo &hand)
void setVelocityUntilAnyContact(const vpColVector &targets)
std::string m_finger_file_name
void setVelocityUntilEachContact(const vpColVector &targets)
std::string m_tactile_file_name
void setTactileThreshold(int threshold)
std::string m_network_interface
vpColVector getVelocity() const
void setPosition(const vpColVector &targets)
void setPositioningVelocity(const vpColVector &targets)
std::string m_motor_file_name
vpColVector getPosition() const
int getNumSensorsPerFinger() const
void wait(int milliseconds)