ORB_SLAM3问题记录汇总(更新中)

因项目要求要跑ORB-SLAM3,在安装和测试的过程中遇到了很多问题,特此在这里记录一下:
一.硬件介绍:
硬件:Intel Realsense D455

二.编译:
关于Pangolin:
https://blog.csdn.net/Robert_Q/article/details/121690089

三.运行Example
目前只跑了Examples/Stereo,因此在这里主要记录这里面的问题

  1. 修改配置文件
  2. 修改Settings.cc
    在Settings.cc中存在一处逻辑错误,会导致在加载camera2参数时报Segmentation fault.
    修改前:
// 修改此方法
    ostream &operator<<(std::ostream& output, const Settings& settings){
        output << "SLAM settings: " << endl;
        ...
        ...
        if(settings.sensor_ == System::STEREO || settings.sensor_ == System::IMU_STEREO){
            output << "\t-Camera 2 parameters (";
            if(settings.cameraType_ == Settings::PinHole || settings.cameraType_ ==  Settings::Rectified){
                cout<<"Pinhole"<<endl;
                output << "Pinhole";
            }
            else{
                output << "Kannala-Brandt";
            }
            output << ")" << ": [";
            for(size_t i = 0; i < settings.originalCalib2_->size(); i++){
                cout<<settings.originalCalib2_->getParameter(i)<<endl;
                output << " " << settings.originalCalib2_->getParameter(i);
            }
            output << " ]" << endl;

            if(!settings.vPinHoleDistorsion2_.empty()){
                output << "\t-Camera 2 distortion parameters: [ ";
                for(float d : settings.vPinHoleDistorsion2_){
                    output << " " << d;
                }
                output << " ]" << endl;
            }
        }

修改后:

    ostream &operator<<(std::ostream& output, const Settings& settings){
        output << "SLAM settings: " << endl;
        ...
        ...
        if(settings.cameraType_ == Settings::PinHole)
        {
            output << ")" << ": [";
            for(size_t i = 0; i < settings.originalCalib2_->size(); i++){
                output << " " << settings.originalCalib2_->getParameter(i);
            }
            output << " ]" << endl;
        }
        else if(settings.cameraType_ == Settings::Rectified)
        {
            output << ")" << ": [";
            for(size_t i = 0; i < settings.originalCalib1_->size(); i++){
                output << " " << settings.originalCalib1_->getParameter(i);
            }
            output << " ]" << endl;
        }

参考自:参考此处

  1. 修改System.cc
    问题1:在保存地图时,经常会出现Segmentation fault,导致地图无法保存,在debug了好久后,目前找到了可能的原因:
    在UI界面点击stop后,stereo_realsense_D435i.cc中的while (!SLAM.isShutDown())会返回mbShutDown这个flag的状态,而这个flag是在System::shutdown()中进行修改的.
void System::Shutdown()
{
    {
        unique_lock<mutex> lock(mMutexReset);
        mbShutDown = true;
    }

    cout << "Shutdown" << endl;

    mpLocalMapper->RequestFinish();
    mpLoopCloser->RequestFinish();
    ...

a. shutdown()是注册在界面端的函数.在界面点击stop()后, mbShutDown 立刻会被设置为 true;
b. 同时在./Examples/Stereo/stereo_realsense_D435i.cc中的while (!SLAM.isShutDown())会检查mbShutDown的值.当mbShutDown==true时,退出while循环. 推出while循环后,后面已无可执行的命令,整个程序退出,SLAM对象销毁.
c. 但是当地图文件很大时,注册在界面端的函数依旧在执行,最后在SaveAtlas()时,会访问SLAM对象中的一些成员,如mStrVocabularyFilePath变量,但此时SLAM已经被销毁,最后访问变量出错,导致Segmentation fault.

修改

void System::Shutdown()
{
    {
        unique_lock<mutex> lock(mMutexReset);
    }
    cout << "Shutdown" << endl;
    mpLocalMapper->RequestFinish();
    mpLoopCloser->RequestFinish();
    
    ...
    
    if(!mStrSaveAtlasToFile.empty())
    {
        Verbose::PrintMess("Atlas saving to file " + mStrSaveAtlasToFile, Verbose::VERBOSITY_NORMAL);
        SaveAtlas(FileType::BINARY_FILE);
    }
    /*if(mpViewer)
        pangolin::BindToContext("ORB-SLAM2: Map Viewer");*/
#ifdef REGISTER_TIMES
    mpTracker->PrintTimeStats();
#endif
     mbShutDown = true;
}

将mbShutDown = true;放在程序的最后,在执行完地图保存后,再修改flag.

  1. 关于点击Stop后,出现Segmentation Fault 的问题
    这里是因为在点击Stop后,Viewer里面触发System.shutdown()函数,其中会把所有的threads都关闭。但是,mpviewer因为停止所需时间较长,不能立刻停止, 而代码里也把这一部分给注释了,导致了内存错误。
    /*if(mpViewer)
    {
        int wait_limit = 0;
        while(!mpViewer->isFinished())
        {
            wait_limit++;
            if (wait_limit > 10)
                break;
            mpViewer->RequestFinish();
            usleep(1000000);
            cout << "mpViewer is not finished" << endl;
        }
    }*/

将这一部分取消注释就好了,编译后一直会申请把mpviewer给close掉,会花费一点时间。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值