From 3d8a16ffa074fe9cf084422d308ed779cf8dbc18 Mon Sep 17 00:00:00 2001 From: pimpest <82343504+pimpest@users.noreply.github.com> Date: Mon, 5 Jan 2026 00:34:54 +0100 Subject: [PATCH] Added timeout for stepper drivers --- firmware/base/src/config.h | 1 + firmware/base/src/main.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/firmware/base/src/config.h b/firmware/base/src/config.h index 630da9b..c6a4c25 100644 --- a/firmware/base/src/config.h +++ b/firmware/base/src/config.h @@ -10,6 +10,7 @@ #define SM_B 1 #define PULSE_PER_REV (1 / 3200.0) +#define SPEED_SET_TIMEOUT 1000 //############################################### //================ CONFIG ENCODERS ===================== diff --git a/firmware/base/src/main.c b/firmware/base/src/main.c index b8c4760..bdf5a93 100644 --- a/firmware/base/src/main.c +++ b/firmware/base/src/main.c @@ -32,6 +32,7 @@ static double wheel_ratio_r = 1; static uint prev_time; static int prev_position_l = 0; static int prev_position_r = 0; +static uint last_speed_change = 100; static unsigned char stepper_instr[2+sizeof(double)*2] = {}; @@ -212,6 +213,7 @@ void stepper_fifo(char c, uint8_t itf) { double vr = btod(stepper_instr + 10); set_speeds(vl, vr); + last_speed_change = SPEED_SET_TIMEOUT; // tud_cdc_n_write(itf, (uint8_t const *) stepper_instr, 18); // tud_cdc_n_write_flush(itf); @@ -263,6 +265,10 @@ int main() while (true) { + if(last_speed_change--) { + set_speeds(0, 0); + last_speed_change = SPEED_SET_TIMEOUT; + } tud_task(); sleep_ms(1); }