drivers,tools: IMU WT61PC 115200 baud / 200 Hz -- mcu.baud 115200, imu_lag_sec 0.01 (uoc luong, can do lai bang wheel_odom/lag), FTDI low-latency 1 ms + log latency_timer, luat udev configuration_files/udev/99-imu.rules; tool vslam_imu_config (do / doi baud + tan so WT61PC bang lenh WitMotion); vslam_vo_bench --pitch-source sensor

This commit is contained in:
trung09122002
2026-10-06 10:17:07 +07:00
parent 6d552e231e
commit b1ab04c51e
7 changed files with 435 additions and 13 deletions

View File

@@ -6,7 +6,8 @@
// [--reset-after N] [--ref-out REF.txt] [--imu-orient]
// [--imu-hz N] [--accel-bias x,y,z] [--gyro-bias x,y,z]
// [--enc-scale K] [--ir-noise SIGMA] [--seed N] [--no-vo]
// [--ga-alpha A]
// [--ga-alpha A] [--pitch-source ga|sensor] [--sensor-hz N]
// [--sensor-bias-deg B] [--sensor-noise-deg S] [--sensor-lag-ms L]
//
// Ra: TRAJ.txt = "giay x y z qx qy qz qw" cua base_footprint trong frame
// odom (goc = tu the robot o khung dau), chi khung odometry TINH DUOC.
@@ -30,6 +31,13 @@
// sai ban kinh) -- ca doan F2M lan tham chieu
// --ir-noise SIGMA nhieu Gauss tren anh IR truoc khi vao VO
// --no-vo chi tinh tham chieu (nhanh)
// --pitch-source sensor pitch cua hang tham chieu lay tu goc DA LOC cua
// chinh cam bien (khung Angle 0x53 cua WT61PC) thay vi
// tu loc gyro/accel tho. Gia lap: pitch THAT (stream
// ground truth) lay mau --sensor-hz, cong bias + nhieu,
// tre --sensor-lag-ms, giu gia tri giua hai mau. LAC
// QUAN: bo loc trong cam bien that co sai rieng (vd khi
// xe tang toc) -- phai do lai tren robot.
// --ga-alpha A alpha bo loc bu cua GravityAlign (mac dinh 0.98 cua
// pipeline.yaml, tinh MOI MAU: 10 Hz -> tau 5 s,
// 200 Hz -> tau 0.25 s)
@@ -52,6 +60,8 @@
// vslam_node se lam khi VO hong. Moi lan reset la mot lan dem.
#include <algorithm>
#include <array>
#include <deque>
#include <chrono>
#include <random>
#include <cmath>
@@ -111,6 +121,8 @@ int main(int argc, char** argv) {
int reset_after = 5;
bool imu_orient = false, no_vo = false;
double imu_hz = 0.0, enc_scale = 1.0, ir_noise = 0.0, ga_alpha = -1.0;
std::string pitch_source = "ga";
double sensor_hz = 10.0, sensor_bias_deg = 0.0, sensor_noise_deg = 0.0, sensor_lag_ms = 0.0;
double accel_bias[3] = {0, 0, 0}, gyro_bias[3] = {0, 0, 0};
uint32_t seed = 1;
rtabmap::ParametersMap params;
@@ -136,6 +148,11 @@ int main(int argc, char** argv) {
else if (a == "--imu-hz") imu_hz = std::atof(next().c_str());
else if (a == "--enc-scale") enc_scale = std::atof(next().c_str());
else if (a == "--ga-alpha") ga_alpha = std::atof(next().c_str());
else if (a == "--pitch-source") pitch_source = next();
else if (a == "--sensor-hz") sensor_hz = std::atof(next().c_str());
else if (a == "--sensor-bias-deg") sensor_bias_deg = std::atof(next().c_str());
else if (a == "--sensor-noise-deg") sensor_noise_deg = std::atof(next().c_str());
else if (a == "--sensor-lag-ms") sensor_lag_ms = std::atof(next().c_str());
else if (a == "--ir-noise") ir_noise = std::atof(next().c_str());
else if (a == "--seed") seed = static_cast<uint32_t>(std::atoi(next().c_str()));
else if (a == "--accel-bias" || a == "--gyro-bias") {
@@ -220,6 +237,14 @@ int main(int argc, char** argv) {
vslam::GravityAlign ga(gcfg);
double rx = 0, ry = 0, rz = 0; // tham chieu: xy ngang + z tich luy
int64_t enc_t = -1, imu_kept_t = -1;
// --pitch-source sensor: goc cam bien gia lap tu ground truth (xem dau file).
const bool use_sensor = pitch_source == "sensor";
double s_roll = 0.0, s_pitch = 0.0;
int64_t s_next = -1;
std::deque<std::array<double, 3>> s_pending; // {t_den_ns, roll, pitch}
std::normal_distribution<double> n_ang(0.0, 1.0);
auto ref_pitch = [&]() { return use_sensor ? s_pitch : ga.pitch(); };
auto ref_roll = [&]() { return use_sensor ? s_roll : ga.roll(); };
std::mt19937 rng(seed);
std::normal_distribution<double> n01(0.0, 1.0);
@@ -255,7 +280,7 @@ int main(int argc, char** argv) {
wx += ds * std::cos(wyaw + 0.5 * dth);
wy += ds * std::sin(wyaw + 0.5 * dth);
// Tham chieu: pitch duong = mui chuc xuong, nen len doc pitch am.
const double p = ga.pitch();
const double p = ref_pitch();
rx += ds * std::cos(p) * std::cos(wyaw + 0.5 * dth);
ry += ds * std::cos(p) * std::sin(wyaw + 0.5 * dth);
rz += -ds * std::sin(p);
@@ -269,6 +294,23 @@ int main(int argc, char** argv) {
enc_init = true;
continue;
}
if (use_sensor && h.stream == vslam::VsrStream::kGroundTruth) {
double g[6];
if (!vslam::DecodeGroundTruthPayload(payload, g)) continue;
const double d2r = M_PI / 180.0;
if (s_next < 0 || t >= s_next) {
s_pending.push_back({static_cast<double>(t) + sensor_lag_ms * 1e6,
g[3] + sensor_noise_deg * d2r * n_ang(rng),
g[4] + sensor_bias_deg * d2r + sensor_noise_deg * d2r * n_ang(rng)});
s_next = t + static_cast<int64_t>(1e9 / sensor_hz);
}
while (!s_pending.empty() && s_pending.front()[0] <= static_cast<double>(t)) {
s_roll = s_pending.front()[1];
s_pitch = s_pending.front()[2];
s_pending.pop_front();
}
continue;
}
if (h.stream == vslam::VsrStream::kImu) {
vslam::Imu m;
if (!vslam::DecodeImuPayload(payload, &m)) continue;
@@ -309,8 +351,8 @@ int main(int argc, char** argv) {
depth.t = ir.t = -1;
if (fr != nullptr) {
const rtabmap::Transform ref(static_cast<float>(rx), static_cast<float>(ry),
static_cast<float>(rz), static_cast<float>(ga.roll()),
static_cast<float>(ga.pitch()), static_cast<float>(wyaw));
static_cast<float>(rz), static_cast<float>(ref_roll()),
static_cast<float>(ref_pitch()), static_cast<float>(wyaw));
WriteTum(fr, t * 1e-9, ref);
}
continue;
@@ -347,8 +389,8 @@ int main(int argc, char** argv) {
depth.t = ir.t = -1;
if (fr != nullptr) {
const rtabmap::Transform ref(static_cast<float>(rx), static_cast<float>(ry),
static_cast<float>(rz), static_cast<float>(ga.roll()),
static_cast<float>(ga.pitch()), static_cast<float>(wyaw));
static_cast<float>(rz), static_cast<float>(ref_roll()),
static_cast<float>(ref_pitch()), static_cast<float>(wyaw));
WriteTum(fr, t * 1e-9, ref);
}
if (pose.isNull()) {