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