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:
@@ -10,7 +10,10 @@
|
||||
// ho host. O day khong co MCU, nen stamp lay tu dong ho HOST luc nhan xong
|
||||
// khung gyro. De jitter khong chui thang vao stamp: cap USB-FTDI gom byte
|
||||
// theo latency_timer (mac dinh 16 ms), nen mot lan read() co the mang nhieu
|
||||
// khung. Thoi diem cua mot khung duoc suy NGUOC tu luc read() tra ve, tru
|
||||
// khung. Driver bat ASYNC_LOW_LATENCY (ftdi_sio -> 1 ms) va luat udev
|
||||
// configuration_files/udev/99-imu.rules dat san 1 ms: o 200 Hz (5 ms/mau)
|
||||
// 16 ms la ~3 mau mot lan doc. Log luc mo cong bao gia tri that.
|
||||
// Thoi diem cua mot khung duoc suy NGUOC tu luc read() tra ve, tru
|
||||
// di thoi gian truyen cua cac byte toi sau no trong cung lan doc.
|
||||
// Phan tre con lai (loc noi bo cua cam bien + thoi gian truyen khung) la
|
||||
// HANG SO, tru bang `mcu.imu_lag_sec`. Con so 0.07 do duoc tren duong ESP32;
|
||||
@@ -39,13 +42,17 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/serial.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <climits>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
@@ -74,6 +81,28 @@ speed_t BaudConstant(uint32_t baud) {
|
||||
}
|
||||
}
|
||||
|
||||
// Cap FTDI gom byte latency_timer ms roi moi day len host (mac dinh 16 ms; o
|
||||
// 200 Hz la ~3 mau mot lan). ASYNC_LOW_LATENCY -> ftdi_sio dat 1 ms. Cong khong
|
||||
// phai FTDI (pty khi test) thi ioctl loi -> bo qua.
|
||||
void SetLowLatency(int fd) {
|
||||
serial_struct ss{};
|
||||
if (::ioctl(fd, TIOCGSERIAL, &ss) != 0) return;
|
||||
ss.flags |= ASYNC_LOW_LATENCY;
|
||||
::ioctl(fd, TIOCSSERIAL, &ss);
|
||||
}
|
||||
|
||||
// latency_timer (ms) cua cap FTDI sau `port` (/dev/imu -> ttyUSB0); -1 = khong
|
||||
// doc duoc (khong phai FTDI, hoac khong co sysfs).
|
||||
int FtdiLatencyMs(const std::string& port) {
|
||||
char real[PATH_MAX];
|
||||
if (::realpath(port.c_str(), real) == nullptr) return -1;
|
||||
const char* name = std::strrchr(real, '/');
|
||||
std::ifstream f(std::string("/sys/class/tty/") + (name != nullptr ? name + 1 : real) +
|
||||
"/device/latency_timer");
|
||||
int ms = -1;
|
||||
return (f >> ms) ? ms : -1;
|
||||
}
|
||||
|
||||
class Wt61pcBridge : public McuInterface {
|
||||
public:
|
||||
Wt61pcBridge(const McuConfig& cfg, ClockPtr clock)
|
||||
@@ -112,6 +141,13 @@ class Wt61pcBridge : public McuInterface {
|
||||
<< ", doc quyen cong. Stamp lay tu dong ho HOST luc nhan xong "
|
||||
"khung gyro, tru imu_lag_sec = " << cfg_.imu_lag_sec * 1000.0
|
||||
<< " ms -- do lai bang log `wheel_odom/lag` sau khi doi nguon IMU.");
|
||||
const int lat = FtdiLatencyMs(cfg_.port);
|
||||
if (lat > 2) {
|
||||
VSLAM_WARN("imu: latency_timer cap FTDI = " << lat << " ms -- moi lan doc gom nhieu "
|
||||
"mau, stamp IMU giat. Cai configuration_files/udev/99-imu.rules (1 ms).");
|
||||
} else if (lat >= 0) {
|
||||
VSLAM_INFO("imu: latency_timer cap FTDI = " << lat << " ms");
|
||||
}
|
||||
if (cfg_.baud <= 9600) {
|
||||
VSLAM_INFO("imu: 9600 baud chi du ~29 Hz (cam bien mac dinh 10 Hz). "
|
||||
"wheel_odom bo gyro khi IMU cham hon encoder -- xem muc mcu "
|
||||
@@ -195,6 +231,7 @@ class Wt61pcBridge : public McuInterface {
|
||||
<< std::strerror(errno) << ") -- chuong trinh khac mo cong "
|
||||
"sau se chia nhau luong byte.");
|
||||
}
|
||||
SetLowLatency(fd);
|
||||
::tcflush(fd, TCIOFLUSH); // bo byte cu, tranh bat dau giua mot khung
|
||||
fd_ = fd;
|
||||
return StatusResponse::Ok();
|
||||
|
||||
Reference in New Issue
Block a user