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