![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
TRR2018 omar
Fork of biniou by
stateMachines.h@22:26fc6e6f7a55, 2018-09-15 (annotated)
- Committer:
- GaspardD
- Date:
- Sat Sep 15 15:56:01 2018 +0000
- Revision:
- 22:26fc6e6f7a55
- Parent:
- 21:de7a0a47f8a3
- Child:
- 23:04d393220daa
avec log
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GaspardD | 12:51b1b40cc017 | 1 | #include "mbed.h" |
GaspardD | 8:1d8c3ca5e508 | 2 | #include <stdint.h> |
GaspardD | 8:1d8c3ca5e508 | 3 | |
GaspardD | 19:771bf61be276 | 4 | //#define DLVV |
GaspardD | 19:771bf61be276 | 5 | #define SAMPLING//commenter pour désactiver |
GaspardD | 19:771bf61be276 | 6 | #define DEBUG -1//-1 pour avoir uniquement la gestion de l'interruption bouton |
GaspardD | 17:8c465656eea4 | 7 | |
GaspardD | 21:de7a0a47f8a3 | 8 | #define NB_INTEGRAL_SAMPLES 5 |
GaspardD | 21:de7a0a47f8a3 | 9 | |
GaspardD | 22:26fc6e6f7a55 | 10 | #define TACHY_CM 8 |
GaspardD | 22:26fc6e6f7a55 | 11 | |
GaspardD | 19:771bf61be276 | 12 | #define DIERCTION_PERIOD_MS 10000 |
GaspardD | 17:8c465656eea4 | 13 | #define DIRECTION_PULSE_MAX 2100 |
GaspardD | 17:8c465656eea4 | 14 | #define DIRECTION_PULSE_MIN 800 |
GaspardD | 17:8c465656eea4 | 15 | #define DIRECTION_PULSE_MIDDLE 1500 |
GaspardD | 17:8c465656eea4 | 16 | |
GaspardD | 19:771bf61be276 | 17 | #define SPEED_PERIOD_US 20000 |
GaspardD | 19:771bf61be276 | 18 | #define BRAKING_PULSE_US 1350 |
GaspardD | 19:771bf61be276 | 19 | #define MAX_PULSE_WIDTH_FOR_TACHY_US 1850 |
GaspardD | 19:771bf61be276 | 20 | #define INITAL_PULSE_SPEED_US 1590 |
GaspardD | 19:771bf61be276 | 21 | #define ZERO_PULSE_SPEED_US 1500 |
GaspardD | 21:de7a0a47f8a3 | 22 | #define COEF_CMPS_TO_PULSE 25 |
GaspardD | 13:af9a59ccf60b | 23 | |
GaspardD | 11:bc24b3ba51a9 | 24 | #define NB_ECHANTILLONS_IR 4 |
GaspardD | 11:bc24b3ba51a9 | 25 | #define NB_ECHANTILLONS_LIDAR 4 |
GaspardD | 11:bc24b3ba51a9 | 26 | |
GaspardD | 21:de7a0a47f8a3 | 27 | #define LIDAR_STRENGTH_THRESOLD 25 //pour la gestion de la vitesse MAX (MAXSpeed_ST) |
GaspardD | 21:de7a0a47f8a3 | 28 | #define LIDAR_ERR 65535 |
GaspardD | 11:bc24b3ba51a9 | 29 | |
GaspardD | 21:de7a0a47f8a3 | 30 | #define IR_DEADZONE_U16_22cm 48000 |
GaspardD | 21:de7a0a47f8a3 | 31 | #define IR_FAR_U16_105cm 12000 |
GaspardD | 11:bc24b3ba51a9 | 32 | |
GaspardD | 18:38504337d2fc | 33 | #define SPEED_DELTA_CMPS 30 |
GaspardD | 11:bc24b3ba51a9 | 34 | |
GaspardD | 22:26fc6e6f7a55 | 35 | #define CAPT_45_DROITE PC_2 |
GaspardD | 22:26fc6e6f7a55 | 36 | #define CAPT_45_GAUCHE PC_0 |
GaspardD | 22:26fc6e6f7a55 | 37 | #define CAPT_90_DROITE PA_1 |
GaspardD | 22:26fc6e6f7a55 | 38 | #define CAPT_90_GAUCHE PC_1 |
GaspardD | 22:26fc6e6f7a55 | 39 | #define CAPT_10_GAUCHE PB_0 |
GaspardD | 22:26fc6e6f7a55 | 40 | #define CAPT_10_DROITE PC_3 |
GaspardD | 22:26fc6e6f7a55 | 41 | #define CAPT_DEVANT PA_4 |
GaspardD | 22:26fc6e6f7a55 | 42 | #define ODOMETRE PA_11 |
GaspardD | 22:26fc6e6f7a55 | 43 | |
GaspardD | 22:26fc6e6f7a55 | 44 | |
GaspardD | 19:771bf61be276 | 45 | #ifdef SAMPLING |
GaspardD | 22:26fc6e6f7a55 | 46 | #define TAILLE_SAMPLES 4000 |
GaspardD | 19:771bf61be276 | 47 | typedef struct states |
GaspardD | 19:771bf61be276 | 48 | { |
GaspardD | 19:771bf61be276 | 49 | char murs_dlvv; |
GaspardD | 19:771bf61be276 | 50 | char section; |
GaspardD | 19:771bf61be276 | 51 | char maxSpeed; |
GaspardD | 19:771bf61be276 | 52 | char throttle; |
GaspardD | 19:771bf61be276 | 53 | }s_States; |
GaspardD | 11:bc24b3ba51a9 | 54 | |
GaspardD | 19:771bf61be276 | 55 | typedef struct sample |
GaspardD | 19:771bf61be276 | 56 | { |
GaspardD | 19:771bf61be276 | 57 | s_States states; |
GaspardD | 22:26fc6e6f7a55 | 58 | int time; |
GaspardD | 22:26fc6e6f7a55 | 59 | int16_t diffgd45; |
GaspardD | 22:26fc6e6f7a55 | 60 | int16_t diffgd90; |
GaspardD | 22:26fc6e6f7a55 | 61 | int16_t pwm_thro_us; |
GaspardD | 22:26fc6e6f7a55 | 62 | int16_t pwm_dir_us; |
GaspardD | 22:26fc6e6f7a55 | 63 | int16_t dist; |
GaspardD | 19:771bf61be276 | 64 | } s_Sample; |
GaspardD | 19:771bf61be276 | 65 | |
GaspardD | 19:771bf61be276 | 66 | #endif |
GaspardD | 11:bc24b3ba51a9 | 67 | |
GaspardD | 8:1d8c3ca5e508 | 68 | typedef enum{ |
GaspardD | 17:8c465656eea4 | 69 | ATTRACTIF_G, |
GaspardD | 17:8c465656eea4 | 70 | ATTRACTIF_D, |
GaspardD | 17:8c465656eea4 | 71 | EQUILIBRAGE_REPULSIF |
GaspardD | 17:8c465656eea4 | 72 | }MUR_ST; |
GaspardD | 17:8c465656eea4 | 73 | |
GaspardD | 17:8c465656eea4 | 74 | #ifdef DLVV |
GaspardD | 17:8c465656eea4 | 75 | typedef enum{//uniquement activé pour dlvv, se rajoute au PID de murOutput |
GaspardD | 17:8c465656eea4 | 76 | FRONT_CLEAR,//pas d'obstacle droit devant |
GaspardD | 17:8c465656eea4 | 77 | FRONT_OBSTRUCTED//un obstacle à été detecté à moins de 20/30 cm tbd |
GaspardD | 17:8c465656eea4 | 78 | }OBSTACLE_ST; |
GaspardD | 17:8c465656eea4 | 79 | #endif |
GaspardD | 17:8c465656eea4 | 80 | |
GaspardD | 17:8c465656eea4 | 81 | typedef enum{ |
GaspardD | 8:1d8c3ca5e508 | 82 | ARRET, |
GaspardD | 8:1d8c3ca5e508 | 83 | LOADING_SECTION, |
GaspardD | 8:1d8c3ca5e508 | 84 | RUNNING_SECTION |
GaspardD | 8:1d8c3ca5e508 | 85 | }SECTION_ST; |
GaspardD | 8:1d8c3ca5e508 | 86 | |
GaspardD | 8:1d8c3ca5e508 | 87 | typedef enum{ |
GaspardD | 17:8c465656eea4 | 88 | SPEED_MAX,//pas de mur, on va a fond |
GaspardD | 21:de7a0a47f8a3 | 89 | SPEED_WARNING,//signal suffisement fort pour gérer la vitesse |
GaspardD | 21:de7a0a47f8a3 | 90 | BLOCKED//nous somme dans la plage de distance ou la vitesse doit être limitée |
GaspardD | 17:8c465656eea4 | 91 | }MAX_SPEED_ST; |
GaspardD | 17:8c465656eea4 | 92 | |
GaspardD | 17:8c465656eea4 | 93 | typedef enum{ |
GaspardD | 21:de7a0a47f8a3 | 94 | REGULATION_SPEED, |
GaspardD | 16:63690703b5b6 | 95 | AT_SPEED, |
GaspardD | 19:771bf61be276 | 96 | BRAKING, |
GaspardD | 19:771bf61be276 | 97 | STOPPED |
GaspardD | 8:1d8c3ca5e508 | 98 | }THROTTLE_ST; |
GaspardD | 8:1d8c3ca5e508 | 99 | |
GaspardD | 8:1d8c3ca5e508 | 100 | |
GaspardD | 8:1d8c3ca5e508 | 101 | typedef struct s_section { |
GaspardD | 22:26fc6e6f7a55 | 102 | int targetSpeed_cmps;//supérieure a 328 |
GaspardD | 22:26fc6e6f7a55 | 103 | int slowSpeed_cmps;//supérieure a 328; pour effectuer les virages: pour ne pas avoir d'a coups entre la vitesse variable et la vitesse limitée: brakingCoefficient = 30*((targetSpeed_cmps/slowSpeed_cmps)-1) |
GaspardD | 11:bc24b3ba51a9 | 104 | int brakingCoefficient; |
GaspardD | 21:de7a0a47f8a3 | 105 | int coef_p_speed; |
GaspardD | 11:bc24b3ba51a9 | 106 | int lidarWarningDist_cm; |
GaspardD | 8:1d8c3ca5e508 | 107 | int lng_section_cm; |
GaspardD | 17:8c465656eea4 | 108 | int coef_p; |
GaspardD | 17:8c465656eea4 | 109 | int coef_i; |
GaspardD | 17:8c465656eea4 | 110 | int coef_d; |
GaspardD | 8:1d8c3ca5e508 | 111 | s_section* nextSection; |
GaspardD | 8:1d8c3ca5e508 | 112 | }s_Section; |
GaspardD | 8:1d8c3ca5e508 | 113 | |
GaspardD | 11:bc24b3ba51a9 | 114 | //*************** fonctions utilitaires *************** |
GaspardD | 8:1d8c3ca5e508 | 115 | |
GaspardD | 11:bc24b3ba51a9 | 116 | void getTachySpeed(); |
GaspardD | 12:51b1b40cc017 | 117 | uint16_t getDistMoy(uint16_t* tab, int size); |
GaspardD | 12:51b1b40cc017 | 118 | void it4cm(); |
GaspardD | 12:51b1b40cc017 | 119 | void it_serial(); |
GaspardD | 11:bc24b3ba51a9 | 120 | |
GaspardD | 11:bc24b3ba51a9 | 121 | //*************** fonctions states machines *************** |
GaspardD | 8:1d8c3ca5e508 | 122 | //gestion de la direction quand la vue est dégagée |
GaspardD | 11:bc24b3ba51a9 | 123 | void mursInit(void); |
GaspardD | 11:bc24b3ba51a9 | 124 | void mursUpdate(void); |
GaspardD | 11:bc24b3ba51a9 | 125 | void mursOutput(void); |
GaspardD | 8:1d8c3ca5e508 | 126 | |
GaspardD | 11:bc24b3ba51a9 | 127 | #ifdef DLVV |
GaspardD | 8:1d8c3ca5e508 | 128 | //gestion de la direction en mode course et de l'évitement en mode DLVV |
GaspardD | 11:bc24b3ba51a9 | 129 | void obstacleInit(void); |
GaspardD | 11:bc24b3ba51a9 | 130 | void obstacleUpdate(void); |
GaspardD | 11:bc24b3ba51a9 | 131 | void obstacleOutput(void); |
GaspardD | 11:bc24b3ba51a9 | 132 | #endif |
GaspardD | 8:1d8c3ca5e508 | 133 | |
GaspardD | 11:bc24b3ba51a9 | 134 | //gestion du comportement en fn de l'avancement sur le parcours |
GaspardD | 11:bc24b3ba51a9 | 135 | void sectionInit(void); |
GaspardD | 11:bc24b3ba51a9 | 136 | void sectionUpdate(void); |
GaspardD | 11:bc24b3ba51a9 | 137 | void sectionOutput(void); |
GaspardD | 11:bc24b3ba51a9 | 138 | |
GaspardD | 11:bc24b3ba51a9 | 139 | //gestion de la gesion de la vitesse max/rotation max des roues la rotation est plus importante que la vitesse :) |
GaspardD | 11:bc24b3ba51a9 | 140 | void maxSpeedInit(void); |
GaspardD | 11:bc24b3ba51a9 | 141 | void maxSpeedUpdate(void); |
GaspardD | 11:bc24b3ba51a9 | 142 | void maxSpeedOutput(void); |
GaspardD | 8:1d8c3ca5e508 | 143 | |
GaspardD | 8:1d8c3ca5e508 | 144 | //gestion de l'allure en fonction des paramètres de la section |
GaspardD | 11:bc24b3ba51a9 | 145 | void throttleInit(void); |
GaspardD | 11:bc24b3ba51a9 | 146 | void throttleUpdate(void); |
GaspardD | 11:bc24b3ba51a9 | 147 | void throttleOutput(void); |