Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00040 #ifndef POSE_GRAPH_SCAN_MANAGER_H
00041 #define POSE_GRAPH_SCAN_MANAGER_H
00042
00043 #include <graph_slam/constraint_generator.h>
00044 #include <karto_scan_matcher/karto_scan_matcher.h>
00045 #include <ros/assert.h>
00046 #include <boost/shared_ptr.hpp>
00047 #include <boost/bimap.hpp>
00048 #include <boost/optional.hpp>
00049
00050 namespace graph_slam
00051 {
00052
00053 namespace pg=pose_graph;
00054
00055 typedef boost::bimap<pg::NodeId, pg::NodeId> NodeSequenceMap;
00056 typedef std::vector<pg::NodeId> Chain;
00057 typedef boost::shared_ptr<karto_scan_matcher::KartoScanMatcher> KartoMatcherPtr;
00058 typedef sensor_msgs::LaserScan::ConstPtr LaserPtr;
00059 typedef std::map<pg::NodeId, LaserPtr> NodeScanMap;
00060 typedef std::set<pg::NodeId> NodeSet;
00061 typedef std::vector<Chain> ChainVec;
00062
00063
00067 class ScanManager
00068 {
00069 public:
00070
00071 ScanManager (const geometry_msgs::Pose2D& laser_offset);
00072
00075 void addNode (pg::NodeId n, LaserPtr scan);
00076
00078 boost::optional<pg::NodeId> lastNode () const;
00079
00081 void resetLastNode ();
00082
00086 pg::NodeId closestNode (const geometry_msgs::Pose2D& pose, const NodeSet& nodes) const;
00087
00090 geometry_msgs::Point computeBarycenterInBaseFrame (const LaserPtr scan) const;
00091
00095 NodeSet nearbyNodes (pg::NodeId n, const geometry_msgs::Point& center, const pg::PoseGraph& graph,
00096 const double max_distance) const;
00097
00098 protected:
00099
00102 NodeConstraint scanChainConstraint (const geometry_msgs::Point& barycenter,
00103 const geometry_msgs::Pose2D& pose, const pg::PrecisionMatrix& prec,
00104 const Chain& chain) const;
00105
00106
00108 template <typename NodeContainer>
00109 std::vector<karto_scan_matcher::ScanWithPose> makeRefScans (const NodeContainer& nodes) const;
00110
00114 Chain getChain (pg::NodeId n, const NodeSet& nodes, const NodeSet& processed) const;
00115
00117 karto_scan_matcher::ScanMatchResult scanMatchNodes (KartoMatcherPtr matcher,
00118 const geometry_msgs::Pose& init_pose_estimate,
00119 const LaserPtr scan, const NodeSet& nodes) const;
00120
00122 const geometry_msgs::Pose2D laser_offset_;
00123
00125 NodeSequenceMap node_sequence_;
00126
00129 boost::optional<geometry_msgs::Point> nodeBarycenter (const pg::NodeId n) const;
00130
00132 geometry_msgs::Pose optimizedPose (const pg::NodeId n) const;
00133
00134 private:
00135
00136 NodeScanMap scans_;
00137 std::map<pg::NodeId, geometry_msgs::Point> barycenters_;
00138 boost::optional<pg::NodeId> last_node_;
00139 mutable boost::optional<NodePoseMap> optimized_poses_;
00140
00142 geometry_msgs::Point nodeBarycenter (const pg::NodeId n, const geometry_msgs::Pose& pose) const;
00143
00145 pg::NodeId closestNode (const geometry_msgs::Point& barycenter, const Chain& chain) const;
00146
00147
00149 void setOptimizedPoses (const NodePoseMap& optimized_poses) const;
00150 void unsetOptimizedPoses () const;
00151 friend class WithOptimizedPoses;
00152
00153
00154 };
00155
00156
00158 struct WithOptimizedPoses
00159 {
00160 WithOptimizedPoses (const ScanManager* matcher, const NodePoseMap& poses);
00161 ~WithOptimizedPoses ();
00162 const ScanManager* matcher;
00163 };
00164
00165
00166
00167
00168 template <typename Map>
00169 Chain onewayChain (const Map& m, const pg::NodeId seed, const NodeSet& allowed, const NodeSet& forbidden)
00170 {
00171 Chain chain;
00172 pg::NodeId current=seed;
00173 while (true) {
00174 if (allowed.find(current)==allowed.end() ||
00175 forbidden.find(current)!=forbidden.end())
00176 break;
00177 chain.push_back(current);
00178 typename Map::const_iterator pos=m.find(current);
00179 if (pos==m.end())
00180 break;
00181 current = pos->second;
00182 }
00183 return chain;
00184 }
00185
00187 pg::PrecisionMatrix getPrecisionMatrix (const karto_scan_matcher::ScanMatchResult& res,
00188 const bool use_covariances);
00189
00190
00191 void addChain (const Chain& chain, ChainVec* chains, NodeSet* processed);
00192
00193
00194 }
00195
00196 #endif // include guard