Files
vslam_cpp/libs/vslam_drivers/include/vslam/driver_config.h
trung09122002 48bd5377dc upload
2026-09-18 18:14:42 +07:00

139 lines
4.5 KiB
C++

#ifndef VSLAM_DRIVER_CONFIG_H
#define VSLAM_DRIVER_CONFIG_H
#include <cstdint>
#include <string>
#include "vslam/scan_sanitizer.h"
namespace vslam {
// --- LiDAR LakiBeam 1L -----------------------------------------------------
enum class LidarStampMode {
// stamp = luc nhan goi DAU cua sweep. Dung quy uoc LaserScan (stamp = tia
// dau tien) va la mac dinh.
kFirstPacket,
// stamp = luc nhan goi CUOI tru scan_time. Dung khi muon bam theo thoi diem
// ket thuc sweep.
kLastPacketMinusScanTime,
};
struct LidarConfig {
std::string host_ip = "0.0.0.0"; // dia chi de bind, KHONG phai IP cua LiDAR
uint16_t port = 2368; // UDP, theo datasheet
std::string frame_id = "laser_link";
// Cau hinh thiet bi. 25 Hz / 0.25 do -> 1081 tia tren 270 do.
double scan_freq_hz = 25.0;
uint32_t samples = 1081;
double fov_rad = 4.712389; // 270 do
LidarStampMode stamp_mode = LidarStampMode::kFirstPacket;
// Bu do tre da do duoc, cong vao stamp. Chua do -> 0.
double stamp_offset_sec = 0.0;
// Canh bao neu do dai sweep lech qua nhieu so voi scan_time du kien. Day la
// bo phat hien mat goi UDP mien phi ma driver goc khong co.
double sweep_duration_tolerance_sec = 0.005;
double recv_timeout_sec = 1.0;
ScanSanitizerConfig sanitizer;
};
// --- Camera RealSense D410 -------------------------------------------------
struct CameraConfig {
std::string serial; // rong = lay thiet bi dau tien
uint32_t depth_width = 640;
uint32_t depth_height = 480;
uint32_t fps = 30;
bool enable_infra1 = true;
bool enable_infra2 = true;
// D410 khong co RGB (chi co Stereo Module) va khong co IMU tich hop.
// Emitter co dinh o 1 (Laser), KHONG bao gio 2 (Laser Auto): che do auto
// lam depth nhap nhay giua cac khung.
int emitter_mode = 1;
// Giam mau ngay tai driver, tuong duong image_proc/crop_decimate.
// 2 -> 320x240. Cap nhat binning_x/y trong CameraInfo chu KHONG chia lai K;
// consumer tu bu, dung nhu image_geometry lam.
uint32_t decimate = 2;
// Bat RS2_OPTION_GLOBAL_TIME_ENABLED de get_timestamp() tra ve dong ho host.
// Neu D410 FW 5.17.0.10 khong ho tro thi fallback sang TIME_OF_ARRIVAL --
// kem chinh xac hon, va driver se log WARN mot lan.
bool use_global_time = true;
std::string depth_frame_id = "camera_depth_optical_frame";
};
// --- MCU: IMU + barometer --------------------------------------------------
struct McuConfig {
std::string port = "/dev/ttyACM0";
uint32_t baud = 921600;
std::string imu_frame_id = "imu_link";
double ping_period_sec = 1.0; // chu ky ping de dong bo dong ho
// Datasheet ICM-42688-P / BMP390. TAT CA deu la doan tu datasheet cho toi
// khi chay allan_variance -- xem docs cua repo cu.
double gyro_variance = 2.4e-7;
double accel_variance = 4.8e-5;
double baro_variance = 9.0;
double read_timeout_sec = 1.0;
};
// --- Base: encoder + motor -------------------------------------------------
// Giao thuc host <-> base. Phan cung CO encoder (xac nhan tu nguoi dung va
// docs/HARDWARE.md muc 4), nhung giao thuc host doc chung thi CHUA XAC DINH
// o bat ky dau trong repo cu -- ban ROS gia dinh "firmware MCU publish
// /joint_states" ma firmware do chua ton tai.
//
// Vi vay transport duoc tach hoan toan khoi phep toan odometry: khi biet giao
// thuc that thi chi them mot lop mong, khong dung toi WheelOdometry.
enum class BaseProtocol {
// Mo rong giao thuc text san co cua MCU bang mot ban ghi:
// E,<micros>,<ticks_l>,<ticks_r>
// Tai dung ClockSync da co, va do la phan kho nhat -- nen day la lua chon
// re nhat neu firmware sua duoc.
kMcuTextEncoder,
// Serial rieng voi giao thuc nhi phan cua nha san xuat base.
kVendorSerial,
// Khong co base that: doc tu ban ghi .vsr.
kReplay,
};
struct BaseConfig {
BaseProtocol protocol = BaseProtocol::kMcuTextEncoder;
// Dung khi protocol = kVendorSerial.
std::string port = "/dev/ttyUSB0";
uint32_t baud = 115200;
// Hinh hoc. PHAI khop robot.yaml -- day la gia tri duy nhat, khong con ban
// sao trong URDF nua.
double wheel_radius = 0.075;
double wheel_separation = 0.36;
uint32_t ticks_per_rev = 0; // 0 = chua biet, PHAI dat truoc khi chay that
// Gioi han gui xuong motor. Lop safety da kep roi; day la chan cuoi.
double max_linear = 0.35;
double max_angular = 0.8;
// Khong nhan duoc lenh trong bao lau thi tu dung. Phai NGAN hon deadman cua
// teleop, de base dung truoc khi lop tren kip phan ung.
double cmd_timeout_sec = 0.3;
double rate_hz = 50.0;
};
} // namespace vslam
#endif // VSLAM_DRIVER_CONFIG_H