Files

Firmware IMU: WT61PC -> ESP32-S3 -> host

Cau noi mot chieu. WT61PC noi voi ESP32 qua UART1 9600 baud; ESP32 phat ra console (UART0 + USB Serial/JTAG), host thay la /dev/ttyACM0.

Vi sao firmware nam trong repo nay

libs/vslam_drivers/include/vslam/mcu_protocol.h tu nhan:

PHAT HANH co y: file nay la DAC TA ma firmware phai khop.

Dac ta o mot repo, ban thuc thi o mot thu muc khong ai theo doi, thi hai cai troi khoi nhau ma khong ai phat hien. Da xay ra that: base_kit bi liet trong .gitignore, va ban tren may dev co src/hardware/IMU_uart/ trong khi ban tren Jetson KHONG co -- hai may da khac nhau tu luc nao khong ro.

De canh nhau thi test/test_mcu_protocol.cc la bai kiem cho ca hai phia.

Sua gi so voi ban base_kit

Goc: base_kit/src/hardware/IMU_uart/main/main.c.

truoc sau
dinh dang xuat 3 dong text Acc/Gyro/Angle mot dong I,<micros>,...
dau thoi gian khong co esp_timer_get_time() tai khung gyro
don vi gyro do/s rad/s (theo dac ta)
tan so ~10 Hz (chua bao gio dat) 20 Hz (0xff 0xaa 0x03 0x07 0x00)
khung Angle doi va in doc roi bo
hang so g 9.8 9.80665

Dat EMIT_LEGACY_TEXT 1 trong main.c de quay ve dinh dang cu.

Vi sao 20 Hz chu khong cao hon

Cam bien van gui DU ca ba khung (Acc + Gyro + Angle = 33 byte) du firmware chi dung hai khung dau. O 9600 baud 8N1 = 960 byte/s, tran la 960/33 = 29 Hz. 20 Hz = 660 byte/s = 69% bus, con bien. 25 Hz la 86% -- sat qua.

Muon cao hon thi phai nang baud cua cam bien (thanh ghi 0x04), nhung thu vien DFRobot khong expose thanh ghi do nen ma phai doan. Doan sai thi cam bien chuyen sang baud khac va cam hoan toan. Chua lam.

Do tre con lai

Cam bien lay mau roi moi day byte. Den luc khung gyro (khung thu hai) nhan xong thi mau da gia ~23 ms:

2 khung x 11 byte x 10 bit / 9600 baud = 22.9 ms

Firmware KHONG tru san con so nay -- tru san la gia dinh cam bien phat ngay sau khi lay mau, dieu chua kiem duoc. No la HANG SO va host DO DUOC: chay --live, lai robot vao ra cua, doc dong wheel_odom/lag, dat ket qua vao mcu.imu_lag_sec trong configuration_files/sensors.yaml. Chay lai thi dong do phai bao ~0 ms -- do la phep tu kiem chung.

Build va flash

Can ESP-IDF v5.x. Chua co thi:

sudo apt install -y git wget flex bison gperf python3-venv cmake ninja-build \
    ccache libffi-dev libssl-dev dfu-util libusb-1.0-0
mkdir -p ~/esp && cd ~/esp
git clone -b v5.1.2 --recursive https://github.com/espressif/esp-idf.git
cd esp-idf && ./install.sh esp32s3

Roi:

. ~/esp/esp-idf/export.sh
cd firmware/imu_uart
idf.py set-target esp32s3
idf.py build
idf.py -p /dev/ttyACM0 flash

⚠️ Tat vslam_node truoc khi flash. ESP32-S3 dung chung /dev/ttyACM0 cho ca du lieu lan nap; esptool khong mo duoc cong neu node dang giu.

Sao luu va khoi phuc

Truoc khi flash lan dau:

pip3 install --user esptool
~/.local/bin/esptool.py -p /dev/ttyACM0 read_flash 0x0 0x400000 ~/imu_firmware_backup.bin

Quay ve ban cu:

~/.local/bin/esptool.py -p /dev/ttyACM0 write_flash 0x0 ~/imu_firmware_backup.bin

Kiem tra sau khi flash

sudo fuser -k /dev/ttyACM0
timeout 5 cat /dev/ttyACM0 > /tmp/imu.txt
grep -c '^I,' /tmp/imu.txt     # chia 5 => Hz, mong doi ~20
head -3 /tmp/imu.txt

Mong doi:

I,12345678,0.00105,-0.00210,0.00000,0.069,-0.127,9.807

Roi bat nhanh co dau thoi gian o host: dat mcu.expect_timestamps: true trong configuration_files/sensors.yaml.