最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C++ Cartographer加載配置文件過程介紹

 更新時(shí)間:2023年03月17日 08:29:00   作者:蝦眠不覺曉,  
這篇文章主要介紹了Cartographer加載配置文件過程,谷歌優(yōu)秀的激光SLAM開源框架Cartographer算法簡(jiǎn)單,但是程序部分太多需要學(xué)習(xí)的地方了,不論是整體框架的結(jié)構(gòu),還是數(shù)據(jù)的使用,都是非常優(yōu)美的

在node_main.cc文件中,有如下代碼

  std::tie(node_options, trajectory_options) =
      LoadOptions(FLAGS_configuration_directory, FLAGS_configuration_basename);

std::tie作用是同時(shí)對(duì)多個(gè)變量賦值,但是只能個(gè)從元組tuple賦值,在node_options.cc中有如下定義:

std::tuple<NodeOptions, TrajectoryOptions> LoadOptions(
    const std::string& configuration_directory,
    const std::string& configuration_basename) {
  // 獲取配置文件所在的目錄
  auto file_resolver =
      absl::make_unique<cartographer::common::ConfigurationFileResolver>(std::vector<std::string>{configuration_directory});
  // 讀取配置文件內(nèi)容到code中
  const std::string code =
      file_resolver->GetFileContentOrDie(configuration_basename);
  // 根據(jù)給定的字符串, 生成一個(gè)lua字典
  cartographer::common::LuaParameterDictionary lua_parameter_dictionary(
      code, std::move(file_resolver));
  // 創(chuàng)建元組tuple,元組定義了一個(gè)有固定數(shù)目元素的容器, 其中的每個(gè)元素類型都可以不相同
  // 將配置文件的內(nèi)容填充進(jìn)NodeOptions與TrajectoryOptions, 并返回
  return std::make_tuple(CreateNodeOptions(&lua_parameter_dictionary),
                         CreateTrajectoryOptions(&lua_parameter_dictionary));
}

這返回值為元組tuple.

ps:vector初始化:

要注意“()”和“{}”這樣的初始化情況,比如:

std::vector<int> nVec(10,1);    // 包含10個(gè)元素,且值為1

std::vector<int> nVec{10,1};    // 包含2個(gè)元素,值分別為10,1

CreateNodeOptions,是定義在node_options.h文件里的一個(gè)結(jié)構(gòu)體,同理CreateTrajectoryOptions,里面的參數(shù)是由lua文件傳入的.

trajectoryoptions只在開始軌跡的時(shí)候用了,見node_main.cc

在trajectory_options.cc中有如下定義

void CheckTrajectoryOptions(const TrajectoryOptions& options) {
  CHECK_GE(options.num_subdivisions_per_laser_scan, 1);
  CHECK_GE(options.num_laser_scans + options.num_multi_echo_laser_scans +
               options.num_point_clouds,
           1)
      << "Configuration error: 'num_laser_scans', "
         "'num_multi_echo_laser_scans' and 'num_point_clouds' are "
         "all zero, but at least one is required.";
}

這個(gè)說明是要至少一個(gè)激光,或者激光+超聲雷達(dá)+點(diǎn)云的個(gè)數(shù)要>1才能運(yùn)行程序

NodeOptions CreateNodeOptions(
    ::cartographer::common::LuaParameterDictionary* const
        lua_parameter_dictionary) {
  NodeOptions options;
  options.map_builder_options =
      ::cartographer::mapping::CreateMapBuilderOptions(
          lua_parameter_dictionary->GetDictionary("map_builder").get());
  options.map_frame = lua_parameter_dictionary->GetString("map_frame");
  options.lookup_transform_timeout_sec =
      lua_parameter_dictionary->GetDouble("lookup_transform_timeout_sec");
  options.submap_publish_period_sec =
      lua_parameter_dictionary->GetDouble("submap_publish_period_sec");
  options.pose_publish_period_sec =
      lua_parameter_dictionary->GetDouble("pose_publish_period_sec");
  options.trajectory_publish_period_sec =
      lua_parameter_dictionary->GetDouble("trajectory_publish_period_sec");
  if (lua_parameter_dictionary->HasKey("publish_to_tf")) {
    options.publish_to_tf =
        lua_parameter_dictionary->GetBool("publish_to_tf");
  }
  if (lua_parameter_dictionary->HasKey("publish_tracked_pose")) {
    options.publish_tracked_pose =
        lua_parameter_dictionary->GetBool("publish_tracked_pose");
  }
  if (lua_parameter_dictionary->HasKey("use_pose_extrapolator")) {
    options.use_pose_extrapolator =
        lua_parameter_dictionary->GetBool("use_pose_extrapolator");
  }
  return options;
}

上面的程序是根據(jù)lua字典中的參數(shù), 生成protobuf的序列化數(shù)據(jù)結(jié)構(gòu), 結(jié)構(gòu)體NodeOptions定義在頭文件中,其中有個(gè)元素為::cartographer::mapping::proto::MapBuilderOptions map_builder_options;是proto類型,在上述程序中的第一個(gè)參數(shù)被賦值

在node_options.cc有個(gè)類ConfigurationFileResolver,定義在configuration_file_resolver.h中,公有繼承來自FileResolver

class ConfigurationFileResolver : public FileResolver{
 public:
  // c++11: explicit關(guān)鍵字 的作用就是防止類構(gòu)造函數(shù)的隱式自動(dòng)轉(zhuǎn)換
  explicit ConfigurationFileResolver(
      const std::vector<std::string>& configuration_files_directories);
  std::string GetFullPathOrDie(const std::string& basename) override;
  std::string GetFileContentOrDie(const std::string& basename) override;
 private:
  std::vector<std::string> configuration_files_directories_;
};

FileResolver定義在lua_parameter_dictionary.h中:

class FileResolver {
 public:
  virtual ~FileResolver() {}
  virtual std::string GetFullPathOrDie(const std::string& basename) = 0;
  virtual std::string GetFileContentOrDie(const std::string& basename) = 0;
};

這個(gè)都是虛函數(shù),只是個(gè)接口

cartographer經(jīng)常有對(duì)接口類的繼承

ConfigurationFileResolver的構(gòu)造函數(shù)在configuration_file_resolver.cc里面

ConfigurationFileResolver::ConfigurationFileResolver(
    const std::vector<std::string>& configuration_files_directories)
    : configuration_files_directories_(configuration_files_directories) {
  configuration_files_directories_.push_back(kConfigurationFilesDirectory);
}

這個(gè)函數(shù)有個(gè)初始化列表,可以看到最終傳入的參數(shù)是kConfigurationFilesDirectory,這個(gè)參數(shù)定義在config.h.這個(gè)文件里,這個(gè)文件是config.h.cmake編譯生成的,如下內(nèi)容

namespace cartographer {
namespace common {
constexpr char kConfigurationFilesDirectory[] =
    "@CARTOGRAPHER_CONFIGURATION_FILES_DIRECTORY@";
constexpr char kSourceDirectory[] = "@PROJECT_SOURCE_DIR@";
}  // namespace common
}  // namespace cartographer

一個(gè)是定義工程配置文件的文件夾,一個(gè)是工程地址的目錄,在config.h中會(huì)生成匹配自己電腦的字符串地址.那么上面的ConfigurationFileResolver的構(gòu)造函數(shù)就是為了傳入自己電腦的某些目錄地址..

GetFullPathOrDie:遍歷整個(gè)文件夾文件名看看能不能找到相應(yīng)文件,如不能就報(bào)錯(cuò)

GetFileContentOrDie的作用是看傳入的地址變量是不是空的,然后通過GetFullPathOrDie暴力查找是否在當(dāng)前目錄中存在,然后讀取配置文件轉(zhuǎn)為string格式然后返回.

再回到node_options.cc中

接下來是讀取配置文件到code中,然后從code和之前讀取的file_resolver生成一個(gè)lua字典

lua是個(gè)類似cpp的程序語言,定義在lua_parameter_dictionary.cc中,不細(xì)說了

如果想自己通過lua文件寫入一些配置和參數(shù),步驟如下

在自己寫的lua配置文件中寫入自己的參數(shù),如th=1.1,

在想一下這個(gè)th是屬于node_options還是trajectory_options,如在node_options中,則在node_options.h中定義好自己的數(shù)據(jù)類型和初始值,如double th = 1.1;

然后在node_options.cc中寫入

  if (lua_parameter_dictionary->HasKey("th")) {
    options.th =
        lua_parameter_dictionary->GetDouble("th");
  }

到此這篇關(guān)于C++ Cartographer加載配置文件過程介紹的文章就介紹到這了,更多相關(guān)C++ Cartographer 內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • matlab鳥群算法求解車間調(diào)度問題詳解及實(shí)現(xiàn)源碼

    matlab鳥群算法求解車間調(diào)度問題詳解及實(shí)現(xiàn)源碼

    這篇文章主要為大家介紹了matlab鳥群算法求解車間調(diào)度的問題分析及實(shí)現(xiàn)源碼,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步
    2022-02-02
  • C語言 實(shí)現(xiàn)N階乘的程序代碼

    C語言 實(shí)現(xiàn)N階乘的程序代碼

    本篇文章是對(duì)c語言中實(shí)現(xiàn)N階乘的程序代碼進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • Cocos2d-x人物動(dòng)作類實(shí)例

    Cocos2d-x人物動(dòng)作類實(shí)例

    這篇文章主要介紹了Cocos2d-x人物動(dòng)作類實(shí)例,本文用大量代碼和圖片講解Cocos2d-x中的動(dòng)作,代碼中同時(shí)包含大量注釋說明,需要的朋友可以參考下
    2014-09-09
  • C語言實(shí)現(xiàn)循環(huán)鏈表

    C語言實(shí)現(xiàn)循環(huán)鏈表

    這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)循環(huán)鏈表,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • C++ Explicit關(guān)鍵字詳細(xì)解析

    C++ Explicit關(guān)鍵字詳細(xì)解析

    以下是對(duì)C++中Explicit關(guān)鍵字的用法進(jìn)行了詳細(xì)的介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助
    2013-09-09
  • C語言頭文件<string.h>函數(shù)詳解

    C語言頭文件<string.h>函數(shù)詳解

    本文主要介紹了C語言頭文件<string.h>函數(shù)詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • C++中volatile關(guān)鍵字的使用詳解以及常見的誤解

    C++中volatile關(guān)鍵字的使用詳解以及常見的誤解

    volatile 關(guān)鍵字是一種類型修飾符,用它聲明的類型變量表示可以被某些編譯器未知的因素更改,比如:操作系統(tǒng),硬件或者其他線程等
    2020-01-01
  • C語言實(shí)現(xiàn)單詞助手功能

    C語言實(shí)現(xiàn)單詞助手功能

    這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)單詞小助手,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-10-10
  • C++中4種管理數(shù)據(jù)內(nèi)存的方式總結(jié)

    C++中4種管理數(shù)據(jù)內(nèi)存的方式總結(jié)

    根據(jù)用于分配內(nèi)存的方法,C++中有3中管理數(shù)據(jù)內(nèi)存的方式:自動(dòng)存儲(chǔ)、靜態(tài)存儲(chǔ)和動(dòng)態(tài)存儲(chǔ)。在存在時(shí)間的長(zhǎng)短方面,以這三種方式分配的數(shù)據(jù)對(duì)象各不相同。下面簡(jiǎn)要介紹這三種類型
    2022-09-09
  • C語言深入分析遞歸函數(shù)的實(shí)現(xiàn)

    C語言深入分析遞歸函數(shù)的實(shí)現(xiàn)

    遞歸(recursive)函數(shù)是“自己調(diào)用自己”的函數(shù),無論是采用直接或間接調(diào)用方式。間接遞歸意味著函數(shù)調(diào)用另一個(gè)函數(shù)(然后可能又調(diào)用第三個(gè)函數(shù)等),最后又調(diào)用第一個(gè)函數(shù)。因?yàn)楹瘮?shù)不可以一直不停地調(diào)用自己,所以遞歸函數(shù)一定具備結(jié)束條件
    2022-04-04

最新評(píng)論

缙云县| 乌拉特后旗| 雷州市| 惠安县| 吐鲁番市| 沿河| 扶风县| 九江市| 洪江市| 楚雄市| 龙海市| 沾化县| 惠来县| 甘肃省| 吉林省| 昆山市| 通化市| 文水县| 和静县| 久治县| 报价| 金平| 宁河县| 金昌市| 江门市| 临沂市| 梅河口市| 阳江市| 鄂州市| 阳新县| 会昌县| 临清市| 盐池县| 叙永县| 大冶市| 广西| 沅陵县| 吉木乃县| 平罗县| 吴江市| 桂平市|