upload
This commit is contained in:
513
app/src/app_config.cc
Normal file
513
app/src/app_config.cc
Normal file
@@ -0,0 +1,513 @@
|
||||
#include "app_config.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
#include "vslam/log.h"
|
||||
#include "vslam/node_constants.h"
|
||||
|
||||
namespace vslam {
|
||||
namespace {
|
||||
|
||||
constexpr double kPi = 3.14159265358979323846;
|
||||
|
||||
// Nap mot file, doi ngoai le thanh StatusResponse.
|
||||
//
|
||||
// ConfigNode::LoadFile nem ConfigError. Mot file config sai KHONG duoc phep
|
||||
// lam sap tien trinh: nguoi van hanh phai doc duoc loi, khong phai mot
|
||||
// backtrace.
|
||||
StatusResponse Open(const std::string& dir, const char* name, ConfigNode* out) {
|
||||
const std::string path = dir + "/" + name;
|
||||
try {
|
||||
*out = ConfigNode::LoadFile(path);
|
||||
return StatusResponse::Ok();
|
||||
} catch (const std::exception& e) {
|
||||
return StatusResponse::Error(StatusCode::kInvalidArgument,
|
||||
std::string(name) + " (" + path + "): " + e.what());
|
||||
}
|
||||
}
|
||||
|
||||
// Tu choi khoi dong khi co khoa la.
|
||||
//
|
||||
// Go sai ten khoa hien tai roi ve mac dinh mot cach im lang. `stop_distence`
|
||||
// thay vi `stop_distance` nghia la robot dung o 0.35 m mac dinh thay vi gia
|
||||
// tri ban vua dat -- va ban se khong biet cho toi khi no khong dung.
|
||||
StatusResponse Reject(const ConfigNode& n, const char* where,
|
||||
const std::vector<std::string>& known) {
|
||||
if (n.IsNull()) return StatusResponse::Ok();
|
||||
const std::vector<std::string> unknown = n.UnknownKeys(known);
|
||||
if (unknown.empty()) return StatusResponse::Ok();
|
||||
std::string m = std::string(where) + ": khoa la:";
|
||||
for (const auto& k : unknown) m += " " + k;
|
||||
return StatusResponse::Error(StatusCode::kInvalidArgument, m);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
StatusResponse LoadAppConfig(const std::string& dir, AppConfig* out) {
|
||||
// ---------- robot.yaml ----------
|
||||
{
|
||||
const StatusResponse st = out->robot.LoadFile(dir + "/" + kRobotConfigFile);
|
||||
if (!st.ok()) return st;
|
||||
}
|
||||
const RobotGeometry& geom = out->robot.geometry();
|
||||
|
||||
// ---------- sensors.yaml ----------
|
||||
{
|
||||
ConfigNode root;
|
||||
const StatusResponse st = Open(dir, kSensorsConfigFile, &root);
|
||||
if (!st.ok()) return st;
|
||||
{
|
||||
const StatusResponse r = Reject(root, "sensors.yaml", {"lidar", "camera", "mcu"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
|
||||
const ConfigNode l = root["lidar"];
|
||||
{
|
||||
const StatusResponse r =
|
||||
Reject(l, "sensors.yaml lidar",
|
||||
{"host", "port", "expected_rate_hz", "range_min", "range_max",
|
||||
"stamp_mismatch_warn", "sector_masks"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
out->sanitizer.range_min = l.get<double>("range_min", 0.05);
|
||||
out->sanitizer.range_max = l.get<double>("range_max", 40.0);
|
||||
out->sensors.lidar_hz = l.get<double>("expected_rate_hz", 25.0);
|
||||
|
||||
// Sector mask ghi bang DO trong YAML (doc duoc bang mat), dung bang RAD.
|
||||
// Doi mot lan o day, khong de moi noi tu doi.
|
||||
const ConfigNode masks = l["sector_masks"];
|
||||
out->sanitizer.sector_masks.clear();
|
||||
if (!masks.IsNull()) {
|
||||
if (!masks.IsSequence()) {
|
||||
return StatusResponse::Error(StatusCode::kInvalidArgument,
|
||||
"sensors.yaml lidar.sector_masks phai la chuoi");
|
||||
}
|
||||
for (size_t i = 0; i < masks.size(); ++i) {
|
||||
const ConfigNode m = masks.at(i);
|
||||
if (!m.IsSequence() || m.size() != 2) {
|
||||
return StatusResponse::Error(
|
||||
StatusCode::kInvalidArgument,
|
||||
"sensors.yaml lidar.sector_masks[" + std::to_string(i) +
|
||||
"] phai la [bat_dau_do, ket_thuc_do]");
|
||||
}
|
||||
const double a = m.at(0).as<double>() * kPi / 180.0;
|
||||
const double b = m.at(1).as<double>() * kPi / 180.0;
|
||||
if (!(b > a)) {
|
||||
return StatusResponse::Error(
|
||||
StatusCode::kInvalidArgument,
|
||||
"sensors.yaml lidar.sector_masks[" + std::to_string(i) +
|
||||
"]: ket thuc phai lon hon bat dau (quat rong 0 do khong che gi)");
|
||||
}
|
||||
out->sanitizer.sector_masks.push_back(SectorMask{a, b});
|
||||
}
|
||||
}
|
||||
|
||||
const ConfigNode c = root["camera"];
|
||||
{
|
||||
const StatusResponse r =
|
||||
Reject(c, "sensors.yaml camera",
|
||||
{"enable", "width", "height", "fps", "decimate", "enable_infra1",
|
||||
"enable_infra2", "prefer_global_time"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
out->sensors.camera_enable = c.get<bool>("enable", true);
|
||||
out->sensors.camera_width = static_cast<uint32_t>(c.get<int>("width", 640));
|
||||
out->sensors.camera_height = static_cast<uint32_t>(c.get<int>("height", 480));
|
||||
out->sensors.camera_hz = c.get<double>("fps", 30.0);
|
||||
out->sensors.camera_decimate = static_cast<uint32_t>(c.get<int>("decimate", 2));
|
||||
|
||||
const ConfigNode mc = root["mcu"];
|
||||
{
|
||||
const StatusResponse r =
|
||||
Reject(mc, "sensors.yaml mcu",
|
||||
{"port", "baud", "sync_window", "max_skew_warn",
|
||||
"expected_imu_rate_hz", "ticks_per_rev"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
out->sensors.imu_hz = mc.get<double>("expected_imu_rate_hz", 200.0);
|
||||
}
|
||||
|
||||
// ---------- pipeline.yaml ----------
|
||||
{
|
||||
ConfigNode root;
|
||||
const StatusResponse st = Open(dir, kPipelineConfigFile, &root);
|
||||
if (!st.ok()) return st;
|
||||
{
|
||||
const StatusResponse r =
|
||||
Reject(root, "pipeline.yaml",
|
||||
{"ekf", "depth_filter", "gravity_align", "cliff_detect"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
|
||||
const ConfigNode e = root["ekf"];
|
||||
{
|
||||
const StatusResponse r =
|
||||
Reject(e, "pipeline.yaml ekf",
|
||||
{"q_x", "q_y", "q_yaw", "q_vx", "q_vyaw", "max_dt"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
out->ekf.q_x = e.get<double>("q_x", out->ekf.q_x);
|
||||
out->ekf.q_y = e.get<double>("q_y", out->ekf.q_y);
|
||||
out->ekf.q_yaw = e.get<double>("q_yaw", out->ekf.q_yaw);
|
||||
out->ekf.q_vx = e.get<double>("q_vx", out->ekf.q_vx);
|
||||
out->ekf.q_vyaw = e.get<double>("q_vyaw", out->ekf.q_vyaw);
|
||||
out->ekf.sensor_timeout = e.get<double>("max_dt", out->ekf.sensor_timeout);
|
||||
|
||||
const ConfigNode d = root["depth_filter"];
|
||||
{
|
||||
const StatusResponse r =
|
||||
Reject(d, "pipeline.yaml depth_filter",
|
||||
{"min_range", "max_range", "voxel_size", "max_rate",
|
||||
"enable_temporal", "min_hits", "temporal_window"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
DepthFilterConfig& df = out->perception.filter;
|
||||
df.min_range = d.get<double>("min_range", df.min_range);
|
||||
df.max_range = d.get<double>("max_range", df.max_range);
|
||||
df.voxel_size = d.get<double>("voxel_size", df.voxel_size);
|
||||
df.max_rate = d.get<double>("max_rate", df.max_rate);
|
||||
df.enable_temporal = d.get<bool>("enable_temporal", df.enable_temporal);
|
||||
df.min_hits = d.get<int>("min_hits", df.min_hits);
|
||||
df.temporal_window = d.get<double>("temporal_window", df.temporal_window);
|
||||
|
||||
const ConfigNode ga = root["gravity_align"];
|
||||
{
|
||||
const StatusResponse r =
|
||||
Reject(ga, "pipeline.yaml gravity_align",
|
||||
{"alpha", "accel_lpf_alpha", "accel_gate", "use_odom_accel",
|
||||
"odom_accel_alpha", "min_height", "max_height"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
GravityAlignConfig& g = out->perception.gravity;
|
||||
g.alpha = ga.get<double>("alpha", g.alpha);
|
||||
g.accel_lpf_alpha = ga.get<double>("accel_lpf_alpha", g.accel_lpf_alpha);
|
||||
g.accel_gate = ga.get<double>("accel_gate", g.accel_gate);
|
||||
g.use_odom_accel = ga.get<bool>("use_odom_accel", g.use_odom_accel);
|
||||
g.odom_accel_alpha = ga.get<double>("odom_accel_alpha", g.odom_accel_alpha);
|
||||
g.min_height = ga.get<double>("min_height", g.min_height);
|
||||
g.max_height = ga.get<double>("max_height", g.max_height);
|
||||
// HE QUA cua robot.yaml, khong doc tu pipeline.yaml.
|
||||
g.wheel_radius = geom.wheel_radius;
|
||||
|
||||
const ConfigNode cd = root["cliff_detect"];
|
||||
{
|
||||
// `nominal_tz` va `wheel_radius` CO Y khong nam trong danh sach nay:
|
||||
// dat chung o pipeline.yaml se tao ra mot ban sao thu hai cua mot gia
|
||||
// tri da co trong robot.yaml. Go chung vao file se bao "khoa la".
|
||||
const StatusResponse r =
|
||||
Reject(cd, "pipeline.yaml cliff_detect",
|
||||
{"enabled", "min_dist", "max_dist", "cliff_margin",
|
||||
"pitch_uncertainty_deg", "pixel_step", "min_neighbors",
|
||||
"min_cluster", "imu_timeout", "require_accel_ok", "self_level",
|
||||
"min_level_samples", "level_gate", "max_level_slope",
|
||||
"max_level_residual", "max_obstructed_frac", "max_level_offset",
|
||||
"max_tz_dev", "fail_safe", "fail_safe_after"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
CliffDetectConfig& cf = out->perception.cliff;
|
||||
cf.enabled = cd.get<bool>("enabled", cf.enabled);
|
||||
cf.min_dist = cd.get<double>("min_dist", cf.min_dist);
|
||||
cf.max_dist = cd.get<double>("max_dist", cf.max_dist);
|
||||
cf.cliff_margin = cd.get<double>("cliff_margin", cf.cliff_margin);
|
||||
cf.pitch_uncertainty_deg =
|
||||
cd.get<double>("pitch_uncertainty_deg", cf.pitch_uncertainty_deg);
|
||||
cf.pixel_step = cd.get<int>("pixel_step", cf.pixel_step);
|
||||
cf.min_neighbors = cd.get<int>("min_neighbors", cf.min_neighbors);
|
||||
cf.min_cluster = cd.get<int>("min_cluster", cf.min_cluster);
|
||||
cf.imu_timeout = cd.get<double>("imu_timeout", cf.imu_timeout);
|
||||
cf.require_accel_ok = cd.get<bool>("require_accel_ok", cf.require_accel_ok);
|
||||
cf.self_level = cd.get<bool>("self_level", cf.self_level);
|
||||
cf.min_level_samples = cd.get<int>("min_level_samples", cf.min_level_samples);
|
||||
cf.level_gate = cd.get<double>("level_gate", cf.level_gate);
|
||||
cf.max_level_slope = cd.get<double>("max_level_slope", cf.max_level_slope);
|
||||
cf.max_level_residual =
|
||||
cd.get<double>("max_level_residual", cf.max_level_residual);
|
||||
cf.max_obstructed_frac =
|
||||
cd.get<double>("max_obstructed_frac", cf.max_obstructed_frac);
|
||||
cf.max_level_offset = cd.get<double>("max_level_offset", cf.max_level_offset);
|
||||
cf.max_tz_dev = cd.get<double>("max_tz_dev", cf.max_tz_dev);
|
||||
cf.fail_safe = cd.get<bool>("fail_safe", cf.fail_safe);
|
||||
cf.fail_safe_after = cd.get<double>("fail_safe_after", cf.fail_safe_after);
|
||||
// HE QUA cua robot.yaml.
|
||||
cf.wheel_radius = geom.wheel_radius;
|
||||
cf.nominal_tz = out->robot.camera_height_above_floor();
|
||||
}
|
||||
|
||||
// ---------- wheel_odom: robot.yaml ----------
|
||||
{
|
||||
const WheelOdomNoise& w = out->robot.wheel_odom();
|
||||
out->wheel_odom.wheel_radius = geom.wheel_radius;
|
||||
out->wheel_odom.wheel_separation = geom.wheel_separation;
|
||||
out->wheel_odom.sigma_x = w.sigma_x_per_m;
|
||||
out->wheel_odom.sigma_y = w.sigma_y_per_m;
|
||||
out->wheel_odom.sigma_yaw = w.sigma_yaw_per_rad;
|
||||
out->wheel_odom.slip_omega_threshold = w.slip_threshold;
|
||||
}
|
||||
|
||||
// ---------- safety.yaml ----------
|
||||
{
|
||||
ConfigNode root;
|
||||
const StatusResponse st = Open(dir, kSafetyConfigFile, &root);
|
||||
if (!st.ok()) return st;
|
||||
{
|
||||
const StatusResponse r =
|
||||
Reject(root, "safety.yaml",
|
||||
{"scan", "ultrasonic", "cliff", "timeouts", "limits", "bumper"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
|
||||
const ConfigNode sc = root["scan"];
|
||||
{
|
||||
const StatusResponse r =
|
||||
Reject(sc, "safety.yaml scan",
|
||||
{"stop_distance", "slow_distance", "slow_factor", "front_angle",
|
||||
"min_valid_range", "min_front_rays"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
SafetyConfig& sf = out->safety;
|
||||
sf.stop_distance = sc.get<double>("stop_distance", sf.stop_distance);
|
||||
sf.slow_distance = sc.get<double>("slow_distance", sf.slow_distance);
|
||||
sf.slow_factor = sc.get<double>("slow_factor", sf.slow_factor);
|
||||
sf.front_angle = sc.get<double>("front_angle", sf.front_angle);
|
||||
sf.min_valid_range = sc.get<double>("min_valid_range", sf.min_valid_range);
|
||||
sf.min_front_rays = sc.get<int>("min_front_rays", sf.min_front_rays);
|
||||
|
||||
const ConfigNode us = root["ultrasonic"];
|
||||
{
|
||||
const StatusResponse r = Reject(us, "safety.yaml ultrasonic", {"us_stop_distance"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
sf.us_stop_distance = us.get<double>("us_stop_distance", sf.us_stop_distance);
|
||||
|
||||
const ConfigNode cl = root["cliff"];
|
||||
{
|
||||
const StatusResponse r = Reject(
|
||||
cl, "safety.yaml cliff", {"enable_cliff_stop", "cliff_timeout", "cliff_hold"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
sf.enable_cliff_stop = cl.get<bool>("enable_cliff_stop", sf.enable_cliff_stop);
|
||||
sf.cliff_timeout = cl.get<double>("cliff_timeout", sf.cliff_timeout);
|
||||
sf.cliff_hold = cl.get<double>("cliff_hold", sf.cliff_hold);
|
||||
|
||||
const ConfigNode to = root["timeouts"];
|
||||
{
|
||||
const StatusResponse r =
|
||||
Reject(to, "safety.yaml timeouts", {"sensor_timeout", "cmd_timeout"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
sf.sensor_timeout = to.get<double>("sensor_timeout", sf.sensor_timeout);
|
||||
sf.cmd_timeout = to.get<double>("cmd_timeout", sf.cmd_timeout);
|
||||
|
||||
const ConfigNode li = root["limits"];
|
||||
{
|
||||
const StatusResponse r = Reject(li, "safety.yaml limits", {"max_linear", "max_angular"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
sf.max_linear = li.get<double>("max_linear", sf.max_linear);
|
||||
sf.max_angular = li.get<double>("max_angular", sf.max_angular);
|
||||
|
||||
const ConfigNode bu = root["bumper"];
|
||||
{
|
||||
const StatusResponse r = Reject(bu, "safety.yaml bumper",
|
||||
{"escape_linear", "escape_angular"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
sf.escape_linear = bu.get<double>("escape_linear", sf.escape_linear);
|
||||
sf.escape_angular = bu.get<double>("escape_angular", sf.escape_angular);
|
||||
|
||||
// --- Kiem CHEO voi robot.yaml, khong tin mot trong hai ---
|
||||
//
|
||||
// safety.cmd_timeout phai DAI hon base.cmd_timeout. Neu ngan hon thi base
|
||||
// da tu dung robot truoc, va nhanh NO_CMD cua FSM khong bao gio chay --
|
||||
// tuc la mot nhanh an toan ton tai tren giay ma khong bao gio duoc thu.
|
||||
if (sf.cmd_timeout <= out->robot.base().cmd_timeout) {
|
||||
return StatusResponse::Error(
|
||||
StatusCode::kInvalidArgument,
|
||||
"safety.yaml timeouts.cmd_timeout (" + std::to_string(sf.cmd_timeout) +
|
||||
") phai LON HON robot.yaml base.cmd_timeout (" +
|
||||
std::to_string(out->robot.base().cmd_timeout) +
|
||||
") -- neu khong, base tu dung truoc va nhanh NO_CMD khong bao gio chay");
|
||||
}
|
||||
// Gioi han cua safety khong duoc VUOT gioi han co hoc cua base.
|
||||
if (sf.max_linear > out->robot.base().max_linear + 1e-9 ||
|
||||
sf.max_angular > out->robot.base().max_angular + 1e-9) {
|
||||
return StatusResponse::Error(
|
||||
StatusCode::kInvalidArgument,
|
||||
"safety.yaml limits vuot qua robot.yaml base -- lop an toan khong "
|
||||
"duoc phep cho phep nhieu hon phan cung chiu duoc");
|
||||
}
|
||||
// Toc do thoat khi bumper dang chot khong duoc vuot gioi han thuong.
|
||||
//
|
||||
// Phia sau KHONG co cam bien nao che, va robot dang CHAM vao vat gi do --
|
||||
// day la luc nguy hiem nhat, khong phai luc de di nhanh hon.
|
||||
if (sf.escape_linear > sf.max_linear + 1e-9 ||
|
||||
sf.escape_angular > sf.max_angular + 1e-9) {
|
||||
return StatusResponse::Error(
|
||||
StatusCode::kInvalidArgument,
|
||||
"safety.yaml bumper.escape_* vuot qua limits.max_* -- toc do THOAT "
|
||||
"khi dang cham vat can khong duoc lon hon toc do binh thuong");
|
||||
}
|
||||
if (sf.escape_linear <= 0.0) {
|
||||
return StatusResponse::Error(
|
||||
StatusCode::kInvalidArgument,
|
||||
"safety.yaml bumper.escape_linear phai > 0 -- bang 0 nghia la robot "
|
||||
"dam roi nam vinh vien tai cho, khong lui ra duoc de reset");
|
||||
}
|
||||
|
||||
// Vuc bien mat khoi tam nhin khi lai gan hon min_dist, nen cliff_hold
|
||||
// phai du dai de phu quang duong do. Duoi 1 s la gan nhu chac chan lot.
|
||||
if (sf.enable_cliff_stop && sf.cliff_hold < 1.0) {
|
||||
VSLAM_WARN("safety.yaml cliff.cliff_hold = "
|
||||
<< sf.cliff_hold
|
||||
<< " s. Vuc bien mat khoi tam nhin camera khi lai gan hon "
|
||||
<< out->perception.cliff.min_dist
|
||||
<< " m; gia tri nay nhieu kha nang qua ngan.");
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- cliff.min_dist co khop HINH HOC camera khong ----------
|
||||
//
|
||||
// `min_dist` KHONG phai mot tham so chinh duoc tuy y: no la vung mu HINH
|
||||
// HOC. Tia duoi cung cua truong nhin cham san o
|
||||
// d = z_camera / tan(pitch + vfov/2)
|
||||
// va duoi d do khong mot tia nao cham san -- detector im lang hoan toan.
|
||||
//
|
||||
// Doi `camera_pitch` trong robot.yaml ma quen sua `min_dist` trong
|
||||
// pipeline.yaml la mot kieu hong IM LANG: cliff_detect van chay, van bao
|
||||
// "judged", chi la no dang nhin vao mot dai khong co du lieu.
|
||||
//
|
||||
// ⚠️ CANH BAO chu khong TU CHOI: `vfov` o day la mac dinh cua D410
|
||||
// (42 do), CHUA doi chieu voi CameraInfo that. Tu choi khoi dong dua tren
|
||||
// mot so chua xac minh la sai. Khi driver camera chay tren thiet bi that
|
||||
// thi thay bang vfov do duoc va co the siet thanh loi.
|
||||
{
|
||||
constexpr double kD410VfovRad = 0.733; // 42 do, mac dinh -- CHUA XAC MINH
|
||||
const double cam_h = out->robot.camera_height_above_floor();
|
||||
const double drop = out->robot.camera_pitch() + kD410VfovRad / 2.0;
|
||||
if (drop > 1e-3 && drop < 1.5 && cam_h > 0.0) {
|
||||
const double geom_min = cam_h / std::tan(drop);
|
||||
const double got = out->perception.cliff.min_dist;
|
||||
if (std::fabs(got - geom_min) > 0.15) {
|
||||
VSLAM_WARN("pipeline.yaml cliff_detect.min_dist = "
|
||||
<< got << " m, nhung hinh hoc camera cho "
|
||||
<< geom_min << " m (cao " << cam_h << " m, chuc "
|
||||
<< out->robot.camera_pitch() * 180.0 / kPi << " do, vfov 42 do). "
|
||||
<< "Dat THAP hon vung mu that thi detector nhin vao dai "
|
||||
"khong co du lieu; dat CAO hon thi bo phi tam nhin.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- slam.yaml ----------
|
||||
#ifdef VSLAM_HAVE_SLAM
|
||||
{
|
||||
ConfigNode root;
|
||||
const StatusResponse st = Open(dir, kSlamConfigFile, &root);
|
||||
if (!st.ok()) return st;
|
||||
// Ten key RTAB-Map duoc kiem trong BuildRtabmapParams (doi chieu voi bang
|
||||
// mac dinh cua chinh RTAB-Map), nen o day khong kiem lai.
|
||||
try {
|
||||
out->slam = LoadRtabmapConfig(root);
|
||||
} catch (const std::exception& e) {
|
||||
return StatusResponse::Error(StatusCode::kInvalidArgument,
|
||||
std::string("slam.yaml: ") + e.what());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// ---------- system.yaml ----------
|
||||
{
|
||||
ConfigNode root;
|
||||
const StatusResponse st = Open(dir, kSystemConfigFile, &root);
|
||||
if (!st.ok()) return st;
|
||||
{
|
||||
const StatusResponse r =
|
||||
Reject(root, "system.yaml",
|
||||
{"web", "logging", "record", "threads", "watchdog"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
|
||||
const ConfigNode w = root["web"];
|
||||
{
|
||||
const StatusResponse r =
|
||||
Reject(w, "system.yaml web",
|
||||
{"port", "bind", "auth_token", "asset_dir", "status_rate_hz",
|
||||
"scan_rate_hz", "cloud_rate_hz", "path_rate_hz",
|
||||
"cloud_max_points", "cloud_quant_m", "map_rebuild_rate_hz"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
out->web.port = static_cast<uint16_t>(w.get<int>("port", 8080));
|
||||
out->web.bind_address = w.get<std::string>("bind", out->web.bind_address);
|
||||
out->web.auth_token = w.get<std::string>("auth_token", "");
|
||||
out->web.asset_dir = w.get<std::string>("asset_dir", "");
|
||||
out->web.state_hz = w.get<double>("status_rate_hz", out->web.state_hz);
|
||||
out->web.scan_hz = w.get<double>("scan_rate_hz", out->web.scan_hz);
|
||||
out->web.cloud_hz = w.get<double>("cloud_rate_hz", out->web.cloud_hz);
|
||||
out->web.path_hz = w.get<double>("path_rate_hz", out->web.path_hz);
|
||||
out->web.cloud_max_points =
|
||||
static_cast<uint32_t>(w.get<int>("cloud_max_points", 4000));
|
||||
out->slam_runtime.map_rebuild_rate_hz =
|
||||
w.get<double>("map_rebuild_rate_hz", out->slam_runtime.map_rebuild_rate_hz);
|
||||
|
||||
if (out->web.auth_token.empty()) {
|
||||
// Khong tu choi khoi dong: mot robot trong phong lab khong can token.
|
||||
// Nhung phai TO, vi bat doi xung cua lop xac thuc (go e-stop can token)
|
||||
// tro nen vo nghia khi khong co token nao.
|
||||
VSLAM_WARN("system.yaml web.auth_token DE TRONG -- bat ky ai vao duoc "
|
||||
"mang deu GO duoc e-stop va reset duoc bumper.");
|
||||
}
|
||||
|
||||
const ConfigNode lg = root["logging"];
|
||||
{
|
||||
const StatusResponse r = Reject(lg, "system.yaml logging", {"level"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
out->log_level = lg.get<std::string>("level", "info");
|
||||
|
||||
const ConfigNode rc = root["record"];
|
||||
{
|
||||
const StatusResponse r =
|
||||
Reject(rc, "system.yaml record",
|
||||
{"enabled", "dir", "max_queue_bytes", "depth_rate_hz",
|
||||
"record_infra1", "record_infra2", "compress"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
out->record.enabled = rc.get<bool>("enabled", false);
|
||||
out->record.dir = rc.get<std::string>("dir", out->record.dir);
|
||||
out->record.max_queue_bytes =
|
||||
static_cast<size_t>(rc.get<int>("max_queue_bytes", 67108864));
|
||||
out->record.depth_rate_hz = rc.get<double>("depth_rate_hz", 10.0);
|
||||
out->record.record_infra1 = rc.get<bool>("record_infra1", false);
|
||||
out->record.record_infra2 = rc.get<bool>("record_infra2", false);
|
||||
out->record.compress = rc.get<bool>("compress", false);
|
||||
|
||||
const ConfigNode th = root["threads"];
|
||||
{
|
||||
const StatusResponse r =
|
||||
Reject(th, "system.yaml threads",
|
||||
{"safety_priority", "driver_priority", "estimator_priority",
|
||||
"use_realtime", "safety_rate_hz"});
|
||||
if (!r.ok()) return r;
|
||||
}
|
||||
out->threads.safety_priority = th.get<int>("safety_priority", 50);
|
||||
out->threads.driver_priority = th.get<int>("driver_priority", 45);
|
||||
out->threads.estimator_priority = th.get<int>("estimator_priority", 40);
|
||||
out->threads.use_realtime = th.get<bool>("use_realtime", true);
|
||||
out->threads.safety_rate_hz = th.get<double>("safety_rate_hz", 20.0);
|
||||
|
||||
// Luong safety phai co uu tien CAO NHAT. Dat nguoc lai la vo hieu hoa ca
|
||||
// ly do dung SCHED_FIFO.
|
||||
if (out->threads.use_realtime &&
|
||||
(out->threads.safety_priority <= out->threads.driver_priority ||
|
||||
out->threads.safety_priority <= out->threads.estimator_priority)) {
|
||||
return StatusResponse::Error(
|
||||
StatusCode::kInvalidArgument,
|
||||
"system.yaml threads: safety_priority phai CAO HON moi uu tien khac");
|
||||
}
|
||||
}
|
||||
|
||||
return StatusResponse::Ok();
|
||||
}
|
||||
|
||||
} // namespace vslam
|
||||
Reference in New Issue
Block a user