iCub-main
Loading...
Searching...
No Matches
CouplingICubHandMk2.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2006-2024 Istituto Italiano di Tecnologia (IIT)
3 * All rights reserved.
4 *
5 * This software may be modified and distributed under the terms of the
6 * BSD-3-Clause license. See the accompanying LICENSE file for details.
7 */
8
10#include <yarp/os/LogStream.h>
11#include <cmath>
12#include <array>
13#include <numeric>
14
15
16YARP_LOG_COMPONENT(COUPLINGICUBHANDMK2, "yarp.device.couplingICubHandMk2")
17
18
19bool CouplingICubHandMk2::populateCouplingParameters() {
20 yarp::sig::VectorOf<size_t> coupled_physical_joints, coupled_actuated_axes;
21 coupled_physical_joints.resize(m_jointNames.size());
22 coupled_actuated_axes.resize(m_COUPLING_actuatedAxesNames.size());
23 std::iota(coupled_physical_joints.begin(), coupled_physical_joints.end(), 0);
24 std::iota(coupled_actuated_axes.begin(), coupled_actuated_axes.end(), 0);
25 std::vector<std::pair<double, double>> physical_joint_limits;
26
27 physical_joint_limits.resize(m_jointNames.size());
28 for (int i = 0; i< m_jointNames.size(); i++)
29 {
30 physical_joint_limits[i] = std::make_pair(m_LIMITS_jntPosMin[i], m_LIMITS_jntPosMax[i]);
31 }
32 initialise(coupled_physical_joints, coupled_actuated_axes, m_jointNames, m_COUPLING_actuatedAxesNames, physical_joint_limits);
33 return true;
34}
35
36bool CouplingICubHandMk2::open(yarp::os::Searchable& config) {
37
38 if(!parseParams(config)) {
39 yCError(COUPLINGICUBHANDMK2) << "Error parsing parameters";
40 return false;
41 }
42
43 if(!populateCouplingParameters()) {
44 yCError(COUPLINGICUBHANDMK2) << "Error populating coupling parameters";
45 return false;
46 }
47
48 yCDebug(COUPLINGICUBHANDMK2) << "Opening CouplingICubHandMk2"<<config.toString();
49 return true;
50}
51
52bool CouplingICubHandMk2::convertFromPhysicalJointsToActuatedAxesPos(const yarp::sig::Vector& physJointsPos, yarp::sig::Vector& actAxesPos) {
53 size_t nrOfPhysicalJoints;
54 size_t nrOfActuatedAxes;
55 auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints);
56 ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes);
57 if (!ok || physJointsPos.size() != nrOfPhysicalJoints || actAxesPos.size() != nrOfActuatedAxes) {
58 yCError(COUPLINGICUBHANDMK2) << "convertFromPhysicalJointsToActuatedAxesPos: input or output vectors have wrong size";
59 return false;
60 }
61
62 // l/r_hand_finger
63 actAxesPos[0] = (20.0 - physJointsPos[12])*3;
64 // l/r_thumb_oppose
65 actAxesPos[1] = physJointsPos[0];
66 // l/r_thumb_proximal
67 actAxesPos[2] = physJointsPos[1];
68 // l/r_thumb_distal
69 actAxesPos[3] = physJointsPos[2] + physJointsPos[3];
70 // l/r_index_proximal
71 actAxesPos[4] = physJointsPos[5];
72 // l/r_index_distal
73 actAxesPos[5] = physJointsPos[6] + physJointsPos[7];
74 // l/r_middle_proximal
75 actAxesPos[6] = physJointsPos[9];
76 // l/r_middle_distal
77 actAxesPos[7] = physJointsPos[10] + physJointsPos[11];
78 // l/r_pinky
79 actAxesPos[8] = physJointsPos[13] + physJointsPos[14] + physJointsPos[15];
80 return true;
81}
82
83bool CouplingICubHandMk2::convertFromPhysicalJointsToActuatedAxesVel(const yarp::sig::Vector& physJointsPos, const yarp::sig::Vector& physJointsVel, yarp::sig::Vector& actAxesVel) {
84 size_t nrOfPhysicalJoints;
85 size_t nrOfActuatedAxes;
86 auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints);
87 ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes);
88 if (!ok || physJointsVel.size() != nrOfPhysicalJoints || actAxesVel.size() != nrOfActuatedAxes) {
89 yCError(COUPLINGICUBHANDMK2) << "convertFromPhysicalJointsToActuatedAxesVel: input or output vectors have wrong size";
90 return false;
91 }
92 // l/r_hand_finger
93 actAxesVel[0] = -physJointsVel[12]*3;
94 // l/r_thumb_oppose
95 actAxesVel[1] = physJointsVel[0];
96 // l/r_thumb_proximal
97 actAxesVel[2] = physJointsVel[1];
98 // l/r_thumb_distal
99 actAxesVel[3] = physJointsVel[2] + physJointsVel[3];
100 // l/r_index_proximal
101 actAxesVel[4] = physJointsVel[5];
102 // l/r_index_distal
103 actAxesVel[5] = physJointsVel[6] + physJointsVel[7];
104 // l/r_middle_proximal
105 actAxesVel[6] = physJointsVel[9];
106 // l/r_middle_distal
107 actAxesVel[7] = physJointsVel[10] + physJointsVel[11];
108 // l/r_pinky
109 actAxesVel[8] = physJointsVel[13] + physJointsVel[14] + physJointsVel[15];
110 return true;
111}
112
113
114bool CouplingICubHandMk2::convertFromPhysicalJointsToActuatedAxesAcc(const yarp::sig::Vector& physJointsPos, const yarp::sig::Vector& physJointsVel, const yarp::sig::Vector& physJointsAcc, yarp::sig::Vector& actAxesAcc) {
115 size_t nrOfPhysicalJoints;
116 size_t nrOfActuatedAxes;
117 auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints);
118 ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes);
119 if (!ok || physJointsAcc.size() != nrOfPhysicalJoints || actAxesAcc.size() != nrOfActuatedAxes) {
120 yCError(COUPLINGICUBHANDMK2) << "convertFromPhysicalJointsToActuatedAxesAcc: input or output vectors have wrong size";
121 return false;
122 }
123 // l/r_hand_finger
124 actAxesAcc[0] = -physJointsAcc[12]*3;
125 // l/r_thumb_oppose
126 actAxesAcc[1] = physJointsAcc[0];
127 // l/r_thumb_proximal
128 actAxesAcc[2] = physJointsAcc[1];
129 // l/r_thumb_distal
130 actAxesAcc[3] = physJointsAcc[2] + physJointsAcc[3];
131 // l/r_index_proximal
132 actAxesAcc[4] = physJointsAcc[5];
133 // l/r_index_distal
134 actAxesAcc[5] = physJointsAcc[6] + physJointsAcc[7];
135 // l/r_middle_proximal
136 actAxesAcc[6] = physJointsAcc[9];
137 // l/r_middle_distal
138 actAxesAcc[7] = physJointsAcc[10] + physJointsAcc[11];
139 // l/r_pinky
140 actAxesAcc[8] = physJointsAcc[13] + physJointsAcc[14] + physJointsAcc[15];
141 return false;
142}
143
144bool CouplingICubHandMk2::convertFromPhysicalJointsToActuatedAxesTrq(const yarp::sig::Vector& physJointsPos, const yarp::sig::Vector& physJointsTrq, yarp::sig::Vector& actAxesTrq) {
145 return false;
146}
147
148
149bool CouplingICubHandMk2::convertFromActuatedAxesToPhysicalJointsPos(const yarp::sig::Vector& actAxesPos, yarp::sig::Vector& physJointsPos) {
150 size_t nrOfPhysicalJoints;
151 size_t nrOfActuatedAxes;
152 auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints);
153 ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes);
154 if (!ok || physJointsPos.size() != nrOfPhysicalJoints || actAxesPos.size() != nrOfActuatedAxes) {
155 yCError(COUPLINGICUBHANDMK2) << "convertFromActuatedAxesToPhysicalJointsPos: input or output vectors have wrong size";
156 return false;
157 }
158
159 // l/r_hand_thumb_0
160 physJointsPos[0] = actAxesPos[1];
161 // l/r_hand_thumb_1
162 physJointsPos[1] = actAxesPos[2];
163 // l/r_hand_thumb_2
164 physJointsPos[2] = actAxesPos[3]/2;
165 // l/r_hand_thumb_3
166 physJointsPos[3] = actAxesPos[3]/2;
167 // l/r_hand_index_0
168 physJointsPos[4] = -(20.0 - actAxesPos[0]/3);
169 // l/r_hand_index_1
170 physJointsPos[5] = actAxesPos[4];
171 // l/r_hand_index_2
172 physJointsPos[6] = actAxesPos[5]/2;
173 // l/r_hand_index_3
174 physJointsPos[7] = actAxesPos[5]/2;
175 // l/r_hand_middle_0
176 physJointsPos[8] = 0.0;
177 // l/r_hand_middle_1
178 physJointsPos[9] = actAxesPos[6];
179 // l/r_hand_middle_2
180 physJointsPos[10] = actAxesPos[7]/2;
181 // l/r_hand_middle_3
182 physJointsPos[11] = actAxesPos[7]/2;
183 // l/r_hand_ring_0
184 physJointsPos[12] = 20.0 - actAxesPos[0]/3;
185 // l/r_hand_ring_1
186 physJointsPos[13] = actAxesPos[8]/3;
187 // l/r_hand_ring_2
188 physJointsPos[14] = actAxesPos[8]/3;
189 // l/r_hand_ring_3
190 physJointsPos[15] = actAxesPos[8]/3;
191 // l/r_hand_little_0
192 physJointsPos[16] = 20.0 - actAxesPos[0]/3;
193 // l/r_hand_little_1
194 physJointsPos[17] = actAxesPos[8]/3;
195 // l/r_hand_little_2
196 physJointsPos[18] = actAxesPos[8]/3;
197 // l/r_hand_little_3
198 physJointsPos[19] = actAxesPos[8]/3;
199
200 return true;
201}
202
203
204bool CouplingICubHandMk2::convertFromActuatedAxesToPhysicalJointsVel(const yarp::sig::Vector& actAxesPos, const yarp::sig::Vector& actAxesVel, yarp::sig::Vector& physJointsVel) {
205 size_t nrOfPhysicalJoints;
206 size_t nrOfActuatedAxes;
207 auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints);
208 ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes);
209 if (!ok || actAxesPos.size() != nrOfActuatedAxes || physJointsVel.size() != nrOfPhysicalJoints || actAxesVel.size() != nrOfActuatedAxes) {
210 yCError(COUPLINGICUBHANDMK2) << "convertFromPhysicalJointsToActuatedAxesVel: input or output vectors have wrong size";
211 return false;
212 }
213
214 // l/r_hand_thumb_0
215 physJointsVel[0] = actAxesVel[1];
216 // l/r_hand_thumb_1
217 physJointsVel[1] = actAxesVel[2];
218 // l/r_hand_thumb_2
219 physJointsVel[2] = actAxesVel[3]/2;
220 // l/r_hand_thumb_3
221 physJointsVel[3] = actAxesVel[3]/2;
222 // l/r_hand_index_0
223 physJointsVel[4] = actAxesVel[0]/3;
224 // l/r_hand_index_1
225 physJointsVel[5] = actAxesVel[4];
226 // l/r_hand_index_2
227 physJointsVel[6] = actAxesVel[5]/2;
228 // l/r_hand_index_3
229 physJointsVel[7] = actAxesVel[5]/2;
230 // l/r_hand_middle_0
231 physJointsVel[8] = 0.0;
232 // l/r_hand_middle_1
233 physJointsVel[9] = actAxesVel[6];
234 // l/r_hand_middle_2
235 physJointsVel[10] = actAxesVel[7]/2;
236 // l/r_hand_middle_3
237 physJointsVel[11] = actAxesVel[7]/2;
238 // l/r_hand_ring_0
239 physJointsVel[12] = -actAxesVel[0]/3;
240 // l/r_hand_ring_1
241 physJointsVel[13] = actAxesVel[8]/3;
242 // l/r_hand_ring_2
243 physJointsVel[14] = actAxesVel[8]/3;
244 // l/r_hand_ring_3
245 physJointsVel[15] = actAxesVel[8]/3;
246 // l/r_hand_little_0
247 physJointsVel[16] = - actAxesVel[0]/3;
248 // l/r_hand_little_1
249 physJointsVel[17] = actAxesVel[8]/3;
250 // l/r_hand_little_2
251 physJointsVel[18] = actAxesVel[8]/3;
252 // l/r_hand_little_3
253 physJointsVel[19] = actAxesVel[8]/3;
254
255 return true;
256}
257
258bool CouplingICubHandMk2::convertFromActuatedAxesToPhysicalJointsAcc(const yarp::sig::Vector& actAxesPos, const yarp::sig::Vector& actAxesVel, const yarp::sig::Vector& actAxesAcc, yarp::sig::Vector& physJointsAcc) {
259 size_t nrOfPhysicalJoints;
260 size_t nrOfActuatedAxes;
261 auto ok = getNrOfPhysicalJoints(nrOfPhysicalJoints);
262 ok = ok && getNrOfActuatedAxes(nrOfActuatedAxes);
263 if (!ok || actAxesPos.size() != nrOfActuatedAxes || physJointsAcc.size() != nrOfPhysicalJoints || actAxesAcc.size() != nrOfActuatedAxes) {
264 yCError(COUPLINGICUBHANDMK2) << "convertFromPhysicalJointsToActuatedAxesAcc: input or output vectors have wrong size";
265 return false;
266 }
267
268 // l/r_hand_thumb_0
269 physJointsAcc[0] = actAxesAcc[1];
270 // l/r_hand_thumb_1
271 physJointsAcc[1] = actAxesAcc[2];
272 // l/r_hand_thumb_2
273 physJointsAcc[2] = actAxesAcc[3]/2;
274 // l/r_hand_thumb_3
275 physJointsAcc[3] = actAxesAcc[3]/2;
276 // l/r_hand_index_0
277 physJointsAcc[4] = actAxesAcc[0]/3;
278 // l/r_hand_index_1
279 physJointsAcc[5] = actAxesAcc[4];
280 // l/r_hand_index_2
281 physJointsAcc[6] = actAxesAcc[5]/2;
282 // l/r_hand_index_3
283 physJointsAcc[7] = actAxesAcc[5]/2;
284 // l/r_hand_middle_0
285 physJointsAcc[8] = 0.0;
286 // l/r_hand_middle_1
287 physJointsAcc[9] = actAxesAcc[6];
288 // l/r_hand_middle_2
289 physJointsAcc[10] = actAxesAcc[7]/2;
290 // l/r_hand_middle_3
291 physJointsAcc[11] = actAxesAcc[7]/2;
292 // l/r_hand_ring_0
293 physJointsAcc[12] = - actAxesAcc[0]/3;
294 // l/r_hand_ring_1
295 physJointsAcc[13] = actAxesAcc[8]/3;
296 // l/r_hand_ring_2
297 physJointsAcc[14] = actAxesAcc[8]/3;
298 // l/r_hand_ring_3
299 physJointsAcc[15] = actAxesAcc[8]/3;
300 // l/r_hand_little_0
301 physJointsAcc[16] = - actAxesAcc[0]/3;
302 // l/r_hand_little_1
303 physJointsAcc[17] = actAxesAcc[8]/3;
304 // l/r_hand_little_2
305 physJointsAcc[18] = actAxesAcc[8]/3;
306 // l/r_hand_little_3
307 physJointsAcc[19] = actAxesAcc[8]/3;
308
309 return false;
310}
311bool CouplingICubHandMk2::convertFromActuatedAxesToPhysicalJointsTrq(const yarp::sig::Vector& actAxesPos, const yarp::sig::Vector& actAxesTrq, yarp::sig::Vector& physJointsTrq) {
312 return false;
313}
bool parseParams(const yarp::os::Searchable &config) override
bool convertFromActuatedAxesToPhysicalJointsPos(const yarp::sig::Vector &actAxesPos, yarp::sig::Vector &physJointsPos) override
bool convertFromActuatedAxesToPhysicalJointsAcc(const yarp::sig::Vector &actAxesPos, const yarp::sig::Vector &actAxesVel, const yarp::sig::Vector &actAxesAcc, yarp::sig::Vector &physJointsAcc) override
bool convertFromPhysicalJointsToActuatedAxesPos(const yarp::sig::Vector &physJointsPos, yarp::sig::Vector &actAxesPos) override
bool convertFromActuatedAxesToPhysicalJointsTrq(const yarp::sig::Vector &actAxesPos, const yarp::sig::Vector &actAxesTrq, yarp::sig::Vector &physJointsTrq) override
bool convertFromPhysicalJointsToActuatedAxesVel(const yarp::sig::Vector &physJointsPos, const yarp::sig::Vector &physJointsVel, yarp::sig::Vector &actAxesVel) override
bool convertFromPhysicalJointsToActuatedAxesAcc(const yarp::sig::Vector &physJointsPos, const yarp::sig::Vector &physJointsVel, const yarp::sig::Vector &physJointsAcc, yarp::sig::Vector &actAxesAcc) override
bool open(yarp::os::Searchable &config) override
Configure with a set of options.
bool convertFromActuatedAxesToPhysicalJointsVel(const yarp::sig::Vector &actAxesPos, const yarp::sig::Vector &actAxesVel, yarp::sig::Vector &physJointsVel) override
bool convertFromPhysicalJointsToActuatedAxesTrq(const yarp::sig::Vector &physJointsPos, const yarp::sig::Vector &physJointsTrq, yarp::sig::Vector &actAxesTrq) override