重讀ORB_SLAM之LocalMapping線程痛點

來源:互聯網
上載者:User

標籤:request   有用   cep   ret   HERE   loop   流程   bundle   mapper   

1. 認清幾個鎖與布爾參數

線程的通訊與相互影響在ORB比較複雜,需要好好縷清思路。
1.1 mbStopRequested,由RequestStop函數設定,主要是在迴環線程裡,在運行全域最佳化時,以及檢測後,調整Loop時,localMapping需要暫停。
1.2 mbStopped:由stop()函數設定。mbNotStop: 由SetNotStop()設定。 這兩個真是把人搞得頭大。在Tracking線程,如果mapping線程被要求暫停,也就是mpLocalMapper->isStopped() || mpLocalMapper->stopRequested() 為真,則停止往裡添加主要畫面格。如果可以添加主要畫面格,則Tracking線程添加主要畫面格時,必須保證LocaMapping不能被終止,則mbNotStop需要為真。

   if(!mpLocalMapper->SetNotStop(true))        return;

這個判斷要為真。

1.3 mpLocalMapper->Release(); 此函數在全域最佳化以及調整Loop後使用,目的是使mbStopped,mbStopRequested都置為false。且清空 mlNewKeyFrames。
1.4 mMutexStop鎖,主要是在設定以上兩個參數時使用,防止同時更改。
1.5 mMutexAccept鎖,也是防止在設定mbAcceptKeyFrames時保持非同步。mMutexNewKFs也是同樣的原理。

2 整體流程
void LocalMapping::Run(){    mbFinished = false;    while(1)    {        // Tracking will see that Local Mapping is busy        SetAcceptKeyFrames(false);        // Check if there are keyframes in the queue        if(CheckNewKeyFrames())        {            // BoW conversion and insertion in Map            /* 1. 首先計算BOW               2. 對於Tracking 線程匹配到的mappoint做一些處理,比如為mappoint增加觀測,更新描述子               3. 更新當前幀與其鄰居幀的關係               4. 最後把主要畫面格加入到map裡 */            ProcessNewKeyFrame();            // Check recent MapPoints            /*                這裡主要處理剛加入的地圖點。剛加入的地圖點一般由上一次CreateNewMapPoints產生。在這裡做刪減。但是這裡不知道mlpRecentAddedMapPoints有什麼作用。好像哪裡都沒有用到,而且list裡erase這些mappoint指標並不會對map裡的mappoint指標有影響。            */            MapPointCulling();            // Triangulate new MapPoints            /*              這裡產生新的地圖點,與Tracking線程裡不太一樣,那裡是直接利用深度資訊產生地圖點。這裡是根據當前幀的鄰居幀,進行再次匹配,利用三角化產生地圖點。這樣就增大了SLAM的可視距離            */            CreateNewMapPoints();            if(!CheckNewKeyFrames())            {                // Find more matches in neighbor keyframes and fuse point duplications                SearchInNeighbors();            }            mbAbortBA = false;            if(!CheckNewKeyFrames() && !stopRequested())            {                // Local BA                if(mpMap->KeyFramesInMap()>2)                    Optimizer::LocalBundleAdjustment(mpCurrentKeyFrame,&mbAbortBA, mpMap);                // Check redundant local Keyframes                /*                如果當前局部地圖裡有這樣的主要畫面格:其所看到的90%的地圖點,也至少被其他三個主要畫面格看到,則應刪除此主要畫面格。                */                KeyFrameCulling();            }            mpLoopCloser->InsertKeyFrame(mpCurrentKeyFrame);        }        else if(Stop())        {            // Safe area to stop            while(isStopped() && !CheckFinish())            {                usleep(3000);            }            if(CheckFinish())                break;        }        ResetIfRequested();        // Tracking will see that Local Mapping is busy        SetAcceptKeyFrames(true);        if(CheckFinish())            break;        usleep(3000);    }    SetFinish();}

重讀ORB_SLAM之LocalMapping線程痛點

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.