grasp
All Data Structures Namespaces Functions Modules
orientationThread.h
1 /* Copyright: (C) 2014 iCub Facility - Istituto Italiano di Tecnologia
2  * Authors: Ilaria Gori
3  * email: ilaria.gori@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 #ifndef __ORIENTATION_THREAD_H__
18 #define __ORIENTATION_THREAD_H__
19 
20 #include <cmath>
21 
22 #include <yarp/os/RateThread.h>
23 #include <yarp/os/ResourceFinder.h>
24 #include <yarp/os/Time.h>
25 #include <yarp/dev/CartesianControl.h>
26 #include <yarp/dev/ControlBoardInterfaces.h>
27 #include <yarp/dev/PolyDriver.h>
28 #include <yarp/sig/Vector.h>
29 #include <yarp/sig/Matrix.h>
30 #include <yarp/math/Math.h>
31 
32 #include <iCub/iKin/iKinFwd.h>
33 
34 class OrientationThread : public yarp::os::RateThread
35 {
36 private:
37 
38  int nAngles;
39  int currentContext;
40  double bestManip;
41  bool done;
42  bool work;
43  bool noResult;
44  std::string hand;
45 
46  yarp::dev::PolyDriver dCtrl;
47  yarp::dev::ICartesianControl *iCtrl;
48  yarp::dev::PolyDriver robotArm;
49  yarp::dev::PolyDriver robotTorso;
50  yarp::dev::IControlLimits *limTorso, *limArm;
51 
52  iCub::iKin::iCubArm *arm;
53  iCub::iKin::iKinChain *chain;
54 
55  yarp::sig::Vector eePos;
56  yarp::sig::Vector px;
57  yarp::sig::Vector py;
58  yarp::sig::Vector pointNormal;
59  yarp::sig::Vector center;
60  yarp::sig::Vector biggestAxis;
61  yarp::sig::Vector thetaMin, thetaMax;
62  yarp::sig::Matrix bestOrientation;
63  yarp::sig::Vector od;
64  yarp::sig::Vector q, q0;
65  yarp::sig::Vector xdhat, odhat;
66  yarp::sig::Vector ones;
67  yarp::sig::Matrix Jacobian, mulJac;
68  yarp::sig::Vector angles;
69 
70  void getAngles(yarp::sig::Vector &angles, int factor);
71  bool normalDirection(std::string &hand, yarp::sig::Vector &normal);
72 
73 public:
74 
75  OrientationThread();
76  ~OrientationThread() {};
77 
78  bool open(std::string &name, std::string &arm, std::string &robot, int &nAngles);
79  void close();
80  bool checkDone();
81  void setInfo(yarp::sig::Vector &eePos, yarp::sig::Vector &px, yarp::sig::Vector &py, yarp::sig::Vector &pointNormal, yarp::sig::Vector &center, yarp::sig::Vector &biggerAxis);
82  void getBestManip(double &manip, yarp::sig::Matrix &orientation);
83  bool getResult();
84  void threadRelease();
85  void run();
86  void reset();
87  void preAskForPose();
88  void postAskForPose();
89 
90 };
91 
92 #endif