diff --git a/blinky.c b/blinky.c new file mode 100644 index 0000000000000000000000000000000000000000..60afff02cbd8d19c40f430b75dead8c2cf9bc385 --- /dev/null +++ b/blinky.c @@ -0,0 +1,45 @@ +/* + * blinky.c + * + * Created on: 12 mai 2022 + * Author: oliver + */ +// Standard includes +#include <ch.h> +#include <hal.h> +#include <leds.h> + +// Project files includes +#include "blinky.h" +#include "check_collision.h" +#include "compute_case.h" + +static THD_WORKING_AREA(waBlinky, 128); +static THD_FUNCTION(Blinky, arg) { + + chRegSetThreadName(__FUNCTION__); + (void)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) ){ + + 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(); + } + // 10Hz + chThdSleepMilliseconds(100); + } +} + +void blinky_start(void){ + chThdCreateStatic(waBlinky, sizeof(waBlinky), NORMALPRIO, Blinky, NULL); +} diff --git a/blinky.h b/blinky.h new file mode 100644 index 0000000000000000000000000000000000000000..4b45d0dd0cbacd4813f9e5b2da3cb9bcb02bbc99 --- /dev/null +++ b/blinky.h @@ -0,0 +1,15 @@ +/* + * blinky.h + * + * Created on: 12 mai 2022 + * Author: oliver + */ + +#ifndef BLINKY_H_ +#define BLINKY_H_ + +void blinky_start(void); + + + +#endif /* BLINKY_H_ */ diff --git a/check_collision.c b/check_collision.c index 4d76b4e33be7a1cf10544c8b8dd8d41c1273a841..fa90501cf4358ed54a9e01649463ae1cdf9e5277 100644 --- a/check_collision.c +++ b/check_collision.c @@ -13,7 +13,7 @@ #include <selector.h> #include <audio/audio_thread.h> -// project files includes +// Project files includes #include "check_collision.h" #include "compute_case.h" diff --git a/compute_case.c b/compute_case.c index 8ebfab1d2047b5f3a7b070725c2465bcbd04e34d..0928223575fd6d1f40e2b933d3029dc14fa31c30 100644 --- a/compute_case.c +++ b/compute_case.c @@ -9,7 +9,7 @@ #include <hal.h> #include <sensors/imu.h> -// project files includes +// Project files includes #include "compute_case.h" #define XAXIS 0 diff --git a/main.c b/main.c index 49f1192841074d099ceec1ab800088c655c573b5..b5853adc74101ef08c3389c77e02775c8b01e002 100644 --- a/main.c +++ b/main.c @@ -1,3 +1,9 @@ +/* + * main.c + * + * Created on: 14 avr. 2022 + * Author: Corentin Jossi + */ // Standard includes #include <stdio.h> #include <stdlib.h> @@ -15,11 +21,12 @@ #include <audio/audio_thread.h> -// project files includes +// Project files includes #include "main.h" #include "compute_case.h" #include "check_collision.h" #include "motor_speed.h" +#include "blinky.h" messagebus_t bus; MUTEX_DECL(bus_lock); @@ -82,6 +89,7 @@ int main(void) check_collision_start(); select_case_start(); motor_speed_start(); + blinky_start(); // Front LED indicates that the calibration is completed for(uint8_t i = 0 ; i < 3; ++i){ @@ -95,22 +103,7 @@ int main(void) /* Infinite loop. */ while (1) { - // Blink the back LED when the robot moves backward - if( ((get_acc_case() == 2) | (get_acc_case() == 4)) & - (get_wall_detection() != 2) ){ - - 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(); - } - // 10Hz - chThdSleepMilliseconds(100); + chThdSleepMilliseconds(1000); } } diff --git a/main.h b/main.h index 91d8a0b365303348337af817cf84a48ebb5d9c64..cf24fd3764e4bdba3192a63cd64868cabad0fec2 100644 --- a/main.h +++ b/main.h @@ -1,3 +1,9 @@ +/* + * main.h + * + * Created on: 14 avr. 2022 + * Author: Corentin Jossi + */ #ifndef MAIN_H #define MAIN_H diff --git a/makefile b/makefile index 23d64370058fd542f10526666d3c446ebf00eb55..4e6033ce946ef38cc9d312d236478ab54ae0420c 100644 --- a/makefile +++ b/makefile @@ -13,6 +13,7 @@ CSRC += ./main.c \ ./compute_case.c \ ./motor_speed.c \ ./check_collision.c \ + ./blinky.c \ #Header folders to include INCDIR += diff --git a/motor_speed.c b/motor_speed.c index 23de1b8cc1fcf9267dca956a13b48f9fe9e9bf03..2c9bd9730bc8cc90acf62ccf2d001456a1914c06 100644 --- a/motor_speed.c +++ b/motor_speed.c @@ -11,7 +11,7 @@ #include <motors.h> #include <selector.h> -// project files includes +// Project files includes #include "motor_speed.h" #include "compute_case.h" #include "check_collision.h"