![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
TRR2018 omar
Fork of biniou by
stateMachines.cpp@51:09ecba68d0cf, 2018-09-21 (annotated)
- Committer:
- ohlimi2
- Date:
- Fri Sep 21 13:17:24 2018 +0000
- Revision:
- 51:09ecba68d0cf
- Parent:
- 47:b17061738568
- Child:
- 52:228703200e35
pas trop mal
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GaspardD | 12:51b1b40cc017 | 1 | #include "stateMachines.h" |
ohlimi2 | 36:bccddd02966a | 2 | //#if DEBUG >0 |
GaspardD | 13:af9a59ccf60b | 3 | Serial pc(USBTX, USBRX); // tx, rx |
ohlimi2 | 36:bccddd02966a | 4 | //#endif |
GaspardD | 29:fc984fe08ca7 | 5 | |
GaspardD | 29:fc984fe08ca7 | 6 | //*************** declarations *************** |
GaspardD | 33:88d8f254c0b7 | 7 | |
GaspardD | 33:88d8f254c0b7 | 8 | //time monitoring |
GaspardD | 23:04d393220daa | 9 | #ifdef DUMP_SAMPLIG_PERIOD |
GaspardD | 22:26fc6e6f7a55 | 10 | Timer timerLog; |
GaspardD | 19:771bf61be276 | 11 | #endif |
GaspardD | 19:771bf61be276 | 12 | |
GaspardD | 33:88d8f254c0b7 | 13 | Timer timeSinceStart;// temps.start()/stop()/sec: read()/ms: read_ms()/µs: read_us() |
GaspardD | 39:de3638276b7e | 14 | Timer timerSinceTachy; |
GaspardD | 42:3f12252862b9 | 15 | Timer timersinceSerial; |
GaspardD | 33:88d8f254c0b7 | 16 | |
GaspardD | 29:fc984fe08ca7 | 17 | double distMurG90[NB_ECHANTILLONS_IR];//buffer tournant ir coté gauche pour moyenne |
GaspardD | 29:fc984fe08ca7 | 18 | double distMurD90[NB_ECHANTILLONS_IR];//buffer tournant ir coté droit pour moyenne |
GaspardD | 29:fc984fe08ca7 | 19 | double shortDistMurG90[NB_ECHANTILLONS_IR];//buffer tournant ir coté gauche petites distances pour moyenne |
GaspardD | 29:fc984fe08ca7 | 20 | double shortDistMurD90[NB_ECHANTILLONS_IR];//buffer tournant ir coté droit petites distances pour moyenne |
GaspardD | 29:fc984fe08ca7 | 21 | double distMurG45[NB_ECHANTILLONS_IR];//buffer tournant ir avant gauche 45deg pour moyenne |
GaspardD | 29:fc984fe08ca7 | 22 | double distMurD45[NB_ECHANTILLONS_IR];//buffer tournant ir avant droit 45deg pour moyenne |
GaspardD | 11:bc24b3ba51a9 | 23 | #ifdef DLVV |
GaspardD | 33:88d8f254c0b7 | 24 | double distMurG10[NB_ECHANTILLONS_IR];//buffer tournant ir avant gauche 10deg pour moyenne |
GaspardD | 33:88d8f254c0b7 | 25 | double distMurD10[NB_ECHANTILLONS_IR];//buffer tournant ir coté droit 10deg pour moyenne |
GaspardD | 33:88d8f254c0b7 | 26 | double distMurFront[NB_ECHANTILLONS_IR];//buffer tournant ir front |
GaspardD | 11:bc24b3ba51a9 | 27 | #endif |
GaspardD | 29:fc984fe08ca7 | 28 | double distMurG90Moy; |
GaspardD | 29:fc984fe08ca7 | 29 | double distMurD90Moy; |
GaspardD | 29:fc984fe08ca7 | 30 | double shortDistMurG90Moy; |
GaspardD | 29:fc984fe08ca7 | 31 | double shortDistMurD90Moy; |
GaspardD | 29:fc984fe08ca7 | 32 | double trueDistMurG90Moy; |
GaspardD | 29:fc984fe08ca7 | 33 | double trueDistMurD90Moy; |
GaspardD | 29:fc984fe08ca7 | 34 | double distMurG45Moy; |
GaspardD | 29:fc984fe08ca7 | 35 | double distMurD45Moy; |
GaspardD | 23:04d393220daa | 36 | |
GaspardD | 12:51b1b40cc017 | 37 | #ifdef DLVV |
GaspardD | 29:fc984fe08ca7 | 38 | double distMurG10Moy; |
GaspardD | 29:fc984fe08ca7 | 39 | double distMurD10Moy; |
GaspardD | 29:fc984fe08ca7 | 40 | double distMurFrontMoy |
GaspardD | 12:51b1b40cc017 | 41 | #endif |
GaspardD | 8:1d8c3ca5e508 | 42 | int index_fifo_ir = 0;//pour géreer le buffer tournant |
GaspardD | 8:1d8c3ca5e508 | 43 | int index_fifo_lidar = 0; |
GaspardD | 11:bc24b3ba51a9 | 44 | //sections |
GaspardD | 11:bc24b3ba51a9 | 45 | s_Section p_section1; |
GaspardD | 39:de3638276b7e | 46 | s_Section p_section2; |
ohlimi2 | 46:9262b07b0833 | 47 | s_Section p_section3; |
GaspardD | 2:fd0ffe46a87d | 48 | |
GaspardD | 15:129f205ff030 | 49 | //PWM Controls |
GaspardD | 12:51b1b40cc017 | 50 | PwmOut PwmMotor(PB_6); // PWM4 ch1 TIM4 |
GaspardD | 12:51b1b40cc017 | 51 | PwmOut PwmDirection(PB_5); // PWM3 ch2 TIM3 |
GaspardD | 8:1d8c3ca5e508 | 52 | |
GaspardD | 21:de7a0a47f8a3 | 53 | int pulseDirection_us = DIRECTION_PULSE_MIDDLE; |
ohlimi2 | 36:bccddd02966a | 54 | double pulseDirection_us_temp ; |
GaspardD | 19:771bf61be276 | 55 | int pulseSpeed_us = INITAL_PULSE_SPEED_US; |
GaspardD | 12:51b1b40cc017 | 56 | //Capteurs direction |
GaspardD | 22:26fc6e6f7a55 | 57 | AnalogIn anaG90(CAPT_90_GAUCHE);//capteur ir coté gauche |
GaspardD | 22:26fc6e6f7a55 | 58 | AnalogIn anaD90(CAPT_90_DROITE);//capteur ir coté droit |
GaspardD | 29:fc984fe08ca7 | 59 | AnalogIn anaShortG90(CAPT_90_GAUCHE_SHORT);//capteur ir coté gauche short |
GaspardD | 29:fc984fe08ca7 | 60 | AnalogIn anaShortD90(CAPT_90_DROITE_SHORT);//capteur ir coté droit short |
GaspardD | 22:26fc6e6f7a55 | 61 | AnalogIn anaG45(CAPT_45_GAUCHE);//capteur ir avant gauche 45 deg |
GaspardD | 22:26fc6e6f7a55 | 62 | AnalogIn anaD45(CAPT_45_DROITE);//capteur ir avant droit 45deg |
GaspardD | 11:bc24b3ba51a9 | 63 | #ifdef DLVV |
GaspardD | 22:26fc6e6f7a55 | 64 | AnalogIn anaDlvvG(CAPT_10_GAUCHE);//capteur ir avant droit 10 deg |
GaspardD | 22:26fc6e6f7a55 | 65 | AnalogIn anaDlvvD(CAPT_10_DROITE);//capteur ir coté droit 10 deg |
GaspardD | 22:26fc6e6f7a55 | 66 | AnalogIn anaDlvvFront(CAPT_DEVANT);//capteur ir avant |
GaspardD | 11:bc24b3ba51a9 | 67 | #endif |
GaspardD | 12:51b1b40cc017 | 68 | |
GaspardD | 29:fc984fe08ca7 | 69 | //piste |
ohlimi2 | 36:bccddd02966a | 70 | double largeurPiste90 = 150.0; |
ohlimi2 | 36:bccddd02966a | 71 | double largeurPiste45 = 150.0; |
GaspardD | 29:fc984fe08ca7 | 72 | double positionSurPiste90 = 75.0; |
GaspardD | 29:fc984fe08ca7 | 73 | double positionSurPiste90Prev = positionSurPiste90; |
GaspardD | 29:fc984fe08ca7 | 74 | double positionSurPiste45 = 75.0; |
GaspardD | 29:fc984fe08ca7 | 75 | double positionSurPiste45Prev = positionSurPiste45; |
GaspardD | 29:fc984fe08ca7 | 76 | |
ohlimi2 | 36:bccddd02966a | 77 | double derive45,derive90; |
GaspardD | 21:de7a0a47f8a3 | 78 | int lastDifferences90[NB_INTEGRAL_SAMPLES] = {0};//for integral correction |
GaspardD | 21:de7a0a47f8a3 | 79 | int lastDifferenceIndex = 0; |
GaspardD | 21:de7a0a47f8a3 | 80 | int integralSum; |
GaspardD | 12:51b1b40cc017 | 81 | |
GaspardD | 12:51b1b40cc017 | 82 | //Capteur vitesse |
GaspardD | 12:51b1b40cc017 | 83 | InterruptIn it_tachymeter(PA_11); |
GaspardD | 2:fd0ffe46a87d | 84 | |
GaspardD | 11:bc24b3ba51a9 | 85 | |
GaspardD | 11:bc24b3ba51a9 | 86 | //LIDAR |
GaspardD | 12:51b1b40cc017 | 87 | Serial serialLidar(PC_10,PC_11); // tx, rx |
GaspardD | 11:bc24b3ba51a9 | 88 | |
GaspardD | 11:bc24b3ba51a9 | 89 | int distLidar;// LiDAR actually measured distance value |
GaspardD | 23:04d393220daa | 90 | int distLidarPrev; |
GaspardD | 11:bc24b3ba51a9 | 91 | int strengthLidar;// LiDAR signal strength |
GaspardD | 23:04d393220daa | 92 | int strengthLidarPrev; |
GaspardD | 11:bc24b3ba51a9 | 93 | int check;// check numerical value storage |
GaspardD | 12:51b1b40cc017 | 94 | int i; |
GaspardD | 11:bc24b3ba51a9 | 95 | int uart[9];// store data measured by LiDAR |
GaspardD | 11:bc24b3ba51a9 | 96 | const int HEADER=0x59;// data package frame header |
GaspardD | 11:bc24b3ba51a9 | 97 | |
GaspardD | 11:bc24b3ba51a9 | 98 | //SPEED |
GaspardD | 29:fc984fe08ca7 | 99 | double maxSpeed_cmps = 0; |
ohlimi2 | 36:bccddd02966a | 100 | double tachySpeed_cmps = 0; //en cm/s |
GaspardD | 39:de3638276b7e | 101 | double tachyStepsRegister = 0; |
GaspardD | 29:fc984fe08ca7 | 102 | double tachySectionDist_cm = 0; |
ohlimi2 | 36:bccddd02966a | 103 | double tachyTotalDist_cm = 0.0; |
GaspardD | 8:1d8c3ca5e508 | 104 | |
GaspardD | 27:f8c3f1524a64 | 105 | #ifdef FREINAGE_ADAPTATIF |
GaspardD | 24:698fefbbee00 | 106 | Timer brakingTimer; |
GaspardD | 24:698fefbbee00 | 107 | int brakingDurationNeeded_us = 0; |
GaspardD | 27:f8c3f1524a64 | 108 | #endif |
GaspardD | 24:698fefbbee00 | 109 | |
GaspardD | 8:1d8c3ca5e508 | 110 | //Etats |
GaspardD | 8:1d8c3ca5e508 | 111 | MUR_ST st_murs; |
GaspardD | 21:de7a0a47f8a3 | 112 | MUR_ST st_tmpMurs; |
GaspardD | 11:bc24b3ba51a9 | 113 | SECTION_ST st_currentSection; |
GaspardD | 21:de7a0a47f8a3 | 114 | SECTION_ST st_tmpSection; |
GaspardD | 11:bc24b3ba51a9 | 115 | MAX_SPEED_ST st_maxSpeed; |
GaspardD | 21:de7a0a47f8a3 | 116 | MAX_SPEED_ST st_tmpMaxSpeed; |
GaspardD | 8:1d8c3ca5e508 | 117 | THROTTLE_ST st_thro; |
GaspardD | 21:de7a0a47f8a3 | 118 | THROTTLE_ST st_tmpThro; |
GaspardD | 11:bc24b3ba51a9 | 119 | #ifdef DLVV |
GaspardD | 11:bc24b3ba51a9 | 120 | OBSTACLE_ST st_obstacle; |
GaspardD | 11:bc24b3ba51a9 | 121 | #endif |
GaspardD | 11:bc24b3ba51a9 | 122 | |
GaspardD | 11:bc24b3ba51a9 | 123 | s_Section* p_sectionCourante = NULL; |
GaspardD | 44:69751c05a8f3 | 124 | bool dumped = false; |
GaspardD | 8:1d8c3ca5e508 | 125 | |
GaspardD | 19:771bf61be276 | 126 | |
GaspardD | 19:771bf61be276 | 127 | // +++++++++++++++++++++++++++++++++++++++++++ SAMPLING +++++++++++++++++++++++++++++++++++++++++++ |
GaspardD | 19:771bf61be276 | 128 | #ifdef SAMPLING |
GaspardD | 19:771bf61be276 | 129 | s_Sample history[TAILLE_SAMPLES]; |
GaspardD | 19:771bf61be276 | 130 | int indexSample = 0; |
GaspardD | 19:771bf61be276 | 131 | void initSamples(void) |
GaspardD | 19:771bf61be276 | 132 | { |
GaspardD | 19:771bf61be276 | 133 | for(int m=0; m<TAILLE_SAMPLES; m++) { |
GaspardD | 19:771bf61be276 | 134 | history[m].states.murs_dlvv = '0'; |
GaspardD | 19:771bf61be276 | 135 | history[m].states.section = '0'; |
GaspardD | 19:771bf61be276 | 136 | history[m].states.maxSpeed = '0'; |
GaspardD | 19:771bf61be276 | 137 | history[m].states.throttle = '0'; |
GaspardD | 19:771bf61be276 | 138 | history[m].time = 0; |
GaspardD | 29:fc984fe08ca7 | 139 | history[m].position45 = 0.0; |
GaspardD | 29:fc984fe08ca7 | 140 | history[m].position90 = 0.0; |
GaspardD | 29:fc984fe08ca7 | 141 | history[m].largeurPiste = 0.0; |
GaspardD | 29:fc984fe08ca7 | 142 | history[m].dist = 0.0; |
GaspardD | 21:de7a0a47f8a3 | 143 | history[m].pwm_thro_us = 0; |
GaspardD | 21:de7a0a47f8a3 | 144 | history[m].pwm_dir_us = 0; |
GaspardD | 23:04d393220daa | 145 | history[m].distLidar = 0; |
GaspardD | 23:04d393220daa | 146 | history[m].strLidar = 0; |
GaspardD | 19:771bf61be276 | 147 | } |
GaspardD | 21:de7a0a47f8a3 | 148 | #if DEBUG > 0 |
GaspardD | 19:771bf61be276 | 149 | pc.printf("[INIT SAMPLE DONE]\r\n"); |
GaspardD | 21:de7a0a47f8a3 | 150 | #endif |
GaspardD | 19:771bf61be276 | 151 | return; |
GaspardD | 19:771bf61be276 | 152 | } |
GaspardD | 19:771bf61be276 | 153 | void sampleLog(void) |
GaspardD | 19:771bf61be276 | 154 | { |
GaspardD | 23:04d393220daa | 155 | #ifdef DUMP_SAMPLIG_PERIOD |
GaspardD | 23:04d393220daa | 156 | if(timerLog.read_us() > DUMP_SAMPLIG_PERIOD) { |
GaspardD | 22:26fc6e6f7a55 | 157 | timerLog.reset(); |
GaspardD | 22:26fc6e6f7a55 | 158 | timerLog.start(); |
GaspardD | 23:04d393220daa | 159 | #endif |
GaspardD | 22:26fc6e6f7a55 | 160 | if(indexSample < TAILLE_SAMPLES) { |
GaspardD | 19:771bf61be276 | 161 | #ifdef DLVV |
GaspardD | 22:26fc6e6f7a55 | 162 | history[indexSample].states.murs_dlvv = (char)st_obstacle; |
GaspardD | 19:771bf61be276 | 163 | #else |
GaspardD | 22:26fc6e6f7a55 | 164 | history[indexSample].states.murs_dlvv = (char)st_murs; |
GaspardD | 19:771bf61be276 | 165 | #endif |
GaspardD | 22:26fc6e6f7a55 | 166 | history[indexSample].states.section = (char)st_currentSection; |
GaspardD | 22:26fc6e6f7a55 | 167 | history[indexSample].states.maxSpeed = (char)st_maxSpeed; |
GaspardD | 22:26fc6e6f7a55 | 168 | history[indexSample].states.throttle = (char)st_thro; |
GaspardD | 22:26fc6e6f7a55 | 169 | history[indexSample].time = timeSinceStart.read_us() ; |
GaspardD | 29:fc984fe08ca7 | 170 | history[indexSample].position45 = positionSurPiste45; |
GaspardD | 29:fc984fe08ca7 | 171 | history[indexSample].position90 = positionSurPiste90; |
ohlimi2 | 36:bccddd02966a | 172 | history[indexSample].largeurPiste = largeurPiste90; |
GaspardD | 22:26fc6e6f7a55 | 173 | history[indexSample].pwm_thro_us = pulseSpeed_us; |
GaspardD | 22:26fc6e6f7a55 | 174 | history[indexSample].pwm_dir_us = pulseDirection_us; |
GaspardD | 22:26fc6e6f7a55 | 175 | history[indexSample].dist = tachySectionDist_cm, |
GaspardD | 41:4dd36f607279 | 176 | history[indexSample].distLidar = distLidar; |
GaspardD | 23:04d393220daa | 177 | history[indexSample].strLidar = strengthLidar; |
GaspardD | 23:04d393220daa | 178 | indexSample++; |
GaspardD | 19:771bf61be276 | 179 | #if DEBUG > 0 |
ohlimi2 | 36:bccddd02966a | 180 | pc.printf("\r\nodo:%d dist = %.4lf \tstrength = %.4ld \tC45D: %.4lf C45G: %.4lf C90D: %.4lf C90G: %.4lf looptime: %.4lf micros",tachySectionDist_cm,distLidar,strengthLidar,distMurD45Moy,distMurG45Moy,distMurD90Moy,distMurG90Moy,timeSinceStart.read_us());// output signal strength value |
ohlimi2 | 36:bccddd02966a | 181 | pc.printf("\r\nstate Murs: %.4lf, state Section %.4lf, state MaxSpeed %.4lf, state Throttle %.4lf\r\n",st_murs,st_currentSection,st_maxSpeed,st_thro); |
ohlimi2 | 34:c98fd59c690a | 182 | //wait(2); |
GaspardD | 22:26fc6e6f7a55 | 183 | timeSinceStart.reset(); |
GaspardD | 22:26fc6e6f7a55 | 184 | timeSinceStart.start(); |
GaspardD | 19:771bf61be276 | 185 | #endif |
GaspardD | 22:26fc6e6f7a55 | 186 | } |
GaspardD | 22:26fc6e6f7a55 | 187 | return; |
GaspardD | 23:04d393220daa | 188 | #ifdef DUMP_SAMPLIG_PERIOD |
GaspardD | 19:771bf61be276 | 189 | } |
GaspardD | 23:04d393220daa | 190 | #endif |
GaspardD | 19:771bf61be276 | 191 | } |
GaspardD | 19:771bf61be276 | 192 | void transmitData(void) |
GaspardD | 19:771bf61be276 | 193 | { |
GaspardD | 21:de7a0a47f8a3 | 194 | #if DEBUG > 0 |
GaspardD | 19:771bf61be276 | 195 | pc.printf("[START TO TRANSMIT]\r\n"); |
GaspardD | 21:de7a0a47f8a3 | 196 | #endif |
GaspardD | 39:de3638276b7e | 197 | serialLidar.printf("time,position 45,position 90,largeur piste,pwm_thro_us,pwm_dir_us,dist,murs/dlvv,section,maxSpeed,throttle\r\n"); |
GaspardD | 19:771bf61be276 | 198 | for(int p=0; p<indexSample; p++) { |
GaspardD | 39:de3638276b7e | 199 | serialLidar.printf("%d,%.5f,%.5f,%.5f,%d,%d,%.5f,%d,%d,%d,%d\r\n", |
GaspardD | 21:de7a0a47f8a3 | 200 | history[p].time, |
GaspardD | 29:fc984fe08ca7 | 201 | history[p].position45, |
GaspardD | 29:fc984fe08ca7 | 202 | history[p].position90, |
GaspardD | 39:de3638276b7e | 203 | history[p].largeurPiste, |
GaspardD | 21:de7a0a47f8a3 | 204 | history[p].pwm_thro_us, |
GaspardD | 21:de7a0a47f8a3 | 205 | history[p].pwm_dir_us, |
GaspardD | 21:de7a0a47f8a3 | 206 | history[p].dist, |
GaspardD | 21:de7a0a47f8a3 | 207 | history[p].states.murs_dlvv, |
GaspardD | 21:de7a0a47f8a3 | 208 | history[p].states.section, |
GaspardD | 21:de7a0a47f8a3 | 209 | history[p].states.maxSpeed, |
GaspardD | 21:de7a0a47f8a3 | 210 | history[p].states.throttle); |
GaspardD | 19:771bf61be276 | 211 | } |
GaspardD | 19:771bf61be276 | 212 | return; |
GaspardD | 19:771bf61be276 | 213 | } |
GaspardD | 19:771bf61be276 | 214 | |
GaspardD | 19:771bf61be276 | 215 | #endif |
GaspardD | 19:771bf61be276 | 216 | |
GaspardD | 19:771bf61be276 | 217 | // +++++++++++++++++++++++++++++++++++++++++++ FUNCTION UTILS +++++++++++++++++++++++++++++++++++++++++++ |
GaspardD | 19:771bf61be276 | 218 | |
GaspardD | 19:771bf61be276 | 219 | #if DEBUG >= -1 |
GaspardD | 19:771bf61be276 | 220 | void pressed(void) |
GaspardD | 19:771bf61be276 | 221 | { |
GaspardD | 21:de7a0a47f8a3 | 222 | #if DEBUG > 0 |
GaspardD | 19:771bf61be276 | 223 | pc.printf("[BTN PRESSED]\r\n"); |
GaspardD | 21:de7a0a47f8a3 | 224 | #endif |
GaspardD | 44:69751c05a8f3 | 225 | if(!dumped) |
GaspardD | 44:69751c05a8f3 | 226 | { |
GaspardD | 19:771bf61be276 | 227 | transmitData(); |
GaspardD | 44:69751c05a8f3 | 228 | dumped = true; |
GaspardD | 44:69751c05a8f3 | 229 | }else{ |
GaspardD | 44:69751c05a8f3 | 230 | initSamples(); |
GaspardD | 44:69751c05a8f3 | 231 | p_sectionCourante = &p_section1; |
GaspardD | 44:69751c05a8f3 | 232 | dumped = false; |
GaspardD | 44:69751c05a8f3 | 233 | } |
GaspardD | 19:771bf61be276 | 234 | } |
GaspardD | 19:771bf61be276 | 235 | #endif |
GaspardD | 19:771bf61be276 | 236 | |
GaspardD | 29:fc984fe08ca7 | 237 | void initIntegrationTable() |
GaspardD | 29:fc984fe08ca7 | 238 | { |
GaspardD | 41:4dd36f607279 | 239 | for(int h=0; h<NB_INTEGRAL_SAMPLES; h++) { |
GaspardD | 29:fc984fe08ca7 | 240 | lastDifferences90[h] = 0; |
GaspardD | 29:fc984fe08ca7 | 241 | } |
GaspardD | 29:fc984fe08ca7 | 242 | return; |
GaspardD | 29:fc984fe08ca7 | 243 | } |
GaspardD | 29:fc984fe08ca7 | 244 | |
GaspardD | 21:de7a0a47f8a3 | 245 | |
GaspardD | 29:fc984fe08ca7 | 246 | double getShortDistMoy(AnalogIn* p,double* tab,int size) |
GaspardD | 11:bc24b3ba51a9 | 247 | { |
GaspardD | 29:fc984fe08ca7 | 248 | tab[index_fifo_ir] = 3.3 * (double)p->read(); // on convertit directement en volts |
GaspardD | 29:fc984fe08ca7 | 249 | //tension proportionelle à l'inverse de la distance en dessous de 2V |
GaspardD | 41:4dd36f607279 | 250 | if(tab[index_fifo_ir]< 0.1034) { |
GaspardD | 41:4dd36f607279 | 251 | tab[index_fifo_ir]= 0.11; |
GaspardD | 41:4dd36f607279 | 252 | } |
GaspardD | 39:de3638276b7e | 253 | tab[index_fifo_ir] = (11.3531/(tab[index_fifo_ir]-0.1034))-0.42; |
GaspardD | 29:fc984fe08ca7 | 254 | |
GaspardD | 29:fc984fe08ca7 | 255 | int sumMoy = 0; |
GaspardD | 29:fc984fe08ca7 | 256 | for(int k=0; k<size; k++) { |
GaspardD | 29:fc984fe08ca7 | 257 | sumMoy+=tab[k]; |
GaspardD | 29:fc984fe08ca7 | 258 | } |
GaspardD | 29:fc984fe08ca7 | 259 | return sumMoy/size; |
GaspardD | 29:fc984fe08ca7 | 260 | } |
GaspardD | 29:fc984fe08ca7 | 261 | |
GaspardD | 29:fc984fe08ca7 | 262 | double getDistMoy(AnalogIn* p,double* tab,int size) |
GaspardD | 29:fc984fe08ca7 | 263 | { |
ohlimi2 | 47:b17061738568 | 264 | double distcapteur = 0; |
ohlimi2 | 51:09ecba68d0cf | 265 | distcapteur = 1.0/(0.0161 * (double)p->read()); // on convertit directement en volts |
ohlimi2 | 51:09ecba68d0cf | 266 | //distcapteur = 1.0/(0.02 * (double)p->read()); // on convertit directement en volts |
GaspardD | 29:fc984fe08ca7 | 267 | //tension proportionelle à l'inverse de la distance |
ohlimi2 | 47:b17061738568 | 268 | //tab[index_fifo_ir] = 1.0/(0.0161 * (double)tab[index_fifo_ir]); |
ohlimi2 | 47:b17061738568 | 269 | //int sumMoy = 0; |
ohlimi2 | 47:b17061738568 | 270 | //for(int k=0; k<size; k++) { |
ohlimi2 | 47:b17061738568 | 271 | // sumMoy+=tab[k]; |
ohlimi2 | 47:b17061738568 | 272 | //} |
ohlimi2 | 47:b17061738568 | 273 | return distcapteur; |
GaspardD | 11:bc24b3ba51a9 | 274 | } |
GaspardD | 39:de3638276b7e | 275 | void tachyCheck() |
GaspardD | 39:de3638276b7e | 276 | { |
GaspardD | 41:4dd36f607279 | 277 | if(timerSinceTachy.read_us() > 500000) { |
GaspardD | 39:de3638276b7e | 278 | tachySpeed_cmps = 0.0; |
GaspardD | 39:de3638276b7e | 279 | } |
GaspardD | 41:4dd36f607279 | 280 | return; |
GaspardD | 39:de3638276b7e | 281 | } |
GaspardD | 39:de3638276b7e | 282 | |
GaspardD | 2:fd0ffe46a87d | 283 | |
GaspardD | 12:51b1b40cc017 | 284 | void it4cm() |
GaspardD | 12:51b1b40cc017 | 285 | { |
GaspardD | 39:de3638276b7e | 286 | //le timer sert de flag sur le freinage: |
GaspardD | 39:de3638276b7e | 287 | //si le biniou ne bouge plus, il n'essaye plus de freiner tant qu'il n'y a pas un nouveau calcul de la vitesse |
GaspardD | 39:de3638276b7e | 288 | //dans la fonction tachyCheck() >> quand il n'y a pas eu d'IT en 500 ms si la vitesse est inférieure à 0.16 m/s, elle sera considérée comme nulle. |
GaspardD | 39:de3638276b7e | 289 | |
ohlimi2 | 36:bccddd02966a | 290 | tachySectionDist_cm += TACHY_CM; |
ohlimi2 | 36:bccddd02966a | 291 | tachyTotalDist_cm += TACHY_CM; |
GaspardD | 39:de3638276b7e | 292 | tachySpeed_cmps = (TACHY_CM * 1000000.0)/(double)timerSinceTachy.read_us(); // a chaque IT on a parcouru 8 cm soit (8*1000000)/durée |
ohlimi2 | 36:bccddd02966a | 293 | #if DEBUG > 2 |
ohlimi2 | 36:bccddd02966a | 294 | pc.printf("IT: distance parcourue %.4lf , vitesse:%.4lf \r\n",tachyTotalDist_cm,tachySpeed_cmps); |
ohlimi2 | 36:bccddd02966a | 295 | #endif |
GaspardD | 39:de3638276b7e | 296 | timerSinceTachy.reset(); |
GaspardD | 39:de3638276b7e | 297 | timerSinceTachy.start(); |
ohlimi2 | 36:bccddd02966a | 298 | return; |
ohlimi2 | 36:bccddd02966a | 299 | |
GaspardD | 19:771bf61be276 | 300 | #if DEBUG > 0 |
GaspardD | 14:d471faa7d1a2 | 301 | pc.printf("IT tachy\r\n"); |
GaspardD | 14:d471faa7d1a2 | 302 | #endif |
GaspardD | 12:51b1b40cc017 | 303 | } |
GaspardD | 12:51b1b40cc017 | 304 | |
GaspardD | 12:51b1b40cc017 | 305 | void it_serial() |
GaspardD | 12:51b1b40cc017 | 306 | { |
GaspardD | 12:51b1b40cc017 | 307 | if(serialLidar.getc()==HEADER) { // determine data package frame header 0x59 |
GaspardD | 12:51b1b40cc017 | 308 | uart[0]=HEADER; |
GaspardD | 12:51b1b40cc017 | 309 | if(serialLidar.getc()==HEADER) { //determine data package frame header 0x59 |
GaspardD | 12:51b1b40cc017 | 310 | uart[1]=HEADER; |
GaspardD | 12:51b1b40cc017 | 311 | for(i=2; i<9; i++) { // store data to array |
GaspardD | 12:51b1b40cc017 | 312 | uart[i]=serialLidar.getc(); |
GaspardD | 12:51b1b40cc017 | 313 | } |
GaspardD | 12:51b1b40cc017 | 314 | check=uart[0]+uart[1]+uart[2]+uart[3]+uart[4]+uart[5]+uart[6]+uart[7]; |
GaspardD | 12:51b1b40cc017 | 315 | if(uart[8]==(check&0xff)) { // check the received data as per protocols |
GaspardD | 23:04d393220daa | 316 | distLidarPrev = distLidar; |
GaspardD | 12:51b1b40cc017 | 317 | distLidar=uart[2]+uart[3]*256;// calculate distance value |
GaspardD | 23:04d393220daa | 318 | strengthLidarPrev = strengthLidar; |
GaspardD | 12:51b1b40cc017 | 319 | strengthLidar=uart[4]+uart[5]*256;// calculate signal strength value |
GaspardD | 42:3f12252862b9 | 320 | timersinceSerial.reset(); |
GaspardD | 42:3f12252862b9 | 321 | timersinceSerial.start(); |
GaspardD | 12:51b1b40cc017 | 322 | } |
GaspardD | 12:51b1b40cc017 | 323 | } |
GaspardD | 12:51b1b40cc017 | 324 | } |
GaspardD | 12:51b1b40cc017 | 325 | } |
GaspardD | 19:771bf61be276 | 326 | // +++++++++++++++++++++++++++++++++++++++++++ STATES MACHINES +++++++++++++++++++++++++++++++++++++++++++ |
GaspardD | 19:771bf61be276 | 327 | |
GaspardD | 8:1d8c3ca5e508 | 328 | //########## INIT STATES MACHINES ########## |
GaspardD | 11:bc24b3ba51a9 | 329 | void mursInit(void) |
GaspardD | 8:1d8c3ca5e508 | 330 | { |
GaspardD | 39:de3638276b7e | 331 | #if DEBUG > 0 |
GaspardD | 13:af9a59ccf60b | 332 | pc.printf("Init Murs\r\n"); |
GaspardD | 13:af9a59ccf60b | 333 | #endif |
GaspardD | 13:af9a59ccf60b | 334 | timeSinceStart.start(); |
GaspardD | 29:fc984fe08ca7 | 335 | st_murs=REF_BIDIR; |
GaspardD | 19:771bf61be276 | 336 | PwmDirection.period_us(SPEED_PERIOD_US); |
GaspardD | 17:8c465656eea4 | 337 | PwmDirection.pulsewidth_us(DIRECTION_PULSE_MIDDLE);// milieu |
GaspardD | 8:1d8c3ca5e508 | 338 | return; |
GaspardD | 8:1d8c3ca5e508 | 339 | } |
GaspardD | 11:bc24b3ba51a9 | 340 | #ifdef DLVV |
GaspardD | 11:bc24b3ba51a9 | 341 | void obstacleInit(void) |
GaspardD | 8:1d8c3ca5e508 | 342 | { |
GaspardD | 19:771bf61be276 | 343 | #if DEBUG > 0 |
GaspardD | 13:af9a59ccf60b | 344 | pc.printf("Init Obstacle\r\n"); |
GaspardD | 13:af9a59ccf60b | 345 | #endif |
GaspardD | 29:fc984fe08ca7 | 346 | st_speedLimit=ALL_CLEAR; |
GaspardD | 8:1d8c3ca5e508 | 347 | return; |
GaspardD | 8:1d8c3ca5e508 | 348 | } |
GaspardD | 11:bc24b3ba51a9 | 349 | #endif |
GaspardD | 11:bc24b3ba51a9 | 350 | void sectionInit(void) |
GaspardD | 2:fd0ffe46a87d | 351 | { |
GaspardD | 19:771bf61be276 | 352 | #if DEBUG > 0 |
GaspardD | 13:af9a59ccf60b | 353 | pc.printf("Init Section\r\n"); |
GaspardD | 13:af9a59ccf60b | 354 | #endif |
GaspardD | 11:bc24b3ba51a9 | 355 | st_currentSection=ARRET; |
GaspardD | 14:d471faa7d1a2 | 356 | p_sectionCourante=&p_section1; |
GaspardD | 12:51b1b40cc017 | 357 | it_tachymeter.fall(&it4cm); |
GaspardD | 39:de3638276b7e | 358 | timerSinceTachy.start(); |
GaspardD | 39:de3638276b7e | 359 | tachySectionDist_cm = 0; |
GaspardD | 39:de3638276b7e | 360 | tachyStepsRegister = 0; |
GaspardD | 11:bc24b3ba51a9 | 361 | |
GaspardD | 23:04d393220daa | 362 | //section de test 1 |
ohlimi2 | 46:9262b07b0833 | 363 | p_section1.nextSection =&p_section3;// &p_section2; |
GaspardD | 29:fc984fe08ca7 | 364 | p_section1.consigne_position = 75.0; |
GaspardD | 39:de3638276b7e | 365 | p_section1.targetSpeed_cmps = 400.0; |
GaspardD | 29:fc984fe08ca7 | 366 | p_section1.slowSpeed_cmps = 328.0; |
GaspardD | 21:de7a0a47f8a3 | 367 | p_section1.coef_p_speed = 1; |
GaspardD | 29:fc984fe08ca7 | 368 | p_section1.lidarWarningDist_cm = 120.0; |
ohlimi2 | 46:9262b07b0833 | 369 | p_section1.lng_section_cm = 1000.0;//10m |
ohlimi2 | 51:09ecba68d0cf | 370 | p_section1.coef_p90 = 4.0; |
ohlimi2 | 51:09ecba68d0cf | 371 | p_section1.coef_d90 = 0.0; |
ohlimi2 | 51:09ecba68d0cf | 372 | p_section1.coef_i90 = 0.0; |
ohlimi2 | 51:09ecba68d0cf | 373 | p_section1.coef_p45 = 0.0; |
ohlimi2 | 51:09ecba68d0cf | 374 | p_section1.coef_d45 = 0.0; |
ohlimi2 | 51:09ecba68d0cf | 375 | p_section1.coef_i45 = 0.0; |
GaspardD | 39:de3638276b7e | 376 | |
GaspardD | 39:de3638276b7e | 377 | //section de test |
ohlimi2 | 46:9262b07b0833 | 378 | p_section2.nextSection = &p_section3; |
GaspardD | 39:de3638276b7e | 379 | p_section2.consigne_position = 75.0; |
GaspardD | 39:de3638276b7e | 380 | p_section2.targetSpeed_cmps = 328.0; |
GaspardD | 39:de3638276b7e | 381 | p_section2.slowSpeed_cmps = 328.0; |
GaspardD | 39:de3638276b7e | 382 | p_section2.coef_p_speed = 1.0; |
GaspardD | 39:de3638276b7e | 383 | p_section2.lidarWarningDist_cm = 300.0; |
GaspardD | 39:de3638276b7e | 384 | p_section2.lng_section_cm = 200.0;//2m |
ohlimi2 | 51:09ecba68d0cf | 385 | p_section2.coef_p90 = 1.0; |
ohlimi2 | 51:09ecba68d0cf | 386 | p_section2.coef_d90 = 0.0; |
ohlimi2 | 51:09ecba68d0cf | 387 | p_section2.coef_i90 = 0.0; |
ohlimi2 | 51:09ecba68d0cf | 388 | p_section2.coef_p45 = 1.0; |
ohlimi2 | 51:09ecba68d0cf | 389 | p_section2.coef_d45 = 0.0; |
ohlimi2 | 51:09ecba68d0cf | 390 | p_section2.coef_i45 = 0.0; |
GaspardD | 23:04d393220daa | 391 | |
ohlimi2 | 46:9262b07b0833 | 392 | p_section3.nextSection = NULL; |
ohlimi2 | 46:9262b07b0833 | 393 | p_section3.consigne_position = 75.0; |
ohlimi2 | 46:9262b07b0833 | 394 | p_section3.targetSpeed_cmps = 0.0; |
ohlimi2 | 46:9262b07b0833 | 395 | p_section3.slowSpeed_cmps = 0.0; |
ohlimi2 | 46:9262b07b0833 | 396 | p_section3.coef_p_speed = 1.0; |
ohlimi2 | 46:9262b07b0833 | 397 | p_section3.lidarWarningDist_cm = 300.0; |
ohlimi2 | 46:9262b07b0833 | 398 | p_section3.lng_section_cm = 200.0;//2m |
ohlimi2 | 51:09ecba68d0cf | 399 | p_section3.coef_p90 = 1.0; |
ohlimi2 | 51:09ecba68d0cf | 400 | p_section3.coef_d90 = 0.0; |
ohlimi2 | 51:09ecba68d0cf | 401 | p_section3.coef_i90 = 0.0; |
ohlimi2 | 51:09ecba68d0cf | 402 | p_section3.coef_p45 = 1.0; |
ohlimi2 | 51:09ecba68d0cf | 403 | p_section3.coef_d45 = 0.0; |
ohlimi2 | 51:09ecba68d0cf | 404 | p_section3.coef_i45 = 0.0; |
ohlimi2 | 46:9262b07b0833 | 405 | |
GaspardD | 8:1d8c3ca5e508 | 406 | return; |
GaspardD | 8:1d8c3ca5e508 | 407 | } |
GaspardD | 11:bc24b3ba51a9 | 408 | |
GaspardD | 11:bc24b3ba51a9 | 409 | void maxSpeedInit(void) |
GaspardD | 11:bc24b3ba51a9 | 410 | { |
GaspardD | 19:771bf61be276 | 411 | #if DEBUG > 0 |
GaspardD | 13:af9a59ccf60b | 412 | pc.printf("Init Max Speed\r\n"); |
GaspardD | 13:af9a59ccf60b | 413 | #endif |
GaspardD | 11:bc24b3ba51a9 | 414 | st_maxSpeed=SPEED_MAX; |
GaspardD | 11:bc24b3ba51a9 | 415 | maxSpeed_cmps= p_sectionCourante->targetSpeed_cmps; |
GaspardD | 11:bc24b3ba51a9 | 416 | serialLidar.baud(115200); |
GaspardD | 14:d471faa7d1a2 | 417 | serialLidar.attach(&it_serial); |
GaspardD | 11:bc24b3ba51a9 | 418 | return; |
GaspardD | 11:bc24b3ba51a9 | 419 | } |
GaspardD | 11:bc24b3ba51a9 | 420 | |
GaspardD | 11:bc24b3ba51a9 | 421 | void throttleInit(void) |
GaspardD | 8:1d8c3ca5e508 | 422 | { |
GaspardD | 19:771bf61be276 | 423 | #if DEBUG > 0 |
GaspardD | 13:af9a59ccf60b | 424 | pc.printf("Init Throttle\r\n"); |
GaspardD | 13:af9a59ccf60b | 425 | #endif |
GaspardD | 21:de7a0a47f8a3 | 426 | st_thro = REGULATION_SPEED; |
ohlimi2 | 36:bccddd02966a | 427 | PwmMotor.period_us(DIRECTION_PERIOD_MS); //20 ms is default |
GaspardD | 19:771bf61be276 | 428 | PwmMotor.pulsewidth_us(1000);//MIN |
GaspardD | 12:51b1b40cc017 | 429 | wait(3); |
GaspardD | 19:771bf61be276 | 430 | PwmMotor.pulsewidth_us(2000);//MAX |
GaspardD | 12:51b1b40cc017 | 431 | wait(1); |
GaspardD | 19:771bf61be276 | 432 | PwmMotor.pulsewidth_us(1500);//ZEROING |
GaspardD | 12:51b1b40cc017 | 433 | wait(1); |
GaspardD | 19:771bf61be276 | 434 | pulseSpeed_us = INITAL_PULSE_SPEED_US; |
GaspardD | 19:771bf61be276 | 435 | #if DEBUG > 0 |
ohlimi2 | 36:bccddd02966a | 436 | pc.printf("temps init: %.4lf micros\r\n",timeSinceStart.read_us()); |
ohlimi2 | 36:bccddd02966a | 437 | pc.printf("\r\nStates INIT: state Murs: %.4lf, state Section %.4lf, state MaxSpeed %.4lf, state Throttle %.4lf\r\n",st_murs,st_currentSection,st_maxSpeed,st_thro); |
GaspardD | 13:af9a59ccf60b | 438 | timeSinceStart.reset(); |
GaspardD | 13:af9a59ccf60b | 439 | timeSinceStart.start(); |
GaspardD | 13:af9a59ccf60b | 440 | #endif |
GaspardD | 23:04d393220daa | 441 | #ifdef DUMP_SAMPLIG_PERIOD |
GaspardD | 22:26fc6e6f7a55 | 442 | timerLog.start(); |
GaspardD | 22:26fc6e6f7a55 | 443 | #endif |
GaspardD | 22:26fc6e6f7a55 | 444 | |
GaspardD | 8:1d8c3ca5e508 | 445 | return; |
GaspardD | 8:1d8c3ca5e508 | 446 | } |
GaspardD | 2:fd0ffe46a87d | 447 | |
GaspardD | 8:1d8c3ca5e508 | 448 | |
GaspardD | 8:1d8c3ca5e508 | 449 | //########## UPDATE STATES ########## |
GaspardD | 11:bc24b3ba51a9 | 450 | void mursUpdate(void) |
GaspardD | 2:fd0ffe46a87d | 451 | { |
GaspardD | 14:d471faa7d1a2 | 452 | #if (DEBUG > 3) |
GaspardD | 14:d471faa7d1a2 | 453 | pc.printf("\r\nUpdate MURS\r\n"); |
GaspardD | 14:d471faa7d1a2 | 454 | #endif |
GaspardD | 11:bc24b3ba51a9 | 455 | //lectures |
GaspardD | 29:fc984fe08ca7 | 456 | |
GaspardD | 29:fc984fe08ca7 | 457 | distMurG45Moy = getDistMoy(&anaG45,distMurG45,NB_ECHANTILLONS_IR); |
GaspardD | 29:fc984fe08ca7 | 458 | distMurD45Moy = getDistMoy(&anaD45,distMurD45,NB_ECHANTILLONS_IR); |
GaspardD | 29:fc984fe08ca7 | 459 | distMurG90Moy = getDistMoy(&anaG90,distMurG90,NB_ECHANTILLONS_IR); |
ohlimi2 | 36:bccddd02966a | 460 | distMurD90Moy = getDistMoy(&anaD90,distMurD90,NB_ECHANTILLONS_IR); |
GaspardD | 39:de3638276b7e | 461 | shortDistMurG90Moy = getShortDistMoy(&anaShortG90,shortDistMurD90,NB_ECHANTILLONS_IR); |
GaspardD | 39:de3638276b7e | 462 | shortDistMurD90Moy = getShortDistMoy(&anaShortD90,shortDistMurD90,NB_ECHANTILLONS_IR); |
GaspardD | 11:bc24b3ba51a9 | 463 | index_fifo_ir = (index_fifo_ir+1)%NB_ECHANTILLONS_IR; |
GaspardD | 29:fc984fe08ca7 | 464 | |
ohlimi2 | 36:bccddd02966a | 465 | |
GaspardD | 41:4dd36f607279 | 466 | trueDistMurD90Moy = distMurD90Moy; |
GaspardD | 41:4dd36f607279 | 467 | trueDistMurG90Moy = distMurG90Moy; |
GaspardD | 39:de3638276b7e | 468 | |
GaspardD | 41:4dd36f607279 | 469 | if(shortDistMurG90Moy < DIST_MIN_LONG_CM) { |
GaspardD | 29:fc984fe08ca7 | 470 | trueDistMurG90Moy = shortDistMurG90Moy; |
GaspardD | 41:4dd36f607279 | 471 | } else { |
GaspardD | 29:fc984fe08ca7 | 472 | trueDistMurG90Moy = distMurG90Moy; |
GaspardD | 29:fc984fe08ca7 | 473 | } |
GaspardD | 41:4dd36f607279 | 474 | if(shortDistMurD90Moy < DIST_MIN_LONG_CM) { |
GaspardD | 29:fc984fe08ca7 | 475 | trueDistMurD90Moy = shortDistMurD90Moy; |
GaspardD | 41:4dd36f607279 | 476 | } else { |
GaspardD | 29:fc984fe08ca7 | 477 | trueDistMurD90Moy = distMurD90Moy; |
GaspardD | 39:de3638276b7e | 478 | } |
ohlimi2 | 36:bccddd02966a | 479 | |
GaspardD | 29:fc984fe08ca7 | 480 | |
GaspardD | 29:fc984fe08ca7 | 481 | #ifdef DLVV |
GaspardD | 29:fc984fe08ca7 | 482 | switch (st_obstacle) { |
GaspardD | 41:4dd36f607279 | 483 | case FRONT_OBSTRUCTED: |
GaspardD | 41:4dd36f607279 | 484 | st_tmpMurs = REF_A_GAUCHE; |
GaspardD | 41:4dd36f607279 | 485 | return; |
GaspardD | 41:4dd36f607279 | 486 | case RIGHT_OBSTRUCTED: |
GaspardD | 41:4dd36f607279 | 487 | st_tmpMurs = REF_A_GAUCHE; |
GaspardD | 41:4dd36f607279 | 488 | return; |
GaspardD | 41:4dd36f607279 | 489 | case LEFT_OBSTRUCTED: |
GaspardD | 41:4dd36f607279 | 490 | st_tmpMurs = REF_A_DROITE; |
GaspardD | 41:4dd36f607279 | 491 | return; |
GaspardD | 41:4dd36f607279 | 492 | default: |
GaspardD | 41:4dd36f607279 | 493 | break; |
GaspardD | 29:fc984fe08ca7 | 494 | } |
GaspardD | 29:fc984fe08ca7 | 495 | |
GaspardD | 29:fc984fe08ca7 | 496 | #endif |
GaspardD | 41:4dd36f607279 | 497 | st_tmpMurs = REF_BIDIR; |
GaspardD | 29:fc984fe08ca7 | 498 | |
GaspardD | 41:4dd36f607279 | 499 | st_murs = st_tmpMurs; |
GaspardD | 12:51b1b40cc017 | 500 | |
GaspardD | 8:1d8c3ca5e508 | 501 | return; |
GaspardD | 8:1d8c3ca5e508 | 502 | } |
GaspardD | 11:bc24b3ba51a9 | 503 | #ifdef DLVV |
GaspardD | 11:bc24b3ba51a9 | 504 | void obstacleUpdate(void) |
GaspardD | 8:1d8c3ca5e508 | 505 | { |
GaspardD | 8:1d8c3ca5e508 | 506 | return; |
GaspardD | 8:1d8c3ca5e508 | 507 | } |
GaspardD | 11:bc24b3ba51a9 | 508 | #endif |
GaspardD | 11:bc24b3ba51a9 | 509 | |
GaspardD | 11:bc24b3ba51a9 | 510 | void sectionUpdate(void) |
GaspardD | 8:1d8c3ca5e508 | 511 | { |
GaspardD | 14:d471faa7d1a2 | 512 | #if (DEBUG > 3) |
GaspardD | 14:d471faa7d1a2 | 513 | pc.printf("\r\nUpdate Section\r\n"); |
GaspardD | 14:d471faa7d1a2 | 514 | #endif |
GaspardD | 43:d2164ee3336a | 515 | |
GaspardD | 43:d2164ee3336a | 516 | if(p_sectionCourante == NULL) { |
GaspardD | 43:d2164ee3336a | 517 | st_tmpSection = ARRET; |
GaspardD | 43:d2164ee3336a | 518 | } else { |
GaspardD | 43:d2164ee3336a | 519 | |
GaspardD | 43:d2164ee3336a | 520 | switch (st_currentSection) { |
GaspardD | 43:d2164ee3336a | 521 | case RUNNING_SECTION: |
GaspardD | 43:d2164ee3336a | 522 | if(tachySectionDist_cm > p_sectionCourante->lng_section_cm) { //on pourrait rajouter un test lidar |
GaspardD | 43:d2164ee3336a | 523 | st_tmpSection = LOADING_SECTION; |
GaspardD | 43:d2164ee3336a | 524 | } else { |
GaspardD | 43:d2164ee3336a | 525 | return; |
GaspardD | 43:d2164ee3336a | 526 | } |
GaspardD | 43:d2164ee3336a | 527 | break; |
GaspardD | 43:d2164ee3336a | 528 | case LOADING_SECTION: |
GaspardD | 43:d2164ee3336a | 529 | if(p_sectionCourante != NULL) { //la section a ete chargee dans sectionOutput |
GaspardD | 43:d2164ee3336a | 530 | st_tmpSection = RUNNING_SECTION; |
GaspardD | 43:d2164ee3336a | 531 | } else { |
GaspardD | 43:d2164ee3336a | 532 | st_tmpSection=ARRET; |
GaspardD | 43:d2164ee3336a | 533 | } |
GaspardD | 43:d2164ee3336a | 534 | break; |
GaspardD | 43:d2164ee3336a | 535 | case ARRET: |
GaspardD | 43:d2164ee3336a | 536 | if(p_sectionCourante != NULL) { |
GaspardD | 43:d2164ee3336a | 537 | st_tmpSection = RUNNING_SECTION; |
GaspardD | 43:d2164ee3336a | 538 | } else { |
GaspardD | 43:d2164ee3336a | 539 | return; |
GaspardD | 43:d2164ee3336a | 540 | } |
GaspardD | 43:d2164ee3336a | 541 | break; |
GaspardD | 43:d2164ee3336a | 542 | default: |
GaspardD | 43:d2164ee3336a | 543 | break; |
GaspardD | 43:d2164ee3336a | 544 | } |
GaspardD | 11:bc24b3ba51a9 | 545 | } |
GaspardD | 11:bc24b3ba51a9 | 546 | st_currentSection = st_tmpSection; |
GaspardD | 8:1d8c3ca5e508 | 547 | return; |
GaspardD | 8:1d8c3ca5e508 | 548 | } |
GaspardD | 8:1d8c3ca5e508 | 549 | |
GaspardD | 11:bc24b3ba51a9 | 550 | void maxSpeedUpdate(void) |
GaspardD | 8:1d8c3ca5e508 | 551 | { |
GaspardD | 14:d471faa7d1a2 | 552 | #if (DEBUG > 3) |
GaspardD | 14:d471faa7d1a2 | 553 | pc.printf("\r\nUpdate MaxSpeed\r\n"); |
GaspardD | 14:d471faa7d1a2 | 554 | #endif |
GaspardD | 45:7d67809bd7bf | 555 | if(p_sectionCourante == NULL) { |
GaspardD | 43:d2164ee3336a | 556 | st_tmpMaxSpeed = BLOCKED; |
GaspardD | 43:d2164ee3336a | 557 | } else if(st_maxSpeed == BLOCKED && strengthLidar > LIDAR_STRENGTH_THRESOLD && distLidar < p_sectionCourante->lidarWarningDist_cm) { |
GaspardD | 41:4dd36f607279 | 558 | st_tmpMaxSpeed = BLOCKED; |
GaspardD | 41:4dd36f607279 | 559 | } else if( strengthLidar > LIDAR_STRENGTH_THRESOLD ) { |
GaspardD | 23:04d393220daa | 560 | if( distLidar > p_sectionCourante->lidarWarningDist_cm ) { |
GaspardD | 19:771bf61be276 | 561 | st_tmpMaxSpeed = SPEED_MAX; |
GaspardD | 29:fc984fe08ca7 | 562 | } else if( strengthLidar > LIDAR_STRENGTH_THRESOLD && |
GaspardD | 24:698fefbbee00 | 563 | strengthLidarPrev > LIDAR_STRENGTH_THRESOLD && |
GaspardD | 24:698fefbbee00 | 564 | distLidar < p_sectionCourante->lidarWarningDist_cm && |
GaspardD | 41:4dd36f607279 | 565 | distLidarPrev-distLidar > 3) { |
GaspardD | 21:de7a0a47f8a3 | 566 | st_tmpMaxSpeed = BLOCKED; |
GaspardD | 41:4dd36f607279 | 567 | } else { |
GaspardD | 24:698fefbbee00 | 568 | st_tmpMaxSpeed = SPEED_WARNING; |
GaspardD | 24:698fefbbee00 | 569 | } |
GaspardD | 21:de7a0a47f8a3 | 570 | } else { |
GaspardD | 11:bc24b3ba51a9 | 571 | st_tmpMaxSpeed = SPEED_MAX; |
GaspardD | 11:bc24b3ba51a9 | 572 | } |
GaspardD | 11:bc24b3ba51a9 | 573 | |
GaspardD | 11:bc24b3ba51a9 | 574 | st_maxSpeed = st_tmpMaxSpeed; |
GaspardD | 11:bc24b3ba51a9 | 575 | return; |
GaspardD | 11:bc24b3ba51a9 | 576 | } |
GaspardD | 11:bc24b3ba51a9 | 577 | |
GaspardD | 11:bc24b3ba51a9 | 578 | void throttleUpdate(void) |
GaspardD | 11:bc24b3ba51a9 | 579 | { |
GaspardD | 14:d471faa7d1a2 | 580 | #if (DEBUG > 3) |
GaspardD | 14:d471faa7d1a2 | 581 | pc.printf("\r\nUpdate Throttle\r\n"); |
GaspardD | 14:d471faa7d1a2 | 582 | #endif |
GaspardD | 11:bc24b3ba51a9 | 583 | switch (st_thro) { |
GaspardD | 21:de7a0a47f8a3 | 584 | case REGULATION_SPEED: |
GaspardD | 24:698fefbbee00 | 585 | if( st_currentSection == ARRET || |
GaspardD | 41:4dd36f607279 | 586 | st_maxSpeed == BLOCKED ) { |
GaspardD | 19:771bf61be276 | 587 | st_tmpThro = BRAKING; |
GaspardD | 29:fc984fe08ca7 | 588 | } |
GaspardD | 27:f8c3f1524a64 | 589 | #ifdef FREINAGE_ADAPTATIF |
GaspardD | 41:4dd36f607279 | 590 | else if(tachySpeed_cmps > (maxSpeed_cmps + SPEED_DELTA_CMPS)) { |
GaspardD | 24:698fefbbee00 | 591 | st_tmpThro = BRAKING; |
GaspardD | 29:fc984fe08ca7 | 592 | brakingDurationNeeded_us = 10000.0 * MASSE_BINIOU_KG *((tachySpeed_cmps-maxSpeed_cmps)*(tachySpeed_cmps+maxSpeed_cmps)) / (PUISSANCE_FREINAGE_W *2) ;//vitesse en m/s et temps en us |
GaspardD | 24:698fefbbee00 | 593 | brakingTimer.reset(); |
GaspardD | 24:698fefbbee00 | 594 | brakingTimer.start(); |
GaspardD | 27:f8c3f1524a64 | 595 | } |
GaspardD | 27:f8c3f1524a64 | 596 | #endif |
GaspardD | 41:4dd36f607279 | 597 | else { |
GaspardD | 19:771bf61be276 | 598 | return; |
GaspardD | 19:771bf61be276 | 599 | } |
GaspardD | 19:771bf61be276 | 600 | break; |
GaspardD | 16:63690703b5b6 | 601 | case BRAKING: |
GaspardD | 42:3f12252862b9 | 602 | if(st_maxSpeed == BLOCKED && timersinceSerial.read_us() > 200000) { |
GaspardD | 42:3f12252862b9 | 603 | p_sectionCourante= NULL; |
GaspardD | 42:3f12252862b9 | 604 | st_tmpThro = STOPPED; |
GaspardD | 42:3f12252862b9 | 605 | } else if( st_maxSpeed == BLOCKED |
GaspardD | 41:4dd36f607279 | 606 | #ifdef FREINAGE_ADAPTATIF |
GaspardD | 42:3f12252862b9 | 607 | || brakingTimer.read_us() < brakingDurationNeeded_us |
GaspardD | 41:4dd36f607279 | 608 | #endif |
GaspardD | 42:3f12252862b9 | 609 | ) { |
GaspardD | 23:04d393220daa | 610 | st_tmpThro = BRAKING; |
GaspardD | 41:4dd36f607279 | 611 | } else if(st_currentSection == ARRET) { |
GaspardD | 21:de7a0a47f8a3 | 612 | st_tmpThro = STOPPED; |
GaspardD | 41:4dd36f607279 | 613 | } else { |
GaspardD | 41:4dd36f607279 | 614 | #ifdef FREINAGE_ADAPTATIF |
GaspardD | 24:698fefbbee00 | 615 | brakingDurationNeeded_us = 0; |
GaspardD | 41:4dd36f607279 | 616 | #endif |
GaspardD | 21:de7a0a47f8a3 | 617 | st_tmpThro = REGULATION_SPEED; |
GaspardD | 21:de7a0a47f8a3 | 618 | } |
GaspardD | 19:771bf61be276 | 619 | break; |
GaspardD | 19:771bf61be276 | 620 | case STOPPED: |
GaspardD | 19:771bf61be276 | 621 | if(st_currentSection == RUNNING_SECTION) { |
GaspardD | 22:26fc6e6f7a55 | 622 | st_tmpThro = REGULATION_SPEED; |
GaspardD | 19:771bf61be276 | 623 | } else { |
GaspardD | 19:771bf61be276 | 624 | st_tmpThro = STOPPED; |
GaspardD | 16:63690703b5b6 | 625 | } |
GaspardD | 19:771bf61be276 | 626 | break; |
GaspardD | 19:771bf61be276 | 627 | default: |
GaspardD | 19:771bf61be276 | 628 | break; |
GaspardD | 11:bc24b3ba51a9 | 629 | } |
GaspardD | 11:bc24b3ba51a9 | 630 | st_thro = st_tmpThro; |
GaspardD | 8:1d8c3ca5e508 | 631 | return; |
GaspardD | 8:1d8c3ca5e508 | 632 | } |
GaspardD | 2:fd0ffe46a87d | 633 | |
GaspardD | 8:1d8c3ca5e508 | 634 | //########## OUTPUT STATES ########## |
GaspardD | 11:bc24b3ba51a9 | 635 | //updating output parameters |
GaspardD | 11:bc24b3ba51a9 | 636 | void mursOutput(void) |
GaspardD | 12:51b1b40cc017 | 637 | { |
GaspardD | 43:d2164ee3336a | 638 | if(p_sectionCourante != NULL) { |
GaspardD | 43:d2164ee3336a | 639 | //pour dériver |
GaspardD | 43:d2164ee3336a | 640 | positionSurPiste45Prev = positionSurPiste45; |
GaspardD | 43:d2164ee3336a | 641 | positionSurPiste90Prev = positionSurPiste90; |
GaspardD | 14:d471faa7d1a2 | 642 | #if (DEBUG > 3) |
GaspardD | 43:d2164ee3336a | 643 | pc.printf("\r\n Output MURS\r\n"); |
GaspardD | 14:d471faa7d1a2 | 644 | #endif |
GaspardD | 23:04d393220daa | 645 | |
GaspardD | 43:d2164ee3336a | 646 | switch (st_murs) { |
GaspardD | 43:d2164ee3336a | 647 | case REF_A_GAUCHE://par defaut, on compte à partir de la bordure gauche |
GaspardD | 43:d2164ee3336a | 648 | largeurPiste90 = 150.0; |
GaspardD | 43:d2164ee3336a | 649 | positionSurPiste90 = ( trueDistMurG90Moy + DEMI_LARGEUR_BINIOU_CM ); |
GaspardD | 43:d2164ee3336a | 650 | positionSurPiste45 = ( distMurG45Moy * 1.414214/2.0 ) + DEMI_LARGEUR_BINIOU_CM; |
GaspardD | 39:de3638276b7e | 651 | #ifdef OMAR |
GaspardD | 43:d2164ee3336a | 652 | pc.printf("REF_A_GAUCHE\r\n"); |
GaspardD | 39:de3638276b7e | 653 | #endif |
GaspardD | 43:d2164ee3336a | 654 | break; |
GaspardD | 43:d2164ee3336a | 655 | case REF_A_DROITE://par defaut, on compte à partir de la bordure gauche |
GaspardD | 43:d2164ee3336a | 656 | largeurPiste90 = 150.0; |
GaspardD | 43:d2164ee3336a | 657 | positionSurPiste90 = largeurPiste90 - ( DEMI_LARGEUR_BINIOU_CM + trueDistMurD90Moy ) ; |
ohlimi2 | 47:b17061738568 | 658 | positionSurPiste45 = largeurPiste90 - ( distMurD45Moy * (1.414214)/2.0 ) + DEMI_LARGEUR_BINIOU_CM; |
GaspardD | 39:de3638276b7e | 659 | #ifdef OMAR |
GaspardD | 43:d2164ee3336a | 660 | pc.printf("REF_A_DROITE\r\n"); |
GaspardD | 39:de3638276b7e | 661 | #endif |
GaspardD | 43:d2164ee3336a | 662 | break; |
GaspardD | 43:d2164ee3336a | 663 | default://REF_BIDIR |
GaspardD | 43:d2164ee3336a | 664 | largeurPiste90 = trueDistMurG90Moy + trueDistMurD90Moy ; |
GaspardD | 43:d2164ee3336a | 665 | largeurPiste45 = distMurG45Moy + distMurD45Moy ; |
GaspardD | 43:d2164ee3336a | 666 | positionSurPiste90 = (trueDistMurG90Moy ); |
GaspardD | 43:d2164ee3336a | 667 | positionSurPiste45 = (distMurG45Moy); |
GaspardD | 39:de3638276b7e | 668 | #ifdef OMAR |
GaspardD | 43:d2164ee3336a | 669 | pc.printf("REF_BIDIR\r\n"); |
GaspardD | 39:de3638276b7e | 670 | #endif |
GaspardD | 43:d2164ee3336a | 671 | break; |
GaspardD | 43:d2164ee3336a | 672 | } |
GaspardD | 23:04d393220daa | 673 | |
GaspardD | 22:26fc6e6f7a55 | 674 | |
GaspardD | 43:d2164ee3336a | 675 | //deriv correction |
GaspardD | 43:d2164ee3336a | 676 | derive45 = positionSurPiste45 - positionSurPiste45Prev; |
GaspardD | 43:d2164ee3336a | 677 | derive90 = positionSurPiste90 - positionSurPiste90Prev; |
GaspardD | 39:de3638276b7e | 678 | |
GaspardD | 39:de3638276b7e | 679 | #ifdef OMAR/* |
GaspardD | 43:d2164ee3336a | 680 | pc.printf("derive45 => %.4lf \r\n ",derive45); |
GaspardD | 43:d2164ee3336a | 681 | pc.printf("derive90 => %.4lf \r\n ",derive90); |
GaspardD | 43:d2164ee3336a | 682 | pc.printf("distMurG45Moy => %.4lf \r\n ",distMurG45Moy); |
GaspardD | 43:d2164ee3336a | 683 | pc.printf("distMurD45Moy => %.4lf \r\n ",distMurD45Moy); |
GaspardD | 43:d2164ee3336a | 684 | pc.printf("trueDistMurG90Moy => %.4lf \r\n ",trueDistMurG90Moy); |
GaspardD | 43:d2164ee3336a | 685 | pc.printf("trueDistMurD90Moy => %.4lf \r\n ",trueDistMurD90Moy); |
GaspardD | 43:d2164ee3336a | 686 | pc.printf("positionSurPiste90 => %.4lf \r\n ",positionSurPiste90); |
GaspardD | 43:d2164ee3336a | 687 | pc.printf("positionSurPiste45 => %.4lf \r\n ",positionSurPiste45); |
GaspardD | 43:d2164ee3336a | 688 | pc.printf("largeurPiste90 => %.4lf \r\n ",largeurPiste90);*/ |
GaspardD | 39:de3638276b7e | 689 | #endif |
GaspardD | 39:de3638276b7e | 690 | |
GaspardD | 43:d2164ee3336a | 691 | //integral correction |
GaspardD | 43:d2164ee3336a | 692 | lastDifferences90[lastDifferenceIndex] = (p_sectionCourante->consigne_position - positionSurPiste90); |
GaspardD | 43:d2164ee3336a | 693 | integralSum=0; |
GaspardD | 43:d2164ee3336a | 694 | for(int f=0; f<NB_INTEGRAL_SAMPLES; f++) { |
GaspardD | 43:d2164ee3336a | 695 | integralSum+=lastDifferences90[f]; |
GaspardD | 43:d2164ee3336a | 696 | } |
GaspardD | 43:d2164ee3336a | 697 | lastDifferenceIndex = (lastDifferenceIndex + 1)%NB_INTEGRAL_SAMPLES; |
GaspardD | 39:de3638276b7e | 698 | |
GaspardD | 41:4dd36f607279 | 699 | |
GaspardD | 41:4dd36f607279 | 700 | |
GaspardD | 41:4dd36f607279 | 701 | |
GaspardD | 43:d2164ee3336a | 702 | //application des coefficients |
GaspardD | 41:4dd36f607279 | 703 | |
GaspardD | 43:d2164ee3336a | 704 | pulseDirection_us = (int)( |
ohlimi2 | 51:09ecba68d0cf | 705 | ((positionSurPiste45 - (largeurPiste45/2)) * p_sectionCourante->coef_p45) |
ohlimi2 | 51:09ecba68d0cf | 706 | + ((positionSurPiste90 - (largeurPiste90/2)) * p_sectionCourante->coef_p90) |
ohlimi2 | 51:09ecba68d0cf | 707 | + ( -derive45 * p_sectionCourante->coef_d45) |
ohlimi2 | 51:09ecba68d0cf | 708 | + ( -derive90 * p_sectionCourante->coef_d90) |
ohlimi2 | 51:09ecba68d0cf | 709 | + ( -integralSum * p_sectionCourante->coef_i90) |
ohlimi2 | 47:b17061738568 | 710 | )//(300.0/(tachySpeed_cmps+1.0)) // faire du test reel pour afiné ou un calcul |
GaspardD | 43:d2164ee3336a | 711 | + DIRECTION_PULSE_MIDDLE; |
GaspardD | 41:4dd36f607279 | 712 | |
GaspardD | 41:4dd36f607279 | 713 | |
GaspardD | 39:de3638276b7e | 714 | #ifdef OMAR |
GaspardD | 43:d2164ee3336a | 715 | pc.printf("p_sectionCourante->consigne_position => %.4lf \r\n ",p_sectionCourante->consigne_position); |
GaspardD | 43:d2164ee3336a | 716 | pc.printf("positionSurPiste45 => %.4lf \r\n ",positionSurPiste45); |
GaspardD | 43:d2164ee3336a | 717 | pc.printf("p_sectionCourante->coef_p => %.4lf \r\n ",p_sectionCourante->coef_p); |
GaspardD | 39:de3638276b7e | 718 | #endif |
GaspardD | 21:de7a0a47f8a3 | 719 | //gestioon du dépassement |
GaspardD | 43:d2164ee3336a | 720 | if(pulseDirection_us > DIRECTION_PULSE_MAX) { //POUR TOURNER A GAUCHE |
GaspardD | 19:771bf61be276 | 721 | #if DEBUG > 1 |
GaspardD | 43:d2164ee3336a | 722 | pc.printf("!!! OVER PWM Direction pulse: %.4lf\r\n",pulseDirection_us); |
GaspardD | 21:de7a0a47f8a3 | 723 | #endif |
GaspardD | 43:d2164ee3336a | 724 | pulseDirection_us = DIRECTION_PULSE_MAX; |
GaspardD | 43:d2164ee3336a | 725 | } else if(pulseDirection_us < DIRECTION_PULSE_MIN ) { //POUR TOURNER A DROITE |
GaspardD | 21:de7a0a47f8a3 | 726 | #if DEBUG > 1 |
GaspardD | 43:d2164ee3336a | 727 | pc.printf("!!! UNDER PWM Direction pulse: %.4lf\r\n",pulseDirection_us); |
GaspardD | 19:771bf61be276 | 728 | #endif |
GaspardD | 43:d2164ee3336a | 729 | pulseDirection_us = DIRECTION_PULSE_MIN ; |
GaspardD | 43:d2164ee3336a | 730 | } |
GaspardD | 21:de7a0a47f8a3 | 731 | #if DEBUG > 1 |
GaspardD | 43:d2164ee3336a | 732 | pc.printf("PWM Direction pulse: %.4lf\r\n",pulseDirection_us); |
GaspardD | 21:de7a0a47f8a3 | 733 | #endif |
GaspardD | 43:d2164ee3336a | 734 | PwmDirection.pulsewidth_us(pulseDirection_us); |
GaspardD | 43:d2164ee3336a | 735 | return; |
GaspardD | 43:d2164ee3336a | 736 | } |
GaspardD | 8:1d8c3ca5e508 | 737 | } |
GaspardD | 8:1d8c3ca5e508 | 738 | |
GaspardD | 11:bc24b3ba51a9 | 739 | #ifdef DLVV |
GaspardD | 11:bc24b3ba51a9 | 740 | void obstacleOutput(void) |
GaspardD | 8:1d8c3ca5e508 | 741 | { |
GaspardD | 8:1d8c3ca5e508 | 742 | return; |
GaspardD | 8:1d8c3ca5e508 | 743 | } |
GaspardD | 11:bc24b3ba51a9 | 744 | #endif |
GaspardD | 11:bc24b3ba51a9 | 745 | void sectionOutput(void) |
GaspardD | 8:1d8c3ca5e508 | 746 | { |
GaspardD | 14:d471faa7d1a2 | 747 | #if (DEBUG > 3) |
GaspardD | 14:d471faa7d1a2 | 748 | pc.printf("\r\n Output Section\r\n"); |
GaspardD | 14:d471faa7d1a2 | 749 | #endif |
GaspardD | 43:d2164ee3336a | 750 | if(p_sectionCourante !=NULL) { |
GaspardD | 43:d2164ee3336a | 751 | switch (st_currentSection) { |
GaspardD | 43:d2164ee3336a | 752 | case RUNNING_SECTION: |
GaspardD | 43:d2164ee3336a | 753 | break; |
GaspardD | 43:d2164ee3336a | 754 | case LOADING_SECTION: |
GaspardD | 43:d2164ee3336a | 755 | p_sectionCourante=p_sectionCourante->nextSection; |
GaspardD | 43:d2164ee3336a | 756 | tachySectionDist_cm = 0; |
GaspardD | 43:d2164ee3336a | 757 | break; |
GaspardD | 43:d2164ee3336a | 758 | case ARRET: |
GaspardD | 43:d2164ee3336a | 759 | //on est à l'arret |
GaspardD | 43:d2164ee3336a | 760 | break; |
GaspardD | 43:d2164ee3336a | 761 | default: |
GaspardD | 43:d2164ee3336a | 762 | break; |
GaspardD | 43:d2164ee3336a | 763 | } |
GaspardD | 11:bc24b3ba51a9 | 764 | } |
GaspardD | 8:1d8c3ca5e508 | 765 | return; |
GaspardD | 8:1d8c3ca5e508 | 766 | } |
GaspardD | 8:1d8c3ca5e508 | 767 | |
GaspardD | 11:bc24b3ba51a9 | 768 | |
GaspardD | 11:bc24b3ba51a9 | 769 | void maxSpeedOutput(void) |
GaspardD | 8:1d8c3ca5e508 | 770 | { |
GaspardD | 14:d471faa7d1a2 | 771 | #if (DEBUG > 3) |
GaspardD | 14:d471faa7d1a2 | 772 | pc.printf("\r\n Output MAX SPEED\r\n"); |
GaspardD | 14:d471faa7d1a2 | 773 | #endif |
GaspardD | 43:d2164ee3336a | 774 | if(p_sectionCourante !=NULL) { |
GaspardD | 43:d2164ee3336a | 775 | switch(st_maxSpeed) { |
GaspardD | 43:d2164ee3336a | 776 | case BLOCKED: |
GaspardD | 43:d2164ee3336a | 777 | maxSpeed_cmps = 0; |
GaspardD | 43:d2164ee3336a | 778 | break; |
GaspardD | 43:d2164ee3336a | 779 | case SPEED_WARNING: |
GaspardD | 43:d2164ee3336a | 780 | maxSpeed_cmps = p_sectionCourante->slowSpeed_cmps; |
GaspardD | 43:d2164ee3336a | 781 | break; |
GaspardD | 43:d2164ee3336a | 782 | default: |
GaspardD | 43:d2164ee3336a | 783 | maxSpeed_cmps = p_sectionCourante->targetSpeed_cmps; |
GaspardD | 43:d2164ee3336a | 784 | break; |
GaspardD | 43:d2164ee3336a | 785 | } |
GaspardD | 43:d2164ee3336a | 786 | } else { |
GaspardD | 43:d2164ee3336a | 787 | maxSpeed_cmps = 0.0; |
GaspardD | 11:bc24b3ba51a9 | 788 | } |
GaspardD | 8:1d8c3ca5e508 | 789 | return; |
GaspardD | 8:1d8c3ca5e508 | 790 | } |
GaspardD | 11:bc24b3ba51a9 | 791 | |
GaspardD | 11:bc24b3ba51a9 | 792 | void throttleOutput(void) |
GaspardD | 11:bc24b3ba51a9 | 793 | { |
GaspardD | 14:d471faa7d1a2 | 794 | #if (DEBUG > 3) |
GaspardD | 14:d471faa7d1a2 | 795 | pc.printf("\r\n Output TROTTLE\r\n"); |
GaspardD | 14:d471faa7d1a2 | 796 | #endif |
GaspardD | 11:bc24b3ba51a9 | 797 | switch (st_thro) { |
GaspardD | 21:de7a0a47f8a3 | 798 | case REGULATION_SPEED: |
GaspardD | 22:26fc6e6f7a55 | 799 | pulseSpeed_us = maxSpeed_cmps * 279 / 2048 + 1558 ; |
GaspardD | 19:771bf61be276 | 800 | break; |
GaspardD | 19:771bf61be276 | 801 | case BRAKING: |
GaspardD | 16:63690703b5b6 | 802 | #if DEBUG > 2 |
GaspardD | 19:771bf61be276 | 803 | pc.printf("BRAKINGGGGGGGGGGGGGGGGGG !!! \r\n"); |
GaspardD | 19:771bf61be276 | 804 | #endif |
GaspardD | 19:771bf61be276 | 805 | pulseSpeed_us = BRAKING_PULSE_US; |
GaspardD | 19:771bf61be276 | 806 | break; |
GaspardD | 19:771bf61be276 | 807 | case STOPPED: |
GaspardD | 19:771bf61be276 | 808 | #if DEBUG > 2 |
GaspardD | 19:771bf61be276 | 809 | pc.printf("STOPPED\r\n"); |
GaspardD | 16:63690703b5b6 | 810 | #endif |
GaspardD | 19:771bf61be276 | 811 | pulseSpeed_us = ZERO_PULSE_SPEED_US; |
GaspardD | 19:771bf61be276 | 812 | break; |
GaspardD | 19:771bf61be276 | 813 | default: |
GaspardD | 19:771bf61be276 | 814 | break; |
GaspardD | 11:bc24b3ba51a9 | 815 | } |
GaspardD | 22:26fc6e6f7a55 | 816 | |
GaspardD | 19:771bf61be276 | 817 | PwmMotor.pulsewidth_us(pulseSpeed_us); |
GaspardD | 15:129f205ff030 | 818 | #if DEBUG > 1 |
ohlimi2 | 36:bccddd02966a | 819 | pc.printf("PWM Thro pulse: %.4lf micros\r\n",pulseSpeed_us); |
GaspardD | 13:af9a59ccf60b | 820 | #endif |
GaspardD | 11:bc24b3ba51a9 | 821 | return; |
GaspardD | 11:bc24b3ba51a9 | 822 | } |