From ab212c3659d32ffee67f90d0ec5c04a8313b63e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pe=C5=82ka?= Date: Fri, 20 Nov 2026 14:36:22 +0100 Subject: [PATCH 1/2] Raw data viewer: average a fast IMU before VQF rest detection VQF drops rest on any single sample deviating more than restThGyr from its low-pass value. At 1451 Hz the Murata IMU's per-sample gyro noise (median 1.2 deg/s, p99 2.5 deg/s while still) crosses the 2 deg/s threshold often enough that 1.5 s of rest is never reached, so no motionless segments were shown. Feed VQF a moving average over SAMPLE_PERIOD; a 200 Hz Livox IMU gets a window of one sample and unchanged input. Co-Authored-By: Claude Opus 5.5 --- .../mandeye_raw_data_viewer.cpp | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/apps/mandeye_raw_data_viewer/mandeye_raw_data_viewer.cpp b/apps/mandeye_raw_data_viewer/mandeye_raw_data_viewer.cpp index 46161202..776c00ad 100644 --- a/apps/mandeye_raw_data_viewer/mandeye_raw_data_viewer.cpp +++ b/apps/mandeye_raw_data_viewer/mandeye_raw_data_viewer.cpp @@ -1161,15 +1161,33 @@ void loadFiles(std::vector input_file_names) bool resting = false; double rest_start = 0.0, previous_t = 0.0; + // VQF resets rest detection on any single sample deviating more than restThGyr / restThAcc, so + // the per-sample noise of an IMU much faster than SAMPLE_PERIOD (e.g. a 1451 Hz Murata) never lets + // it detect rest. Feed VQF a moving average over SAMPLE_PERIOD; at 200 Hz that is a single sample. + const size_t vqf_window = std::max(1, static_cast(std::lround(SAMPLE_PERIOD / avg_dt))); + if (vqf_window > 1) + spdlog::info("VQF input averaged over {} samples", vqf_window); + int counter = 1; - for (const auto& [timestamp_pair, gyr, acc] : imu_data) + for (size_t i = 0; i < imu_data.size(); i++) { + const auto& [timestamp_pair, gyr, acc] = imu_data[i]; + + const size_t window_begin = i + 1 >= vqf_window ? i + 1 - vqf_window : 0; + Eigen::Vector3d gyr_avg = Eigen::Vector3d::Zero(); + Eigen::Vector3d acc_avg = Eigen::Vector3d::Zero(); + for (size_t k = window_begin; k <= i; k++) + { + gyr_avg += std::get<1>(imu_data[k]).cast(); + acc_avg += std::get<2>(imu_data[k]).cast(); + } + gyr_avg /= static_cast(i + 1 - window_begin); + acc_avg /= static_cast(i + 1 - window_begin); + const double g = 9.81; - vqf_real_t gyr_vqf[3] = { static_cast(gyr.x()), static_cast(gyr.y()), static_cast(gyr.z()) }; - vqf_real_t acc_vqf[3] = { static_cast(acc.x()) * g, - static_cast(acc.y()) * g, - static_cast(acc.z()) * g }; + vqf_real_t gyr_vqf[3] = { gyr_avg.x(), gyr_avg.y(), gyr_avg.z() }; + vqf_real_t acc_vqf[3] = { acc_avg.x() * g, acc_avg.y() * g, acc_avg.z() * g }; vqf.update(gyr_vqf, acc_vqf); From 1f4e088ef15fa1574f82692f5bdc0c031b75909d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pe=C5=82ka?= Date: Fri, 20 Nov 2026 14:36:22 +0100 Subject: [PATCH 2/2] Raw data viewer: save motionless segments as separate LAZ files A menu entry writes the points of each motionless segment to motionless_NNN.laz in a chosen folder, in the LiDAR frame with their recorded timestamps. Co-Authored-By: Claude Opus 5.5 --- .../mandeye_raw_data_viewer.cpp | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/apps/mandeye_raw_data_viewer/mandeye_raw_data_viewer.cpp b/apps/mandeye_raw_data_viewer/mandeye_raw_data_viewer.cpp index 776c00ad..fef970bc 100644 --- a/apps/mandeye_raw_data_viewer/mandeye_raw_data_viewer.cpp +++ b/apps/mandeye_raw_data_viewer/mandeye_raw_data_viewer.cpp @@ -1808,6 +1808,57 @@ static void playbackBar() ImGui::End(); } +//! Writes the points of every motionless segment to `folder`/motionless_NNN.laz, in the LiDAR frame and +//! with their recorded timestamps. +static void saveMotionlessSegments(const fs::path& folder) +{ + std::vector> points(motionless_segments.size()); + std::vector> intensities(motionless_segments.size()); + std::vector> timestamps(motionless_segments.size()); + + // The segments are sorted and disjoint, so a point can only fall into the last one starting before it. + for (const auto& file_points : g_points_per_file) + { + for (const auto& p : file_points) + { + const auto next = std::upper_bound( + motionless_segments.begin(), + motionless_segments.end(), + p.timestamp, + [](double t, const std::pair& segment) + { + return t < segment.first; + }); + if (next == motionless_segments.begin()) + continue; + const size_t s = static_cast(std::distance(motionless_segments.begin(), next)) - 1; + if (p.timestamp > motionless_segments[s].second) + continue; + points[s].push_back(p.point); + intensities[s].push_back(static_cast(p.intensity)); + timestamps[s].push_back(p.timestamp); + } + } + + for (size_t s = 0; s < motionless_segments.size(); s++) + { + const auto [from, to] = motionless_segments[s]; + std::ostringstream name; + name << "motionless_" << std::setw(3) << std::setfill('0') << s << ".laz"; + const fs::path file = folder / name.str(); + if (points[s].empty()) + { + spdlog::warn("motionless segment {} has no points, '{}' not written", s, file.string()); + continue; + } + const double origin = chunkStartSec(0); + if (exportLaz(file.string(), points[s], intensities[s], timestamps[s])) + spdlog::info("saved '{}': {:.3f} .. {:.3f} s, {} points", file.string(), from - origin, to - origin, points[s].size()); + else + spdlog::error("problem with saving file: '{}'", file.string()); + } +} + void display() { ImGuiIO& io = ImGui::GetIO(); @@ -2075,6 +2126,16 @@ void display() if (ImGui::IsItemHovered()) ImGui::SetTooltip("Drop the points of the first LAZ file on the next load, as step 1 does"); + ImGui::Separator(); + if (ImGui::MenuItem("Save motionless segments as LAZ", nullptr, false, is_init && !motionless_segments.empty())) + { + const std::string folder = mandeye::fd::SelectFolder("Select folder for motionless segments"); + if (!folder.empty()) + saveMotionlessSegments(folder); + } + if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) + ImGui::SetTooltip("Write the points of each green 'motionless' band to its own motionless_NNN.laz in a chosen folder"); + ImGui::EndPopup(); }