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