squelette de demarrage projet ERS3 IUT NICE GEII
Dependencies: EthernetInterface bloc_io html mbed-rtos mbed
Fork of scooter_mbed_etudiant by
main.cpp@1:a9ee3c2f4fc8, 2017-11-15 (annotated)
- Committer:
- lebg
- Date:
- Wed Nov 15 13:51:19 2017 +0000
- Revision:
- 1:a9ee3c2f4fc8
- Parent:
- 0:e30c9ba95bd4
kk
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
superphil06 | 0:e30c9ba95bd4 | 1 | |
superphil06 | 0:e30c9ba95bd4 | 2 | |
superphil06 | 0:e30c9ba95bd4 | 3 | //#include "EthernetInterface.h" |
superphil06 | 0:e30c9ba95bd4 | 4 | #include <stdlib.h> |
superphil06 | 0:e30c9ba95bd4 | 5 | #include <string.h> |
superphil06 | 0:e30c9ba95bd4 | 6 | #include "mbed.h" |
superphil06 | 0:e30c9ba95bd4 | 7 | #include "rtos.h" // need for main thread sleep |
superphil06 | 0:e30c9ba95bd4 | 8 | #include "html.h" // need for html patch working with web server |
superphil06 | 0:e30c9ba95bd4 | 9 | #include "bloc_io.h" |
superphil06 | 0:e30c9ba95bd4 | 10 | #define RADIUS 0.2F // wheel size |
superphil06 | 0:e30c9ba95bd4 | 11 | #define NBPOLES 8 // magnetic pole number |
superphil06 | 0:e30c9ba95bd4 | 12 | #define DELTA_T 0.1F // speed measurement counting period |
lebg | 1:a9ee3c2f4fc8 | 13 | #define AUTO 0 //definition des valeurs pour les differents modes |
lebg | 1:a9ee3c2f4fc8 | 14 | #define MANUEL 1 |
lebg | 1:a9ee3c2f4fc8 | 15 | #define DT 0.2 |
lebg | 1:a9ee3c2f4fc8 | 16 | #define pi 3.14159 |
lebg | 1:a9ee3c2f4fc8 | 17 | #define POLE 8 |
lebg | 1:a9ee3c2f4fc8 | 18 | #define RAYON 0.19 |
lebg | 1:a9ee3c2f4fc8 | 19 | #define TICKER_PROGRESSIF 0.05 |
lebg | 1:a9ee3c2f4fc8 | 20 | #define TICKER_TENSION_BATTERIE 0.2 |
lebg | 1:a9ee3c2f4fc8 | 21 | #define TICKER_TENSION_TEMPERATURE 0.2 |
lebg | 1:a9ee3c2f4fc8 | 22 | #define TEMP_MAX 373 |
lebg | 1:a9ee3c2f4fc8 | 23 | #define TENSION_BAT_MAX 30 |
lebg | 1:a9ee3c2f4fc8 | 24 | #define TENSION_BAT_MIN 20 |
lebg | 1:a9ee3c2f4fc8 | 25 | #define TENSION_TEMP_MAX 3.73 |
lebg | 1:a9ee3c2f4fc8 | 26 | #define BAT_MAX 0.386 |
lebg | 1:a9ee3c2f4fc8 | 27 | #define TICKER_TENSION_COURANT 0.2 |
lebg | 1:a9ee3c2f4fc8 | 28 | #define RESISTANCE_EQUIVALENTE 0.5409836 |
lebg | 1:a9ee3c2f4fc8 | 29 | #define PENTE_CAPTEUR_COURANT 0.185 |
lebg | 1:a9ee3c2f4fc8 | 30 | #define TENSION_CPT_COURANT_MIN 2.505 |
superphil06 | 0:e30c9ba95bd4 | 31 | |
superphil06 | 0:e30c9ba95bd4 | 32 | Bloc_IO MyPLD(p25,p26,p5,p6,p7,p8,p9,p10,p23,p24);// instantiate object needed to communicate with PLD |
lebg | 1:a9ee3c2f4fc8 | 33 | // analog input connected to mbed |
superphil06 | 0:e30c9ba95bd4 | 34 | Serial pc(USBTX, USBRX); // tx, rx |
lebg | 1:a9ee3c2f4fc8 | 35 | // Top_Hall Pin |
lebg | 1:a9ee3c2f4fc8 | 36 | |
lebg | 1:a9ee3c2f4fc8 | 37 | |
lebg | 1:a9ee3c2f4fc8 | 38 | |
lebg | 1:a9ee3c2f4fc8 | 39 | |
superphil06 | 0:e30c9ba95bd4 | 40 | /************ persistent file parameters section *****************/ |
superphil06 | 0:e30c9ba95bd4 | 41 | LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
lebg | 1:a9ee3c2f4fc8 | 42 | |
lebg | 1:a9ee3c2f4fc8 | 43 | |
lebg | 1:a9ee3c2f4fc8 | 44 | |
superphil06 | 0:e30c9ba95bd4 | 45 | |
lebg | 1:a9ee3c2f4fc8 | 46 | |
lebg | 1:a9ee3c2f4fc8 | 47 | |
lebg | 1:a9ee3c2f4fc8 | 48 | |
superphil06 | 0:e30c9ba95bd4 | 49 | /********************* web server section **********************************/ |
superphil06 | 0:e30c9ba95bd4 | 50 | |
superphil06 | 0:e30c9ba95bd4 | 51 | var_field_t tab_balise[10]; //une balise est présente dans le squelette |
lebg | 1:a9ee3c2f4fc8 | 52 | int iCounter=0;// acces counting |
superphil06 | 0:e30c9ba95bd4 | 53 | |
superphil06 | 0:e30c9ba95bd4 | 54 | |
superphil06 | 0:e30c9ba95bd4 | 55 | /*********************** can bus section ************/ |
lebg | 1:a9ee3c2f4fc8 | 56 | // determine message ID used to send Gaz ref over can bus |
superphil06 | 0:e30c9ba95bd4 | 57 | #define _CAN_DEBUG // used to debug can bus activity |
superphil06 | 0:e30c9ba95bd4 | 58 | //#define USE_CAN_REF // uncomment to receive gaz ref over can_bus |
superphil06 | 0:e30c9ba95bd4 | 59 | CAN can_port (p30, p29); // initialisation du Bus CAN sur les broches 30 (rd) et 29(td) for lpc1768 + mbed shield |
superphil06 | 0:e30c9ba95bd4 | 60 | bool bCan_Active=false; |
superphil06 | 0:e30c9ba95bd4 | 61 | |
superphil06 | 0:e30c9ba95bd4 | 62 | |
superphil06 | 0:e30c9ba95bd4 | 63 | |
superphil06 | 0:e30c9ba95bd4 | 64 | DigitalOut led1(LED1); //initialisation des Leds présentes sur le micro-controleur Mbed*/ |
superphil06 | 0:e30c9ba95bd4 | 65 | DigitalOut led2(LED2); |
superphil06 | 0:e30c9ba95bd4 | 66 | DigitalOut led3(LED3); // blink when can message is sent |
lebg | 1:a9ee3c2f4fc8 | 67 | DigitalOut led4(LED4); // blink when can message is received |
lebg | 1:a9ee3c2f4fc8 | 68 | DigitalOut valid_pwm(p21); |
lebg | 1:a9ee3c2f4fc8 | 69 | AnalogIn Vgaz(p17); |
lebg | 1:a9ee3c2f4fc8 | 70 | Ticker COMMANDE; |
lebg | 1:a9ee3c2f4fc8 | 71 | Ticker VITESSE; |
lebg | 1:a9ee3c2f4fc8 | 72 | Ticker GAZ; |
lebg | 1:a9ee3c2f4fc8 | 73 | Ticker TENSION_BATTERIE; |
lebg | 1:a9ee3c2f4fc8 | 74 | Ticker TENSION_TEMPERATURE; |
lebg | 1:a9ee3c2f4fc8 | 75 | Ticker TENSION_COURANT; |
lebg | 1:a9ee3c2f4fc8 | 76 | InterruptIn valid(p22); |
lebg | 1:a9ee3c2f4fc8 | 77 | AnalogIn Vbat(p18); |
lebg | 1:a9ee3c2f4fc8 | 78 | AnalogIn Vtemp(p19); |
lebg | 1:a9ee3c2f4fc8 | 79 | AnalogIn Vcourant(p20); |
superphil06 | 0:e30c9ba95bd4 | 80 | |
superphil06 | 0:e30c9ba95bd4 | 81 | |
superphil06 | 0:e30c9ba95bd4 | 82 | //************ local function prototypes ******************* |
lebg | 1:a9ee3c2f4fc8 | 83 | void commande_gaz(); //fonction de commande des gaz par la poignée |
lebg | 1:a9ee3c2f4fc8 | 84 | void cpt_vit(); |
lebg | 1:a9ee3c2f4fc8 | 85 | void calc_vit(); |
lebg | 1:a9ee3c2f4fc8 | 86 | void acceleration_progressive(); |
lebg | 1:a9ee3c2f4fc8 | 87 | void tension_batterie(); |
lebg | 1:a9ee3c2f4fc8 | 88 | void tension_temperature(); |
lebg | 1:a9ee3c2f4fc8 | 89 | void tension_courant(); |
superphil06 | 0:e30c9ba95bd4 | 90 | |
superphil06 | 0:e30c9ba95bd4 | 91 | |
superphil06 | 0:e30c9ba95bd4 | 92 | |
lebg | 1:a9ee3c2f4fc8 | 93 | //*************************Variable globale********************************************************/ |
lebg | 1:a9ee3c2f4fc8 | 94 | float Nmin,Nmax,Ngaz,fVbat,fTension,Puissance_Gaz,fTemperature,fVtemp,fCourant,fVcourant; |
lebg | 1:a9ee3c2f4fc8 | 95 | int iREF_PWM_MANUEL_BRUT; |
lebg | 1:a9ee3c2f4fc8 | 96 | int iREF_PWM_AUTO_BRUT,iREF_PWM_AUTO_FINALE; |
lebg | 1:a9ee3c2f4fc8 | 97 | int imode; |
lebg | 1:a9ee3c2f4fc8 | 98 | int ireg; |
lebg | 1:a9ee3c2f4fc8 | 99 | int iHALL,iBRAKE,iFALT,iOC,iDIR; |
lebg | 1:a9ee3c2f4fc8 | 100 | int iLim_vit; |
lebg | 1:a9ee3c2f4fc8 | 101 | float fv,fcpt,fnbr_poles; |
superphil06 | 0:e30c9ba95bd4 | 102 | |
superphil06 | 0:e30c9ba95bd4 | 103 | /**************** Read persistent data from text file located on local file system ****************/ |
superphil06 | 0:e30c9ba95bd4 | 104 | |
superphil06 | 0:e30c9ba95bd4 | 105 | |
superphil06 | 0:e30c9ba95bd4 | 106 | |
superphil06 | 0:e30c9ba95bd4 | 107 | /**************** write persitant data to text file located on local file system ****************/ |
superphil06 | 0:e30c9ba95bd4 | 108 | |
superphil06 | 0:e30c9ba95bd4 | 109 | |
superphil06 | 0:e30c9ba95bd4 | 110 | |
superphil06 | 0:e30c9ba95bd4 | 111 | |
superphil06 | 0:e30c9ba95bd4 | 112 | |
superphil06 | 0:e30c9ba95bd4 | 113 | |
superphil06 | 0:e30c9ba95bd4 | 114 | //************** calibation gaz function needed to record min_gaz and max_gaz value to persistent text file ****************** |
superphil06 | 0:e30c9ba95bd4 | 115 | |
superphil06 | 0:e30c9ba95bd4 | 116 | |
superphil06 | 0:e30c9ba95bd4 | 117 | // ************top hall counting interrupt needed for speed measurement |
superphil06 | 0:e30c9ba95bd4 | 118 | |
superphil06 | 0:e30c9ba95bd4 | 119 | |
superphil06 | 0:e30c9ba95bd4 | 120 | //********************** timer interrupt for speed measurement each 100ms ************************* |
superphil06 | 0:e30c9ba95bd4 | 121 | |
lebg | 1:a9ee3c2f4fc8 | 122 | |
lebg | 1:a9ee3c2f4fc8 | 123 | |
lebg | 1:a9ee3c2f4fc8 | 124 | |
superphil06 | 0:e30c9ba95bd4 | 125 | |
superphil06 | 0:e30c9ba95bd4 | 126 | |
superphil06 | 0:e30c9ba95bd4 | 127 | //********************* Timer Interrupt for gaz ref management each 10ms ******************** |
superphil06 | 0:e30c9ba95bd4 | 128 | |
superphil06 | 0:e30c9ba95bd4 | 129 | |
superphil06 | 0:e30c9ba95bd4 | 130 | |
superphil06 | 0:e30c9ba95bd4 | 131 | /********* main cgi function used to patch data to the web server thread **********************************/ |
superphil06 | 0:e30c9ba95bd4 | 132 | void CGI_Function(void) // cgi function that patch web data to empty web page |
superphil06 | 0:e30c9ba95bd4 | 133 | |
lebg | 1:a9ee3c2f4fc8 | 134 | { char ma_chaine4[20]={};// needed to form html response |
lebg | 1:a9ee3c2f4fc8 | 135 | sprintf (ma_chaine4,"%d",iCounter);// convert speed as ascii string |
lebg | 1:a9ee3c2f4fc8 | 136 | Html_Patch (tab_balise,0,ma_chaine4);// patch first label with dyn.string |
lebg | 1:a9ee3c2f4fc8 | 137 | iCounter++; |
superphil06 | 0:e30c9ba95bd4 | 138 | } |
lebg | 1:a9ee3c2f4fc8 | 139 | |
lebg | 1:a9ee3c2f4fc8 | 140 | |
lebg | 1:a9ee3c2f4fc8 | 141 | /*********************** CAN BUS SECTION **********************/ |
lebg | 1:a9ee3c2f4fc8 | 142 | |
superphil06 | 0:e30c9ba95bd4 | 143 | |
superphil06 | 0:e30c9ba95bd4 | 144 | |
superphil06 | 0:e30c9ba95bd4 | 145 | void CAN_REC_THREAD(void const *args) |
lebg | 1:a9ee3c2f4fc8 | 146 | { |
lebg | 1:a9ee3c2f4fc8 | 147 | int iCount,iError; |
superphil06 | 0:e30c9ba95bd4 | 148 | |
lebg | 1:a9ee3c2f4fc8 | 149 | while (bCan_Active) { |
lebg | 1:a9ee3c2f4fc8 | 150 | Thread::wait(100);// wait 100ms |
lebg | 1:a9ee3c2f4fc8 | 151 | // code todo |
lebg | 1:a9ee3c2f4fc8 | 152 | |
superphil06 | 0:e30c9ba95bd4 | 153 | } |
lebg | 1:a9ee3c2f4fc8 | 154 | |
superphil06 | 0:e30c9ba95bd4 | 155 | } |
superphil06 | 0:e30c9ba95bd4 | 156 | |
superphil06 | 0:e30c9ba95bd4 | 157 | |
superphil06 | 0:e30c9ba95bd4 | 158 | |
lebg | 1:a9ee3c2f4fc8 | 159 | //*************************** main function ***************************************** |
lebg | 1:a9ee3c2f4fc8 | 160 | int main() |
lebg | 1:a9ee3c2f4fc8 | 161 | { |
lebg | 1:a9ee3c2f4fc8 | 162 | |
lebg | 1:a9ee3c2f4fc8 | 163 | |
lebg | 1:a9ee3c2f4fc8 | 164 | char cChoix=0; |
lebg | 1:a9ee3c2f4fc8 | 165 | char cCalibre=0; |
lebg | 1:a9ee3c2f4fc8 | 166 | char cRegistre=0; |
lebg | 1:a9ee3c2f4fc8 | 167 | char cVitesse=0; |
lebg | 1:a9ee3c2f4fc8 | 168 | char cAlim=0; |
lebg | 1:a9ee3c2f4fc8 | 169 | valid_pwm.write(0); |
lebg | 1:a9ee3c2f4fc8 | 170 | iREF_PWM_MANUEL_BRUT=0; |
lebg | 1:a9ee3c2f4fc8 | 171 | iREF_PWM_AUTO_BRUT=0; |
lebg | 1:a9ee3c2f4fc8 | 172 | iREF_PWM_AUTO_FINALE=0; |
lebg | 1:a9ee3c2f4fc8 | 173 | // limite de vitesse en m/h par défaut |
superphil06 | 0:e30c9ba95bd4 | 174 | |
superphil06 | 0:e30c9ba95bd4 | 175 | |
lebg | 1:a9ee3c2f4fc8 | 176 | valid.mode(PullUp); |
lebg | 1:a9ee3c2f4fc8 | 177 | MyPLD.write(0); |
lebg | 1:a9ee3c2f4fc8 | 178 | valid_pwm.write(1); |
lebg | 1:a9ee3c2f4fc8 | 179 | imode=AUTO; //mode d'initialisation = AUTO |
lebg | 1:a9ee3c2f4fc8 | 180 | FILE *fp = fopen("/local/scoot.txt", "r"); |
lebg | 1:a9ee3c2f4fc8 | 181 | if(fp!= NULL) { |
lebg | 1:a9ee3c2f4fc8 | 182 | fscanf(fp,"%f %f %d",&Nmin,&Nmax,&iLim_vit); |
lebg | 1:a9ee3c2f4fc8 | 183 | fclose(fp); |
lebg | 1:a9ee3c2f4fc8 | 184 | } else { |
lebg | 1:a9ee3c2f4fc8 | 185 | pc.printf("fichier non ouvert\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 186 | fclose(fp); |
lebg | 1:a9ee3c2f4fc8 | 187 | } |
lebg | 1:a9ee3c2f4fc8 | 188 | /*Nmax=0.5; |
lebg | 1:a9ee3c2f4fc8 | 189 | Nmin=0.3;*/ |
lebg | 1:a9ee3c2f4fc8 | 190 | |
superphil06 | 0:e30c9ba95bd4 | 191 | //***************************************** web section ********************************************/ |
lebg | 1:a9ee3c2f4fc8 | 192 | pc.printf("\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 193 | pc.printf("searching broadcast...\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 194 | pc.printf("wait...\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 195 | Init_Web_Server(&CGI_Function); // create and initialize tcp server socket and pass function pointer to local CGI function |
lebg | 1:a9ee3c2f4fc8 | 196 | Thread WebThread(Web_Server_Thread);// create and launch web server thread |
lebg | 1:a9ee3c2f4fc8 | 197 | Gen_HtmlCode_From_File("/local/pagecgi2.htm",tab_balise,1);// read and localise ^VARDEF[X] tag in empty html file |
lebg | 1:a9ee3c2f4fc8 | 198 | /********* main cgi function used to patch data to the web server thread **********************************/ |
lebg | 1:a9ee3c2f4fc8 | 199 | |
superphil06 | 0:e30c9ba95bd4 | 200 | |
lebg | 1:a9ee3c2f4fc8 | 201 | //******************************************* end web section ************************************* / |
lebg | 1:a9ee3c2f4fc8 | 202 | COMMANDE.attach(&commande_gaz,0.1); |
lebg | 1:a9ee3c2f4fc8 | 203 | valid.rise(&cpt_vit); |
lebg | 1:a9ee3c2f4fc8 | 204 | VITESSE.attach(&calc_vit,DT); |
lebg | 1:a9ee3c2f4fc8 | 205 | GAZ.attach(&acceleration_progressive,TICKER_PROGRESSIF); |
lebg | 1:a9ee3c2f4fc8 | 206 | TENSION_BATTERIE.attach(&tension_batterie,TICKER_TENSION_BATTERIE ); |
lebg | 1:a9ee3c2f4fc8 | 207 | TENSION_TEMPERATURE.attach(&tension_temperature,TICKER_TENSION_TEMPERATURE); |
lebg | 1:a9ee3c2f4fc8 | 208 | TENSION_COURANT.attach(&tension_courant,TICKER_TENSION_COURANT); |
superphil06 | 0:e30c9ba95bd4 | 209 | |
superphil06 | 0:e30c9ba95bd4 | 210 | |
superphil06 | 0:e30c9ba95bd4 | 211 | |
lebg | 1:a9ee3c2f4fc8 | 212 | pc.printf(" programme scooter mbed \n\r"); |
superphil06 | 0:e30c9ba95bd4 | 213 | |
superphil06 | 0:e30c9ba95bd4 | 214 | |
superphil06 | 0:e30c9ba95bd4 | 215 | |
superphil06 | 0:e30c9ba95bd4 | 216 | //********************* can bus section initialisation ******************************************* |
superphil06 | 0:e30c9ba95bd4 | 217 | //bCan_Active=true;// needed to lauchn CAN thread |
superphil06 | 0:e30c9ba95bd4 | 218 | //Thread CanThread(CAN_REC_THREAD);// create and launch can receiver thread |
superphil06 | 0:e30c9ba95bd4 | 219 | //********************* end can bus section ***************************************************** |
superphil06 | 0:e30c9ba95bd4 | 220 | |
superphil06 | 0:e30c9ba95bd4 | 221 | |
lebg | 1:a9ee3c2f4fc8 | 222 | while(cChoix!='q' and cChoix!='Q') |
lebg | 1:a9ee3c2f4fc8 | 223 | |
lebg | 1:a9ee3c2f4fc8 | 224 | { |
lebg | 1:a9ee3c2f4fc8 | 225 | pc.printf(" veuillez saisir un choix parmi la liste proposee: \n\r"); |
lebg | 1:a9ee3c2f4fc8 | 226 | pc.printf(" 1:lecture poignée gaz\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 227 | pc.printf(" 2:lecture courant\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 228 | pc.printf(" 3:parametre batterie\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 229 | pc.printf(" 4:lecture temperature\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 230 | pc.printf(" 5:parametres vitesse\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 231 | pc.printf(" 6:lecture pe\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 232 | pc.printf(" 7:parametres Nmin,Nmax\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 233 | pc.printf(" 8:saisir PWM (0 a 255)\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 234 | pc.printf(" 9:lecture du registre\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 235 | pc.printf(" q:quitter \n"); |
lebg | 1:a9ee3c2f4fc8 | 236 | pc.printf(" mode=%d\n\r",imode); |
lebg | 1:a9ee3c2f4fc8 | 237 | cRegistre=0; |
lebg | 1:a9ee3c2f4fc8 | 238 | cCalibre=0; |
lebg | 1:a9ee3c2f4fc8 | 239 | cVitesse=0; |
lebg | 1:a9ee3c2f4fc8 | 240 | cAlim=0; |
lebg | 1:a9ee3c2f4fc8 | 241 | valid_pwm.write(1); |
lebg | 1:a9ee3c2f4fc8 | 242 | /************* multithreading : main thread need to sleep in order to allow web response */ |
lebg | 1:a9ee3c2f4fc8 | 243 | while (pc.readable()==0) { // determine if char availabler |
lebg | 1:a9ee3c2f4fc8 | 244 | Thread::wait(10); // wait 10 until char available on serial input |
lebg | 1:a9ee3c2f4fc8 | 245 | } |
lebg | 1:a9ee3c2f4fc8 | 246 | /************* end of main thread sleep ****************/ |
lebg | 1:a9ee3c2f4fc8 | 247 | |
lebg | 1:a9ee3c2f4fc8 | 248 | pc.scanf(" %c",&cChoix); |
lebg | 1:a9ee3c2f4fc8 | 249 | switch (cChoix) { |
lebg | 1:a9ee3c2f4fc8 | 250 | case '1': |
lebg | 1:a9ee3c2f4fc8 | 251 | pc.printf("poignee = %f\n\r",Ngaz); |
lebg | 1:a9ee3c2f4fc8 | 252 | break; |
lebg | 1:a9ee3c2f4fc8 | 253 | case '2': |
lebg | 1:a9ee3c2f4fc8 | 254 | break; |
lebg | 1:a9ee3c2f4fc8 | 255 | case '3': |
lebg | 1:a9ee3c2f4fc8 | 256 | while(cAlim!='q') { |
lebg | 1:a9ee3c2f4fc8 | 257 | pc.printf("1:lecture tension batterie\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 258 | pc.printf("2:lecture courant batterie\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 259 | pc.printf("3:lecture temperature batterie\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 260 | pc.printf("q:menu principal\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 261 | pc.scanf(" %c",&cAlim); |
lebg | 1:a9ee3c2f4fc8 | 262 | switch(cAlim) { |
lebg | 1:a9ee3c2f4fc8 | 263 | case '1': |
lebg | 1:a9ee3c2f4fc8 | 264 | pc.printf("tension batterie : %f V\n\r",fTension); |
lebg | 1:a9ee3c2f4fc8 | 265 | break; |
lebg | 1:a9ee3c2f4fc8 | 266 | case '2': |
lebg | 1:a9ee3c2f4fc8 | 267 | pc.printf("courant mesure : %f A\n\r",fCourant); |
lebg | 1:a9ee3c2f4fc8 | 268 | break; |
lebg | 1:a9ee3c2f4fc8 | 269 | case '3': |
lebg | 1:a9ee3c2f4fc8 | 270 | pc.printf("temperature batterie :%f °C\n\r",fTemperature); |
lebg | 1:a9ee3c2f4fc8 | 271 | break; |
lebg | 1:a9ee3c2f4fc8 | 272 | } |
lebg | 1:a9ee3c2f4fc8 | 273 | } |
lebg | 1:a9ee3c2f4fc8 | 274 | |
lebg | 1:a9ee3c2f4fc8 | 275 | break; |
lebg | 1:a9ee3c2f4fc8 | 276 | case '4': |
lebg | 1:a9ee3c2f4fc8 | 277 | break; |
lebg | 1:a9ee3c2f4fc8 | 278 | case '5': |
lebg | 1:a9ee3c2f4fc8 | 279 | while(cVitesse!='q') { |
lebg | 1:a9ee3c2f4fc8 | 280 | pc.printf("1:lecture vitesse en m/s\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 281 | pc.printf("2:lecture vitesse en m/h\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 282 | pc.printf("3:lecture vitesse en km/h\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 283 | pc.printf("4:limite de vitesse = %d , redefinir ?\n\r",iLim_vit); |
lebg | 1:a9ee3c2f4fc8 | 284 | pc.printf("q:menu principal\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 285 | pc.scanf("%c",&cVitesse); |
lebg | 1:a9ee3c2f4fc8 | 286 | switch(cVitesse) { |
lebg | 1:a9ee3c2f4fc8 | 287 | case '1': |
lebg | 1:a9ee3c2f4fc8 | 288 | pc.printf("%f m/s\n\r",fv); |
lebg | 1:a9ee3c2f4fc8 | 289 | break; |
lebg | 1:a9ee3c2f4fc8 | 290 | case '2': |
lebg | 1:a9ee3c2f4fc8 | 291 | pc.printf("%f m/h\n\r",fv*3600); |
lebg | 1:a9ee3c2f4fc8 | 292 | break; |
lebg | 1:a9ee3c2f4fc8 | 293 | case '3': |
lebg | 1:a9ee3c2f4fc8 | 294 | pc.printf("%f km/h\n\r",fv*3.6); |
lebg | 1:a9ee3c2f4fc8 | 295 | break; |
lebg | 1:a9ee3c2f4fc8 | 296 | case'4': |
lebg | 1:a9ee3c2f4fc8 | 297 | pc.printf("choisir limite : "); |
lebg | 1:a9ee3c2f4fc8 | 298 | pc.scanf("%d",&iLim_vit); |
lebg | 1:a9ee3c2f4fc8 | 299 | |
lebg | 1:a9ee3c2f4fc8 | 300 | } |
lebg | 1:a9ee3c2f4fc8 | 301 | } |
lebg | 1:a9ee3c2f4fc8 | 302 | break; |
lebg | 1:a9ee3c2f4fc8 | 303 | case '6': |
lebg | 1:a9ee3c2f4fc8 | 304 | break; |
lebg | 1:a9ee3c2f4fc8 | 305 | case '7': |
lebg | 1:a9ee3c2f4fc8 | 306 | valid_pwm.write(0); |
lebg | 1:a9ee3c2f4fc8 | 307 | while(cCalibre!='q') { |
lebg | 1:a9ee3c2f4fc8 | 308 | pc.printf("1:definir Nmin ? mettre poignee au min puis saisir 1\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 309 | pc.printf("2:definir Nmax ? mettre poignee au max puis saisir 2\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 310 | pc.printf("3:lecture Nmin,Nmax\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 311 | pc.printf("q:menu principal\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 312 | pc.scanf("%c",&cCalibre); |
lebg | 1:a9ee3c2f4fc8 | 313 | |
lebg | 1:a9ee3c2f4fc8 | 314 | switch(cCalibre) { |
lebg | 1:a9ee3c2f4fc8 | 315 | case '1': |
lebg | 1:a9ee3c2f4fc8 | 316 | Nmin=Ngaz; |
lebg | 1:a9ee3c2f4fc8 | 317 | pc.printf("Nmin = %f\n\r",Nmin); |
lebg | 1:a9ee3c2f4fc8 | 318 | break; |
lebg | 1:a9ee3c2f4fc8 | 319 | case '2': |
lebg | 1:a9ee3c2f4fc8 | 320 | Nmax=Ngaz; |
lebg | 1:a9ee3c2f4fc8 | 321 | pc.printf("Nmax = %f\n\r",Nmax); |
lebg | 1:a9ee3c2f4fc8 | 322 | break; |
lebg | 1:a9ee3c2f4fc8 | 323 | case '3': |
lebg | 1:a9ee3c2f4fc8 | 324 | pc.printf("Nmin=%f\n\r",Nmin); |
lebg | 1:a9ee3c2f4fc8 | 325 | pc.printf("Nmax=%f\n\r",Nmax); |
lebg | 1:a9ee3c2f4fc8 | 326 | pc.printf("puissance=%f %%\n\r",Puissance_Gaz); |
lebg | 1:a9ee3c2f4fc8 | 327 | break; |
lebg | 1:a9ee3c2f4fc8 | 328 | } |
lebg | 1:a9ee3c2f4fc8 | 329 | } |
lebg | 1:a9ee3c2f4fc8 | 330 | |
lebg | 1:a9ee3c2f4fc8 | 331 | |
lebg | 1:a9ee3c2f4fc8 | 332 | break; |
lebg | 1:a9ee3c2f4fc8 | 333 | case '8': |
lebg | 1:a9ee3c2f4fc8 | 334 | pc.printf("choisir pwm :"); |
lebg | 1:a9ee3c2f4fc8 | 335 | pc.scanf("%d",&iREF_PWM_MANUEL_BRUT); |
lebg | 1:a9ee3c2f4fc8 | 336 | if(iREF_PWM_MANUEL_BRUT>255) { |
lebg | 1:a9ee3c2f4fc8 | 337 | iREF_PWM_MANUEL_BRUT=0; |
lebg | 1:a9ee3c2f4fc8 | 338 | } |
lebg | 1:a9ee3c2f4fc8 | 339 | pc.printf("%d\n\r",iREF_PWM_MANUEL_BRUT); |
lebg | 1:a9ee3c2f4fc8 | 340 | |
lebg | 1:a9ee3c2f4fc8 | 341 | break; |
lebg | 1:a9ee3c2f4fc8 | 342 | case '9': |
lebg | 1:a9ee3c2f4fc8 | 343 | while(cRegistre!='q') { |
lebg | 1:a9ee3c2f4fc8 | 344 | pc.printf("1:lecture registre\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 345 | pc.printf("q:quitter\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 346 | pc.scanf(" %c",&cRegistre); |
lebg | 1:a9ee3c2f4fc8 | 347 | |
lebg | 1:a9ee3c2f4fc8 | 348 | switch(cRegistre) { |
lebg | 1:a9ee3c2f4fc8 | 349 | case'1': |
lebg | 1:a9ee3c2f4fc8 | 350 | ireg=MyPLD.read(); |
lebg | 1:a9ee3c2f4fc8 | 351 | iHALL=ireg & 0x07; |
lebg | 1:a9ee3c2f4fc8 | 352 | iBRAKE=ireg & 0x20; |
lebg | 1:a9ee3c2f4fc8 | 353 | iDIR=ireg & 0x08; |
lebg | 1:a9ee3c2f4fc8 | 354 | iFALT=ireg & 0x10; |
lebg | 1:a9ee3c2f4fc8 | 355 | iOC=ireg & 0x40; |
lebg | 1:a9ee3c2f4fc8 | 356 | pc.printf("secteur = %d\n\r",iHALL); |
lebg | 1:a9ee3c2f4fc8 | 357 | if(iBRAKE==0) { |
lebg | 1:a9ee3c2f4fc8 | 358 | pc.printf(" frein actif\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 359 | } |
lebg | 1:a9ee3c2f4fc8 | 360 | if(iBRAKE==32) { |
lebg | 1:a9ee3c2f4fc8 | 361 | pc.printf(" frein inactif\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 362 | } |
lebg | 1:a9ee3c2f4fc8 | 363 | if(iDIR==8) { |
lebg | 1:a9ee3c2f4fc8 | 364 | pc.printf(" marche avant\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 365 | } |
lebg | 1:a9ee3c2f4fc8 | 366 | if(iDIR==0) { |
lebg | 1:a9ee3c2f4fc8 | 367 | pc.printf(" marche arriere\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 368 | } |
lebg | 1:a9ee3c2f4fc8 | 369 | if(iFALT==16) { |
lebg | 1:a9ee3c2f4fc8 | 370 | pc.printf(" erreur\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 371 | } |
lebg | 1:a9ee3c2f4fc8 | 372 | if(iFALT==0) { |
lebg | 1:a9ee3c2f4fc8 | 373 | pc.printf(" pas d'erreur\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 374 | } |
lebg | 1:a9ee3c2f4fc8 | 375 | if(iOC==0) { |
lebg | 1:a9ee3c2f4fc8 | 376 | pc.printf(" surtension\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 377 | } |
lebg | 1:a9ee3c2f4fc8 | 378 | if(iOC==64) { |
lebg | 1:a9ee3c2f4fc8 | 379 | pc.printf(" tension normale\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 380 | } |
lebg | 1:a9ee3c2f4fc8 | 381 | |
lebg | 1:a9ee3c2f4fc8 | 382 | |
lebg | 1:a9ee3c2f4fc8 | 383 | |
lebg | 1:a9ee3c2f4fc8 | 384 | break; |
lebg | 1:a9ee3c2f4fc8 | 385 | |
lebg | 1:a9ee3c2f4fc8 | 386 | } |
lebg | 1:a9ee3c2f4fc8 | 387 | } |
lebg | 1:a9ee3c2f4fc8 | 388 | |
lebg | 1:a9ee3c2f4fc8 | 389 | break; |
lebg | 1:a9ee3c2f4fc8 | 390 | case 'a': |
lebg | 1:a9ee3c2f4fc8 | 391 | imode=AUTO; //mis en mode AUTO |
lebg | 1:a9ee3c2f4fc8 | 392 | break; |
lebg | 1:a9ee3c2f4fc8 | 393 | case 'm': |
lebg | 1:a9ee3c2f4fc8 | 394 | imode=MANUEL; //mis en mode AUTO |
lebg | 1:a9ee3c2f4fc8 | 395 | break; |
lebg | 1:a9ee3c2f4fc8 | 396 | |
lebg | 1:a9ee3c2f4fc8 | 397 | case 'q': |
lebg | 1:a9ee3c2f4fc8 | 398 | MyPLD.write(0); |
lebg | 1:a9ee3c2f4fc8 | 399 | valid_pwm=0; |
lebg | 1:a9ee3c2f4fc8 | 400 | COMMANDE.detach(); |
lebg | 1:a9ee3c2f4fc8 | 401 | VITESSE.detach(); |
lebg | 1:a9ee3c2f4fc8 | 402 | GAZ.detach(); |
lebg | 1:a9ee3c2f4fc8 | 403 | FILE *fp=fopen("/local/scoot.txt", "w"); |
lebg | 1:a9ee3c2f4fc8 | 404 | if(fp!= NULL) { |
lebg | 1:a9ee3c2f4fc8 | 405 | fprintf(fp,"%f %f %d",Nmin,Nmax,iLim_vit); |
lebg | 1:a9ee3c2f4fc8 | 406 | fclose(fp); |
lebg | 1:a9ee3c2f4fc8 | 407 | } else { |
lebg | 1:a9ee3c2f4fc8 | 408 | pc.printf("fichier non ouvert\n\r"); |
lebg | 1:a9ee3c2f4fc8 | 409 | fclose(fp); |
lebg | 1:a9ee3c2f4fc8 | 410 | } //'arret du scooter' |
lebg | 1:a9ee3c2f4fc8 | 411 | break; |
lebg | 1:a9ee3c2f4fc8 | 412 | } |
lebg | 1:a9ee3c2f4fc8 | 413 | } // end while |
lebg | 1:a9ee3c2f4fc8 | 414 | |
lebg | 1:a9ee3c2f4fc8 | 415 | //************** thread deinit ********************* |
lebg | 1:a9ee3c2f4fc8 | 416 | //bCan_Active=false; |
lebg | 1:a9ee3c2f4fc8 | 417 | //CanThread=false;// close can received thread |
lebg | 1:a9ee3c2f4fc8 | 418 | pc.printf(" fin programme scooter mbed \n\r"); |
lebg | 1:a9ee3c2f4fc8 | 419 | DeInit_Web_Server() ;// disable web server thread |
superphil06 | 0:e30c9ba95bd4 | 420 | } // end main |
lebg | 1:a9ee3c2f4fc8 | 421 | void commande_gaz() |
lebg | 1:a9ee3c2f4fc8 | 422 | { |
lebg | 1:a9ee3c2f4fc8 | 423 | Ngaz=Vgaz.read(); |
lebg | 1:a9ee3c2f4fc8 | 424 | iREF_PWM_AUTO_BRUT=255*(Ngaz-Nmin)/(Nmax-Nmin); |
lebg | 1:a9ee3c2f4fc8 | 425 | if(iREF_PWM_AUTO_BRUT<0) { |
lebg | 1:a9ee3c2f4fc8 | 426 | iREF_PWM_AUTO_BRUT=0; |
lebg | 1:a9ee3c2f4fc8 | 427 | } |
lebg | 1:a9ee3c2f4fc8 | 428 | if(iREF_PWM_AUTO_BRUT>255) { |
lebg | 1:a9ee3c2f4fc8 | 429 | iREF_PWM_AUTO_BRUT=255; |
lebg | 1:a9ee3c2f4fc8 | 430 | } |
lebg | 1:a9ee3c2f4fc8 | 431 | if ( imode==MANUEL) { |
lebg | 1:a9ee3c2f4fc8 | 432 | MyPLD.write(iREF_PWM_MANUEL_BRUT); |
lebg | 1:a9ee3c2f4fc8 | 433 | } else { |
lebg | 1:a9ee3c2f4fc8 | 434 | MyPLD.write(iREF_PWM_AUTO_FINALE); |
lebg | 1:a9ee3c2f4fc8 | 435 | } |
lebg | 1:a9ee3c2f4fc8 | 436 | if(Puissance_Gaz>=0 && Puissance_Gaz<=100) { |
lebg | 1:a9ee3c2f4fc8 | 437 | Puissance_Gaz=(Ngaz-Nmin)/(Nmax-Nmin)*100; |
lebg | 1:a9ee3c2f4fc8 | 438 | } |
lebg | 1:a9ee3c2f4fc8 | 439 | if(Puissance_Gaz>100) { |
lebg | 1:a9ee3c2f4fc8 | 440 | Puissance_Gaz=100; |
lebg | 1:a9ee3c2f4fc8 | 441 | } |
lebg | 1:a9ee3c2f4fc8 | 442 | if(Puissance_Gaz<0) { |
lebg | 1:a9ee3c2f4fc8 | 443 | Puissance_Gaz=0; |
lebg | 1:a9ee3c2f4fc8 | 444 | } |
lebg | 1:a9ee3c2f4fc8 | 445 | |
lebg | 1:a9ee3c2f4fc8 | 446 | } |
lebg | 1:a9ee3c2f4fc8 | 447 | void cpt_vit() |
lebg | 1:a9ee3c2f4fc8 | 448 | { |
lebg | 1:a9ee3c2f4fc8 | 449 | fcpt++; |
lebg | 1:a9ee3c2f4fc8 | 450 | } |
lebg | 1:a9ee3c2f4fc8 | 451 | void calc_vit() |
lebg | 1:a9ee3c2f4fc8 | 452 | { |
lebg | 1:a9ee3c2f4fc8 | 453 | fnbr_poles=fcpt; |
lebg | 1:a9ee3c2f4fc8 | 454 | fv=(fnbr_poles*2*pi*RAYON)/(6*POLE*DT); |
lebg | 1:a9ee3c2f4fc8 | 455 | fcpt=0; |
lebg | 1:a9ee3c2f4fc8 | 456 | |
lebg | 1:a9ee3c2f4fc8 | 457 | } |
lebg | 1:a9ee3c2f4fc8 | 458 | void acceleration_progressive() |
lebg | 1:a9ee3c2f4fc8 | 459 | { |
lebg | 1:a9ee3c2f4fc8 | 460 | ireg=MyPLD.read(); |
lebg | 1:a9ee3c2f4fc8 | 461 | iBRAKE=ireg & 0x20; //lecture du frein |
lebg | 1:a9ee3c2f4fc8 | 462 | if(iBRAKE==0) { |
lebg | 1:a9ee3c2f4fc8 | 463 | iREF_PWM_AUTO_FINALE = 0; |
lebg | 1:a9ee3c2f4fc8 | 464 | } else { |
lebg | 1:a9ee3c2f4fc8 | 465 | if(fv*3600>iLim_vit) { |
lebg | 1:a9ee3c2f4fc8 | 466 | if(iREF_PWM_AUTO_FINALE>0) { |
lebg | 1:a9ee3c2f4fc8 | 467 | iREF_PWM_AUTO_FINALE--; |
lebg | 1:a9ee3c2f4fc8 | 468 | } else { |
lebg | 1:a9ee3c2f4fc8 | 469 | iREF_PWM_AUTO_FINALE=0; |
lebg | 1:a9ee3c2f4fc8 | 470 | } |
lebg | 1:a9ee3c2f4fc8 | 471 | } else { |
lebg | 1:a9ee3c2f4fc8 | 472 | |
lebg | 1:a9ee3c2f4fc8 | 473 | if(iREF_PWM_AUTO_FINALE<iREF_PWM_AUTO_BRUT) { |
lebg | 1:a9ee3c2f4fc8 | 474 | |
lebg | 1:a9ee3c2f4fc8 | 475 | iREF_PWM_AUTO_FINALE++; |
lebg | 1:a9ee3c2f4fc8 | 476 | } else { |
lebg | 1:a9ee3c2f4fc8 | 477 | iREF_PWM_AUTO_FINALE=iREF_PWM_AUTO_BRUT; |
lebg | 1:a9ee3c2f4fc8 | 478 | } |
lebg | 1:a9ee3c2f4fc8 | 479 | } |
lebg | 1:a9ee3c2f4fc8 | 480 | } |
lebg | 1:a9ee3c2f4fc8 | 481 | } |
lebg | 1:a9ee3c2f4fc8 | 482 | void tension_batterie() |
lebg | 1:a9ee3c2f4fc8 | 483 | { |
lebg | 1:a9ee3c2f4fc8 | 484 | fVbat=Vbat.read(); |
lebg | 1:a9ee3c2f4fc8 | 485 | fTension=fVbat/BAT_MAX*TENSION_BAT_MAX; |
lebg | 1:a9ee3c2f4fc8 | 486 | } |
lebg | 1:a9ee3c2f4fc8 | 487 | void tension_temperature() |
lebg | 1:a9ee3c2f4fc8 | 488 | { |
lebg | 1:a9ee3c2f4fc8 | 489 | fVtemp=Vtemp.read(); |
lebg | 1:a9ee3c2f4fc8 | 490 | fTemperature=fVtemp*3.3/TENSION_TEMP_MAX*TEMP_MAX-273; |
lebg | 1:a9ee3c2f4fc8 | 491 | } |
lebg | 1:a9ee3c2f4fc8 | 492 | void tension_courant() |
lebg | 1:a9ee3c2f4fc8 | 493 | { |
lebg | 1:a9ee3c2f4fc8 | 494 | fVcourant=Vcourant.read()*3.3/RESISTANCE_EQUIVALENTE; |
lebg | 1:a9ee3c2f4fc8 | 495 | fCourant=(fVcourant-TENSION_CPT_COURANT_MIN)/PENTE_CAPTEUR_COURANT; |
lebg | 1:a9ee3c2f4fc8 | 496 | } |