Do tre 80 ms cua IMU da truy ra goc trong firmware ESP32 cua base_kit: - WT61PC noi ESP32 o 9600 baud. 33 byte moi mau = 34 ms tren day, va tran tan so la 960/33 = 29 Hz. - main.c khong he goi modifyFrequency() nen cam bien chay o toc do luu san. Do duoc: 10 Hz (50 dong Gyro / 5 s). Tuoi mau trung binh 50 ms. - 34 + 50 = 84 ms, khop voi 80 ms may do bao. Phia host cua base_kit (imu_ros_node.cpp) dong dau bang dong ho ROS luc doc duoc dong -- y het mcu_bridge cu, khong sua duoc gi. Nhung firmware thi sua duoc. firmware/imu_uart/ (moi, nhung tu base_kit): - dong dau esp_timer_get_time() ngay khi khung gyro qua checksum - phat `I,<micros>,...` theo mcu_protocol.h, rad/s va m/s^2 - 10 -> 20 Hz. Khong len nua: cam bien van gui ca 3 khung nen 9600 baud chi cho toi 29 Hz, va khong nang baud cam bien vi thanh ghi 0x04 khong co trong thu vien DFRobot -- doan sai la cam bien cam han. - bo khung Angle: khong ai doc imu.orientation trong libs/ va app/ Firmware vao repo nay chu khong o base_kit vi mcu_protocol.h tu nhan la DAC TA ma firmware phai khop. Da thay cai gia cua viec de roi: base_kit nam trong .gitignore, va ban tren may dev co src/hardware/IMU_uart con ban tren Jetson thi khong -- hai may lech nhau tu luc nao khong ro. mcu_bridge: nhanh expect_timestamps dung ParseMcuLine + McuTimeUnwrapper + ClockSync. Chua co ping/pong nen t_send = t_recv: offset lech dung do tre mot chieu cua USB (co ms), con skew va viec khu jitter van dung vi chung den tu fit tuyen tinh. Phan hang so con lai gop vao imu_lag_sec. Nhanh text cu giu nguyen, mac dinh van la no. Them test cho mối noi firmware <-> dac ta, trong do co bay doi don vi hai lan: ban ghi I la rad/s san, nhanh text cu moi phai nhan deg2rad.
102 lines
3.4 KiB
Markdown
102 lines
3.4 KiB
Markdown
# 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`.
|