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
00039 #ifndef LASER_SLAM_SCAN_MATCH_CONSTRAINTS_H
00040 #define LASER_SLAM_SCAN_MATCH_CONSTRAINTS__H
00041
00042 #include <laser_slam/util.h>
00043 #include <laser_slam/scan_matching.h>
00044 #include <laser_slam/LocalizedScan.h>
00045 #include <graph_mapping_msgs/LocalizationDistribution.h>
00046 #include <graph_slam/localization_buffer.h>
00047 #include <graph_mapping_msgs/NodePoses.h>
00048 #include <pose_graph/graph_db.h>
00049 #include <geometry_msgs/Pose2D.h>
00050 #include <boost/optional.hpp>
00051 #include <std_msgs/UInt64.h>
00052
00053 namespace laser_slam
00054 {
00055
00056 namespace msg=graph_mapping_msgs;
00057 namespace pg=pose_graph;
00058 namespace gm=geometry_msgs;
00059
00060 typedef std::vector<unsigned> Chain;
00061 typedef std::vector<msg::GraphConstraint> ConstraintVec;
00062
00063 const std::string PREV_NODE_TOPIC("scan_match_constraints_prev_node");
00064 const std::string NEXT_NODE_TOPIC("scan_match_constraints_next_node");
00065
00066
00068 class ScanMatchConstraints
00069 {
00070 public:
00071 ScanMatchConstraints (ros::NodeHandle param_nh, TfPtr tf);
00072
00073
00074 private:
00075
00076 void addConstraints (OptionalDiff diff, const pg::ConstraintGraph& g);
00077 ConstraintVec getRunningConstraints (const unsigned n, const pg::ConstraintGraph& g,
00078 const gm::PoseStamped& l, const pg::NodeSet& running) const;
00079 ConstraintVec getNearLinkConstraints (const unsigned n, const pg::ConstraintGraph& g,
00080 const gm::PoseStamped& l, const pg::NodeSet& running) const;
00081 ConstraintVec getLoopConstraints (const unsigned n, const pg::ConstraintGraph& g,
00082 const gm::PoseStamped& l, const pg::NodeSet& running) const;
00083 pg::NodeSet getRunningNodes(const pg::ConstraintGraph& g, const unsigned n,
00084 const gm::PoseStamped& l) const;
00085 msg::GraphConstraint makeConstraint (const pg::ConstraintGraph& g, const unsigned n,
00086 const karto_scan_matcher::ScanMatchResult& res,
00087 const pg::NodeSet& nodes, LocalizedScan::ConstPtr scan) const;
00088 msg::GraphConstraint makeConstraint (const pg::ConstraintGraph& g, const unsigned n,
00089 const unsigned ref, const karto_scan_matcher::ScanMatchResult& res,
00090 LocalizedScan::ConstPtr scan) const;
00091 unsigned nodeWithNearestBarycenter (const pg::ConstraintGraph& g,
00092 const pg::NodeSet& nodes, const geometry_msgs::Point& p) const;
00093 void locCallback (msg::LocalizationDistribution::ConstPtr m);
00094 boost::optional<unsigned> previousNode (const unsigned n) const;
00095 boost::optional<unsigned> nextNode (const unsigned n) const;
00096 void addSequenceLink (const unsigned n1, const unsigned n2);
00097 Chain getChain (const unsigned n, const pg::NodeSet& nodes,
00098 const pg::NodeSet& forbidden) const;
00099 void updateDistanceTravelled (const ros::TimerEvent& e);
00100 tf::Pose fixedFramePose (const unsigned n) const;
00101
00102
00103
00104
00105
00106 const std::string fixed_frame_;
00107 const std::string base_frame_;
00108 const std::string laser_frame_;
00109 const std::string opt_frame_;
00110 const double local_window_size_;
00111 const double running_scan_match_size_;
00112 const double running_scan_match_res_;
00113 const unsigned near_link_min_chain_size_;
00114 const double chain_distance_threshold_;
00115 const double loop_scan_match_size_;
00116 const double loop_scan_match_res_;
00117 const double loop_match_window_size_;
00118 const unsigned loop_match_min_chain_size_;
00119 const double min_loop_response_;
00120 const double max_loop_match_variance_;
00121 const double min_sequential_response_;
00122 const double max_nbd_size_;
00123 const unsigned running_buffer_size_;
00124 tf::Pose laser_offset_;
00125
00126
00127
00128
00129
00130 bool initialized_;
00131 boost::optional<unsigned> last_added_node_;
00132 double distance_since_last_added_node_;
00133 boost::circular_buffer<unsigned> running_nodes_;
00134 pg::NodePoseMap optimized_poses_;
00135
00136
00137
00138
00139
00140 boost::mutex mutex_;
00141 TfPtr tf_;
00142 warehouse::WarehouseClient db_;
00143 pose_graph::CachedNodeMap<std_msgs::UInt64> before_, after_;
00144 ScanMap scans_;
00145 pose_graph::CachedNodeMap<geometry_msgs::Pose> ff_poses_;
00146 graph_slam::LocalizationBuffer loc_buf_;
00147 ros::NodeHandle nh_;
00148 pg::DiffSubscriber diff_sub_;
00149 ros::Subscriber loc_sub_;
00150 ros::Publisher constraint_pub_;
00151 ros::Publisher marker_pub_, pose_pub_;
00152 ros::ServiceClient get_poses_client_;
00153 MatcherPtr sequential_matcher_;
00154 MatcherPtr loop_matcher_;
00155 ros::Timer distance_update_timer_;
00156
00157 };
00158
00159 }
00160
00161 #endif // include guard