| 
									
										
										
										
											2010-01-12 10:10:42 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  *  @file  BearingFactor.H | 
					
						
							|  |  |  |  *  @authors Frank Dellaert | 
					
						
							|  |  |  |  **/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Rot2.h"
 | 
					
						
							|  |  |  | #include "Pose2.h"
 | 
					
						
							|  |  |  | #include "Point2.h"
 | 
					
						
							| 
									
										
										
										
											2010-01-14 12:35:18 +08:00
										 |  |  | #include "NonlinearFactor.h"
 | 
					
						
							| 
									
										
										
										
											2010-01-12 10:10:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Calculate bearing to a landmark | 
					
						
							|  |  |  | 	 * @param pose 2D pose of robot | 
					
						
							|  |  |  | 	 * @param point 2D location of landmark | 
					
						
							|  |  |  | 	 * @return 2D rotation \in SO(2) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	Rot2 bearing(const Pose2& pose, const Point2& point) { | 
					
						
							|  |  |  | 		Point2 d = transform_to(pose, point); | 
					
						
							|  |  |  | 		return relativeBearing(d); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Calculate bearing and optional derivative(s) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	Rot2 bearing(const Pose2& pose, const Point2& point, | 
					
						
							|  |  |  | 			boost::optional<Matrix&> H1, boost::optional<Matrix&> H2) { | 
					
						
							| 
									
										
										
										
											2010-01-14 12:35:18 +08:00
										 |  |  | 		if (!H1 && !H2) return bearing(pose, point); | 
					
						
							| 
									
										
										
										
											2010-01-12 10:10:42 +08:00
										 |  |  | 		Point2 d = transform_to(pose, point); | 
					
						
							|  |  |  | 		Matrix D_result_d; | 
					
						
							|  |  |  | 		Rot2 result = relativeBearing(d, D_result_d); | 
					
						
							|  |  |  | 		if (H1) *H1 = D_result_d * Dtransform_to1(pose, point); | 
					
						
							|  |  |  | 		if (H2) *H2 = D_result_d * Dtransform_to2(pose, point); | 
					
						
							|  |  |  | 		return result; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-14 12:35:18 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Non-linear factor for a constraint derived from a 2D measurement, | 
					
						
							|  |  |  | 	 * i.e. the main building block for visual SLAM. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	template<class Config, class PoseKey, class PointKey> | 
					
						
							|  |  |  | 	class BearingFactor: public NonlinearFactor2<Config, PoseKey, Pose2, | 
					
						
							|  |  |  | 			PointKey, Point2> { | 
					
						
							|  |  |  | 	private: | 
					
						
							| 
									
										
										
										
											2010-01-12 10:10:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-14 12:35:18 +08:00
										 |  |  | 		Rot2 z_; /** measurement */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		typedef NonlinearFactor2<Config, PoseKey, Pose2, PointKey, Point2> Base; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		BearingFactor(); /* Default constructor */ | 
					
						
							|  |  |  | 		BearingFactor(const Rot2& z, double sigma, const PoseKey& i, | 
					
						
							|  |  |  | 				const PointKey& j) : | 
					
						
							|  |  |  | 			Base(sigma, i, j), z_(z) { | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/** h(x)-z -> between(z,h(x)) for Rot2 manifold */ | 
					
						
							|  |  |  | 		Vector evaluateError(const Pose2& pose, const Point2& point, | 
					
						
							|  |  |  | 				boost::optional<Matrix&> H1, boost::optional<Matrix&> H2) const { | 
					
						
							|  |  |  | 			Rot2 hx = bearing(pose, point, H1, H2); | 
					
						
							|  |  |  | 			return logmap(between(z_, hx)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}; // BearingFactor
 | 
					
						
							| 
									
										
										
										
											2010-01-12 10:10:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } // namespace gtsam
 |