Archive STM32 firmware to legacy/stm32/: - src/, include/, lib/USB_CDC/, platformio.ini, test stubs, flash_firmware.py - test/test_battery_adc.c, test_hw_button.c, test_pid_schedule.c, test_vesc_can.c, test_can_watchdog.c - USB_CDC_BUG.md Rename: stm32_protocol → esp32_protocol, mamba_protocol → balance_protocol, stm32_cmd_node → esp32_cmd_node, stm32_cmd_params → esp32_cmd_params, stm32_cmd.launch.py → esp32_cmd.launch.py, test_stm32_protocol → test_esp32_protocol, test_stm32_cmd_node → test_esp32_cmd_node Content cleanup across all files: - Mamba F722S → ESP32-S3 BALANCE - BlackPill → ESP32-S3 IO - STM32F722/F7xx → ESP32-S3 - stm32Mode/Version/Port → esp32Mode/Version/Port - STM32 State/Mode labels → ESP32 State/Mode - Jetson Nano → Jetson Orin Nano Super - /dev/stm32 → /dev/esp32 - stm32_bridge → esp32_bridge - STM32 HAL → ESP-IDF docs/SALTYLAB.md: - Update "Drone FC Details" to describe ESP32-S3 BALANCE board (Waveshare ESP32-S3 Touch LCD 1.28) - Replace verbose "Self-Balancing Control" STM32 section with brief note pointing to SAUL-TEE-SYSTEM-REFERENCE.md TEAM.md: Update Embedded Firmware Engineer role to ESP32-S3 / ESP-IDF No new functionality — cleanup only. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
77 lines
2.8 KiB
C
77 lines
2.8 KiB
C
#ifndef JETSON_CMD_H
|
|
#define JETSON_CMD_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
/*
|
|
* Jetson→STM32 command protocol over USB CDC (bidirectional, same /dev/ttyACM0)
|
|
*
|
|
* Commands (newline-terminated ASCII, sent by Jetson):
|
|
* H\n — heartbeat (every 200ms). Must arrive within 500ms or
|
|
* jetson_cmd_is_active() returns false → steer reverts to 0.
|
|
* C<spd>,<str>\n — drive command: speed -1000..+1000, steer -1000..+1000.
|
|
* Also refreshes the heartbeat timer.
|
|
*
|
|
* Speed→setpoint:
|
|
* Speed is converted to a setpoint offset (degrees) before calling balance_update().
|
|
* Positive speed → forward tilt → robot moves forward.
|
|
* Max offset is ±JETSON_SPEED_MAX_DEG (see below).
|
|
*
|
|
* Steer:
|
|
* Passed directly to motor_driver_update() as steer_cmd.
|
|
* Motor driver ramps and clamps with balance headroom (see motor_driver.h).
|
|
*
|
|
* Integration pattern in main.c (after the cdc_cmd_ready block):
|
|
*
|
|
* // Process buffered C command (parsed here, not in ISR)
|
|
* if (jetson_cmd_ready) { jetson_cmd_ready = 0; jetson_cmd_process(); }
|
|
*
|
|
* // Apply setpoint offset and steer when active
|
|
* float base_sp = bal.setpoint;
|
|
* if (jetson_cmd_is_active(now)) bal.setpoint += jetson_cmd_sp_offset();
|
|
* balance_update(&bal, &imu, dt);
|
|
* bal.setpoint = base_sp;
|
|
*
|
|
* // Steer injection in 50Hz ESC block
|
|
* int16_t jsteer = jetson_cmd_is_active(now) ? jetson_cmd_steer() : 0;
|
|
* motor_driver_update(&motors, bal.motor_cmd, jsteer, now);
|
|
*/
|
|
|
|
/* Heartbeat timeout: if no H or C within this window, commands deactivate */
|
|
#define JETSON_HB_TIMEOUT_MS 500
|
|
|
|
/* Max setpoint offset from Jetson speed command (speed=1000 → +N degrees tilt) */
|
|
#define JETSON_SPEED_MAX_DEG 4.0f /* ±4° → enough for ~0.5 m/s */
|
|
|
|
/*
|
|
* jetson_cmd_process()
|
|
* Call from main loop (NOT ISR) when jetson_cmd_ready is set.
|
|
* Parses jetson_cmd_buf (the C<spd>,<str> frame) with sscanf.
|
|
*/
|
|
void jetson_cmd_process(void);
|
|
|
|
/*
|
|
* jetson_cmd_is_active(now)
|
|
* Returns true if a heartbeat (H or C command) arrived within JETSON_HB_TIMEOUT_MS.
|
|
* If false, main loop should fall back to RC or zero steer.
|
|
*/
|
|
bool jetson_cmd_is_active(uint32_t now_ms);
|
|
|
|
/* Current steer command after latest C frame, clamped to ±1000 */
|
|
int16_t jetson_cmd_steer(void);
|
|
|
|
/* Setpoint offset (degrees) derived from latest speed command. */
|
|
float jetson_cmd_sp_offset(void);
|
|
|
|
/*
|
|
* Externals — declared here, defined in usbd_cdc_if.c alongside the other
|
|
* CDC volatile flags (cdc_streaming, cdc_arm_request, etc.).
|
|
* Main loop checks jetson_cmd_ready; ISR sets it.
|
|
*/
|
|
extern volatile uint8_t jetson_cmd_ready; /* set by ISR on C frame */
|
|
extern volatile char jetson_cmd_buf[32]; /* C<spd>,<str>\0 from ISR */
|
|
extern volatile uint32_t jetson_hb_tick; /* HAL_GetTick() of last H or C */
|
|
|
|
#endif /* JETSON_CMD_H */
|