drivers: IMU WT61PC noi thang UART (mcu.protocol: wt61pc), bo ESP32 -- doc quyen cong, tach khung co resync, canh bao khi im
This commit is contained in:
@@ -175,7 +175,17 @@ struct CameraConfig {
|
||||
|
||||
// --- MCU: IMU + barometer --------------------------------------------------
|
||||
|
||||
// Cach IMU noi vao may.
|
||||
enum class McuProtocol {
|
||||
// ESP32-S3 + WT61PC, text qua USB-CDC (/dev/ttyACM0). Xem mcu_bridge.cc.
|
||||
kEspText,
|
||||
// WT61PC noi THANG UART hoac cap USB-FTDI (/dev/imu), khung nhi phan 0x55.
|
||||
// Khong con ESP32, khong co ClockSync. Xem wt61pc_bridge.cc.
|
||||
kWt61pc,
|
||||
};
|
||||
|
||||
struct McuConfig {
|
||||
McuProtocol protocol = McuProtocol::kEspText;
|
||||
std::string port = "/dev/ttyACM0";
|
||||
// 115200, theo firmware that (base_kit/src/imu_uart). Gia tri cu o day la
|
||||
// 921600 -- doc sai baud thi ra rac chu khong ra loi, nen no im lang.
|
||||
@@ -219,6 +229,10 @@ struct McuConfig {
|
||||
double baro_variance = 9.0;
|
||||
|
||||
double read_timeout_sec = 1.0;
|
||||
|
||||
// Chi cho kWt61pc: khong co khung hop le nao trong chung nay (giay) thi WARN
|
||||
// kem goi y. Cam bien 10 Hz nen 2 s la mat ~20 khung, khong con la jitter.
|
||||
double no_data_warn_sec = 2.0;
|
||||
};
|
||||
|
||||
// --- Base: encoder + motor -------------------------------------------------
|
||||
|
||||
81
libs/vslam_drivers/include/vslam/wt61pc_protocol.h
Normal file
81
libs/vslam_drivers/include/vslam/wt61pc_protocol.h
Normal file
@@ -0,0 +1,81 @@
|
||||
#ifndef VSLAM_WT61PC_PROTOCOL_H
|
||||
#define VSLAM_WT61PC_PROTOCOL_H
|
||||
|
||||
// Khung nhi phan cua WT61PC (IMU 6 truc, WitMotion) khi cam THANG vao UART hoac
|
||||
// cap USB-FTDI cua Jetson, khong qua ESP32.
|
||||
//
|
||||
// Khac mcu_protocol.h: day KHONG phai giao thuc cua du an. No la giao thuc cua
|
||||
// cam bien, nen file nay GHI LAI dac ta cua nha san xuat; ben phai khop la
|
||||
// cam bien, khong phai firmware.
|
||||
//
|
||||
// ================== KHUNG ==================
|
||||
// 11 byte. Cam bien phat lien tuc, moi chu ky ba khung theo thu tu:
|
||||
// 0x55 0x51 axL axH ayL ayH azL azH TL TH SUM gia toc
|
||||
// 0x55 0x52 gxL gxH gyL gyH gzL gzH TL TH SUM van toc goc
|
||||
// 0x55 0x53 rL rH pL pH yL yH TL TH SUM goc (roll, pitch, yaw)
|
||||
// Moi truong la int16 little-endian. SUM = tong 10 byte dau, lay 8 bit thap.
|
||||
//
|
||||
// ================== DOI DON VI ==================
|
||||
// gia toc : raw / 32768 * 16 g -> m/s^2 (g = 9.80665)
|
||||
// van toc : raw / 32768 * 2000 do/s -> rad/s
|
||||
// goc : raw / 32768 * 180 do -> rad
|
||||
// Cung cong thuc voi firmware/imu_uart/main/main.c, nen truc va dau KHONG doi so
|
||||
// voi ban ghi `I` cua ESP32: doi nguon IMU khong dong toi EKF hay gravity_align.
|
||||
//
|
||||
// ================== TAN SO ==================
|
||||
// Mac dinh cua cam bien la 10 Hz o 9600 baud (do duoc: chu ky 0.1001 s). Moi
|
||||
// chu ky 33 byte, nen 9600 baud tran o ~29 Hz. Muon cao hon phai doi baud CUA
|
||||
// CAM BIEN (lenh cau hinh cua WitMotion), khong phai chi baud ben host.
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace vslam {
|
||||
|
||||
constexpr size_t kWt61pcFrameBytes = 11;
|
||||
constexpr uint8_t kWt61pcHeader = 0x55;
|
||||
|
||||
enum class Wt61pcType : uint8_t {
|
||||
kAccel = 0x51, // m/s^2
|
||||
kGyro = 0x52, // rad/s
|
||||
kAngle = 0x53, // rad
|
||||
};
|
||||
|
||||
struct Wt61pcFrame {
|
||||
Wt61pcType type = Wt61pcType::kAccel;
|
||||
// Da DOI DON VI theo `type`, xem tren.
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
double z = 0.0;
|
||||
};
|
||||
|
||||
// Bo tach khung theo tung byte. Khong doc dong ho, khong goi he thong: chi la
|
||||
// ham thuan tren chuoi byte, nen test duoc ma khong can cong serial.
|
||||
class Wt61pcParser {
|
||||
public:
|
||||
// Nap mot byte. true khi byte nay hoan tat mot khung HOP LE loai
|
||||
// kAccel/kGyro/kAngle (checksum dung) va *out da duoc dien.
|
||||
bool Push(uint8_t byte, Wt61pcFrame* out);
|
||||
|
||||
void Reset();
|
||||
|
||||
uint64_t bad_checksum() const { return bad_checksum_; }
|
||||
// Byte bi bo vi khong thuoc khung nao (rac, hoac mat dong bo).
|
||||
uint64_t skipped_bytes() const { return skipped_bytes_; }
|
||||
// Khung dung checksum nhung loai khac 0x51..0x53 (vd 0x54). WT61PC khong co
|
||||
// tu ke nen binh thuong bang 0; dem de thay khi cam nham mot cam bien khac.
|
||||
uint64_t other_frames() const { return other_frames_; }
|
||||
|
||||
private:
|
||||
void Resync();
|
||||
|
||||
uint8_t buf_[kWt61pcFrameBytes] = {};
|
||||
size_t n_ = 0;
|
||||
uint64_t bad_checksum_ = 0;
|
||||
uint64_t skipped_bytes_ = 0;
|
||||
uint64_t other_frames_ = 0;
|
||||
};
|
||||
|
||||
} // namespace vslam
|
||||
|
||||
#endif // VSLAM_WT61PC_PROTOCOL_H
|
||||
Reference in New Issue
Block a user