|
@@ -29,7 +29,6 @@ int main(int argc, char* argv[]) {
|
|
|
|
|
|
void hdl_backend::init() {
|
|
|
map_frame_id = "map";
|
|
|
-
|
|
|
odom_frame_id = "odom";
|
|
|
map_cloud_resolution = 0.05;
|
|
|
trans_odom2map.setIdentity();
|
|
@@ -55,11 +54,11 @@ void hdl_backend::init() {
|
|
|
|
|
|
read_until_pub = nh.advertise<std_msgs::Header>("/hdl_graph_slam/read_until", 32);
|
|
|
|
|
|
- save_map_service_server = nh.advertiseService("/hdl_graph_slam/save_map", &hdl_backend::save_map_service, this);
|
|
|
+
|
|
|
|
|
|
graph_updated = false;
|
|
|
|
|
|
- double graph_update_interval = 1;
|
|
|
+ double graph_update_interval = 1;
|
|
|
double map_cloud_update_interval = 4;
|
|
|
|
|
|
optimization_timer = nh.createWallTimer(ros::WallDuration(graph_update_interval), &hdl_backend::optimization_timer_callback, this);
|
|
@@ -75,13 +74,12 @@ void hdl_backend::init() {
|
|
|
* @param event
|
|
|
*/
|
|
|
void hdl_backend::optimization_timer_callback(const ros::WallTimerEvent& event) {
|
|
|
- LOG(INFO) << "optimization_timer_callback";
|
|
|
+ LOG(INFO) << "进入optimization_timer_callback函数";
|
|
|
|
|
|
std::lock_guard<std::mutex> lock(main_thread_mutex);
|
|
|
|
|
|
|
|
|
bool keyframe_updated = flush_keyframe_queue();
|
|
|
-
|
|
|
|
|
|
if(!keyframe_updated) {
|
|
|
std_msgs::Header read_until;
|
|
@@ -93,9 +91,11 @@ void hdl_backend::optimization_timer_callback(const ros::WallTimerEvent& event)
|
|
|
}
|
|
|
if(!keyframe_updated) {
|
|
|
|
|
|
- LOG(INFO) << "!keyframe_updated";
|
|
|
+ LOG(INFO) << "关键帧没有更新,退出optimization_timer_callback函数";
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
std::vector<hdl_graph_slam::Loop::Ptr> loops = loop_detector->detect(keyframes, new_keyframes, *graph_slam);
|
|
|
|
|
@@ -106,8 +106,7 @@ void hdl_backend::optimization_timer_callback(const ros::WallTimerEvent& event)
|
|
|
auto edge = graph_slam->add_se3_edge(loop->key1->node, loop->key2->node, relpose, information_matrix);
|
|
|
graph_slam->add_robust_kernel(edge, "Huber", 1.0);
|
|
|
}
|
|
|
- LOG(INFO) << "!111111111";
|
|
|
-
|
|
|
+ LOG(INFO) << "完成闭环检测";
|
|
|
|
|
|
std::copy(new_keyframes.begin(), new_keyframes.end(), std::back_inserter(keyframes));
|
|
|
new_keyframes.clear();
|
|
@@ -115,45 +114,46 @@ void hdl_backend::optimization_timer_callback(const ros::WallTimerEvent& event)
|
|
|
|
|
|
|
|
|
|
|
|
- if(anchor_node && true) {
|
|
|
+ if(anchor_node && true) {
|
|
|
Eigen::Isometry3d anchor_target = static_cast<g2o::VertexSE3*>(anchor_edge->vertices()[1])->estimate();
|
|
|
anchor_node->setEstimate(anchor_target);
|
|
|
|
|
|
}
|
|
|
- LOG(INFO) << "!2222222222";
|
|
|
|
|
|
int num_iterations = 512;
|
|
|
graph_slam->optimize(num_iterations);
|
|
|
-
|
|
|
+ LOG(INFO) << "完成g2o的图优化";
|
|
|
|
|
|
std::vector<hdl_graph_slam::KeyFrameSnapshot::Ptr> snapshot(keyframes.size());
|
|
|
std::transform(keyframes.begin(), keyframes.end(), snapshot.begin(), [=](const hdl_graph_slam::KeyFrame::Ptr& k) { return std::make_shared<hdl_graph_slam::KeyFrameSnapshot>(k); });
|
|
|
|
|
|
- keyframes_snapshot_mutex.lock();
|
|
|
+
|
|
|
keyframes_snapshot.swap(snapshot);
|
|
|
- keyframes_snapshot_mutex.unlock();
|
|
|
+
|
|
|
graph_updated = true;
|
|
|
- LOG(INFO) << "graph_updated";
|
|
|
+ LOG(INFO) << "准备发布TF变换";
|
|
|
|
|
|
|
|
|
const auto& keyframe = keyframes.back();
|
|
|
Eigen::Isometry3d trans = keyframe->node->estimate() * keyframe->odom.inverse();
|
|
|
- trans_odom2map_mutex.lock();
|
|
|
+
|
|
|
trans_odom2map = trans.matrix().cast<float>();
|
|
|
- trans_odom2map_mutex.unlock();
|
|
|
+
|
|
|
|
|
|
- if(odom2map_pub.getNumSubscribers()) {
|
|
|
- geometry_msgs::TransformStamped ts = hdl_graph_slam::matrix2transform(keyframe->stamp, trans.matrix().cast<float>(), map_frame_id, odom_frame_id);
|
|
|
- odom2map_pub.publish(ts);
|
|
|
- LOG(INFO) << "pub odom2map_pub";
|
|
|
- }
|
|
|
+
|
|
|
+ geometry_msgs::TransformStamped ts = hdl_graph_slam::matrix2transform(keyframe->stamp, trans.matrix().cast<float>(), map_frame_id, odom_frame_id);
|
|
|
+
|
|
|
+
|
|
|
+ LOG(INFO) << "odom2map TF变换发布完成";
|
|
|
+
|
|
|
|
|
|
if(markers_pub.getNumSubscribers()) {
|
|
|
auto markers = create_marker_array(ros::Time::now());
|
|
|
markers_pub.publish(markers);
|
|
|
- LOG(INFO) << "pub markers_pub";
|
|
|
+ LOG(INFO) << "markers_pub 发布完成";
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -163,36 +163,57 @@ void hdl_backend::optimization_timer_callback(const ros::WallTimerEvent& event)
|
|
|
void hdl_backend::map_points_publish_timer_callback(const ros::WallTimerEvent& event) {
|
|
|
|
|
|
|
|
|
- if(!map_points_pub.getNumSubscribers() || !graph_updated) {
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- std::vector<hdl_graph_slam::KeyFrameSnapshot::Ptr> snapshot;
|
|
|
+
|
|
|
|
|
|
-
|
|
|
- snapshot = keyframes_snapshot;
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
+
|
|
|
+ LOG(INFO) << "准备发布点云数据";
|
|
|
+ std::vector<hdl_graph_slam::KeyFrameSnapshot::Ptr> snapshot;
|
|
|
+ snapshot = keyframes_snapshot;
|
|
|
auto cloud = map_cloud_generator->generate(snapshot, map_cloud_resolution);
|
|
|
+ LOG(INFO) << "获得点云数据";
|
|
|
if(!cloud) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
cloud->header.frame_id = map_frame_id;
|
|
|
cloud->header.stamp = snapshot.back()->cloud->header.stamp;
|
|
|
|
|
|
sensor_msgs::PointCloud2Ptr cloud_msg(new sensor_msgs::PointCloud2());
|
|
|
pcl::toROSMsg(*cloud, *cloud_msg);
|
|
|
|
|
|
-
|
|
|
- LOG(INFO) << cloud_msg->header.frame_id;
|
|
|
-
|
|
|
map_points_pub.publish(*cloud_msg);
|
|
|
-
|
|
|
-}
|
|
|
+ LOG(INFO) << "点云数据发布完成";
|
|
|
+
|
|
|
+ LOG(INFO) << "map_points_publish_timer_callback 函数执行完毕";
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
|
|
|
* @brief 接收点云数据并放到 keyframe_queue 中
|
|
@@ -211,7 +232,7 @@ void hdl_backend::cloud_callback(const nav_msgs::OdometryConstPtr& odom_msg, con
|
|
|
}
|
|
|
|
|
|
|
|
|
- if(!keyframe_updater->update(odom)) {
|
|
|
+ if(!keyframe_updater->update(odom)) {
|
|
|
|
|
|
std::lock_guard<std::mutex> lock(keyframe_queue_mutex);
|
|
|
|