Go to the documentation of this file.00001
00006 #ifndef GRAPH_H
00007 #define GRAPH_H
00008
00009 #include <ros/ros.h>
00010 #include <tf/transform_broadcaster.h>
00011 #include <g2o/core/sparse_optimizer.h>
00012 #include <g2o/core/block_solver.h>
00013 #include <g2o/solvers/cholmod/linear_solver_cholmod.h>
00014 #include <g2o/core/optimization_algorithm_gauss_newton.h>
00015 #include <g2o/types/slam3d/edge_se3.h>
00016 #include <g2o/core/optimization_algorithm_levenberg.h>
00017 #include <g2o/solvers/dense/linear_solver_dense.h>
00018 #include "common/tools.h"
00019
00020 using namespace std;
00021 using namespace tools;
00022
00023 typedef g2o::BlockSolver< g2o::BlockSolverTraits<-1, -1> > SlamBlockSolver;
00024 typedef g2o::LinearSolverCholmod<SlamBlockSolver::PoseMatrixType> SlamLinearSolver;
00025
00026 namespace slam
00027 {
00028
00029 class Graph
00030 {
00031
00032 public:
00033
00034
00035 Graph();
00036
00037 struct Params
00038 {
00039 int g2o_algorithm;
00040 int go2_opt_max_iter;
00041 string save_dir;
00042 string pose_frame_id;
00043 string pose_child_frame_id;
00044
00045
00046 Params () {
00047 g2o_algorithm = 1;
00048 go2_opt_max_iter = 20;
00049 save_dir = "";
00050 pose_frame_id = "/map";
00051 pose_child_frame_id = "/robot";
00052 }
00053 };
00054
00058 inline void setParams(const Params& params)
00059 {
00060 params_ = params;
00061 init();
00062 }
00063
00067 inline Params params() const { return params_; }
00068
00069
00070 void getLastPoses(tf::Transform current_odom,
00071 tf::Transform &last_graph_pose,
00072 tf::Transform &last_graph_odom);
00073
00074
00075 void findClosestNodes(int discart_first_n,
00076 int best_n,
00077 vector<int> &neighbors);
00078
00079
00080 int addVertice(tf::Transform pose_corrected);
00081 int addVertice(tf::Transform pose,
00082 tf::Transform pose_corrected,
00083 double timestamp);
00084
00085
00086 void setVerticeEstimate(int vertice_id, tf::Transform pose);
00087
00088
00089 void addEdge(int i, int j, tf::Transform edge);
00090
00091
00092 void update();
00093
00094
00095 bool saveGraphToFile();
00096
00097 protected:
00098
00099 bool init();
00100
00101 private:
00102
00103
00104 vector< pair<tf::Transform,double> >
00105 odom_history_;
00106
00107
00108 g2o::SparseOptimizer
00109 graph_optimizer_;
00110
00111
00112 Params params_;
00113 };
00114
00115 }
00116
00117 #endif // GRAPH_H