iCub-main
main.cpp
Go to the documentation of this file.
1 
16 #include <cmath>
17 #include <iostream>
18 #include <iomanip>
19 
20 #include <yarp/os/all.h>
21 #include <yarp/sig/all.h>
22 #include <yarp/math/Math.h>
23 #include <yarp/math/Rand.h>
24 
25 #include <iCub/ctrl/math.h>
27 
28 using namespace std;
29 using namespace yarp::os;
30 using namespace yarp::sig;
31 using namespace yarp::math;
32 using namespace iCub::ctrl;
33 using namespace iCub::optimization;
34 
35 
36 int main()
37 {
38  // define our working bounding box
39  Vector min(3),max(3);
40  min[0]=-5.0; max[0]=5.0;
41  min[1]=-5.0; max[1]=5.0;
42  min[2]=-5.0; max[2]=5.0;
43 
44  // define the "unknown" transformation:
45  // translation
46  Vector p(3);
47  p[0]=0.3; p[1]=-2.0; p[2]=3.1;
48  // rotation
49  Vector euler(3);
50  euler[0]=M_PI/4.0; euler[1]=M_PI/6.0; euler[2]=M_PI/3.0;
51 
52  Matrix H=euler2dcm(euler);
53  H(0,3)=p[0]; H(1,3)=p[1]; H(2,3)=p[2];
54 
55  // ansisotropic scale
56  Vector scale(3);
57  scale[0]=0.9; scale[1]=0.8; scale[2]=1.1;
58  Vector h_scale=scale;
59  h_scale.push_back(1.0);
60 
61  // create the calibrator
63 
64  // generate randomly the two clouds of matching 3D points
65  for (int i=0; i<10; i++)
66  {
67  Vector p0=Rand::vector(min,max);
68  p0.push_back(1.0);
69 
70  // make data a bit dirty (add up noise in the range (-1,1) [cm])
71  Vector eps=Rand::vector(Vector(3,-0.01),Vector(3,0.01));
72  eps.push_back(0.0);
73  Vector p1=h_scale*(H*p0)+eps;
74 
75  // feed the calibrator with the matching pair
76  calibrator.addPoints(p0,p1);
77  }
78 
79  // set the working bounding box where the solution is seeked
80  calibrator.setBounds(min,max);
81 
82  // carry out the calibration
83  Matrix Hcap;
84  Vector scalecap;
85  double error;
86  double t0=SystemClock::nowSystem();
87  calibrator.calibrate(Hcap,scalecap,error);
88  double dt=SystemClock::nowSystem()-t0;
89 
90  // the final report
91  cout<<endl;
92  cout<<"H"<<endl<<H.toString(3,3)<<endl;
93  cout<<"scale = "<<scale.toString(3,3)<<endl;
94  cout<<endl;
95  cout<<"Hcap"<<endl<<Hcap.toString(3,3)<<endl;
96  cout<<"scalecap = "<<scalecap.toString(3,3)<<endl;
97  cout<<endl;
98  cout<<"residual error = "<<error<<" [m]"<<endl;
99  cout<<"calibration performed in "<<dt<<" [s]"<<endl;
100  cout<<endl;
101 
102  return 0;
103 }
104 
105 
#define M_PI
Definition: XSensMTx.cpp:24
A class that deals with the problem of determining the roto-translation matrix H and scaling factors ...
virtual bool calibrate(yarp::sig::Matrix &H, double &error)
Perform reference calibration to determine the matrix H.
virtual void setBounds(const yarp::sig::Matrix &min, const yarp::sig::Matrix &max)
Allow specifying the minimum and maximum bounds of the elements belonging to the transformation.
virtual bool addPoints(const yarp::sig::Vector &p0, const yarp::sig::Vector &p1)
Add to the internal database the 3D-point p0 and the 3D-point p1 which is supposed to correspond to H...
int main(int argc, char *argv[])
Definition: main.cpp:31
const FSC max
Definition: strain.h:48
const FSC min
Definition: strain.h:49