在雷达标定过程中,在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();
文件效果如下:
因时间原因,以上代码是直接提取出来的