116 lines
4.1 KiB
C++
116 lines
4.1 KiB
C++
#ifndef VSLAM_SCAN_SANITIZER_H
|
|
#define VSLAM_SCAN_SANITIZER_H
|
|
|
|
// Ve sinh LaserScan tho tu LiDAR truoc khi bat ky ai dung no.
|
|
//
|
|
// Gop hai thu cua ban ROS lam mot:
|
|
// 1. robot_drivers/ScanHeaderFixFilter -- sua ba bug cua driver LakiBeam
|
|
// 2. hai laser_filters/LaserScanAngularBoundsFilterInPlace -- cat quat bi
|
|
// than robot che
|
|
//
|
|
// GOP LAI LA CO Y. Ban ROS phai ghi mot khoi comment canh bao rang filter 1
|
|
// BAT BUOC chay truoc filter 2, vi filter 2 blank tia bang `range_max + 1.0`:
|
|
// neu chay truoc thi sentinel thanh 101.0 thay vi 41.0, va safety_monitor doc
|
|
// sai so tia bi che. Gop vao mot ham thi thu tu do khong the sai duoc nua.
|
|
//
|
|
// ================== BA BUG CUA DRIVER LAKIBEAM ==================
|
|
// Da doc source de xac nhan (xem docs/HARDWARE.md cua repo cu):
|
|
// range_min = 0.0 <- thiet bi that: 0.05
|
|
// range_max = 100.0 <- thiet bi that: 40.0
|
|
// time_increment = duration / n / 2 <- thua phep chia 2
|
|
//
|
|
// `range_min = 0.0` la cai nguy hiem nhat. Phep loc chuan cua MOI consumer la
|
|
// `if (r < range_min) continue;`. Voi range_min = 0.0 thi `0.0 < 0.0` la sai,
|
|
// nen mot tia bao 0.0 -- von nghia la "khong do duoc" -- duoc CHAP NHAN thanh
|
|
// vat can ngay goc LiDAR. Hau qua: safety_monitor thay vat can 0.0 m va dung
|
|
// vinh vien.
|
|
//
|
|
// ================== BA NGU NGHIA CUA MOT TIA ==================
|
|
// Phan biet ba thu KHAC NHAU, khong duoc gop:
|
|
//
|
|
// NaN "khong do duoc" consumer bo qua, KHONG clear free space
|
|
// inf "khong co gi trong tam" duoc phep clear free space
|
|
// range_max+1.0 "khong duoc phep nhin" bi than robot che; safety_monitor
|
|
// dem rieng (front_blanked) va khong
|
|
// tinh vao front_usable
|
|
//
|
|
// Vi sao 0.0 -> NaN chu khong phai inf: LiDAR tra 0.0 cho CA HAI truong hop
|
|
// "khong co vat trong tam" VA "be mat den nuot het xung". Map sang inf thi
|
|
// robot se clear free space XUYEN QUA ghe da den. Map sang NaN thi hong ve
|
|
// phia "coi nhu co vat", tuc an toan.
|
|
|
|
#include <cstddef>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "vslam/stats.h"
|
|
#include "vslam/vslam_common.h"
|
|
|
|
namespace vslam {
|
|
|
|
struct SectorMask {
|
|
double lower_rad = 0.0; // cat cac tia co goc trong [lower, upper]
|
|
double upper_rad = 0.0;
|
|
};
|
|
|
|
struct ScanSanitizerConfig {
|
|
// Ep header ve gia tri that cua thiet bi.
|
|
double range_min = 0.05;
|
|
double range_max = 40.0;
|
|
|
|
// true = bo phep chia 2 thua cua driver.
|
|
bool fix_time_increment = true;
|
|
|
|
// "nan" hoac "inf". Mac dinh "nan" -- xem khoi comment tren.
|
|
std::string zero_is = "nan";
|
|
|
|
// Quat bi than robot che. Voi cau hinh hien tai: laser o x=0.24, than robot
|
|
// nua rong 0.17 va mat truoc x=0.14 -> tu che ngoai +-120.5 do, cat o +-118
|
|
// de co bien an toan. Con lai ~236 do huu dung tren 270 do.
|
|
std::vector<SectorMask> sector_masks;
|
|
|
|
// Xoay toan bo scan. Dung khi huong 0 do vat ly cua LiDAR khong trung voi
|
|
// truc x cua robot. GIA TRI THAT CHUA DO DUOC -- xem tools/vslam_scan_check.
|
|
double angle_offset_rad = 0.0;
|
|
};
|
|
|
|
struct ScanSanitizerStats {
|
|
uint64_t scans = 0;
|
|
uint64_t rays_total = 0;
|
|
uint64_t rays_zero = 0; // driver tra 0.0
|
|
uint64_t rays_below_min = 0;
|
|
uint64_t rays_above_max = 0;
|
|
uint64_t rays_blanked = 0; // bi sector mask cat
|
|
uint64_t rays_valid = 0;
|
|
};
|
|
|
|
class ScanSanitizer {
|
|
public:
|
|
explicit ScanSanitizer(ScanSanitizerConfig cfg);
|
|
|
|
// Nem std::invalid_argument neu cau hinh vo ly (range_min <= 0, range_max
|
|
// <= range_min). Kiem o day chu khong im lang roi ve default: mot LiDAR
|
|
// cau hinh sai la mot robot dam vao tuong.
|
|
static void Validate(const ScanSanitizerConfig& cfg);
|
|
|
|
// Sua TAI CHO. Giu nguyen stamp, angle_*, va so luong tia.
|
|
void Apply(LaserScan* scan);
|
|
|
|
const ScanSanitizerStats& stats() const { return stats_; }
|
|
void ResetStats() { stats_ = ScanSanitizerStats{}; }
|
|
|
|
// Gia tri sentinel ma sector mask dung, theo cau hinh hien tai.
|
|
float blank_value() const { return static_cast<float>(cfg_.range_max) + 1.0f; }
|
|
|
|
private:
|
|
bool InMaskedSector(double angle) const;
|
|
|
|
ScanSanitizerConfig cfg_;
|
|
bool zero_to_inf_ = false;
|
|
ScanSanitizerStats stats_;
|
|
};
|
|
|
|
} // namespace vslam
|
|
|
|
#endif // VSLAM_SCAN_SANITIZER_H
|