Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of biniou by
stateMachines.cpp@46:9262b07b0833, 2018-09-20 (annotated)
- Committer:
- ohlimi2
- Date:
- Thu Sep 20 18:45:07 2018 +0000
- Revision:
- 46:9262b07b0833
- Parent:
- 45:7d67809bd7bf
- Child:
- 47:b17061738568
test en cours
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 | { |
| GaspardD | 29:fc984fe08ca7 | 264 | tab[index_fifo_ir] = 3.3 * (double)p->read(); // on convertit directement en volts |
| GaspardD | 29:fc984fe08ca7 | 265 | //tension proportionelle à l'inverse de la distance |
| ohlimi2 | 36:bccddd02966a | 266 | tab[index_fifo_ir] = 1.0/(0.0161 * (double)tab[index_fifo_ir]); |
| GaspardD | 11:bc24b3ba51a9 | 267 | int sumMoy = 0; |
| GaspardD | 19:771bf61be276 | 268 | for(int k=0; k<size; k++) { |
| GaspardD | 11:bc24b3ba51a9 | 269 | sumMoy+=tab[k]; |
| GaspardD | 11:bc24b3ba51a9 | 270 | } |
| GaspardD | 11:bc24b3ba51a9 | 271 | return sumMoy/size; |
| GaspardD | 11:bc24b3ba51a9 | 272 | } |
| GaspardD | 39:de3638276b7e | 273 | void tachyCheck() |
| GaspardD | 39:de3638276b7e | 274 | { |
| GaspardD | 41:4dd36f607279 | 275 | if(timerSinceTachy.read_us() > 500000) { |
| GaspardD | 39:de3638276b7e | 276 | tachySpeed_cmps = 0.0; |
| GaspardD | 39:de3638276b7e | 277 | } |
| GaspardD | 41:4dd36f607279 | 278 | return; |
| GaspardD | 39:de3638276b7e | 279 | } |
| GaspardD | 39:de3638276b7e | 280 | |
| GaspardD | 2:fd0ffe46a87d | 281 | |
| GaspardD | 12:51b1b40cc017 | 282 | void it4cm() |
| GaspardD | 12:51b1b40cc017 | 283 | { |
| GaspardD | 39:de3638276b7e | 284 | //le timer sert de flag sur le freinage: |
| GaspardD | 39:de3638276b7e | 285 | //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 | 286 | //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 | 287 | |
| ohlimi2 | 36:bccddd02966a | 288 | tachySectionDist_cm += TACHY_CM; |
| ohlimi2 | 36:bccddd02966a | 289 | tachyTotalDist_cm += TACHY_CM; |
| GaspardD | 39:de3638276b7e | 290 | 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 | 291 | #if DEBUG > 2 |
| ohlimi2 | 36:bccddd02966a | 292 | pc.printf("IT: distance parcourue %.4lf , vitesse:%.4lf \r\n",tachyTotalDist_cm,tachySpeed_cmps); |
| ohlimi2 | 36:bccddd02966a | 293 | #endif |
| GaspardD | 39:de3638276b7e | 294 | timerSinceTachy.reset(); |
| GaspardD | 39:de3638276b7e | 295 | timerSinceTachy.start(); |
| ohlimi2 | 36:bccddd02966a | 296 | return; |
| ohlimi2 | 36:bccddd02966a | 297 | |
| GaspardD | 19:771bf61be276 | 298 | #if DEBUG > 0 |
| GaspardD | 14:d471faa7d1a2 | 299 | pc.printf("IT tachy\r\n"); |
| GaspardD | 14:d471faa7d1a2 | 300 | #endif |
| GaspardD | 12:51b1b40cc017 | 301 | } |
| GaspardD | 12:51b1b40cc017 | 302 | |
| GaspardD | 12:51b1b40cc017 | 303 | void it_serial() |
| GaspardD | 12:51b1b40cc017 | 304 | { |
| GaspardD | 12:51b1b40cc017 | 305 | if(serialLidar.getc()==HEADER) { // determine data package frame header 0x59 |
| GaspardD | 12:51b1b40cc017 | 306 | uart[0]=HEADER; |
| GaspardD | 12:51b1b40cc017 | 307 | if(serialLidar.getc()==HEADER) { //determine data package frame header 0x59 |
| GaspardD | 12:51b1b40cc017 | 308 | uart[1]=HEADER; |
| GaspardD | 12:51b1b40cc017 | 309 | for(i=2; i<9; i++) { // store data to array |
| GaspardD | 12:51b1b40cc017 | 310 | uart[i]=serialLidar.getc(); |
| GaspardD | 12:51b1b40cc017 | 311 | } |
| GaspardD | 12:51b1b40cc017 | 312 | check=uart[0]+uart[1]+uart[2]+uart[3]+uart[4]+uart[5]+uart[6]+uart[7]; |
| GaspardD | 12:51b1b40cc017 | 313 | if(uart[8]==(check&0xff)) { // check the received data as per protocols |
| GaspardD | 23:04d393220daa | 314 | distLidarPrev = distLidar; |
| GaspardD | 12:51b1b40cc017 | 315 | distLidar=uart[2]+uart[3]*256;// calculate distance value |
| GaspardD | 23:04d393220daa | 316 | strengthLidarPrev = strengthLidar; |
| GaspardD | 12:51b1b40cc017 | 317 | strengthLidar=uart[4]+uart[5]*256;// calculate signal strength value |
| GaspardD | 42:3f12252862b9 | 318 | timersinceSerial.reset(); |
| GaspardD | 42:3f12252862b9 | 319 | timersinceSerial.start(); |
| GaspardD | 12:51b1b40cc017 | 320 | } |
| GaspardD | 12:51b1b40cc017 | 321 | } |
| GaspardD | 12:51b1b40cc017 | 322 | } |
| GaspardD | 12:51b1b40cc017 | 323 | } |
| GaspardD | 19:771bf61be276 | 324 | // +++++++++++++++++++++++++++++++++++++++++++ STATES MACHINES +++++++++++++++++++++++++++++++++++++++++++ |
| GaspardD | 19:771bf61be276 | 325 | |
| GaspardD | 8:1d8c3ca5e508 | 326 | //########## INIT STATES MACHINES ########## |
| GaspardD | 11:bc24b3ba51a9 | 327 | void mursInit(void) |
| GaspardD | 8:1d8c3ca5e508 | 328 | { |
| GaspardD | 39:de3638276b7e | 329 | #if DEBUG > 0 |
| GaspardD | 13:af9a59ccf60b | 330 | pc.printf("Init Murs\r\n"); |
| GaspardD | 13:af9a59ccf60b | 331 | #endif |
| GaspardD | 13:af9a59ccf60b | 332 | timeSinceStart.start(); |
| GaspardD | 29:fc984fe08ca7 | 333 | st_murs=REF_BIDIR; |
| GaspardD | 19:771bf61be276 | 334 | PwmDirection.period_us(SPEED_PERIOD_US); |
| GaspardD | 17:8c465656eea4 | 335 | PwmDirection.pulsewidth_us(DIRECTION_PULSE_MIDDLE);// milieu |
| GaspardD | 8:1d8c3ca5e508 | 336 | return; |
| GaspardD | 8:1d8c3ca5e508 | 337 | } |
| GaspardD | 11:bc24b3ba51a9 | 338 | #ifdef DLVV |
| GaspardD | 11:bc24b3ba51a9 | 339 | void obstacleInit(void) |
| GaspardD | 8:1d8c3ca5e508 | 340 | { |
| GaspardD | 19:771bf61be276 | 341 | #if DEBUG > 0 |
| GaspardD | 13:af9a59ccf60b | 342 | pc.printf("Init Obstacle\r\n"); |
| GaspardD | 13:af9a59ccf60b | 343 | #endif |
| GaspardD | 29:fc984fe08ca7 | 344 | st_speedLimit=ALL_CLEAR; |
| GaspardD | 8:1d8c3ca5e508 | 345 | return; |
| GaspardD | 8:1d8c3ca5e508 | 346 | } |
| GaspardD | 11:bc24b3ba51a9 | 347 | #endif |
| GaspardD | 11:bc24b3ba51a9 | 348 | void sectionInit(void) |
| GaspardD | 2:fd0ffe46a87d | 349 | { |
| GaspardD | 19:771bf61be276 | 350 | #if DEBUG > 0 |
| GaspardD | 13:af9a59ccf60b | 351 | pc.printf("Init Section\r\n"); |
| GaspardD | 13:af9a59ccf60b | 352 | #endif |
| GaspardD | 11:bc24b3ba51a9 | 353 | st_currentSection=ARRET; |
| GaspardD | 14:d471faa7d1a2 | 354 | p_sectionCourante=&p_section1; |
| GaspardD | 12:51b1b40cc017 | 355 | it_tachymeter.fall(&it4cm); |
| GaspardD | 39:de3638276b7e | 356 | timerSinceTachy.start(); |
| GaspardD | 39:de3638276b7e | 357 | tachySectionDist_cm = 0; |
| GaspardD | 39:de3638276b7e | 358 | tachyStepsRegister = 0; |
| GaspardD | 11:bc24b3ba51a9 | 359 | |
| GaspardD | 23:04d393220daa | 360 | //section de test 1 |
| ohlimi2 | 46:9262b07b0833 | 361 | p_section1.nextSection =&p_section3;// &p_section2; |
| GaspardD | 29:fc984fe08ca7 | 362 | p_section1.consigne_position = 75.0; |
| GaspardD | 39:de3638276b7e | 363 | p_section1.targetSpeed_cmps = 400.0; |
| GaspardD | 29:fc984fe08ca7 | 364 | p_section1.slowSpeed_cmps = 328.0; |
| GaspardD | 21:de7a0a47f8a3 | 365 | p_section1.coef_p_speed = 1; |
| GaspardD | 29:fc984fe08ca7 | 366 | p_section1.lidarWarningDist_cm = 120.0; |
| ohlimi2 | 46:9262b07b0833 | 367 | p_section1.lng_section_cm = 1000.0;//10m |
| ohlimi2 | 46:9262b07b0833 | 368 | p_section1.coef_p = 4.0; |
| ohlimi2 | 46:9262b07b0833 | 369 | p_section1.coef_d = 0.2; |
| ohlimi2 | 46:9262b07b0833 | 370 | p_section1.coef_i = 0.000; |
| GaspardD | 39:de3638276b7e | 371 | |
| GaspardD | 39:de3638276b7e | 372 | //section de test |
| ohlimi2 | 46:9262b07b0833 | 373 | p_section2.nextSection = &p_section3; |
| GaspardD | 39:de3638276b7e | 374 | p_section2.consigne_position = 75.0; |
| GaspardD | 39:de3638276b7e | 375 | p_section2.targetSpeed_cmps = 328.0; |
| GaspardD | 39:de3638276b7e | 376 | p_section2.slowSpeed_cmps = 328.0; |
| GaspardD | 39:de3638276b7e | 377 | p_section2.coef_p_speed = 1.0; |
| GaspardD | 39:de3638276b7e | 378 | p_section2.lidarWarningDist_cm = 300.0; |
| GaspardD | 39:de3638276b7e | 379 | p_section2.lng_section_cm = 200.0;//2m |
| GaspardD | 39:de3638276b7e | 380 | p_section2.coef_p = 1; |
| GaspardD | 39:de3638276b7e | 381 | p_section2.coef_i = 0.00001; |
| GaspardD | 39:de3638276b7e | 382 | p_section2.coef_d = 0.00001; |
| GaspardD | 23:04d393220daa | 383 | |
| ohlimi2 | 46:9262b07b0833 | 384 | p_section3.nextSection = NULL; |
| ohlimi2 | 46:9262b07b0833 | 385 | p_section3.consigne_position = 75.0; |
| ohlimi2 | 46:9262b07b0833 | 386 | p_section3.targetSpeed_cmps = 0.0; |
| ohlimi2 | 46:9262b07b0833 | 387 | p_section3.slowSpeed_cmps = 0.0; |
| ohlimi2 | 46:9262b07b0833 | 388 | p_section3.coef_p_speed = 1.0; |
| ohlimi2 | 46:9262b07b0833 | 389 | p_section3.lidarWarningDist_cm = 300.0; |
| ohlimi2 | 46:9262b07b0833 | 390 | p_section3.lng_section_cm = 200.0;//2m |
| ohlimi2 | 46:9262b07b0833 | 391 | p_section3.coef_p = 1.0; |
| ohlimi2 | 46:9262b07b0833 | 392 | p_section3.coef_i = 0.2; |
| ohlimi2 | 46:9262b07b0833 | 393 | p_section3.coef_d = 0.0000; |
| ohlimi2 | 46:9262b07b0833 | 394 | |
| GaspardD | 8:1d8c3ca5e508 | 395 | return; |
| GaspardD | 8:1d8c3ca5e508 | 396 | } |
| GaspardD | 11:bc24b3ba51a9 | 397 | |
| GaspardD | 11:bc24b3ba51a9 | 398 | void maxSpeedInit(void) |
| GaspardD | 11:bc24b3ba51a9 | 399 | { |
| GaspardD | 19:771bf61be276 | 400 | #if DEBUG > 0 |
| GaspardD | 13:af9a59ccf60b | 401 | pc.printf("Init Max Speed\r\n"); |
| GaspardD | 13:af9a59ccf60b | 402 | #endif |
| GaspardD | 11:bc24b3ba51a9 | 403 | st_maxSpeed=SPEED_MAX; |
| GaspardD | 11:bc24b3ba51a9 | 404 | maxSpeed_cmps= p_sectionCourante->targetSpeed_cmps; |
| GaspardD | 11:bc24b3ba51a9 | 405 | serialLidar.baud(115200); |
| GaspardD | 14:d471faa7d1a2 | 406 | serialLidar.attach(&it_serial); |
| GaspardD | 11:bc24b3ba51a9 | 407 | return; |
| GaspardD | 11:bc24b3ba51a9 | 408 | } |
| GaspardD | 11:bc24b3ba51a9 | 409 | |
| GaspardD | 11:bc24b3ba51a9 | 410 | void throttleInit(void) |
| GaspardD | 8:1d8c3ca5e508 | 411 | { |
| GaspardD | 19:771bf61be276 | 412 | #if DEBUG > 0 |
| GaspardD | 13:af9a59ccf60b | 413 | pc.printf("Init Throttle\r\n"); |
| GaspardD | 13:af9a59ccf60b | 414 | #endif |
| GaspardD | 21:de7a0a47f8a3 | 415 | st_thro = REGULATION_SPEED; |
| ohlimi2 | 36:bccddd02966a | 416 | PwmMotor.period_us(DIRECTION_PERIOD_MS); //20 ms is default |
| GaspardD | 19:771bf61be276 | 417 | PwmMotor.pulsewidth_us(1000);//MIN |
| GaspardD | 12:51b1b40cc017 | 418 | wait(3); |
| GaspardD | 19:771bf61be276 | 419 | PwmMotor.pulsewidth_us(2000);//MAX |
| GaspardD | 12:51b1b40cc017 | 420 | wait(1); |
| GaspardD | 19:771bf61be276 | 421 | PwmMotor.pulsewidth_us(1500);//ZEROING |
| GaspardD | 12:51b1b40cc017 | 422 | wait(1); |
| GaspardD | 19:771bf61be276 | 423 | pulseSpeed_us = INITAL_PULSE_SPEED_US; |
| GaspardD | 19:771bf61be276 | 424 | #if DEBUG > 0 |
| ohlimi2 | 36:bccddd02966a | 425 | pc.printf("temps init: %.4lf micros\r\n",timeSinceStart.read_us()); |
| ohlimi2 | 36:bccddd02966a | 426 | 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 | 427 | timeSinceStart.reset(); |
| GaspardD | 13:af9a59ccf60b | 428 | timeSinceStart.start(); |
| GaspardD | 13:af9a59ccf60b | 429 | #endif |
| GaspardD | 23:04d393220daa | 430 | #ifdef DUMP_SAMPLIG_PERIOD |
| GaspardD | 22:26fc6e6f7a55 | 431 | timerLog.start(); |
| GaspardD | 22:26fc6e6f7a55 | 432 | #endif |
| GaspardD | 22:26fc6e6f7a55 | 433 | |
| GaspardD | 8:1d8c3ca5e508 | 434 | return; |
| GaspardD | 8:1d8c3ca5e508 | 435 | } |
| GaspardD | 2:fd0ffe46a87d | 436 | |
| GaspardD | 8:1d8c3ca5e508 | 437 | |
| GaspardD | 8:1d8c3ca5e508 | 438 | //########## UPDATE STATES ########## |
| GaspardD | 11:bc24b3ba51a9 | 439 | void mursUpdate(void) |
| GaspardD | 2:fd0ffe46a87d | 440 | { |
| GaspardD | 14:d471faa7d1a2 | 441 | #if (DEBUG > 3) |
| GaspardD | 14:d471faa7d1a2 | 442 | pc.printf("\r\nUpdate MURS\r\n"); |
| GaspardD | 14:d471faa7d1a2 | 443 | #endif |
| GaspardD | 11:bc24b3ba51a9 | 444 | //lectures |
| GaspardD | 29:fc984fe08ca7 | 445 | |
| GaspardD | 29:fc984fe08ca7 | 446 | distMurG45Moy = getDistMoy(&anaG45,distMurG45,NB_ECHANTILLONS_IR); |
| GaspardD | 29:fc984fe08ca7 | 447 | distMurD45Moy = getDistMoy(&anaD45,distMurD45,NB_ECHANTILLONS_IR); |
| GaspardD | 29:fc984fe08ca7 | 448 | distMurG90Moy = getDistMoy(&anaG90,distMurG90,NB_ECHANTILLONS_IR); |
| ohlimi2 | 36:bccddd02966a | 449 | distMurD90Moy = getDistMoy(&anaD90,distMurD90,NB_ECHANTILLONS_IR); |
| GaspardD | 39:de3638276b7e | 450 | shortDistMurG90Moy = getShortDistMoy(&anaShortG90,shortDistMurD90,NB_ECHANTILLONS_IR); |
| GaspardD | 39:de3638276b7e | 451 | shortDistMurD90Moy = getShortDistMoy(&anaShortD90,shortDistMurD90,NB_ECHANTILLONS_IR); |
| GaspardD | 11:bc24b3ba51a9 | 452 | index_fifo_ir = (index_fifo_ir+1)%NB_ECHANTILLONS_IR; |
| GaspardD | 29:fc984fe08ca7 | 453 | |
| ohlimi2 | 36:bccddd02966a | 454 | |
| GaspardD | 41:4dd36f607279 | 455 | trueDistMurD90Moy = distMurD90Moy; |
| GaspardD | 41:4dd36f607279 | 456 | trueDistMurG90Moy = distMurG90Moy; |
| GaspardD | 39:de3638276b7e | 457 | |
| GaspardD | 41:4dd36f607279 | 458 | if(shortDistMurG90Moy < DIST_MIN_LONG_CM) { |
| GaspardD | 29:fc984fe08ca7 | 459 | trueDistMurG90Moy = shortDistMurG90Moy; |
| GaspardD | 41:4dd36f607279 | 460 | } else { |
| GaspardD | 29:fc984fe08ca7 | 461 | trueDistMurG90Moy = distMurG90Moy; |
| GaspardD | 29:fc984fe08ca7 | 462 | } |
| GaspardD | 41:4dd36f607279 | 463 | if(shortDistMurD90Moy < DIST_MIN_LONG_CM) { |
| GaspardD | 29:fc984fe08ca7 | 464 | trueDistMurD90Moy = shortDistMurD90Moy; |
| GaspardD | 41:4dd36f607279 | 465 | } else { |
| GaspardD | 29:fc984fe08ca7 | 466 | trueDistMurD90Moy = distMurD90Moy; |
| GaspardD | 39:de3638276b7e | 467 | } |
| ohlimi2 | 36:bccddd02966a | 468 | |
| GaspardD | 29:fc984fe08ca7 | 469 | |
| GaspardD | 29:fc984fe08ca7 | 470 | #ifdef DLVV |
| GaspardD | 29:fc984fe08ca7 | 471 | switch (st_obstacle) { |
| GaspardD | 41:4dd36f607279 | 472 | case FRONT_OBSTRUCTED: |
| GaspardD | 41:4dd36f607279 | 473 | st_tmpMurs = REF_A_GAUCHE; |
| GaspardD | 41:4dd36f607279 | 474 | return; |
| GaspardD | 41:4dd36f607279 | 475 | case RIGHT_OBSTRUCTED: |
| GaspardD | 41:4dd36f607279 | 476 | st_tmpMurs = REF_A_GAUCHE; |
| GaspardD | 41:4dd36f607279 | 477 | return; |
| GaspardD | 41:4dd36f607279 | 478 | case LEFT_OBSTRUCTED: |
| GaspardD | 41:4dd36f607279 | 479 | st_tmpMurs = REF_A_DROITE; |
| GaspardD | 41:4dd36f607279 | 480 | return; |
| GaspardD | 41:4dd36f607279 | 481 | default: |
| GaspardD | 41:4dd36f607279 | 482 | break; |
| GaspardD | 29:fc984fe08ca7 | 483 | } |
| GaspardD | 29:fc984fe08ca7 | 484 | |
| GaspardD | 29:fc984fe08ca7 | 485 | #endif |
| GaspardD | 41:4dd36f607279 | 486 | st_tmpMurs = REF_BIDIR; |
| GaspardD | 29:fc984fe08ca7 | 487 | |
| GaspardD | 41:4dd36f607279 | 488 | st_murs = st_tmpMurs; |
| GaspardD | 12:51b1b40cc017 | 489 | |
| GaspardD | 8:1d8c3ca5e508 | 490 | return; |
| GaspardD | 8:1d8c3ca5e508 | 491 | } |
| GaspardD | 11:bc24b3ba51a9 | 492 | #ifdef DLVV |
| GaspardD | 11:bc24b3ba51a9 | 493 | void obstacleUpdate(void) |
| GaspardD | 8:1d8c3ca5e508 | 494 | { |
| GaspardD | 8:1d8c3ca5e508 | 495 | return; |
| GaspardD | 8:1d8c3ca5e508 | 496 | } |
| GaspardD | 11:bc24b3ba51a9 | 497 | #endif |
| GaspardD | 11:bc24b3ba51a9 | 498 | |
| GaspardD | 11:bc24b3ba51a9 | 499 | void sectionUpdate(void) |
| GaspardD | 8:1d8c3ca5e508 | 500 | { |
| GaspardD | 14:d471faa7d1a2 | 501 | #if (DEBUG > 3) |
| GaspardD | 14:d471faa7d1a2 | 502 | pc.printf("\r\nUpdate Section\r\n"); |
| GaspardD | 14:d471faa7d1a2 | 503 | #endif |
| GaspardD | 43:d2164ee3336a | 504 | |
| GaspardD | 43:d2164ee3336a | 505 | if(p_sectionCourante == NULL) { |
| GaspardD | 43:d2164ee3336a | 506 | st_tmpSection = ARRET; |
| GaspardD | 43:d2164ee3336a | 507 | } else { |
| GaspardD | 43:d2164ee3336a | 508 | |
| GaspardD | 43:d2164ee3336a | 509 | switch (st_currentSection) { |
| GaspardD | 43:d2164ee3336a | 510 | case RUNNING_SECTION: |
| GaspardD | 43:d2164ee3336a | 511 | if(tachySectionDist_cm > p_sectionCourante->lng_section_cm) { //on pourrait rajouter un test lidar |
| GaspardD | 43:d2164ee3336a | 512 | st_tmpSection = LOADING_SECTION; |
| GaspardD | 43:d2164ee3336a | 513 | } else { |
| GaspardD | 43:d2164ee3336a | 514 | return; |
| GaspardD | 43:d2164ee3336a | 515 | } |
| GaspardD | 43:d2164ee3336a | 516 | break; |
| GaspardD | 43:d2164ee3336a | 517 | case LOADING_SECTION: |
| GaspardD | 43:d2164ee3336a | 518 | if(p_sectionCourante != NULL) { //la section a ete chargee dans sectionOutput |
| GaspardD | 43:d2164ee3336a | 519 | st_tmpSection = RUNNING_SECTION; |
| GaspardD | 43:d2164ee3336a | 520 | } else { |
| GaspardD | 43:d2164ee3336a | 521 | st_tmpSection=ARRET; |
| GaspardD | 43:d2164ee3336a | 522 | } |
| GaspardD | 43:d2164ee3336a | 523 | break; |
| GaspardD | 43:d2164ee3336a | 524 | case ARRET: |
| GaspardD | 43:d2164ee3336a | 525 | if(p_sectionCourante != NULL) { |
| GaspardD | 43:d2164ee3336a | 526 | st_tmpSection = RUNNING_SECTION; |
| GaspardD | 43:d2164ee3336a | 527 | } else { |
| GaspardD | 43:d2164ee3336a | 528 | return; |
| GaspardD | 43:d2164ee3336a | 529 | } |
| GaspardD | 43:d2164ee3336a | 530 | break; |
| GaspardD | 43:d2164ee3336a | 531 | default: |
| GaspardD | 43:d2164ee3336a | 532 | break; |
| GaspardD | 43:d2164ee3336a | 533 | } |
| GaspardD | 11:bc24b3ba51a9 | 534 | } |
| GaspardD | 11:bc24b3ba51a9 | 535 | st_currentSection = st_tmpSection; |
| GaspardD | 8:1d8c3ca5e508 | 536 | return; |
| GaspardD | 8:1d8c3ca5e508 | 537 | } |
| GaspardD | 8:1d8c3ca5e508 | 538 | |
| GaspardD | 11:bc24b3ba51a9 | 539 | void maxSpeedUpdate(void) |
| GaspardD | 8:1d8c3ca5e508 | 540 | { |
| GaspardD | 14:d471faa7d1a2 | 541 | #if (DEBUG > 3) |
| GaspardD | 14:d471faa7d1a2 | 542 | pc.printf("\r\nUpdate MaxSpeed\r\n"); |
| GaspardD | 14:d471faa7d1a2 | 543 | #endif |
| GaspardD | 45:7d67809bd7bf | 544 | if(p_sectionCourante == NULL) { |
| GaspardD | 43:d2164ee3336a | 545 | st_tmpMaxSpeed = BLOCKED; |
| GaspardD | 43:d2164ee3336a | 546 | } else if(st_maxSpeed == BLOCKED && strengthLidar > LIDAR_STRENGTH_THRESOLD && distLidar < p_sectionCourante->lidarWarningDist_cm) { |
| GaspardD | 41:4dd36f607279 | 547 | st_tmpMaxSpeed = BLOCKED; |
| GaspardD | 41:4dd36f607279 | 548 | } else if( strengthLidar > LIDAR_STRENGTH_THRESOLD ) { |
| GaspardD | 23:04d393220daa | 549 | if( distLidar > p_sectionCourante->lidarWarningDist_cm ) { |
| GaspardD | 19:771bf61be276 | 550 | st_tmpMaxSpeed = SPEED_MAX; |
| GaspardD | 29:fc984fe08ca7 | 551 | } else if( strengthLidar > LIDAR_STRENGTH_THRESOLD && |
| GaspardD | 24:698fefbbee00 | 552 | strengthLidarPrev > LIDAR_STRENGTH_THRESOLD && |
| GaspardD | 24:698fefbbee00 | 553 | distLidar < p_sectionCourante->lidarWarningDist_cm && |
| GaspardD | 41:4dd36f607279 | 554 | distLidarPrev-distLidar > 3) { |
| GaspardD | 21:de7a0a47f8a3 | 555 | st_tmpMaxSpeed = BLOCKED; |
| GaspardD | 41:4dd36f607279 | 556 | } else { |
| GaspardD | 24:698fefbbee00 | 557 | st_tmpMaxSpeed = SPEED_WARNING; |
| GaspardD | 24:698fefbbee00 | 558 | } |
| GaspardD | 21:de7a0a47f8a3 | 559 | } else { |
| GaspardD | 11:bc24b3ba51a9 | 560 | st_tmpMaxSpeed = SPEED_MAX; |
| GaspardD | 11:bc24b3ba51a9 | 561 | } |
| GaspardD | 11:bc24b3ba51a9 | 562 | |
| GaspardD | 11:bc24b3ba51a9 | 563 | st_maxSpeed = st_tmpMaxSpeed; |
| GaspardD | 11:bc24b3ba51a9 | 564 | return; |
| GaspardD | 11:bc24b3ba51a9 | 565 | } |
| GaspardD | 11:bc24b3ba51a9 | 566 | |
| GaspardD | 11:bc24b3ba51a9 | 567 | void throttleUpdate(void) |
| GaspardD | 11:bc24b3ba51a9 | 568 | { |
| GaspardD | 14:d471faa7d1a2 | 569 | #if (DEBUG > 3) |
| GaspardD | 14:d471faa7d1a2 | 570 | pc.printf("\r\nUpdate Throttle\r\n"); |
| GaspardD | 14:d471faa7d1a2 | 571 | #endif |
| GaspardD | 11:bc24b3ba51a9 | 572 | switch (st_thro) { |
| GaspardD | 21:de7a0a47f8a3 | 573 | case REGULATION_SPEED: |
| GaspardD | 24:698fefbbee00 | 574 | if( st_currentSection == ARRET || |
| GaspardD | 41:4dd36f607279 | 575 | st_maxSpeed == BLOCKED ) { |
| GaspardD | 19:771bf61be276 | 576 | st_tmpThro = BRAKING; |
| GaspardD | 29:fc984fe08ca7 | 577 | } |
| GaspardD | 27:f8c3f1524a64 | 578 | #ifdef FREINAGE_ADAPTATIF |
| GaspardD | 41:4dd36f607279 | 579 | else if(tachySpeed_cmps > (maxSpeed_cmps + SPEED_DELTA_CMPS)) { |
| GaspardD | 24:698fefbbee00 | 580 | st_tmpThro = BRAKING; |
| GaspardD | 29:fc984fe08ca7 | 581 | 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 | 582 | brakingTimer.reset(); |
| GaspardD | 24:698fefbbee00 | 583 | brakingTimer.start(); |
| GaspardD | 27:f8c3f1524a64 | 584 | } |
| GaspardD | 27:f8c3f1524a64 | 585 | #endif |
| GaspardD | 41:4dd36f607279 | 586 | else { |
| GaspardD | 19:771bf61be276 | 587 | return; |
| GaspardD | 19:771bf61be276 | 588 | } |
| GaspardD | 19:771bf61be276 | 589 | break; |
| GaspardD | 16:63690703b5b6 | 590 | case BRAKING: |
| GaspardD | 42:3f12252862b9 | 591 | if(st_maxSpeed == BLOCKED && timersinceSerial.read_us() > 200000) { |
| GaspardD | 42:3f12252862b9 | 592 | p_sectionCourante= NULL; |
| GaspardD | 42:3f12252862b9 | 593 | st_tmpThro = STOPPED; |
| GaspardD | 42:3f12252862b9 | 594 | } else if( st_maxSpeed == BLOCKED |
| GaspardD | 41:4dd36f607279 | 595 | #ifdef FREINAGE_ADAPTATIF |
| GaspardD | 42:3f12252862b9 | 596 | || brakingTimer.read_us() < brakingDurationNeeded_us |
| GaspardD | 41:4dd36f607279 | 597 | #endif |
| GaspardD | 42:3f12252862b9 | 598 | ) { |
| GaspardD | 23:04d393220daa | 599 | st_tmpThro = BRAKING; |
| GaspardD | 41:4dd36f607279 | 600 | } else if(st_currentSection == ARRET) { |
| GaspardD | 21:de7a0a47f8a3 | 601 | st_tmpThro = STOPPED; |
| GaspardD | 41:4dd36f607279 | 602 | } else { |
| GaspardD | 41:4dd36f607279 | 603 | #ifdef FREINAGE_ADAPTATIF |
| GaspardD | 24:698fefbbee00 | 604 | brakingDurationNeeded_us = 0; |
| GaspardD | 41:4dd36f607279 | 605 | #endif |
| GaspardD | 21:de7a0a47f8a3 | 606 | st_tmpThro = REGULATION_SPEED; |
| GaspardD | 21:de7a0a47f8a3 | 607 | } |
| GaspardD | 19:771bf61be276 | 608 | break; |
| GaspardD | 19:771bf61be276 | 609 | case STOPPED: |
| GaspardD | 19:771bf61be276 | 610 | if(st_currentSection == RUNNING_SECTION) { |
| GaspardD | 22:26fc6e6f7a55 | 611 | st_tmpThro = REGULATION_SPEED; |
| GaspardD | 19:771bf61be276 | 612 | } else { |
| GaspardD | 19:771bf61be276 | 613 | st_tmpThro = STOPPED; |
| GaspardD | 16:63690703b5b6 | 614 | } |
| GaspardD | 19:771bf61be276 | 615 | break; |
| GaspardD | 19:771bf61be276 | 616 | default: |
| GaspardD | 19:771bf61be276 | 617 | break; |
| GaspardD | 11:bc24b3ba51a9 | 618 | } |
| GaspardD | 11:bc24b3ba51a9 | 619 | st_thro = st_tmpThro; |
| GaspardD | 8:1d8c3ca5e508 | 620 | return; |
| GaspardD | 8:1d8c3ca5e508 | 621 | } |
| GaspardD | 2:fd0ffe46a87d | 622 | |
| GaspardD | 8:1d8c3ca5e508 | 623 | //########## OUTPUT STATES ########## |
| GaspardD | 11:bc24b3ba51a9 | 624 | //updating output parameters |
| GaspardD | 11:bc24b3ba51a9 | 625 | void mursOutput(void) |
| GaspardD | 12:51b1b40cc017 | 626 | { |
| GaspardD | 43:d2164ee3336a | 627 | if(p_sectionCourante != NULL) { |
| GaspardD | 43:d2164ee3336a | 628 | //pour dériver |
| GaspardD | 43:d2164ee3336a | 629 | positionSurPiste45Prev = positionSurPiste45; |
| GaspardD | 43:d2164ee3336a | 630 | positionSurPiste90Prev = positionSurPiste90; |
| GaspardD | 14:d471faa7d1a2 | 631 | #if (DEBUG > 3) |
| GaspardD | 43:d2164ee3336a | 632 | pc.printf("\r\n Output MURS\r\n"); |
| GaspardD | 14:d471faa7d1a2 | 633 | #endif |
| GaspardD | 23:04d393220daa | 634 | |
| GaspardD | 43:d2164ee3336a | 635 | switch (st_murs) { |
| GaspardD | 43:d2164ee3336a | 636 | case REF_A_GAUCHE://par defaut, on compte à partir de la bordure gauche |
| GaspardD | 43:d2164ee3336a | 637 | largeurPiste90 = 150.0; |
| GaspardD | 43:d2164ee3336a | 638 | positionSurPiste90 = ( trueDistMurG90Moy + DEMI_LARGEUR_BINIOU_CM ); |
| GaspardD | 43:d2164ee3336a | 639 | positionSurPiste45 = ( distMurG45Moy * 1.414214/2.0 ) + DEMI_LARGEUR_BINIOU_CM; |
| GaspardD | 39:de3638276b7e | 640 | #ifdef OMAR |
| GaspardD | 43:d2164ee3336a | 641 | pc.printf("REF_A_GAUCHE\r\n"); |
| GaspardD | 39:de3638276b7e | 642 | #endif |
| GaspardD | 43:d2164ee3336a | 643 | break; |
| GaspardD | 43:d2164ee3336a | 644 | case REF_A_DROITE://par defaut, on compte à partir de la bordure gauche |
| GaspardD | 43:d2164ee3336a | 645 | largeurPiste90 = 150.0; |
| GaspardD | 43:d2164ee3336a | 646 | positionSurPiste90 = largeurPiste90 - ( DEMI_LARGEUR_BINIOU_CM + trueDistMurD90Moy ) ; |
| GaspardD | 43:d2164ee3336a | 647 | positionSurPiste45 = largeurPiste90 - ( distMurD45Moy * (1.414214)/2 ) + DEMI_LARGEUR_BINIOU_CM; |
| GaspardD | 39:de3638276b7e | 648 | #ifdef OMAR |
| GaspardD | 43:d2164ee3336a | 649 | pc.printf("REF_A_DROITE\r\n"); |
| GaspardD | 39:de3638276b7e | 650 | #endif |
| GaspardD | 43:d2164ee3336a | 651 | break; |
| GaspardD | 43:d2164ee3336a | 652 | default://REF_BIDIR |
| GaspardD | 43:d2164ee3336a | 653 | largeurPiste90 = trueDistMurG90Moy + trueDistMurD90Moy ; |
| GaspardD | 43:d2164ee3336a | 654 | largeurPiste45 = distMurG45Moy + distMurD45Moy ; |
| GaspardD | 43:d2164ee3336a | 655 | positionSurPiste90 = (trueDistMurG90Moy ); |
| GaspardD | 43:d2164ee3336a | 656 | positionSurPiste45 = (distMurG45Moy); |
| GaspardD | 39:de3638276b7e | 657 | #ifdef OMAR |
| GaspardD | 43:d2164ee3336a | 658 | pc.printf("REF_BIDIR\r\n"); |
| GaspardD | 39:de3638276b7e | 659 | #endif |
| GaspardD | 43:d2164ee3336a | 660 | break; |
| GaspardD | 43:d2164ee3336a | 661 | } |
| GaspardD | 23:04d393220daa | 662 | |
| GaspardD | 22:26fc6e6f7a55 | 663 | |
| GaspardD | 43:d2164ee3336a | 664 | //deriv correction |
| GaspardD | 43:d2164ee3336a | 665 | derive45 = positionSurPiste45 - positionSurPiste45Prev; |
| GaspardD | 43:d2164ee3336a | 666 | derive90 = positionSurPiste90 - positionSurPiste90Prev; |
| GaspardD | 39:de3638276b7e | 667 | |
| GaspardD | 39:de3638276b7e | 668 | #ifdef OMAR/* |
| GaspardD | 43:d2164ee3336a | 669 | pc.printf("derive45 => %.4lf \r\n ",derive45); |
| GaspardD | 43:d2164ee3336a | 670 | pc.printf("derive90 => %.4lf \r\n ",derive90); |
| GaspardD | 43:d2164ee3336a | 671 | pc.printf("distMurG45Moy => %.4lf \r\n ",distMurG45Moy); |
| GaspardD | 43:d2164ee3336a | 672 | pc.printf("distMurD45Moy => %.4lf \r\n ",distMurD45Moy); |
| GaspardD | 43:d2164ee3336a | 673 | pc.printf("trueDistMurG90Moy => %.4lf \r\n ",trueDistMurG90Moy); |
| GaspardD | 43:d2164ee3336a | 674 | pc.printf("trueDistMurD90Moy => %.4lf \r\n ",trueDistMurD90Moy); |
| GaspardD | 43:d2164ee3336a | 675 | pc.printf("positionSurPiste90 => %.4lf \r\n ",positionSurPiste90); |
| GaspardD | 43:d2164ee3336a | 676 | pc.printf("positionSurPiste45 => %.4lf \r\n ",positionSurPiste45); |
| GaspardD | 43:d2164ee3336a | 677 | pc.printf("largeurPiste90 => %.4lf \r\n ",largeurPiste90);*/ |
| GaspardD | 39:de3638276b7e | 678 | #endif |
| GaspardD | 39:de3638276b7e | 679 | |
| GaspardD | 43:d2164ee3336a | 680 | //integral correction |
| GaspardD | 43:d2164ee3336a | 681 | lastDifferences90[lastDifferenceIndex] = (p_sectionCourante->consigne_position - positionSurPiste90); |
| GaspardD | 43:d2164ee3336a | 682 | integralSum=0; |
| GaspardD | 43:d2164ee3336a | 683 | for(int f=0; f<NB_INTEGRAL_SAMPLES; f++) { |
| GaspardD | 43:d2164ee3336a | 684 | integralSum+=lastDifferences90[f]; |
| GaspardD | 43:d2164ee3336a | 685 | } |
| GaspardD | 43:d2164ee3336a | 686 | lastDifferenceIndex = (lastDifferenceIndex + 1)%NB_INTEGRAL_SAMPLES; |
| GaspardD | 39:de3638276b7e | 687 | |
| GaspardD | 41:4dd36f607279 | 688 | |
| GaspardD | 41:4dd36f607279 | 689 | |
| GaspardD | 41:4dd36f607279 | 690 | |
| GaspardD | 43:d2164ee3336a | 691 | //application des coefficients |
| GaspardD | 41:4dd36f607279 | 692 | |
| GaspardD | 43:d2164ee3336a | 693 | pulseDirection_us = (int)( |
| ohlimi2 | 46:9262b07b0833 | 694 | ((positionSurPiste45 - 75.0) * p_sectionCourante->coef_p) |
| ohlimi2 | 46:9262b07b0833 | 695 | //+ ((positionSurPiste90 - 75.0) * p_sectionCourante->coef_p) |
| ohlimi2 | 46:9262b07b0833 | 696 | //+ ( -derive45 * p_sectionCourante->coef_d) |
| ohlimi2 | 46:9262b07b0833 | 697 | //+ ( -derive90 * p_sectionCourante->coef_d) |
| ohlimi2 | 46:9262b07b0833 | 698 | //+ ( -integralSum * p_sectionCourante->coef_i) |
| ohlimi2 | 46:9262b07b0833 | 699 | )* 1;//(300.0/(tachySpeed_cmps+1.0)) // faire du test reel pour afiné ou un calcul |
| GaspardD | 43:d2164ee3336a | 700 | + DIRECTION_PULSE_MIDDLE; |
| GaspardD | 41:4dd36f607279 | 701 | |
| GaspardD | 41:4dd36f607279 | 702 | |
| GaspardD | 39:de3638276b7e | 703 | #ifdef OMAR |
| GaspardD | 43:d2164ee3336a | 704 | pc.printf("p_sectionCourante->consigne_position => %.4lf \r\n ",p_sectionCourante->consigne_position); |
| GaspardD | 43:d2164ee3336a | 705 | pc.printf("positionSurPiste45 => %.4lf \r\n ",positionSurPiste45); |
| GaspardD | 43:d2164ee3336a | 706 | pc.printf("p_sectionCourante->coef_p => %.4lf \r\n ",p_sectionCourante->coef_p); |
| GaspardD | 39:de3638276b7e | 707 | #endif |
| GaspardD | 21:de7a0a47f8a3 | 708 | //gestioon du dépassement |
| GaspardD | 43:d2164ee3336a | 709 | if(pulseDirection_us > DIRECTION_PULSE_MAX) { //POUR TOURNER A GAUCHE |
| GaspardD | 19:771bf61be276 | 710 | #if DEBUG > 1 |
| GaspardD | 43:d2164ee3336a | 711 | pc.printf("!!! OVER PWM Direction pulse: %.4lf\r\n",pulseDirection_us); |
| GaspardD | 21:de7a0a47f8a3 | 712 | #endif |
| GaspardD | 43:d2164ee3336a | 713 | pulseDirection_us = DIRECTION_PULSE_MAX; |
| GaspardD | 43:d2164ee3336a | 714 | } else if(pulseDirection_us < DIRECTION_PULSE_MIN ) { //POUR TOURNER A DROITE |
| GaspardD | 21:de7a0a47f8a3 | 715 | #if DEBUG > 1 |
| GaspardD | 43:d2164ee3336a | 716 | pc.printf("!!! UNDER PWM Direction pulse: %.4lf\r\n",pulseDirection_us); |
| GaspardD | 19:771bf61be276 | 717 | #endif |
| GaspardD | 43:d2164ee3336a | 718 | pulseDirection_us = DIRECTION_PULSE_MIN ; |
| GaspardD | 43:d2164ee3336a | 719 | } |
| GaspardD | 21:de7a0a47f8a3 | 720 | #if DEBUG > 1 |
| GaspardD | 43:d2164ee3336a | 721 | pc.printf("PWM Direction pulse: %.4lf\r\n",pulseDirection_us); |
| GaspardD | 21:de7a0a47f8a3 | 722 | #endif |
| GaspardD | 43:d2164ee3336a | 723 | PwmDirection.pulsewidth_us(pulseDirection_us); |
| GaspardD | 43:d2164ee3336a | 724 | return; |
| GaspardD | 43:d2164ee3336a | 725 | } |
| GaspardD | 8:1d8c3ca5e508 | 726 | } |
| GaspardD | 8:1d8c3ca5e508 | 727 | |
| GaspardD | 11:bc24b3ba51a9 | 728 | #ifdef DLVV |
| GaspardD | 11:bc24b3ba51a9 | 729 | void obstacleOutput(void) |
| GaspardD | 8:1d8c3ca5e508 | 730 | { |
| GaspardD | 8:1d8c3ca5e508 | 731 | return; |
| GaspardD | 8:1d8c3ca5e508 | 732 | } |
| GaspardD | 11:bc24b3ba51a9 | 733 | #endif |
| GaspardD | 11:bc24b3ba51a9 | 734 | void sectionOutput(void) |
| GaspardD | 8:1d8c3ca5e508 | 735 | { |
| GaspardD | 14:d471faa7d1a2 | 736 | #if (DEBUG > 3) |
| GaspardD | 14:d471faa7d1a2 | 737 | pc.printf("\r\n Output Section\r\n"); |
| GaspardD | 14:d471faa7d1a2 | 738 | #endif |
| GaspardD | 43:d2164ee3336a | 739 | if(p_sectionCourante !=NULL) { |
| GaspardD | 43:d2164ee3336a | 740 | switch (st_currentSection) { |
| GaspardD | 43:d2164ee3336a | 741 | case RUNNING_SECTION: |
| GaspardD | 43:d2164ee3336a | 742 | break; |
| GaspardD | 43:d2164ee3336a | 743 | case LOADING_SECTION: |
| GaspardD | 43:d2164ee3336a | 744 | p_sectionCourante=p_sectionCourante->nextSection; |
| GaspardD | 43:d2164ee3336a | 745 | tachySectionDist_cm = 0; |
| GaspardD | 43:d2164ee3336a | 746 | break; |
| GaspardD | 43:d2164ee3336a | 747 | case ARRET: |
| GaspardD | 43:d2164ee3336a | 748 | //on est à l'arret |
| GaspardD | 43:d2164ee3336a | 749 | break; |
| GaspardD | 43:d2164ee3336a | 750 | default: |
| GaspardD | 43:d2164ee3336a | 751 | break; |
| GaspardD | 43:d2164ee3336a | 752 | } |
| GaspardD | 11:bc24b3ba51a9 | 753 | } |
| GaspardD | 8:1d8c3ca5e508 | 754 | return; |
| GaspardD | 8:1d8c3ca5e508 | 755 | } |
| GaspardD | 8:1d8c3ca5e508 | 756 | |
| GaspardD | 11:bc24b3ba51a9 | 757 | |
| GaspardD | 11:bc24b3ba51a9 | 758 | void maxSpeedOutput(void) |
| GaspardD | 8:1d8c3ca5e508 | 759 | { |
| GaspardD | 14:d471faa7d1a2 | 760 | #if (DEBUG > 3) |
| GaspardD | 14:d471faa7d1a2 | 761 | pc.printf("\r\n Output MAX SPEED\r\n"); |
| GaspardD | 14:d471faa7d1a2 | 762 | #endif |
| GaspardD | 43:d2164ee3336a | 763 | if(p_sectionCourante !=NULL) { |
| GaspardD | 43:d2164ee3336a | 764 | switch(st_maxSpeed) { |
| GaspardD | 43:d2164ee3336a | 765 | case BLOCKED: |
| GaspardD | 43:d2164ee3336a | 766 | maxSpeed_cmps = 0; |
| GaspardD | 43:d2164ee3336a | 767 | break; |
| GaspardD | 43:d2164ee3336a | 768 | case SPEED_WARNING: |
| GaspardD | 43:d2164ee3336a | 769 | maxSpeed_cmps = p_sectionCourante->slowSpeed_cmps; |
| GaspardD | 43:d2164ee3336a | 770 | break; |
| GaspardD | 43:d2164ee3336a | 771 | default: |
| GaspardD | 43:d2164ee3336a | 772 | maxSpeed_cmps = p_sectionCourante->targetSpeed_cmps; |
| GaspardD | 43:d2164ee3336a | 773 | break; |
| GaspardD | 43:d2164ee3336a | 774 | } |
| GaspardD | 43:d2164ee3336a | 775 | } else { |
| GaspardD | 43:d2164ee3336a | 776 | maxSpeed_cmps = 0.0; |
| GaspardD | 11:bc24b3ba51a9 | 777 | } |
| GaspardD | 8:1d8c3ca5e508 | 778 | return; |
| GaspardD | 8:1d8c3ca5e508 | 779 | } |
| GaspardD | 11:bc24b3ba51a9 | 780 | |
| GaspardD | 11:bc24b3ba51a9 | 781 | void throttleOutput(void) |
| GaspardD | 11:bc24b3ba51a9 | 782 | { |
| GaspardD | 14:d471faa7d1a2 | 783 | #if (DEBUG > 3) |
| GaspardD | 14:d471faa7d1a2 | 784 | pc.printf("\r\n Output TROTTLE\r\n"); |
| GaspardD | 14:d471faa7d1a2 | 785 | #endif |
| GaspardD | 11:bc24b3ba51a9 | 786 | switch (st_thro) { |
| GaspardD | 21:de7a0a47f8a3 | 787 | case REGULATION_SPEED: |
| GaspardD | 22:26fc6e6f7a55 | 788 | pulseSpeed_us = maxSpeed_cmps * 279 / 2048 + 1558 ; |
| GaspardD | 19:771bf61be276 | 789 | break; |
| GaspardD | 19:771bf61be276 | 790 | case BRAKING: |
| GaspardD | 16:63690703b5b6 | 791 | #if DEBUG > 2 |
| GaspardD | 19:771bf61be276 | 792 | pc.printf("BRAKINGGGGGGGGGGGGGGGGGG !!! \r\n"); |
| GaspardD | 19:771bf61be276 | 793 | #endif |
| GaspardD | 19:771bf61be276 | 794 | pulseSpeed_us = BRAKING_PULSE_US; |
| GaspardD | 19:771bf61be276 | 795 | break; |
| GaspardD | 19:771bf61be276 | 796 | case STOPPED: |
| GaspardD | 19:771bf61be276 | 797 | #if DEBUG > 2 |
| GaspardD | 19:771bf61be276 | 798 | pc.printf("STOPPED\r\n"); |
| GaspardD | 16:63690703b5b6 | 799 | #endif |
| GaspardD | 19:771bf61be276 | 800 | pulseSpeed_us = ZERO_PULSE_SPEED_US; |
| GaspardD | 19:771bf61be276 | 801 | break; |
| GaspardD | 19:771bf61be276 | 802 | default: |
| GaspardD | 19:771bf61be276 | 803 | break; |
| GaspardD | 11:bc24b3ba51a9 | 804 | } |
| GaspardD | 22:26fc6e6f7a55 | 805 | |
| GaspardD | 19:771bf61be276 | 806 | PwmMotor.pulsewidth_us(pulseSpeed_us); |
| GaspardD | 15:129f205ff030 | 807 | #if DEBUG > 1 |
| ohlimi2 | 36:bccddd02966a | 808 | pc.printf("PWM Thro pulse: %.4lf micros\r\n",pulseSpeed_us); |
| GaspardD | 13:af9a59ccf60b | 809 | #endif |
| GaspardD | 11:bc24b3ba51a9 | 810 | return; |
| GaspardD | 11:bc24b3ba51a9 | 811 | } |
