iCub-main
Loading...
Searching...
No Matches
module.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2014 iCub Facility - Istituto Italiano di Tecnologia
3 * Author: Ugo Pattacini
4 * email: ugo.pattacini@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 __DEPTH2KIN_MODULE_H__
19#define __DEPTH2KIN_MODULE_H__
20
21#include <mutex>
22#include <string>
23#include <deque>
24
25#include <opencv2/opencv.hpp>
26
27#include <yarp/os/all.h>
28#include <yarp/sig/all.h>
29#include <yarp/dev/all.h>
30
31#include <iCub/iKin/iKinFwd.h>
32
33#include "depth2kin_IDL.h"
34#include "methods.h"
35#include "nlp.h"
36
37using namespace std;
38using namespace yarp::os;
39using namespace yarp::dev;
40using namespace yarp::sig;
41using namespace iCub::iKin;
42
43// forward declaration
44class CalibModule;
45
46
47/************************************************************************/
48class DisparityProcessor : public BufferedPort<ImageOf<PixelMono> >
49{
50protected:
51 CalibModule *module;
52 void onRead(ImageOf<PixelMono> &imgIn);
53
54public:
56};
57
58
59
60/************************************************************************/
61class CalibModule : public RFModule, public depth2kin_IDL
62{
63protected:
64 ResourceFinder *rf;
65 PolyDriver drvArmL;
66 PolyDriver drvArmR;
67 PolyDriver drvMAIS_L;
68 PolyDriver drvMAIS_R;
69 PolyDriver drvCartL;
70 PolyDriver drvCartR;
71 PolyDriver drvGaze;
72 IControlMode *imods;
73 IEncoders *iencs;
74 IPositionControl *iposs;
75 IEncoderArrays *iencarray;
76 ICartesianControl *iarm;
77 IGazeControl *igaze;
78
79 mutex mtx;
82
86
87 string arm;
90 double max_dist;
91 double block_eyes;
96 int nEncs;
97 int test;
98 bool enabled;
101 bool closing;
105
112
115
116 BufferedPort<Bottle> touchInPort;
118 BufferedPort<ImageOf<PixelBgr> > depthOutPort;
119 RpcClient depthRpcPort;
120 RpcServer rpcPort;
121
122 bool attach(RpcServer &source);
123 bool createTargets(const Vector &c, const Vector &size);
124 bool isTypeValid(const string &type);
125 Calibrator *factory(const string &type);
126 bool factory(Value &v);
127 cv::Rect extractFingerTip(ImageOf<PixelMono> &imgIn, ImageOf<PixelBgr> &imgOut,
128 const Vector &c, Vector &px);
129 double getMinVer() const;
130 bool getGazeParams(const string &eye, const string &type, Matrix &M);
131 bool pushExtrinsics(const string &eye, const Matrix &H);
132 bool getDepth(const Vector &px, Vector &x, Vector &pxr);
133 bool getDepthAveraged(const Vector &px, Vector &x, Vector &pxr, const int maxSamples=5);
134 void openHand(IControlMode *imod, IPositionControl *ipos);
135 void postureHelper(const Vector &gaze_ang, const Matrix &targetL, const Matrix &targetR);
136 void prepareRobot();
137 int removeOutliers();
138 void doMotorExploration();
139 void doTouch(const Vector &xd);
140 void doTest();
141
142public:
143 CalibModule();
144 bool configure(ResourceFinder &rf);
145 void onRead(ImageOf<PixelMono> &imgIn);
146 double getPeriod();
147 bool updateModule();
148 void terminate();
149 bool close();
150
151 // IDL methods
152 int getNumExperts();
153 bool clearExperts();
154 bool load();
155 bool save();
156 bool log(const string &type);
157 bool explore();
158 bool stop();
159 bool setMaxDist(const double max_dist);
160 double getMaxDist();
161 bool setRoi(const int side);
162 int getRoi();
163 bool setBlockEyes(const double block_eyes);
164 double getBlockEyes();
165 bool blockEyes();
166 bool clearEyes();
167 bool setArm(const string &arm);
168 string getArm();
169 bool setCalibrationType(const string &type, const string &extrapolation);
170 string getCalibrationType();
171 Property calibrate(const bool rm_outliers);
172 bool pushCalibrator();
173 bool setTouchWithExperts(const string &sw);
174 string getTouchWithExperts();
175 bool touch(const int u, const int v);
176 PointReq getPoint(const string &arm, const double x, const double y, const double z);
177 vector<PointReq> getPoints(const string &arm, const vector<double> &coordinates);
178 bool setExperiment(const string &exp, const string &v);
179 string getExperiment(const string &exp);
180 Vector getExtrinsics(const string &eye);
181 bool resetExtrinsics(const string &eye);
182 bool setExplorationWait(const double wait);
183 double getExplorationWait();
184 bool setExplorationInTargetTol(const double tol);
186 bool setTouchInTargetTol(const double tol);
187 double getTouchInTargetTol();
188 bool setExplorationSpace(const double cx, const double cy, const double cz,
189 const double a, const double b);
190 bool setExplorationSpaceDelta(const double dcx, const double dcy, const double dcz,
191 const double da, const double db);
192 Property getExplorationData();
194 bool posture(const string &type);
195 bool calibrateDepth();
196 bool quit();
197};
198
199
200#endif
201
202
void prepareRobot()
Definition module.cpp:514
ICartesianControl * iarm
Definition module.h:76
bool isSaved
Definition module.h:100
bool attach(RpcServer &source)
Definition module.cpp:61
bool motorExplorationAsyncStop
Definition module.h:107
void openHand(IControlMode *imod, IPositionControl *ipos)
Definition module.cpp:334
enum CalibModule::@38 motorExplorationState
bool exp_aligneyes
Definition module.h:103
IEncoderArrays * iencarray
Definition module.h:75
double getExplorationWait()
Return the current wait timeout used during exploration between two consecutive data points.
Definition module.cpp:1648
bool setTouchWithExperts(const string &sw)
Enable/disable the use of experts for touch test.
Definition module.cpp:1478
PolyDriver drvMAIS_L
Definition module.h:67
iCubFinger finger
Definition module.h:80
bool closing
Definition module.h:101
double getExplorationInTargetTol()
Return the current cartesian tolerance used during exploration.
Definition module.cpp:1663
bool enabled
Definition module.h:98
bool explore()
Start the exploration phase.
Definition module.cpp:1273
void doTouch(const Vector &xd)
Definition module.cpp:701
bool getGazeParams(const string &eye, const string &type, Matrix &M)
Definition module.cpp:240
void doMotorExploration()
Definition module.cpp:624
PolyDriver drvGaze
Definition module.h:71
Vector curExplorationCenter
Definition module.h:81
int removeOutliers()
Definition module.cpp:588
double getTouchInTargetTol()
Return the current cartesian tolerance used during touch actions.
Definition module.cpp:1678
string getCalibrationType()
Return the current calibration type.
Definition module.cpp:1403
string arm
Definition module.h:87
PointReq getPoint(const string &arm, const double x, const double y, const double z)
Retrieve the compensated kinematic point corresponding to the input depth point.
Definition module.cpp:1531
void onRead(ImageOf< PixelMono > &imgIn)
Definition module.cpp:1050
bool posture(const string &type)
Make the robot reach a predefined posture.
Definition module.cpp:441
bool stop()
Yield an asynchronous stop of the exploration phase.
Definition module.cpp:1285
bool load()
Reload the list of experts stored within the configuration file.
Definition module.cpp:1157
Vector getExtrinsics(const string &eye)
Retrieve the current extrinsics camera parameters.
Definition module.cpp:1620
double exploration_intargettol
Definition module.h:93
bool setMaxDist(const double max_dist)
Set the maximum allowed distance between the depth point and kinematic prediction to enable data coll...
Definition module.cpp:1295
bool quit()
Quit the module.
Definition module.cpp:1750
string getExperiment(const string &exp)
Return the current status of the experiment.
Definition module.cpp:1608
double getMaxDist()
Return the maximum allowed distance between depth point and kinematic prediction to enable data colle...
Definition module.cpp:1303
RpcServer rpcPort
Definition module.h:120
bool pushExtrinsics(const string &eye, const Matrix &H)
Definition module.cpp:265
Calibrator * calibrator
Definition module.h:83
bool setRoi(const int side)
Definition module.cpp:1310
bool touchWithExperts
Definition module.h:104
PolyDriver drvArmL
Definition module.h:65
@ motorExplorationStateTrigger
Definition module.h:109
@ motorExplorationStateLog
Definition module.h:111
@ motorExplorationStateReach
Definition module.h:110
@ motorExplorationStateIdle
Definition module.h:108
bool useArmL
Definition module.h:88
int context_gaze
Definition module.h:114
bool setArm(const string &arm)
Select the arm to deal with.
Definition module.cpp:1362
bool setBlockEyes(const double block_eyes)
Set the vergence angle used to keep the gaze fixed.
Definition module.cpp:1325
double getMinVer() const
Definition module.cpp:231
DisparityProcessor depthInPort
Definition module.h:117
bool clearExperts()
Clear the list of currently available experts.
Definition module.cpp:1148
bool pushCalibrator()
Push the current calibrator in the list of experts.
Definition module.cpp:1463
double getPeriod()
Definition module.cpp:1757
double block_eyes
Definition module.h:91
bool clearExplorationData()
Clean up the internal list of explored points pairs.
Definition module.cpp:1736
EyeAligner aligner
Definition module.h:85
PolyDriver drvArmR
Definition module.h:66
double exploration_wait
Definition module.h:92
int context_arm
Definition module.h:113
RpcClient depthRpcPort
Definition module.h:119
bool setCalibrationType(const string &type, const string &extrapolation)
Set up the calibrator type.
Definition module.cpp:1386
bool setExplorationInTargetTol(const double tol)
Set up the cartesian tolerance used during exploration.
Definition module.cpp:1655
bool updateModule()
Definition module.cpp:1764
bool setExplorationSpace(const double cx, const double cy, const double cz, const double a, const double b)
Set up the internally coded exploration space composed by two co-centered ellipses,...
Definition module.cpp:1685
PolyDriver drvMAIS_R
Definition module.h:68
bool setExplorationWait(const double wait)
Set up the wait timeout used during exploration between two consecutive data points.
Definition module.cpp:1640
bool calibrated
Definition module.h:99
ResourceFinder * rf
Definition module.h:64
int getNumExperts()
Return the number of available experts.
Definition module.cpp:1140
bool setExperiment(const string &exp, const string &v)
Set on/off an experiment.
Definition module.cpp:1587
LocallyWeightedExperts expertsR
Definition module.h:84
IGazeControl * igaze
Definition module.h:77
bool getDepthAveraged(const Vector &px, Vector &x, Vector &pxr, const int maxSamples=5)
Definition module.cpp:306
Property calibrate(const bool rm_outliers)
Ask the current calibrator to carry out the calibration.
Definition module.cpp:1410
PolyDriver drvCartL
Definition module.h:69
IControlMode * imods
Definition module.h:72
bool close()
Definition module.cpp:1821
bool log(const string &type)
Store on file the log of system response computed out of the explored set of input-output pairs.
Definition module.cpp:1223
bool clearEyes()
Remove the block on the eyes.
Definition module.cpp:1355
bool blockEyes()
Tell the gaze to immediately steer the eyes to the stored vergence angle and stay still.
Definition module.cpp:1345
void terminate()
Definition module.cpp:1786
bool isTypeValid(const string &type)
Definition module.cpp:118
bool setTouchInTargetTol(const double tol)
Set up the cartesian tolerance used during a touch actions.
Definition module.cpp:1670
bool useArmR
Definition module.h:88
int nEncs
Definition module.h:96
BufferedPort< ImageOf< PixelBgr > > depthOutPort
Definition module.h:118
vector< PointReq > getPoints(const string &arm, const vector< double > &coordinates)
Retrieve the compensated kinematic points corresponding to the input depth points.
Definition module.cpp:1556
string getTouchWithExperts()
Return the current status of the switch for experts usage during touch test.
Definition module.cpp:1489
double touch_intargettol
Definition module.h:94
IPositionControl * iposs
Definition module.h:74
bool selectArmEnabled
Definition module.h:89
void doTest()
Definition module.cpp:752
IEncoders * iencs
Definition module.h:73
bool exp_depth2kin
Definition module.h:102
bool setExplorationSpaceDelta(const double dcx, const double dcy, const double dcz, const double da, const double db)
Set up the exploration space in terms of differences with respect to the internally coded couple of e...
Definition module.cpp:1701
Property getExplorationData()
Return some progress about the ongoing exploration.
Definition module.cpp:1720
bool resetExtrinsics(const string &eye)
Reset the extrinsics matrix to default eye matrix.
Definition module.cpp:1633
mutex mtx
Definition module.h:79
BufferedPort< Bottle > touchInPort
Definition module.h:116
Calibrator * factory(const string &type)
Definition module.cpp:126
bool save()
Save the current list of experts into the configuration file.
Definition module.cpp:1178
int roi_side
Definition module.h:95
int test
Definition module.h:97
bool touch(const int u, const int v)
Definition module.cpp:1496
LocallyWeightedExperts * experts
Definition module.h:84
deque< Vector > targetsConsumed
Definition module.h:106
PolyDriver drvCartR
Definition module.h:70
string getArm()
Return the current arm.
Definition module.cpp:1379
bool createTargets(const Vector &c, const Vector &size)
Definition module.cpp:68
bool configure(ResourceFinder &rf)
Definition module.cpp:890
double getBlockEyes()
Return the current angle to keep the vergence at.
Definition module.cpp:1338
cv::Rect extractFingerTip(ImageOf< PixelMono > &imgIn, ImageOf< PixelBgr > &imgOut, const Vector &c, Vector &px)
Definition module.cpp:170
deque< Vector > targets
Definition module.h:106
int getRoi()
Return the side of the squared window used to filter data collection in the image plane.
Definition module.cpp:1318
bool getDepth(const Vector &px, Vector &x, Vector &pxr)
Definition module.cpp:283
double max_dist
Definition module.h:90
LocallyWeightedExperts expertsL
Definition module.h:84
void postureHelper(const Vector &gaze_ang, const Matrix &targetL, const Matrix &targetR)
Definition module.cpp:364
bool calibrateDepth()
Put the robot in a suitable predefined posture and then execute depth calibration.
Definition module.cpp:488
CalibModule *void onRead(ImageOf< PixelMono > &imgIn)
Definition module.cpp:48
PointReq IDL structure to send/receive points.
Definition PointReq.h:23
depth2kin_IDL IDL Interface to depth2kin services.
A class for defining the iCub Finger.
Definition iKinFwd.h:1233
exp(-x3 *T)]