From: Jason C. <Ba...@us...> - 2011-06-08 20:52:22
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 21fa8c7c828a2ab7dbc159e3bc6543597f5a2ddd (commit) from f32c0b6cd08a7a7055286d9b17d148a4e0eee4f8 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 21fa8c7c828a2ab7dbc159e3bc6543597f5a2ddd Author: jchevrie <jas...@cr...> Date: Wed Jun 8 22:51:35 2011 +0200 Ajout du calcul de l'angle ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Balise_IR/Carte_capteurs/Firmware/controller_motor_stm32/controller_motor_stm32.mk b/elec/boards/Balise_IR/Carte_capteurs/Firmware/controller_motor_stm32/controller_motor_stm32.mk index 258c050..614a6e1 100644 --- a/elec/boards/Balise_IR/Carte_capteurs/Firmware/controller_motor_stm32/controller_motor_stm32.mk +++ b/elec/boards/Balise_IR/Carte_capteurs/Firmware/controller_motor_stm32/controller_motor_stm32.mk @@ -9,7 +9,7 @@ Firmware_DEBUG = 1 # Our target application TRG += controller_motor_stm32 -controller_motor_stm32_PREFIX = "/home/justin/opt/arm-i386/bin/arm-none-eabi-" +controller_motor_stm32_PREFIX = "/home/jason/opt/arm-i386/bin/arm-none-eabi-" controller_motor_stm32_SUFFIX = "" diff --git a/elec/boards/Balise_IR/Carte_capteurs/Firmware/controller_motor_stm32/main.c b/elec/boards/Balise_IR/Carte_capteurs/Firmware/controller_motor_stm32/main.c index 3c23c58..5f22f06 100644 --- a/elec/boards/Balise_IR/Carte_capteurs/Firmware/controller_motor_stm32/main.c +++ b/elec/boards/Balise_IR/Carte_capteurs/Firmware/controller_motor_stm32/main.c @@ -53,10 +53,10 @@ static void init(void) static void NORETURN ind_process(void) { while(1) { - LED1_ON(); - timer_delay(500); - LED1_OFF(); - timer_delay(500); + /*LED1_ON(); + timer_delay(250); + LED1_OFF();*/ + timer_delay(250); } } diff --git a/elec/boards/Balise_IR/Carte_capteurs/Firmware/controller_motor_stm32/reception.c b/elec/boards/Balise_IR/Carte_capteurs/Firmware/controller_motor_stm32/reception.c index fe2d17b..9f36a29 100644 --- a/elec/boards/Balise_IR/Carte_capteurs/Firmware/controller_motor_stm32/reception.c +++ b/elec/boards/Balise_IR/Carte_capteurs/Firmware/controller_motor_stm32/reception.c @@ -71,7 +71,9 @@ void receptionInit() { //Init readValues for(i=0;i<NUM_SENSORS;i++) { - readValues[i]=0; + readValues[i][0]=0; + readValues[i][1]=0; + detectionState[i]=0; } return; } @@ -80,39 +82,112 @@ void NORETURN reception_process(void) { Timer timer_reception_process; int i; + float theta; + uint16_t control; + uint16_t opponentSensor; + uint16_t maxWeight; + + timer_setDelay(&timer_reception_process, us_to_ticks((utime_t)(reception_refresh))); timer_setEvent(&timer_reception_process); while(1) { + timer_add(&timer_reception_process);// Start process timer - readSensors(); - for(i=0;i<NUM_SENSORS;i++) { - if(readValues[0]==0) LED2_ON(); - else LED2_OFF(); - } + + uint16_t weight_tab[NUM_SENSORS]={0}; + + control=refreshDetection(); + + if (control >= NB_DETECT_MIN){ // process only when enough sensors are enlightened + + maxWeight = 0; + + for(i=0 ; i<NUM_SENSORS ; i++){ + + weight_tab[i] = calculate_weight(i); + + if (weight_tab[i] > maxWeight){ + + maxWeight = weight_tab[i]; + opponentSensor = i; + + } + } + + theta = 2*M_PI - (2*M_PI/32 + opponentSensor * 2*M_PI/16); + + } + + + if (control >= NB_DETECT_MIN) LED2_ON(); + else LED2_OFF(); + if (theta < M_PI/2) LED1_ON(); + else LED1_OFF(); + timer_waitEvent(&timer_reception_process); // Wait until the end of counting } } -void readSensors(void) { +void readSensors(int indice) { //Read all sensors - readValues[0]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOB_BASE), BV(9)); //read PB9 - readValues[1]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOB_BASE), BV(8)); //read PB8 - readValues[2]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOB_BASE), BV(7)); //read PB7 - readValues[3]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOB_BASE), BV(6)); //read PB6 - readValues[4]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOD_BASE), BV(2)); //read PD2 - readValues[5]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOC_BASE), BV(12)); //read PC12 - readValues[6]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOC_BASE), BV(11)); //read PC11 - readValues[7]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOC_BASE), BV(10)); //read PC10 - readValues[8]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOC_BASE), BV(9)); //read PC9 - readValues[9]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOC_BASE), BV(8)); //read PC8 - readValues[10]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOC_BASE), BV(7)); //read PC7 - readValues[11]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOC_BASE), BV(6)); //read PC6 - readValues[12]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOB_BASE), BV(15)); //read PB15 - readValues[13]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOB_BASE), BV(14)); //read PB14 - readValues[14]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOB_BASE), BV(13)); //read PB13 - readValues[15]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOB_BASE), BV(12)); //read PB12 + readValues[0][indice]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOB_BASE), BV(9)); //read PB9 + readValues[1][indice]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOB_BASE), BV(8)); //read PB8 + readValues[2][indice]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOB_BASE), BV(7)); //read PB7 + readValues[3][indice]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOB_BASE), BV(6)); //read PB6 + readValues[4][indice]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOD_BASE), BV(2)); //read PD2 + readValues[5][indice]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOC_BASE), BV(12)); //read PC12 + readValues[6][indice]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOC_BASE), BV(11)); //read PC11 + readValues[7][indice]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOC_BASE), BV(10)); //read PC10 + readValues[8][indice]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOC_BASE), BV(9)); //read PC9 + readValues[9][indice]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOC_BASE), BV(8)); //read PC8 + readValues[10][indice]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOC_BASE), BV(7)); //read PC7 + readValues[11][indice]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOC_BASE), BV(6)); //read PC6 + readValues[12][indice]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOB_BASE), BV(15)); //read PB15 + readValues[13][indice]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOB_BASE), BV(14)); //read PB14 + readValues[14][indice]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOB_BASE), BV(13)); //read PB13 + readValues[15][indice]=stm32_gpioPinRead(((struct stm32_gpio *)GPIOB_BASE), BV(12)); //read PB12 return; } + +uint16_t refreshDetection(void){ + + int i; + uint8_t control_sum=0; + + readSensors(0); + timer_delay(1); + readSensors(1); + + for(i=0 ; i < NUM_SENSORS ; i++){ + + if (readValues[i][0]!=readValues[i][1]) detectionState[i] = 1; + else detectionState[i] = 0; + control_sum += detectionState[i]; + } + + + + return control_sum; +} + +uint16_t calculate_weight(uint16_t k){ + + int i; + uint16_t weight=0; + + for(i=0 ; i<NUM_SENSORS ; i++){ + + if((abs(k-i) < 5) & (i!=k)){ + + weight += detectionState[i]*pow(3,5-abs(k-i)); + + } + + } + + return weight; + +} diff --git a/elec/boards/Balise_IR/Carte_capteurs/Firmware/controller_motor_stm32/reception.h b/elec/boards/Balise_IR/Carte_capteurs/Firmware/controller_motor_stm32/reception.h index e37ca60..16bb082 100644 --- a/elec/boards/Balise_IR/Carte_capteurs/Firmware/controller_motor_stm32/reception.h +++ b/elec/boards/Balise_IR/Carte_capteurs/Firmware/controller_motor_stm32/reception.h @@ -10,10 +10,11 @@ #define PWM_56k 1286 #define NUM_SENSORS 16 +#define NB_DETECT_MIN 5 +#define reception_refresh 10000 -#define reception_refresh 200 - -uint16_t readValues[NUM_SENSORS]; +uint16_t readValues[NUM_SENSORS][2]; +uint16_t detectionState[NUM_SENSORS]; void receptionInit(void); @@ -22,8 +23,11 @@ void enableClock(void); void disableClock(void); -void readSensors(void); +void readSensors(int); +uint16_t refreshDetection(void); +uint16_t calculate_weight(uint16_t); void NORETURN reception_process(void); + #endif hooks/post-receive -- krobot |