karma
All Modules
module.h
1 /*
2  * Copyright (C) 2011 Department of Robotics Brain and Cognitive Sciences - Istituto Italiano di Tecnologia
3  * Author: Vadim Tikhanoff Ugo Pattacini
4  * email: vadim.tikhanoff@iit.it
5  * Permission is granted to copy, distribute, and/or modify this program
6  * under the terms of the GNU General Public License, version 2 or any
7  * later version published by the Free Software Foundation.
8  *
9  * A copy of the license can be found at
10  * http://www.robotcub.org/icub/license/gpl.txt
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15  * Public License for more details
16 */
17 
18 #ifndef __MODULE_H__
19 #define __MODULE_H__
20 
21 #include <string>
22 #include <map>
23 
24 #include <yarp/os/Time.h>
25 #include <yarp/os/RFModule.h>
26 #include <yarp/os/RpcServer.h>
27 #include <yarp/os/RpcClient.h>
28 #include <yarp/os/BufferedPort.h>
29 #include <yarp/os/Port.h>
30 #include <yarp/sig/Image.h>
31 #include <yarp/sig/Vector.h>
32 
33 #include <opencv2/opencv.hpp>
34 
35 #include "iCub/utils.h"
36 
37 #define LEFTARM 0
38 #define RIGHTARM 1
39 
40 /**********************************************************/
41 struct blobsData
42 {
43  int index;
44  double lenght;
45  double vdrawError;
46  cv::Point posistion;
47  double bestDistance;
48  double bestAngle;
49  std::string name;
50 };
51 /**********************************************************/
52 class Manager : public yarp::os::RFModule
53 {
54 protected:
55 
56  std::string name; //name of the module
57  std::string hand; //name of the module
58  std::string camera; //name of the camera
59  yarp::os::Port rpcHuman; //human rpc port (receive commands via rpc)
60  yarp::os::RpcClient rpcMotorAre; //rpc motor port ARE
61  yarp::os::RpcClient rpcMotorKarma; //rpc motor port KARMA
62  yarp::os::RpcClient iolStateMachine; //rpc to iol state machine
63  yarp::os::RpcClient rpcMIL; //rpc mil port
64  yarp::os::RpcClient rpcKarmaLearn; //rpc mil port
65  yarp::os::RpcClient rpcReconstruct; //rpc reconstruct
66  yarp::os::RpcClient rpcGraspEstimate; //rpc graspEstimate
67  yarp::os::RpcClient rpcOPC; //rpc graspEstimate
68 
69  ParticleFilter particleFilter; //class to receive positions from the templateTracker module
70  SegmentationPoint segmentPoint; //class to request segmentation from activeSegmentation module
71  PointedLocation pointedLoc; //port class to receive pointed locations
72 
73  yarp::os::BufferedPort<yarp::os::Bottle> blobExtractor;
74  yarp::os::BufferedPort<yarp::os::Bottle> particleTracks;
75 
76  std::mutex mutexResources; //mutex for ressources
77  bool pointGood; //boolean for if got a point location
78  cv::Point pointLocation; //x and y of the pointed location
79  bool init;
80  yarp::os::Bottle lastBlobs;
81  yarp::os::Bottle lastTool;
82  yarp::sig::Vector objectPos;
83  yarp::sig::Vector toolSmall, toolBig;
84 
85  std::string obj;
86  double userTheta;
87  blobsData *blobsDetails;
88 
89  std::map<int, double> randActions;
90 
91  yarp::os::Bottle getBlobs();
92  cv::Point getBlobCOG(const yarp::os::Bottle &blobs, const int i);
93  double getBlobLenght(const yarp::os::Bottle &blobs, const int i);
94 
95  bool get3DPosition(const cv::Point &point, yarp::sig::Vector &x);
96  yarp::os::Bottle findClosestBlob(const yarp::os::Bottle &blobs, const cv::Point &loc);
97  int processHumanCmd(const yarp::os::Bottle &cmd, yarp::os::Bottle &b);
98  int executeOnLoc(bool shouldTrain);
99  int executeToolOnLoc();
100  yarp::os::Bottle executeToolLearning();
101  int executeToolSearchOnLoc( const std::string &objName );
102  yarp::os::Bottle executeBlobRecog( const std::string &objName );
103 
104  bool executeCloseHand(int ARM);
105  bool executeDropAway(int ARM);
106  bool executeGiveAction(int ARM);
107  bool executeSpeech( const std::string &speech );
108  double executeVirtualDraw(blobsData &blobsDetails);
109  double executeToolDrawNear(blobsData &blobsDetails);
110  int executeToolAttach(const yarp::sig::Vector &tool);
111  yarp::os::Bottle executeKarmaOptimize( const yarp::sig::Vector &tool, const std::string &objName);
112  yarp::os::Bottle classifyThem();
113 
114  yarp::os::Bottle findBlobLoc();
115  yarp::os::Bottle blobLoc;
116  yarp::os::Bottle blobList;
117 
118  bool executePCLGrasp( const std::string &objName );
119  double latchTimer, idleTmo;
120 
121  void takeMotionARE();
122  void segmentAndTrack( int x, int y );
123 
124  yarp::os::Bottle getOffset(yarp::os::Bottle &closestBlob, double actionOrient, yarp::sig::Vector &initPos);
125 
126  void getPraticleTracks();
127  void goHome();
128  void goHomeArmsHead();
129  double wrapAng (const double ang);
130 
131  yarp::os::Bottle classify(const yarp::os::Bottle &blobs, int index);
132  yarp::os::Bottle getType(const yarp::os::Bottle *mils, int index);
133 
134 public:
135  bool configure(yarp::os::ResourceFinder &rf);
136  bool interruptModule();
137  bool close();
138  bool updateModule();
139  double getPeriod();
140 };
141 #endif
142