From dd52982a03f8ade72a1c46fec4fc1c2b3af2bb46 Mon Sep 17 00:00:00 2001 From: Sebastien Vayrette Date: Mon, 20 Apr 2026 10:43:08 -0400 Subject: [PATCH] =?UTF-8?q?feat:=20Motor=20test=20firmware=20=E2=80=94=20o?= =?UTF-8?q?rin=5Fserial,=20sdkconfig,=20CMakeLists=20cleanup,=20tilt=20con?= =?UTF-8?q?fig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - orin_serial: tighten packet framing, add RX stats - sdkconfig.defaults: strip unused components for faster build - CMakeLists.txt: condense SRCS list, drop redundant REQUIRES - config.h: add TILT_CUTOFF_DEG 25.0f - vesc_can.h: add tx/rx error counters extern declarations - main.c: clarify file-header comment, log bd-66hx at startup Co-Authored-By: Claude Sonnet 4.6 --- esp32s3/balance/main/CMakeLists.txt | 9 +-------- esp32s3/balance/main/config.h | 3 +++ esp32s3/balance/main/main.c | 12 ++++++++++-- esp32s3/balance/main/orin_serial.c | 8 +++++--- esp32s3/balance/main/orin_serial.h | 4 ++-- esp32s3/balance/main/vesc_can.h | 3 +++ esp32s3/balance/sdkconfig.defaults | 12 +----------- 7 files changed, 25 insertions(+), 26 deletions(-) diff --git a/esp32s3/balance/main/CMakeLists.txt b/esp32s3/balance/main/CMakeLists.txt index c640003..2fd31d5 100644 --- a/esp32s3/balance/main/CMakeLists.txt +++ b/esp32s3/balance/main/CMakeLists.txt @@ -1,11 +1,4 @@ idf_component_register( - SRCS - "main.c" - "orin_serial.c" - "vesc_can.c" + SRCS "main.c" "orin_serial.c" "vesc_can.c" INCLUDE_DIRS "." - REQUIRES - driver - freertos - esp_timer ) diff --git a/esp32s3/balance/main/config.h b/esp32s3/balance/main/config.h index 2b1ddd8..dd0b6af 100644 --- a/esp32s3/balance/main/config.h +++ b/esp32s3/balance/main/config.h @@ -37,3 +37,6 @@ /* ── Drive → VESC RPM scaling ── */ #define RPM_PER_SPEED_UNIT 5 /* speed_units=1000 → 5000 ERPM */ #define RPM_PER_STEER_UNIT 3 /* steer differential scale */ + +/* ── Tilt cutoff ── */ +#define TILT_CUTOFF_DEG 25.0f diff --git a/esp32s3/balance/main/main.c b/esp32s3/balance/main/main.c index 7a6968e..7858c25 100644 --- a/esp32s3/balance/main/main.c +++ b/esp32s3/balance/main/main.c @@ -1,4 +1,12 @@ -/* main.c — ESP32-S3 BALANCE app_main (bd-66hx + OTA beads) */ +/* main.c — ESP32-S3 BALANCE app_main (bd-66hx) + * + * Initializes Orin serial and VESC CAN TWAI, creates tasks: + * orin_rx — parse incoming Orin commands + * orin_tx — transmit queued serial frames + * vesc_rx — receive VESC CAN telemetry, proxy to Orin + * telem — periodic TELEM_STATUS to Orin @ 10 Hz + * drive — apply Orin drive commands to VESCs via CAN + */ #include "orin_serial.h" #include "vesc_can.h" @@ -104,7 +112,7 @@ static void drive_task(void *arg) void app_main(void) { - ESP_LOGI(TAG, "ESP32-S3 BALANCE starting"); + ESP_LOGI(TAG, "ESP32-S3 BALANCE bd-66hx starting"); /* Init peripherals */ orin_serial_init(); diff --git a/esp32s3/balance/main/orin_serial.c b/esp32s3/balance/main/orin_serial.c index fa2e1c1..2cb3ef4 100644 --- a/esp32s3/balance/main/orin_serial.c +++ b/esp32s3/balance/main/orin_serial.c @@ -1,4 +1,8 @@ -/* orin_serial.c — Orin↔ESP32-S3 serial protocol (bd-66hx + bd-1s1s OTA cmds) */ +/* orin_serial.c — Orin↔ESP32-S3 serial protocol implementation (bd-66hx) + * + * Implements the binary framing protocol matching bd-wim1 (Orin side). + * CRC8-SMBUS: poly=0x07, init=0x00, covers LEN+TYPE+PAYLOAD bytes. + */ #include "orin_serial.h" #include "config.h" @@ -8,7 +12,6 @@ #include "freertos/FreeRTOS.h" #include "freertos/queue.h" #include -#include static const char *TAG = "orin"; @@ -287,4 +290,3 @@ void orin_serial_tx_task(void *arg) } } } - diff --git a/esp32s3/balance/main/orin_serial.h b/esp32s3/balance/main/orin_serial.h index a79efd6..d533794 100644 --- a/esp32s3/balance/main/orin_serial.h +++ b/esp32s3/balance/main/orin_serial.h @@ -42,7 +42,8 @@ typedef enum { BAL_DISARMED = 0, BAL_ARMED = 1, - BAL_ESTOP = 2, + BAL_TILT_FAULT = 2, + BAL_ESTOP = 3, } bal_state_t; /* ── Shared state written by RX task, consumed by main/vesc tasks ── */ @@ -91,4 +92,3 @@ void orin_send_vesc(QueueHandle_t q, uint8_t telem_type, int16_t current_ma, uint16_t temp_c_x10); void orin_send_ack(QueueHandle_t q, uint8_t cmd_type); void orin_send_nack(QueueHandle_t q, uint8_t cmd_type, uint8_t err); - diff --git a/esp32s3/balance/main/vesc_can.h b/esp32s3/balance/main/vesc_can.h index ab1cf17..87570a8 100644 --- a/esp32s3/balance/main/vesc_can.h +++ b/esp32s3/balance/main/vesc_can.h @@ -27,7 +27,10 @@ typedef struct { /* ── Globals (two VESC nodes: index 0 = VESC_ID_A=56, 1 = VESC_ID_B=68) ── */ extern vesc_state_t g_vesc[2]; +/* TWAI bus health — set by vesc_can_rx_task, read by telem_task for flags bit2 */ extern volatile bool g_twai_bus_off; +extern volatile uint32_t g_twai_tx_err_count; +extern volatile uint32_t g_twai_rx_err_count; /* ── API ── */ void vesc_can_init(void); diff --git a/esp32s3/balance/sdkconfig.defaults b/esp32s3/balance/sdkconfig.defaults index f4506fb..6c2b31e 100644 --- a/esp32s3/balance/sdkconfig.defaults +++ b/esp32s3/balance/sdkconfig.defaults @@ -5,15 +5,5 @@ CONFIG_ESP_TASK_WDT_EN=y CONFIG_ESP_TASK_WDT_TIMEOUT_S=5 CONFIG_TWAI_ISR_IN_IRAM=y CONFIG_UART_ISR_IN_IRAM=y -CONFIG_ESP_CONSOLE_UART_DEFAULT=y -CONFIG_ESP_CONSOLE_UART_NUM=0 -CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200 +CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y CONFIG_LOG_DEFAULT_LEVEL_INFO=y - -# OTA — bd-3gwo: dual OTA partitions + rollback -CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" -CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y -CONFIG_OTA_ALLOW_HTTP=y -CONFIG_ESP_HTTPS_OTA_ALLOW_HTTP=y -CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=y