From 17607c45953ed292bdcff9af733dbb8b7be92f9e Mon Sep 17 00:00:00 2001 From: DNOALEE <oliver.ljungberg@epfl.ch> Date: Sun, 15 May 2022 12:31:06 +0200 Subject: [PATCH] Optimisation of bliky --- blinky.c | 20 +++++++++----------- check_collision.c | 11 ----------- check_collision.h | 2 -- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/blinky.c b/blinky.c index 60afff0..c3494f3 100644 --- a/blinky.c +++ b/blinky.c @@ -22,18 +22,16 @@ static THD_FUNCTION(Blinky, arg) { while(1){ // Blink the back LED when the robot moves backward - if( ((get_acc_case() == 2) | (get_acc_case() == 4)) & - (get_wall_detection() != 2) ){ + if(get_wall_detection() != 2){ + if( ((get_acc_case() == 2) | (get_acc_case() == 4)) ){ - set_led(LED5, 1); - chThdSleepMilliseconds(300); - set_led(LED5, 0); - chThdSleepMilliseconds(200); - }else if( ((get_acc_case() == 0) | (get_acc_case() == 1) | (get_acc_case() == 3)) & - (get_wall_detection() != 2) & (get_check_back_wall() == 1) ){ - - set_led(LED5, 0); - clear_check_back_wall(); + set_led(LED5, 1); + chThdSleepMilliseconds(300); + set_led(LED5, 0); + chThdSleepMilliseconds(200); + }else{ + set_led(LED5, 0); + } } // 10Hz chThdSleepMilliseconds(100); diff --git a/check_collision.c b/check_collision.c index fa90501..b936d5d 100644 --- a/check_collision.c +++ b/check_collision.c @@ -24,7 +24,6 @@ * wall_detection = 2 -> wall detected in the back or (front and back) */ static uint8_t wall_detection = 0; -static uint8_t check_back_wall = 0; // Declaration of functions void clear_led_but_back(void); @@ -93,7 +92,6 @@ static THD_FUNCTION(CheckCollision, arg) { // Front and back detected }else{ wall_detection = 2; - check_back_wall = 1; // Set acc_case to 0 reset_acc_case(); @@ -121,7 +119,6 @@ static THD_FUNCTION(CheckCollision, arg) { // Set back LEDs and clear front LEDs wall_detection = 2; - check_back_wall = 1; set_led(LED1, 0); set_rgb_led(LED2, 0, 0, 0); @@ -165,14 +162,6 @@ uint8_t get_wall_detection(void){ return wall_detection; } -uint8_t get_check_back_wall(void){ - return check_back_wall; -} - -void clear_check_back_wall(void){ - check_back_wall = 0; -} - // Clear all LEDs except the back LED void clear_led_but_back(void){ set_led(LED1, 0); diff --git a/check_collision.h b/check_collision.h index 1ed6597..a42498d 100644 --- a/check_collision.h +++ b/check_collision.h @@ -13,7 +13,5 @@ void check_collision_start(void); // Getter of wall_detection uint8_t get_wall_detection(void); -uint8_t get_check_back_wall(void); -void clear_check_back_wall(void); #endif /* CHECK_COLLISION_H_ */ -- GitLab