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