grasp
All Data Structures Namespaces Functions Modules
psoThread.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 __PSO_THREAD_H__
18 #define __PSO_THREAD_H__
19 
20 #include <cmath>
21 #include <algorithm>
22 #include <fstream>
23 #include <yarp/os/RateThread.h>
24 #include <yarp/os/ResourceFinder.h>
25 #include <yarp/os/Time.h>
26 #include <yarp/os/Random.h>
27 #include <yarp/sig/Vector.h>
28 #include <yarp/sig/Matrix.h>
29 #include <yarp/math/Math.h>
30 #include <yarp/math/Rand.h>
31 #include <yarp/dev/CartesianControl.h>
32 #include <yarp/dev/ControlBoardInterfaces.h>
33 #include <yarp/dev/PolyDriver.h>
34 #include <iCub/iKin/iKinFwd.h>
35 #include <iCub/grasp/forceClosure.h>
36 #include <pcl/common/common_headers.h>
37 #include <pcl/io/io.h>
38 #include <pcl/octree/octree.h>
39 #include <pcl/kdtree/kdtree_flann.h>
40 
41 class PsoThread : public yarp::os::RateThread
42 {
43 private:
44  bool done;
45  bool work;
46  bool init;
47  bool set;
48  int particles;
49  int iterations;
50  int overlapping_cones;
51  int dimension;
52  int rand_method;
53  double omega;
54  double phi_p;
55  double phi_g;
56  double limit_finger_min;
57  double limit_finger_max;
58  double hand_area;
59  double fg;
60  double cost;
61  double alpha;
62  double vmax,vmin;
63 
64  std::deque<yarp::sig::Vector> x;
65  std::deque<yarp::sig::Vector> ns;
66  std::deque<yarp::sig::Vector> v;
67  std::deque<yarp::sig::Vector> p;
68  yarp::sig::Vector nsg;
69  yarp::sig::Vector fp;
70  yarp::sig::Vector g;
71  std::vector<yarp::sig::Vector> visited;
72 
73  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud;
74  pcl::PointCloud <pcl::Normal>::Ptr normals;
75  pcl::KdTreeFLANN<pcl::PointXYZ> kdtree;
76 
77  yarp::sig::Vector findDifferentIds(const yarp::sig::Vector &ids);
78  yarp::sig::Vector findTriplet(const yarp::sig::Vector &vect);
79  int findClosestPoint(pcl::PointXYZ &point);
80  yarp::sig::Vector assignPoints(const yarp::sig::Vector &ids);
81  yarp::sig::Vector assignNormals(const yarp::sig::Vector &ids);
82  double fitness(iCub::grasp::ContactPoints &triplet);
83  bool counterOverlap(yarp::sig::Vector &n1, yarp::sig::Vector &n2, double &angle);
84  double penaltyCones(int n_cones, yarp::sig::Vector &idx, yarp::sig::Vector &angles);
85  double triangleArea(yarp::sig::Vector &p1, yarp::sig::Vector &p2, yarp::sig::Vector &p3);
86  iCub::grasp::ContactPoints fillContactPoints(yarp::sig::Vector &xi, yarp::sig::Vector &nsi);
87  void initialization();
88  yarp::sig::Vector findRandomId();
89 
90 public:
91 
92  PsoThread();
93  ~PsoThread() {};
94 
95  bool open(const yarp::os::Property &options);
96  bool checkDone();
97  void threadRelease();
98  void close();
99  void run();
100  void setData(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, pcl::PointCloud <pcl::Normal>::Ptr normals, double alpha, int overlapping_cones);
101  iCub::grasp::ContactPoints getBestTriplet();
102  double getCost();
103  bool isSuccessful();
104 
105 };
106 
107 #endif
Definition of the ForceClosure.
Definition: forceClosure.h:60