| 
									
										
										
										
											2010-01-23 08:57:54 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Pose2SLAMOptimizer.h | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Created on: Jan 22, 2010 | 
					
						
							|  |  |  |  *      Author: dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef POSE2SLAMOPTIMIZER_H_
 | 
					
						
							|  |  |  | #define POSE2SLAMOPTIMIZER_H_
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-23 11:49:05 +08:00
										 |  |  | #include <boost/foreach.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-23 08:57:54 +08:00
										 |  |  | #include "pose2SLAM.h"
 | 
					
						
							|  |  |  | #include "Ordering.h"
 | 
					
						
							|  |  |  | #include "SubgraphPreconditioner.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Optimizer class for use in MATLAB | 
					
						
							|  |  |  | 	 * Keeps a Pose2Config estimate | 
					
						
							|  |  |  | 	 * Returns all relevant matrices so MATLAB can optimize :-) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	class Pose2SLAMOptimizer { | 
					
						
							|  |  |  | 	private: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/** Non-linear factor graph */ | 
					
						
							|  |  |  | 		boost::shared_ptr<Pose2Graph> graph_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/** Current non-linear estimate */ | 
					
						
							|  |  |  | 		boost::shared_ptr<Pose2Config> theta_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/** Non-linear solver */ | 
					
						
							|  |  |  | 		typedef SubgraphPCG<Pose2Graph, Pose2Config> SPCG_Solver; | 
					
						
							|  |  |  | 		SPCG_Solver solver_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/** Linear Solver */ | 
					
						
							|  |  |  | 		boost::shared_ptr<SubgraphPreconditioner> system_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 		/**
 | 
					
						
							|  |  |  | 		 * Create optimizer: finds spanning tree and ordering | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		Pose2SLAMOptimizer(const std::string& dataset = "", | 
					
						
							|  |  |  | 				const std::string& path = ""); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-23 12:46:00 +08:00
										 |  |  | 		/**
 | 
					
						
							|  |  |  | 		 * print the object | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		void print(const std::string& str = "") const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-23 08:57:54 +08:00
										 |  |  | 		/**
 | 
					
						
							|  |  |  | 		 * Virtual destructor | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		virtual ~Pose2SLAMOptimizer() { | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/**
 | 
					
						
							|  |  |  | 		 * return graph pointer | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		boost::shared_ptr<const Pose2Graph> graph() const { | 
					
						
							|  |  |  | 			 return graph_; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-01-23 11:49:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-23 08:57:54 +08:00
										 |  |  | 		/**
 | 
					
						
							| 
									
										
										
										
											2010-01-23 11:49:05 +08:00
										 |  |  | 		 * return the current linearization point | 
					
						
							| 
									
										
										
										
											2010-01-23 08:57:54 +08:00
										 |  |  | 		 */ | 
					
						
							|  |  |  | 		boost::shared_ptr<const Pose2Config> theta() const { | 
					
						
							|  |  |  | 			return theta_; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-01-23 11:49:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-23 08:57:54 +08:00
										 |  |  | 		/**
 | 
					
						
							|  |  |  | 		 * linearize around current theta | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		void linearize() { | 
					
						
							|  |  |  | 			system_ = solver_.linearize(*graph_, *theta_); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/**
 | 
					
						
							| 
									
										
										
										
											2010-01-23 09:08:42 +08:00
										 |  |  | 		 * Optimize to get a | 
					
						
							| 
									
										
										
										
											2010-01-23 08:57:54 +08:00
										 |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2010-01-23 11:49:05 +08:00
										 |  |  | 		Vector optimize() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		double error() const; | 
					
						
							| 
									
										
										
										
											2010-01-23 08:57:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/**
 | 
					
						
							|  |  |  | 		 * Return matrices associated with optimization problem | 
					
						
							|  |  |  | 		 * around current non-linear estimate theta | 
					
						
							|  |  |  | 		 * Returns [IJS] sparse representation | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2010-01-23 11:49:05 +08:00
										 |  |  | 		Matrix a1() const { return system_->A1(*solver_.ordering()); } | 
					
						
							|  |  |  | 		Matrix a2() const { return system_->A2(*solver_.ordering()); } | 
					
						
							|  |  |  | 		Vector b1() const { return system_->b1(); } | 
					
						
							|  |  |  | 		Vector b2() const { return system_->b2(); } | 
					
						
							| 
									
										
										
										
											2010-01-23 13:16:29 +08:00
										 |  |  | 		std::pair<Matrix,Vector> Ab1() const { return system_->Ab1(*solver_.ordering()); } | 
					
						
							|  |  |  | 		std::pair<Matrix,Vector> Ab2() const { return system_->Ab2(*solver_.ordering()); } | 
					
						
							| 
									
										
										
										
											2010-01-23 08:57:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/**
 | 
					
						
							|  |  |  | 		 * update estimate with pure delta config x | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		void update(const Vector& x); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/**
 | 
					
						
							|  |  |  | 		 * update estimate with pre-conditioned delta config y | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		void updatePreconditioned(const Vector& y); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* POSE2SLAMOPTIMIZER_H_ */
 |