| 40 | } |
| 41 | |
| 42 | void PoseGraph::addKeyFrame(KeyFrame* cur_kf, bool flag_detect_loop) |
| 43 | { |
| 44 | //shift to base frame |
| 45 | Vector3d vio_P_cur; |
| 46 | Matrix3d vio_R_cur; |
| 47 | if (sequence_cnt != cur_kf->sequence) |
| 48 | { |
| 49 | sequence_cnt++; |
| 50 | sequence_loop.push_back(0); |
| 51 | w_t_vio = Eigen::Vector3d(0, 0, 0); |
| 52 | w_r_vio = Eigen::Matrix3d::Identity(); |
| 53 | m_drift.lock(); |
| 54 | t_drift = Eigen::Vector3d(0, 0, 0); |
| 55 | r_drift = Eigen::Matrix3d::Identity(); |
| 56 | m_drift.unlock(); |
| 57 | } |
| 58 | |
| 59 | cur_kf->getVioPose(vio_P_cur, vio_R_cur); |
| 60 | vio_P_cur = w_r_vio * vio_P_cur + w_t_vio; |
| 61 | vio_R_cur = w_r_vio * vio_R_cur; |
| 62 | cur_kf->updateVioPose(vio_P_cur, vio_R_cur); |
| 63 | cur_kf->index = global_index; |
| 64 | global_index++; |
| 65 | int loop_index = -1; |
| 66 | if (flag_detect_loop) |
| 67 | { |
| 68 | TicToc tmp_t; |
| 69 | loop_index = detectLoop(cur_kf, cur_kf->index); |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | addKeyFrameIntoVoc(cur_kf); |
| 74 | } |
| 75 | if (loop_index != -1) |
| 76 | { |
| 77 | //printf(" %d detect loop with %d \n", cur_kf->index, loop_index); |
| 78 | KeyFrame* old_kf = getKeyFrame(loop_index); |
| 79 | |
| 80 | if (cur_kf->findConnection(old_kf)) |
| 81 | { |
| 82 | if (earliest_loop_index > loop_index || earliest_loop_index == -1) |
| 83 | earliest_loop_index = loop_index; |
| 84 | |
| 85 | Vector3d w_P_old, w_P_cur, vio_P_cur; |
| 86 | Matrix3d w_R_old, w_R_cur, vio_R_cur; |
| 87 | old_kf->getVioPose(w_P_old, w_R_old); |
| 88 | cur_kf->getVioPose(vio_P_cur, vio_R_cur); |
| 89 | |
| 90 | Vector3d relative_t; |
| 91 | Quaterniond relative_q; |
| 92 | relative_t = cur_kf->getLoopRelativeT(); |
| 93 | relative_q = (cur_kf->getLoopRelativeQ()).toRotationMatrix(); |
| 94 | w_P_cur = w_R_old * relative_t + w_P_old; |
| 95 | w_R_cur = w_R_old * relative_q; |
| 96 | double shift_yaw; |
| 97 | Matrix3d shift_r; |
| 98 | Vector3d shift_t; |
| 99 | shift_yaw = Utility::R2ypr(w_R_cur).x() - Utility::R2ypr(vio_R_cur).x(); |
no test coverage detected