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>
75 lines
2.6 KiB
C
75 lines
2.6 KiB
C
#ifndef MODE_MANAGER_H
|
|
#define MODE_MANAGER_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
/*
|
|
* SaltyLab Mode Manager
|
|
*
|
|
* Resolves three operating modes selected by RC CH6 (3-pos switch):
|
|
*
|
|
* RC_MANUAL — RC steer (CH4) and speed bias (CH3) applied directly.
|
|
* Balance PID remains active for stability.
|
|
* RC_ASSISTED — RC inputs blended 50/50 with Jetson autonomous commands.
|
|
* AUTONOMOUS — Jetson commands only; RC CH5 arm switch still kills motors.
|
|
*
|
|
* Transitions between modes are smoothed over MODE_BLEND_MS (~500ms) to
|
|
* prevent jerky handoffs. A single `blend` scalar (0=pure RC, 1=pure auto)
|
|
* drives all interpolation; adjacent-mode steps take ~250ms each.
|
|
*
|
|
* RC safety rule: if RC is alive and CH5 is disarmed, the main loop MUST
|
|
* disarm regardless of mode. mode_manager only blends commands — kill
|
|
* authority lives in the main loop.
|
|
*
|
|
* Autonomous commands are set by the Jetson serial bridge via
|
|
* mode_manager_set_auto_cmd(). They default to zero (no motion).
|
|
*/
|
|
|
|
typedef enum {
|
|
MODE_RC_MANUAL = 0,
|
|
MODE_RC_ASSISTED = 1,
|
|
MODE_AUTONOMOUS = 2,
|
|
} robot_mode_t;
|
|
|
|
typedef struct {
|
|
robot_mode_t target; /* Mode requested by CH6 (or fallback) */
|
|
float blend; /* 0.0=pure RC .. 1.0=pure auto, smoothly ramped */
|
|
bool rc_alive; /* Cached RC liveness (set in update) */
|
|
int16_t auto_steer; /* Jetson steer cmd (-1000..+1000) */
|
|
int16_t auto_speed_bias;/* Jetson speed bias (-MOTOR_RC_SPEED_MAX..+) */
|
|
} mode_manager_t;
|
|
|
|
/* Initialise — call once before the main loop */
|
|
void mode_manager_init(mode_manager_t *m);
|
|
|
|
/*
|
|
* Call every main-loop tick (1ms) to:
|
|
* - read CH6, update target mode
|
|
* - cache RC liveness
|
|
* - advance blend ramp toward target blend value
|
|
*/
|
|
void mode_manager_update(mode_manager_t *m, uint32_t now);
|
|
|
|
/* Set autonomous commands from the Jetson serial bridge */
|
|
void mode_manager_set_auto_cmd(mode_manager_t *m,
|
|
int16_t steer,
|
|
int16_t speed_bias);
|
|
|
|
/*
|
|
* Blended steer command to pass to motor_driver_update().
|
|
* Returns 0 when RC is not alive and no autonomous steer set.
|
|
*/
|
|
int16_t mode_manager_get_steer(const mode_manager_t *m);
|
|
|
|
/*
|
|
* Blended speed bias to add to bal.motor_cmd before motor_driver_update().
|
|
* Returns 0 when RC is not alive and no autonomous speed set.
|
|
*/
|
|
int16_t mode_manager_get_speed_bias(const mode_manager_t *m);
|
|
|
|
/* Quantised current mode (based on blend position, not target) */
|
|
robot_mode_t mode_manager_active(const mode_manager_t *m);
|
|
|
|
#endif
|