yaml-cpp保存标定文件-Node/Emitter

1 篇文章 0 订阅

在雷达标定过程中,在ubuntu系统下使用了yaml-cpp保存标定文件,以此记录。库的安装和使用,可参考yaml-cpp官方教材

Node类型

直接上代码:

    YAML::Node node_res; 
    assert(node_res.IsNull());  //初始化的节点是Null类型

    time_t time_now = time(nullptr);
    char time_ch[64];
    strftime(time_ch, sizeof(time_ch), "%Y-%m-%d-%H:%M:%S", localtime(&time_now));
    string MLC_calib_date = time_ch;

    node_res["MLC_calib_version"] = "v1.0.0";
    node_res["MLC_calib_details"] = "output by MLC calibration";
    node_res["MLC_calib_date"] = MLC_calib_date;
    node_res["sensor_name"] = "front";
    node_res["sensor_type"] = "LiDAR";
    node_res["timestamp_shift"] = 0;
    node_res["vehicle_xyz"] = "front_left_up";

    node_res["r_s2b"] = vector<double>{0, 0, 0};
    node_res["t_s2b"] = vector<double>{0, 0, 0};
    node_res["lidar_width"] = 960;
    node_res["lidar_height"] = 96;

    std::ofstream file("./lidar_front.yaml");
    file << "%YAML:1.0"<<endl;
    file << "---"<<endl;
    file << node_res <<std::endl;
    file.close();

文件效果如下:
在这里插入图片描述

Emitter类型

直接上代码:

  std::ofstream fout("./lidar_front.yaml");
  vector<double> r_s2b = {0, 0, 0};
  vector<double> t_s2b = {0, 0, 0};

  time_t time_now = time(nullptr);
  char time_ch[64];
  strftime(time_ch, sizeof(time_ch), "%Y-%m-%d-%H:%M:%S", localtime(&time_now));
  string MLC_calib_date = time_ch;
  YAML::Emitter ofile(fout);
  fout << std::string("%YAML:1.0\n");
  fout << "---\n";
  ofile << YAML::BeginMap;
  ofile << YAML::Key << "MLC_calib_version" << YAML::Value << YAML::DoubleQuoted << "v1.0.0";
  ofile << YAML::Key << "MLC_calib_details" << YAML::Value << YAML::DoubleQuoted << "output by MLC calibration";
  ofile << YAML::Key << "MLC_calib_date" << YAML::Value << YAML::DoubleQuoted << MLC_calib_date ;
  
  ofile << YAML::Key << "sensor_name" << YAML::Value << YAML::DoubleQuoted << "front"
        << YAML::Comment("传感器命名");
  ofile << YAML::Key << "sensor_type" << YAML::Value << YAML::DoubleQuoted << "LiDAR"
        << YAML::Comment("传感器类型");
  ofile << YAML::Key << "timestamp_shift" << YAML::Value << YAML::DoubleQuoted << 0
        << YAML::Comment("时间戳延时, 单位 ms, 真实时间戳 = 得到时间戳 + timestamp_shift");
  ofile << YAML::Key << "vehicle_xyz" << YAML::Value << YAML::DoubleQuoted << "front_left_up"
        << YAML::Comment("车体系定义, 前左上, 后轴中心接地点"); // -- 车体坐标系方向定义
  
  ofile << YAML::Key << "r_s2b"
        << YAML::Comment("传感器到车体系的旋转, i.e. p_b = R(r_s2b)*p_s, p_b表示车体系下的点, "
                         "R(.)表示把旋转向量转换成旋转矩阵的函数, p_s表示传感器系的点")
        << YAML::Flow << r_s2b;
  ofile << YAML::Key << "t_s2b" << YAML::Comment("传感器到车体的平移, 单位 m") << YAML::Flow << t_s2b;
  
  ofile << YAML::Key << "width" << YAML::Value << YAML::DoubleQuoted << 960
        << YAML::Comment("角分辨率, 一圈点的个数");
  ofile << YAML::Key << "height" << YAML::Value << YAML::DoubleQuoted << 96
        << YAML::Comment("线束");
  ofile << YAML::EndMap;
  fout.close();

文件效果如下:
在这里插入图片描述
因时间原因,以上代码是直接提取出来的

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值