From 8ebf9dc23052be9831097f91054a6f8ded205ef1 Mon Sep 17 00:00:00 2001 From: EmanuelFeru Date: Tue, 18 Jun 2019 18:06:58 +0200 Subject: [PATCH] =?UTF-8?q?=E2=96=BA=20Added=20protection=20on=20start-up?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For safety reasons, the motors are enabled on start-up, only if the input is very small. --- Src/main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Src/main.c b/Src/main.c index e0d3e1f..e73f68b 100644 --- a/Src/main.c +++ b/Src/main.c @@ -222,7 +222,7 @@ int main(void) { float board_temp_adc_filtered = (float)adc_buffer.temp; float board_temp_deg_c; - enable = 1; // enable motors + enable = 0; // initially motors are disabled for SAFETY while(1) { @@ -263,6 +263,11 @@ int main(void) { timeout = 0; #endif + // ####### MOTOR ENABLING: Only if the initial input is very small (SAFETY) ####### + if (enable == 0 && (cmd1 > -50 && cmd1 < 50) && (cmd2 > -50 && cmd2 < 50)){ + enable = 1; // enable motors + } + // Bypass - only for testing purposes // cmd2 = cmd2-500; // cmd1 = 0; @@ -282,7 +287,7 @@ int main(void) { // ####### SET OUTPUTS (if the target change less than +/- 50) ####### - if ((speedL < lastSpeedL + 50 && speedL > lastSpeedL - 50) && (speedR < lastSpeedR + 50 && speedR > lastSpeedR - 50) && timeout < TIMEOUT) { + if ((speedL > lastSpeedL-50 && speedL < lastSpeedL+50) && (speedR > lastSpeedR-50 && speedR < lastSpeedR+50) && timeout < TIMEOUT) { #ifdef INVERT_R_DIRECTION pwmr = speedR; #else