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