grasp
All Data Structures Namespaces Functions Modules
handIK.h
1 /* Copyright: (C) 2014 iCub Facility - Istituto Italiano di Tecnologia
2  * Authors: Ugo Pattacini
3  * email: ugo.pattacini@iit.it
4  * Permission is granted to copy, distribute, and/or modify this program
5  * under the terms of the GNU General Public License, version 2 or any
6  * later version published by the Free Software Foundation.
7  *
8  * A copy of the license can be found in the file LICENSE located in the
9  * root directory.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14  * Public License for more details
15 */
16 
17 
18 #ifndef __HANDIK_H__
19 #define __HANDIK_H__
20 
21 #include <deque>
22 #include <yarp/sig/all.h>
23 #include <iCub/iKin/iKinFwd.h>
24 
25 
26 /****************************************************************/
27 struct HandIK_Problem
28 {
29  iCub::iKin::iCubFinger thumb;
30  iCub::iKin::iCubFinger index;
31  iCub::iKin::iCubFinger middle;
32 
33  int nJoints;
34  int nVars;
35  int nFingers;
36  std::string hand;
37  std::deque<yarp::sig::Vector> normalDirs; // to be given as list of 4x1 homogeneous unity vectors
38  std::deque<yarp::sig::Vector> contactPoints; // to be given as list of 4x1 homogeneous vectors
39  yarp::sig::Vector dimensions; // to be given as 3x1 vector
40 
41  HandIK_Problem(const std::string &_hand="right", const int fingers=2) :
42  hand(_hand),
43  nFingers(fingers),
44  thumb(_hand+"_thumb"),
45  index(_hand+"_index"),
46  middle(_hand+"_middle")
47  {
48  nJoints=(nFingers==2)?6:8;
49  nVars=3+3+nJoints;
50  dimensions.resize(3,0.0);
51  }
52 };
53 
54 
55 /****************************************************************/
56 struct HandIK_Variables
57 {
58  yarp::sig::Vector xyz_ee;
59  yarp::sig::Vector rpy_ee;
60  yarp::sig::Vector joints;
61  int nFingers;
62  double cost_fun;
63 
64  HandIK_Variables(const int fingers=2) : nFingers(fingers)
65  {
66  xyz_ee.resize(3,0.0);
67  rpy_ee.resize(3,0.0);
68  joints.resize((nFingers==2)?6:8,0.0);
69  cost_fun=0.0;
70  }
71 
72  void print();
73 };
74 
75 
76 /****************************************************************/
77 class HandIK_Solver
78 {
79 protected:
80  HandIK_Problem &problem;
81  HandIK_Variables guess;
82 
83 public:
84  HandIK_Solver(HandIK_Problem &_problem) : problem(_problem) { }
85  bool setInitialGuess(const HandIK_Variables &_guess);
86  bool solve(HandIK_Variables &solution);
87 };
88 
89 
90 #endif
91 
92