GCOP  1.0
kinrccarpath.h
Go to the documentation of this file.
00001 #ifndef GCOP_KINRCCARPATH_H
00002 #define GCOP_KINRCCARPATH_H
00003 
00004 #include <Eigen/Dense>
00005 #include <vector>
00006 #include <type_traits>
00007 #include "se3.h"
00008 #include <iostream>
00009 #include "utils.h"
00010 #include "kinrccar.h"
00011 
00012 namespace gcop {
00013   
00014   using namespace std;
00015   using namespace Eigen;
00016 
00017   
00021   class KinRccarPath {
00022   public:
00029     KinRccarPath(KinRccar &sys, bool wheel_odometry = false, bool yaw_odometry = false, bool forces = false, bool estimate_length = false);
00030 
00031     virtual void AddControl(const Vector2d &u, const Vector2d& v, double h);
00032     virtual void AddObservation(const vector< pair<int, Vector3d> > &z, Matrix4d cam_transform = MatrixXd::Identity(4,4));
00033 
00034     KinRccar &sys;     
00035 
00036     bool wheel_odometry;
00037     bool yaw_odometry;
00038     bool extforce;         
00039     bool forces;           
00040     bool estimate_length;  
00041     
00042     vector<double> ts;     
00043 
00044     vector<Matrix4d> xs;      
00045     vector<Vector2d> us;   
00046     vector<Vector2d> vs;   
00047     
00048     vector<Matrix4d> xos;     
00049     vector<Vector2d> uos;     
00050 
00051     VectorXd p;            
00052 
00053     vector< vector<pair<int, Vector3d> > > zs;  
00054 
00055     double cp;             
00056     Vector2d cv;           
00057     Vector2d cw;           
00058 
00059   };
00060 
00061 KinRccarPath::KinRccarPath(KinRccar &sys, bool wheel_odometry, bool yaw_odometry, bool forces, bool estimate_length) : 
00062   sys(sys), wheel_odometry(wheel_odometry), yaw_odometry(yaw_odometry), forces(forces), extforce(false), estimate_length(estimate_length),  p(estimate_length + extforce*3)
00063 {
00064   Matrix4d x = MatrixXd::Identity(4,4);
00065   xs.push_back(x);
00066   xos.push_back(x);
00067   ts.push_back(0);
00068 
00069   cw = Vector2d(.01, pow(1.5*M_PI/180.,2));
00070   cv = Vector2d(.01, pow(2.5*M_PI/180.,2));
00071   cp = .01;
00072 
00073   if(estimate_length)
00074   {
00075     p(0) = .25;    
00076   }
00077 }
00078 
00079 void KinRccarPath::AddControl(const Vector2d &u, const Vector2d& v, double h)
00080 {
00081   Eigen::Matrix4d xn;
00082   double t = ts.back();
00083 
00084   sys.Step(xn, t, xs.back(), u, h);
00085   xs.push_back(xn);
00086   us.push_back(u);
00087 
00088   sys.Step(xn, t, xos.back(), u, h);
00089   xos.push_back(xn);
00090   uos.push_back(u);
00091 
00092   vs.push_back(v);
00093   ts.push_back(t + h);
00094   zs.push_back(vector<pair<int, Vector3d> >());
00095 }
00096 
00097 void KinRccarPath::AddObservation(const vector< pair<int, Vector3d> > &z, Matrix4d cam_transform)
00098 {
00099   for(int i = 0; i < z.size(); i++)
00100   {
00101     Vector4d z_h(z[i].second(0), z[i].second(1), z[i].second(2), 1);
00102     z_h = cam_transform*z_h;
00103     pair<int, Vector3d> zi(z[i].first, Vector3d(z_h(0), z_h(1), z_h(2)));
00104     if(3*z[i].first >= p.size()-estimate_length-extforce*3)
00105     {
00106         p.conservativeResize(p.size() + 3);
00107         const Matrix3d &Rn = xs.back().block<3,3>(0,0);
00108         const Vector3d &pxn = xs.back().block<3,1>(0,3);
00109         // Initialize landmark position from estimated state
00110         p.tail<3>() = Rn*zi.second + pxn;
00111     } 
00112     zs.back().push_back(zi);
00113   }
00114 }
00115 
00116 } // namespace gcop
00117 #endif