TRR 2018 / Mbed 2 deprecated biniou-TRR2019-DLVV

Dependencies:   mbed MPU6050

Committer:
GaspardD
Date:
Fri Oct 04 22:20:23 2019 +0000
Revision:
12:58ad06f9847d
Parent:
11:2156cb77d0d6
Child:
13:3868cbdfa5ce
dernier code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GaspardD 3:1b7eb426247e 1 #include "sm_sections.h"
GaspardD 8:f23601373e8b 2 #include "sm_mpu.h"
GaspardD 3:1b7eb426247e 3
GaspardD 3:1b7eb426247e 4
GaspardD 4:efa207509f63 5 s_Section s_section1;
GaspardD 4:efa207509f63 6 s_Section s_section2;
GaspardD 12:58ad06f9847d 7 s_Section s_section2_1;
GaspardD 11:2156cb77d0d6 8 s_Section s_section3;
GaspardD 12:58ad06f9847d 9 s_Section s_section3_1;
GaspardD 12:58ad06f9847d 10 s_Section s_section4;
GaspardD 12:58ad06f9847d 11 s_Section s_section5;
GaspardD 12:58ad06f9847d 12 s_Section s_section5_1;
GaspardD 12:58ad06f9847d 13 s_Section s_section6_0;
GaspardD 12:58ad06f9847d 14 s_Section s_section6;
GaspardD 12:58ad06f9847d 15 s_Section s_section7;
GaspardD 12:58ad06f9847d 16 s_Section s_section8;
GaspardD 12:58ad06f9847d 17 s_Section s_section9;
GaspardD 12:58ad06f9847d 18 s_Section s_section9_1;
GaspardD 12:58ad06f9847d 19 s_Section s_section10;
GaspardD 12:58ad06f9847d 20 s_Section s_section11;
GaspardD 12:58ad06f9847d 21 s_Section s_section12;
GaspardD 3:1b7eb426247e 22
GaspardD 8:f23601373e8b 23 E_STATE_SECTIONS e_SECTIONS_state;
GaspardD 8:f23601373e8b 24
GaspardD 3:1b7eb426247e 25
GaspardD 8:f23601373e8b 26 void init_sm_sections()
GaspardD 8:f23601373e8b 27 {
GaspardD 3:1b7eb426247e 28
GaspardD 4:efa207509f63 29 d_ODOM_distFromSectionStart_m = 0.0;
GaspardD 8:f23601373e8b 30 e_SECTIONS_state = STOPPED;
GaspardD 8:f23601373e8b 31 s_section1.nextSection = NULL;
GaspardD 4:efa207509f63 32
GaspardD 4:efa207509f63 33
GaspardD 8:f23601373e8b 34 //section de départ
GaspardD 4:efa207509f63 35 s_section1.nextSection = &s_section2;
GaspardD 9:1b54bac6d9a7 36 s_section1.consigne_position = 0.5;
GaspardD 12:58ad06f9847d 37 s_section1.targetSpeed_mps = 1750;
GaspardD 12:58ad06f9847d 38 s_section1.lng_section_m = 0.8;
GaspardD 12:58ad06f9847d 39 s_section1.coef_pos = 40;
GaspardD 12:58ad06f9847d 40 s_section1.coef_bord = 0.6;
GaspardD 12:58ad06f9847d 41 s_section1.plagePulseFreinage = 20;
GaspardD 3:1b7eb426247e 42
GaspardD 12:58ad06f9847d 43 //ligne droite debut
GaspardD 12:58ad06f9847d 44 s_section2.nextSection = &s_section2_1;
GaspardD 9:1b54bac6d9a7 45 s_section2.consigne_position = 0.5;
GaspardD 12:58ad06f9847d 46 s_section2.targetSpeed_mps = 1770;
GaspardD 12:58ad06f9847d 47 s_section2.lng_section_m = 10.0;
GaspardD 12:58ad06f9847d 48 s_section2.coef_pos = 30;
GaspardD 12:58ad06f9847d 49 s_section2.coef_bord = 0.5;
GaspardD 12:58ad06f9847d 50 s_section2.plagePulseFreinage = 50;
GaspardD 12:58ad06f9847d 51
GaspardD 12:58ad06f9847d 52
GaspardD 12:58ad06f9847d 53 //ligne droite debut
GaspardD 12:58ad06f9847d 54 s_section2_1.nextSection = &s_section3;
GaspardD 12:58ad06f9847d 55 s_section2_1.consigne_position = 0.4;
GaspardD 12:58ad06f9847d 56 s_section2_1.targetSpeed_mps = 1600;
GaspardD 12:58ad06f9847d 57 s_section2_1.lng_section_m = 3.0;
GaspardD 12:58ad06f9847d 58 s_section2_1.coef_pos = 30;
GaspardD 12:58ad06f9847d 59 s_section2_1.coef_bord = 0.4;
GaspardD 12:58ad06f9847d 60 s_section2_1.plagePulseFreinage = 50;
GaspardD 12:58ad06f9847d 61
GaspardD 12:58ad06f9847d 62 //epingle 1 debut
GaspardD 12:58ad06f9847d 63 s_section3.nextSection = &s_section3_1;
GaspardD 12:58ad06f9847d 64 s_section3.consigne_position = 0.7;
GaspardD 12:58ad06f9847d 65 s_section3.targetSpeed_mps = 1620;
GaspardD 12:58ad06f9847d 66 s_section3.lng_section_m = 2.0;
GaspardD 12:58ad06f9847d 67 s_section3.coef_pos = 30;
GaspardD 12:58ad06f9847d 68 s_section3.coef_bord = 2.0;
GaspardD 12:58ad06f9847d 69 s_section3.plagePulseFreinage = 20;
GaspardD 12:58ad06f9847d 70
GaspardD 12:58ad06f9847d 71 //epingle 1 milieu
GaspardD 12:58ad06f9847d 72 s_section3_1.nextSection = &s_section4;
GaspardD 12:58ad06f9847d 73 s_section3_1.consigne_position = 0.7;
GaspardD 12:58ad06f9847d 74 s_section3_1.targetSpeed_mps = 1690;
GaspardD 12:58ad06f9847d 75 s_section3_1.lng_section_m = 4.0;
GaspardD 12:58ad06f9847d 76 s_section3_1.coef_pos = 30;
GaspardD 12:58ad06f9847d 77 s_section3_1.coef_bord = 2.0;
GaspardD 12:58ad06f9847d 78 s_section3_1.plagePulseFreinage = 20;
GaspardD 12:58ad06f9847d 79
GaspardD 12:58ad06f9847d 80 //post epingle 1
GaspardD 12:58ad06f9847d 81 s_section4.nextSection = &s_section5;
GaspardD 12:58ad06f9847d 82 s_section4.consigne_position = 0.8;
GaspardD 12:58ad06f9847d 83 s_section4.targetSpeed_mps = 1720;
GaspardD 12:58ad06f9847d 84 s_section4.lng_section_m = 5.0;
GaspardD 12:58ad06f9847d 85 s_section4.coef_pos = 30;
GaspardD 12:58ad06f9847d 86 s_section4.coef_bord = 1.3;
GaspardD 12:58ad06f9847d 87 s_section4.plagePulseFreinage = 30;
GaspardD 12:58ad06f9847d 88
GaspardD 12:58ad06f9847d 89 //droite epingle chicane
GaspardD 12:58ad06f9847d 90 s_section5.nextSection = &s_section5_1;
GaspardD 12:58ad06f9847d 91 s_section5.consigne_position = 0.6;
GaspardD 12:58ad06f9847d 92 s_section5.targetSpeed_mps = 1780;
GaspardD 12:58ad06f9847d 93 s_section5.lng_section_m = 7.0;
GaspardD 12:58ad06f9847d 94 s_section5.coef_pos = 30;
GaspardD 12:58ad06f9847d 95 s_section5.coef_bord = 0.7;
GaspardD 12:58ad06f9847d 96 s_section5.plagePulseFreinage = 40;
GaspardD 11:2156cb77d0d6 97
GaspardD 11:2156cb77d0d6 98
GaspardD 12:58ad06f9847d 99 //avant chicane
GaspardD 12:58ad06f9847d 100 s_section5_1.nextSection = &s_section6_0;
GaspardD 12:58ad06f9847d 101 s_section5_1.consigne_position = 0.8;
GaspardD 12:58ad06f9847d 102 s_section5_1.targetSpeed_mps = 1650;
GaspardD 12:58ad06f9847d 103 s_section5_1.lng_section_m = 4.0;
GaspardD 12:58ad06f9847d 104 s_section5_1.coef_pos = 30;
GaspardD 12:58ad06f9847d 105 s_section5_1.coef_bord = 2.0;
GaspardD 12:58ad06f9847d 106 s_section5_1.plagePulseFreinage = 40;
GaspardD 12:58ad06f9847d 107
GaspardD 12:58ad06f9847d 108 //pre chicane
GaspardD 12:58ad06f9847d 109 s_section6_0.nextSection = &s_section6;
GaspardD 12:58ad06f9847d 110 s_section6_0.consigne_position = 0.5;
GaspardD 12:58ad06f9847d 111 s_section6_0.targetSpeed_mps = 1650;
GaspardD 12:58ad06f9847d 112 s_section6_0.lng_section_m = 3.0;
GaspardD 12:58ad06f9847d 113 s_section6_0.coef_pos = 30;//50
GaspardD 12:58ad06f9847d 114 s_section6_0.coef_bord = 1.0;//2.0
GaspardD 12:58ad06f9847d 115 s_section6_0.plagePulseFreinage = 45;
GaspardD 12:58ad06f9847d 116
GaspardD 12:58ad06f9847d 117
GaspardD 12:58ad06f9847d 118 //chicane
GaspardD 12:58ad06f9847d 119 s_section6.nextSection = &s_section7;
GaspardD 12:58ad06f9847d 120 s_section6.consigne_position = 0.58;
GaspardD 12:58ad06f9847d 121 s_section6.targetSpeed_mps = 1675;
GaspardD 12:58ad06f9847d 122 s_section6.lng_section_m = 18.0;
GaspardD 12:58ad06f9847d 123 s_section6.coef_pos = 30;//50
GaspardD 12:58ad06f9847d 124 s_section6.coef_bord = 2.0;//2.0
GaspardD 12:58ad06f9847d 125 s_section6.plagePulseFreinage = 50;
GaspardD 12:58ad06f9847d 126
GaspardD 12:58ad06f9847d 127 //ligne droite postchicane
GaspardD 12:58ad06f9847d 128 s_section7.nextSection = &s_section8;
GaspardD 12:58ad06f9847d 129 s_section7.consigne_position = 0.5;
GaspardD 12:58ad06f9847d 130 s_section7.targetSpeed_mps = 1770;
GaspardD 12:58ad06f9847d 131 s_section7.lng_section_m = 8.0;
GaspardD 12:58ad06f9847d 132 s_section7.coef_pos = 30;
GaspardD 12:58ad06f9847d 133 s_section7.coef_bord = 0.5;
GaspardD 12:58ad06f9847d 134 s_section7.plagePulseFreinage = 50;
GaspardD 12:58ad06f9847d 135
GaspardD 12:58ad06f9847d 136
GaspardD 12:58ad06f9847d 137 //ligne droite debut
GaspardD 12:58ad06f9847d 138 s_section8.nextSection = &s_section9;
GaspardD 12:58ad06f9847d 139 s_section8.consigne_position = 0.4;
GaspardD 12:58ad06f9847d 140 s_section8.targetSpeed_mps = 1600;
GaspardD 12:58ad06f9847d 141 s_section8.lng_section_m = 3.0;
GaspardD 12:58ad06f9847d 142 s_section8.coef_pos = 30;
GaspardD 12:58ad06f9847d 143 s_section8.coef_bord = 0.4;
GaspardD 12:58ad06f9847d 144 s_section8.plagePulseFreinage = 50;
GaspardD 12:58ad06f9847d 145
GaspardD 12:58ad06f9847d 146 //epingle 2 debut
GaspardD 12:58ad06f9847d 147 s_section9.nextSection = &s_section9_1;
GaspardD 12:58ad06f9847d 148 s_section9.consigne_position = 0.7;
GaspardD 12:58ad06f9847d 149 s_section9.targetSpeed_mps = 1620;
GaspardD 12:58ad06f9847d 150 s_section9.lng_section_m = 2.0;
GaspardD 12:58ad06f9847d 151 s_section9.coef_pos = 30;
GaspardD 12:58ad06f9847d 152 s_section9.coef_bord = 2.0;
GaspardD 12:58ad06f9847d 153 s_section9.plagePulseFreinage = 20;
GaspardD 12:58ad06f9847d 154
GaspardD 12:58ad06f9847d 155 //epingle 2 milieu
GaspardD 12:58ad06f9847d 156 s_section9_1.nextSection = &s_section10;
GaspardD 12:58ad06f9847d 157 s_section9_1.consigne_position = 0.7;
GaspardD 12:58ad06f9847d 158 s_section9_1.targetSpeed_mps = 1680;
GaspardD 12:58ad06f9847d 159 s_section9_1.lng_section_m = 4.0;
GaspardD 12:58ad06f9847d 160 s_section9_1.coef_pos = 30;
GaspardD 12:58ad06f9847d 161 s_section9_1.coef_bord = 2.0;
GaspardD 12:58ad06f9847d 162 s_section9_1.plagePulseFreinage = 20;
GaspardD 12:58ad06f9847d 163
GaspardD 12:58ad06f9847d 164 //post epingle 2
GaspardD 12:58ad06f9847d 165 s_section10.nextSection = &s_section11;
GaspardD 12:58ad06f9847d 166 s_section10.consigne_position = 0.8;
GaspardD 12:58ad06f9847d 167 s_section10.targetSpeed_mps = 1720;
GaspardD 12:58ad06f9847d 168 s_section10.lng_section_m = 5.0;
GaspardD 12:58ad06f9847d 169 s_section10.coef_pos = 30;
GaspardD 12:58ad06f9847d 170 s_section10.coef_bord = 1.3;
GaspardD 12:58ad06f9847d 171 s_section10.plagePulseFreinage = 30;
GaspardD 12:58ad06f9847d 172
GaspardD 12:58ad06f9847d 173 //dernière ligne droite
GaspardD 12:58ad06f9847d 174 s_section11.nextSection = &s_section12;
GaspardD 12:58ad06f9847d 175 s_section11.consigne_position = 0.5;
GaspardD 12:58ad06f9847d 176 s_section11.targetSpeed_mps = 1790;
GaspardD 12:58ad06f9847d 177 s_section11.lng_section_m = 37.0;
GaspardD 12:58ad06f9847d 178 s_section11.coef_pos = 30;
GaspardD 12:58ad06f9847d 179 s_section11.coef_bord = 0.7;
GaspardD 12:58ad06f9847d 180 s_section11.plagePulseFreinage = 100;
GaspardD 12:58ad06f9847d 181
GaspardD 12:58ad06f9847d 182
GaspardD 12:58ad06f9847d 183 //frein
GaspardD 12:58ad06f9847d 184 s_section12.nextSection = NULL;
GaspardD 12:58ad06f9847d 185 s_section12.consigne_position = 0.5;
GaspardD 12:58ad06f9847d 186 s_section12.targetSpeed_mps = 1300;
GaspardD 12:58ad06f9847d 187 s_section12.lng_section_m = 0.1;
GaspardD 12:58ad06f9847d 188 s_section12.coef_pos = 80;
GaspardD 12:58ad06f9847d 189 s_section12.coef_bord = 1.0;
GaspardD 12:58ad06f9847d 190 s_section12.plagePulseFreinage = 20;
GaspardD 3:1b7eb426247e 191
GaspardD 3:1b7eb426247e 192 return;
GaspardD 3:1b7eb426247e 193 }
GaspardD 8:f23601373e8b 194 void update_sm_sections()
GaspardD 8:f23601373e8b 195 {
GaspardD 8:f23601373e8b 196
GaspardD 8:f23601373e8b 197 E_STATE_SECTIONS e_next_state = e_SECTIONS_state;
GaspardD 4:efa207509f63 198
GaspardD 9:1b54bac6d9a7 199 //rs_LOG_pc.printf("\r\nUpdate Section\r\n");
GaspardD 8:f23601373e8b 200
GaspardD 8:f23601373e8b 201 if(b_UTILS_flag_emergency_stop) {
GaspardD 12:58ad06f9847d 202 rs_LOG.printf("emergency stop -> STOPPED\r\n");
GaspardD 4:efa207509f63 203 e_next_state = STOPPED;
GaspardD 4:efa207509f63 204 } else {
GaspardD 8:f23601373e8b 205 switch (e_SECTIONS_state) {
GaspardD 4:efa207509f63 206 case INIT_SECTION:
GaspardD 8:f23601373e8b 207 e_next_state = RUNNING_SECTION;
GaspardD 9:1b54bac6d9a7 208 //rs_LOG_pc.printf("RUNNING SECTION\r\n");
GaspardD 8:f23601373e8b 209 break;
GaspardD 4:efa207509f63 210 case RUNNING_SECTION:
GaspardD 6:ab9f3695633f 211 if(d_ODOM_distFromSectionStart_m > s_UTILS_currentSection->lng_section_m) {
GaspardD 4:efa207509f63 212 e_next_state = LOADING_SECTION;
GaspardD 9:1b54bac6d9a7 213 //rs_LOG_pc.printf("LOADING SECTION !\r\n");
GaspardD 4:efa207509f63 214 }
GaspardD 4:efa207509f63 215 break;
GaspardD 4:efa207509f63 216 case LOADING_SECTION:
GaspardD 8:f23601373e8b 217 if(s_UTILS_currentSection != NULL) {
GaspardD 4:efa207509f63 218 e_next_state = RUNNING_SECTION;
GaspardD 9:1b54bac6d9a7 219 //rs_LOG_pc.printf("RUNNING SECTION !\r\n");
GaspardD 4:efa207509f63 220 } else {
GaspardD 8:f23601373e8b 221 b_UTILS_flag_emergency_stop = true;
GaspardD 11:2156cb77d0d6 222 log_stop();
GaspardD 8:f23601373e8b 223 e_next_state = STOPPED;
GaspardD 4:efa207509f63 224 }
GaspardD 4:efa207509f63 225 break;
GaspardD 4:efa207509f63 226 case STOPPED:
GaspardD 8:f23601373e8b 227 if(b_UTILS_flag_button_SECTIONS) {
GaspardD 8:f23601373e8b 228 e_next_state = INIT_SECTION;
GaspardD 12:58ad06f9847d 229 rs_LOG.printf("INIT SECTION !\r\n");
GaspardD 4:efa207509f63 230 }
GaspardD 4:efa207509f63 231 break;
GaspardD 4:efa207509f63 232 default:
GaspardD 4:efa207509f63 233 break;
GaspardD 4:efa207509f63 234 }
GaspardD 4:efa207509f63 235 }
GaspardD 8:f23601373e8b 236 e_SECTIONS_state = e_next_state;
GaspardD 3:1b7eb426247e 237 return;
GaspardD 3:1b7eb426247e 238 }
GaspardD 8:f23601373e8b 239 void output_sm_sections()
GaspardD 8:f23601373e8b 240 {
GaspardD 8:f23601373e8b 241 switch (e_SECTIONS_state) {
GaspardD 8:f23601373e8b 242 case INIT_SECTION:
GaspardD 8:f23601373e8b 243 b_UTILS_flag_button_SECTIONS = false;
GaspardD 6:ab9f3695633f 244 s_UTILS_currentSection = &s_section1;
GaspardD 12:58ad06f9847d 245 rs_LOG.printf("sect 1 INITIALIZED\r\n");
GaspardD 8:f23601373e8b 246 case RUNNING_SECTION:
GaspardD 8:f23601373e8b 247 break;
GaspardD 8:f23601373e8b 248 case LOADING_SECTION:
GaspardD 9:1b54bac6d9a7 249 //rs_LOG_pc.printf("next section loading\r\n");
GaspardD 8:f23601373e8b 250 s_UTILS_currentSection=s_UTILS_currentSection->nextSection;
GaspardD 8:f23601373e8b 251 d_ODOM_distFromSectionStart_m = 0.0;
GaspardD 8:f23601373e8b 252 break;
GaspardD 8:f23601373e8b 253 case STOPPED:
GaspardD 8:f23601373e8b 254 //on est à l'arret
GaspardD 8:f23601373e8b 255 break;
GaspardD 8:f23601373e8b 256 default:
GaspardD 8:f23601373e8b 257 break;
GaspardD 4:efa207509f63 258 }
GaspardD 3:1b7eb426247e 259 return;
GaspardD 3:1b7eb426247e 260 }