scooter correction for mbed_os V5.2
Dependencies: bloc_io html_mbed_os
Fork of scooter_mbed by
main.cpp@3:ac3990c4a479, 2016-11-26 (annotated)
- Committer:
- jlsalvat
- Date:
- Sat Nov 26 16:08:37 2016 +0000
- Revision:
- 3:ac3990c4a479
- Parent:
- 1:e3cb81b3cbea
change scooter for mbed_os 5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
superphil06 | 0:8871b0c9af3b | 1 | |
superphil06 | 0:8871b0c9af3b | 2 | |
superphil06 | 1:e3cb81b3cbea | 3 | //#include "EthernetInterface.h" |
superphil06 | 0:8871b0c9af3b | 4 | #include <stdlib.h> |
superphil06 | 0:8871b0c9af3b | 5 | #include <string.h> |
superphil06 | 0:8871b0c9af3b | 6 | #include "mbed.h" |
superphil06 | 1:e3cb81b3cbea | 7 | #include "rtos.h" // need for main thread sleep |
superphil06 | 0:8871b0c9af3b | 8 | #include "html.h" // need for html patch working with web server |
superphil06 | 0:8871b0c9af3b | 9 | #include "bloc_io.h" |
superphil06 | 0:8871b0c9af3b | 10 | #define RADIUS 0.2F // wheel size |
superphil06 | 0:8871b0c9af3b | 11 | #define NBPOLES 8 // magnetic pole number |
superphil06 | 0:8871b0c9af3b | 12 | #define DELTA_T 0.1F // speed measurement counting period |
superphil06 | 0:8871b0c9af3b | 13 | |
superphil06 | 0:8871b0c9af3b | 14 | Ticker IT_Timer_Gaz,IT_Speed; |
jlsalvat | 3:ac3990c4a479 | 15 | int gCPT=0; |
superphil06 | 0:8871b0c9af3b | 16 | float fSpeed=0; |
superphil06 | 0:8871b0c9af3b | 17 | float fTabVal[10];// need to store analog value |
superphil06 | 0:8871b0c9af3b | 18 | float fGaz,fTemp,fBat,fIdc; |
superphil06 | 0:8871b0c9af3b | 19 | float fGAZ_MAX=70,fGAZ_MIN=15; |
superphil06 | 0:8871b0c9af3b | 20 | unsigned int uiCptImpuls=0; |
superphil06 | 0:8871b0c9af3b | 21 | Bloc_IO MyPLD(p25,p26,p5,p6,p7,p8,p9,p10,p23,p24);// instantiate object needed to communicate with PLD |
superphil06 | 0:8871b0c9af3b | 22 | AnalogIn Gaz(p17),Bat(p18),Temp(p19),Idc(p20);// analog input connected to mbed |
superphil06 | 0:8871b0c9af3b | 23 | DigitalOut ValidPWM (p21,0);// reset valid pmw pin |
superphil06 | 0:8871b0c9af3b | 24 | Serial pc(USBTX, USBRX); // tx, rx |
superphil06 | 0:8871b0c9af3b | 25 | InterruptIn TopHall(p22); |
superphil06 | 0:8871b0c9af3b | 26 | |
superphil06 | 0:8871b0c9af3b | 27 | |
superphil06 | 0:8871b0c9af3b | 28 | float fGaz_Brute; |
superphil06 | 0:8871b0c9af3b | 29 | |
superphil06 | 0:8871b0c9af3b | 30 | /************ persistent file parameters section *****************/ |
superphil06 | 0:8871b0c9af3b | 31 | LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
superphil06 | 0:8871b0c9af3b | 32 | |
superphil06 | 0:8871b0c9af3b | 33 | |
superphil06 | 0:8871b0c9af3b | 34 | |
superphil06 | 0:8871b0c9af3b | 35 | |
superphil06 | 0:8871b0c9af3b | 36 | |
superphil06 | 0:8871b0c9af3b | 37 | |
superphil06 | 0:8871b0c9af3b | 38 | |
superphil06 | 0:8871b0c9af3b | 39 | /********************* web server section **********************************/ |
superphil06 | 1:e3cb81b3cbea | 40 | //char * ma_chaine3; |
superphil06 | 0:8871b0c9af3b | 41 | var_field_t tab_balise[10]; //une balise est présente dans le squelette |
superphil06 | 0:8871b0c9af3b | 42 | int giCounter=0;// acces counting |
superphil06 | 0:8871b0c9af3b | 43 | |
superphil06 | 0:8871b0c9af3b | 44 | |
superphil06 | 1:e3cb81b3cbea | 45 | /*********************** can bus section ************/ |
superphil06 | 1:e3cb81b3cbea | 46 | #define GAZ_CAN_ID 1000 // determine message ID used to send Gaz ref over can bus |
superphil06 | 1:e3cb81b3cbea | 47 | #define _CAN_DEBUG // used to debug can bus activity |
superphil06 | 1:e3cb81b3cbea | 48 | #define USE_CAN_REF // uncomment to receive gaz ref over can_bus |
superphil06 | 1:e3cb81b3cbea | 49 | CANMessage msg_receive,msg_send; |
superphil06 | 1:e3cb81b3cbea | 50 | DigitalOut led1(LED1); //initialisation des Leds présentes sur le micro-controleur Mbed*/ |
superphil06 | 1:e3cb81b3cbea | 51 | DigitalOut led2(LED2); |
superphil06 | 1:e3cb81b3cbea | 52 | DigitalOut led3(LED3); // blink when can message is sent |
superphil06 | 1:e3cb81b3cbea | 53 | DigitalOut led4(LED4); // blink when can message is received |
superphil06 | 1:e3cb81b3cbea | 54 | CAN can_port (p30, p29); // initialisation du Bus CAN sur les broches 30 (rd) et 29(td) for lpc1768 + mbed shield |
superphil06 | 1:e3cb81b3cbea | 55 | int iGaz_Can=0; |
superphil06 | 1:e3cb81b3cbea | 56 | bool bCan_Active=false; |
superphil06 | 1:e3cb81b3cbea | 57 | |
superphil06 | 0:8871b0c9af3b | 58 | |
superphil06 | 0:8871b0c9af3b | 59 | |
superphil06 | 0:8871b0c9af3b | 60 | //************ prototypes ******************* |
superphil06 | 0:8871b0c9af3b | 61 | |
superphil06 | 0:8871b0c9af3b | 62 | |
superphil06 | 0:8871b0c9af3b | 63 | |
superphil06 | 0:8871b0c9af3b | 64 | |
superphil06 | 0:8871b0c9af3b | 65 | |
superphil06 | 0:8871b0c9af3b | 66 | |
superphil06 | 0:8871b0c9af3b | 67 | //*********** |
superphil06 | 0:8871b0c9af3b | 68 | //* functions |
superphil06 | 0:8871b0c9af3b | 69 | |
superphil06 | 1:e3cb81b3cbea | 70 | /**************** Read persistent data from text file located on local file system ****************/ |
superphil06 | 0:8871b0c9af3b | 71 | int Read_File_Data(char * pcFileName) |
superphil06 | 0:8871b0c9af3b | 72 | { |
superphil06 | 0:8871b0c9af3b | 73 | float fRayon; |
superphil06 | 0:8871b0c9af3b | 74 | int iPoles,iVit_Max; |
superphil06 | 0:8871b0c9af3b | 75 | FILE *DataFile; |
superphil06 | 0:8871b0c9af3b | 76 | DataFile= fopen(pcFileName, "rt"); |
superphil06 | 0:8871b0c9af3b | 77 | if ( DataFile == NULL) |
superphil06 | 0:8871b0c9af3b | 78 | { printf("\r\nError Open File: %s", pcFileName); //open data file from disk |
superphil06 | 0:8871b0c9af3b | 79 | return(NULL); |
superphil06 | 0:8871b0c9af3b | 80 | } |
superphil06 | 0:8871b0c9af3b | 81 | else |
superphil06 | 0:8871b0c9af3b | 82 | {fscanf (DataFile,"rayon:%f ",&fRayon);// insert ' ' after %format mode to separe numeric data |
superphil06 | 0:8871b0c9af3b | 83 | fscanf (DataFile,"poles:%d ",&iPoles); |
superphil06 | 0:8871b0c9af3b | 84 | fscanf (DataFile,"vit_max:%d ",&iVit_Max); |
superphil06 | 1:e3cb81b3cbea | 85 | fscanf (DataFile,"fgaz_max:%f ",&fGAZ_MAX); |
superphil06 | 1:e3cb81b3cbea | 86 | fscanf (DataFile,"fgaz_min:%f ",&fGAZ_MIN); |
superphil06 | 1:e3cb81b3cbea | 87 | printf("valeurs lues: rayon:%f poles:%d vit_max:%d gaz_max:%f gaz_min:%f \n\r",fRayon,iPoles,iVit_Max,fGAZ_MAX,fGAZ_MIN); |
superphil06 | 0:8871b0c9af3b | 88 | fclose(DataFile); |
superphil06 | 0:8871b0c9af3b | 89 | return 0; |
superphil06 | 0:8871b0c9af3b | 90 | } |
superphil06 | 0:8871b0c9af3b | 91 | |
superphil06 | 0:8871b0c9af3b | 92 | } |
superphil06 | 0:8871b0c9af3b | 93 | |
superphil06 | 1:e3cb81b3cbea | 94 | |
superphil06 | 1:e3cb81b3cbea | 95 | /**************** write persitant data to text file located on local file system ****************/ |
superphil06 | 0:8871b0c9af3b | 96 | int Write_File_Data(char * pcFileName) |
superphil06 | 0:8871b0c9af3b | 97 | { |
superphil06 | 0:8871b0c9af3b | 98 | float fRayon=0.45; |
superphil06 | 0:8871b0c9af3b | 99 | int iPoles=10,iVit_Max=15000; |
superphil06 | 0:8871b0c9af3b | 100 | FILE *DataFile; |
superphil06 | 0:8871b0c9af3b | 101 | DataFile= fopen(pcFileName,"wt"); |
superphil06 | 0:8871b0c9af3b | 102 | |
superphil06 | 0:8871b0c9af3b | 103 | |
superphil06 | 0:8871b0c9af3b | 104 | |
superphil06 | 0:8871b0c9af3b | 105 | if ( DataFile == NULL) |
superphil06 | 0:8871b0c9af3b | 106 | { printf("\r\nError Open File: %s", pcFileName); //open data file from disk |
superphil06 | 0:8871b0c9af3b | 107 | return(NULL); |
superphil06 | 0:8871b0c9af3b | 108 | } |
superphil06 | 0:8871b0c9af3b | 109 | else |
superphil06 | 1:e3cb81b3cbea | 110 | { fprintf (DataFile, "rayon:%f poles:%d vit_max:%d gaz_max:%f gaz_min:%f \n\r",fRayon,iPoles,iVit_Max,fGAZ_MAX,fGAZ_MIN); |
superphil06 | 0:8871b0c9af3b | 111 | |
superphil06 | 1:e3cb81b3cbea | 112 | printf("valeurs ecrites: rayon:%f poles:%d vit_max:%d gaz_max:%f gaz_min:%f \n\r",fRayon,iPoles,iVit_Max,fGAZ_MAX,fGAZ_MIN); |
superphil06 | 0:8871b0c9af3b | 113 | fclose(DataFile); |
superphil06 | 0:8871b0c9af3b | 114 | return 0; |
superphil06 | 0:8871b0c9af3b | 115 | } |
superphil06 | 0:8871b0c9af3b | 116 | |
superphil06 | 0:8871b0c9af3b | 117 | } |
superphil06 | 0:8871b0c9af3b | 118 | |
superphil06 | 0:8871b0c9af3b | 119 | |
superphil06 | 0:8871b0c9af3b | 120 | |
superphil06 | 0:8871b0c9af3b | 121 | |
superphil06 | 0:8871b0c9af3b | 122 | |
superphil06 | 0:8871b0c9af3b | 123 | |
superphil06 | 1:e3cb81b3cbea | 124 | //************** needed to record min_gaz and max_gaz value to persistent text file ****************** |
superphil06 | 0:8871b0c9af3b | 125 | void Calibrate_Gaz(void) |
superphil06 | 0:8871b0c9af3b | 126 | { char cJunk; |
superphil06 | 0:8871b0c9af3b | 127 | |
superphil06 | 0:8871b0c9af3b | 128 | fGaz=Gaz.read()*100; |
superphil06 | 0:8871b0c9af3b | 129 | fTemp=Temp.read()*100; |
superphil06 | 0:8871b0c9af3b | 130 | fBat=Bat.read()*100; |
superphil06 | 0:8871b0c9af3b | 131 | fIdc=Idc.read()*100; |
superphil06 | 0:8871b0c9af3b | 132 | |
superphil06 | 0:8871b0c9af3b | 133 | pc.printf("mettre la poignee au minimum et appuyer sur une touche \n"); |
superphil06 | 0:8871b0c9af3b | 134 | pc.scanf(" %c",&cJunk); |
superphil06 | 0:8871b0c9af3b | 135 | fTabVal[0]=Gaz.read()*100;// read min gaz value) |
superphil06 | 0:8871b0c9af3b | 136 | fGAZ_MIN=fTabVal[0];// update local GAZ_MIN constante |
superphil06 | 0:8871b0c9af3b | 137 | pc.printf("mettre la poignee au maximum et appuyer sur une touche \n"); |
superphil06 | 0:8871b0c9af3b | 138 | pc.scanf(" %c",&cJunk); |
superphil06 | 0:8871b0c9af3b | 139 | fTabVal[1]=Gaz.read()*100;// read max gaz value |
superphil06 | 0:8871b0c9af3b | 140 | fGAZ_MAX=fTabVal[1];// update local GAZ_MIN constante |
superphil06 | 0:8871b0c9af3b | 141 | pc.printf("calibration terminee: gaz_min=%f gaz_max=%f \n",fTabVal[0],fTabVal[1]); |
superphil06 | 1:e3cb81b3cbea | 142 | Write_File_Data("/local/persist.txt"); // write persistent data to text file |
superphil06 | 0:8871b0c9af3b | 143 | |
superphil06 | 0:8871b0c9af3b | 144 | } |
superphil06 | 0:8871b0c9af3b | 145 | |
superphil06 | 1:e3cb81b3cbea | 146 | // ************top hall counting interupt needed for speed measurement |
superphil06 | 0:8871b0c9af3b | 147 | void SpeedCount(void) |
superphil06 | 0:8871b0c9af3b | 148 | {uiCptImpuls++;// top hall encoured increment speed counter |
superphil06 | 0:8871b0c9af3b | 149 | } |
superphil06 | 0:8871b0c9af3b | 150 | |
superphil06 | 0:8871b0c9af3b | 151 | |
superphil06 | 1:e3cb81b3cbea | 152 | //********************** timer interrupt for speed measurement each 100ms ************************* |
superphil06 | 0:8871b0c9af3b | 153 | void MyITSpeed(void) |
superphil06 | 0:8871b0c9af3b | 154 | {unsigned int uiCptSpeed; |
superphil06 | 0:8871b0c9af3b | 155 | |
superphil06 | 0:8871b0c9af3b | 156 | uiCptSpeed=uiCptImpuls;// read actual count |
superphil06 | 0:8871b0c9af3b | 157 | uiCptImpuls=0;// reset counter for next counting period |
superphil06 | 0:8871b0c9af3b | 158 | fSpeed=2*(float)3.14159*RADIUS*(float)uiCptSpeed*3600/(6*NBPOLES*DELTA_T); |
superphil06 | 0:8871b0c9af3b | 159 | } |
superphil06 | 0:8871b0c9af3b | 160 | |
superphil06 | 0:8871b0c9af3b | 161 | |
superphil06 | 0:8871b0c9af3b | 162 | |
superphil06 | 0:8871b0c9af3b | 163 | |
superphil06 | 0:8871b0c9af3b | 164 | |
superphil06 | 1:e3cb81b3cbea | 165 | //********************* Timer Interrupt for gaz ref management each 10ms ******************** |
superphil06 | 0:8871b0c9af3b | 166 | void MyITGaz (void) |
superphil06 | 0:8871b0c9af3b | 167 | {unsigned char byRefPWM=0; |
superphil06 | 0:8871b0c9af3b | 168 | |
superphil06 | 0:8871b0c9af3b | 169 | fGaz=Gaz.read()*100;// read actual gaz |
superphil06 | 0:8871b0c9af3b | 170 | fBat=Bat.read()*100;// read actual Bat voltage |
superphil06 | 0:8871b0c9af3b | 171 | fIdc=Idc.read()*100;// read actual Idc current |
superphil06 | 0:8871b0c9af3b | 172 | fTemp=Temp.read()*100;// readf actual Temp |
superphil06 | 1:e3cb81b3cbea | 173 | |
superphil06 | 1:e3cb81b3cbea | 174 | #ifndef USE_CAN_REF |
superphil06 | 1:e3cb81b3cbea | 175 | fGaz_Brute= (float)255/(fGAZ_MAX-fGAZ_MIN)* (fGaz-fGAZ_MIN);/ use local ref |
superphil06 | 1:e3cb81b3cbea | 176 | #else |
superphil06 | 1:e3cb81b3cbea | 177 | fGaz_Brute= iGaz_Can;// use can bus gaz ref |
superphil06 | 1:e3cb81b3cbea | 178 | #endif |
superphil06 | 1:e3cb81b3cbea | 179 | |
superphil06 | 0:8871b0c9af3b | 180 | if (fGaz_Brute>255) fGaz_Brute=255; |
superphil06 | 0:8871b0c9af3b | 181 | if (fGaz_Brute<0) fGaz_Brute=0; |
superphil06 | 0:8871b0c9af3b | 182 | byRefPWM=(unsigned char) fGaz_Brute; |
superphil06 | 0:8871b0c9af3b | 183 | MyPLD.write(byRefPWM);// update pwm ref on pld |
superphil06 | 0:8871b0c9af3b | 184 | } |
superphil06 | 0:8871b0c9af3b | 185 | |
superphil06 | 0:8871b0c9af3b | 186 | |
superphil06 | 1:e3cb81b3cbea | 187 | /********* main cgi function used to patch data to the web server thread **********************************/ |
superphil06 | 1:e3cb81b3cbea | 188 | void CGI_Function(void) // cgi function that patch web data to empty web page |
superphil06 | 1:e3cb81b3cbea | 189 | { char ma_chaine4[20]={};// needed to form html response |
jlsalvat | 3:ac3990c4a479 | 190 | sprintf (ma_chaine4,"%d",(int)gCPT++);// convert speed as ascii string |
superphil06 | 1:e3cb81b3cbea | 191 | Html_Patch (tab_balise,0,ma_chaine4);// patch first label with dyn.string |
superphil06 | 1:e3cb81b3cbea | 192 | |
superphil06 | 1:e3cb81b3cbea | 193 | sprintf (ma_chaine4,"%d",(int)(fGaz_Brute*100)/255);// convert count as ascii string |
superphil06 | 1:e3cb81b3cbea | 194 | Html_Patch (tab_balise,1,ma_chaine4);// patch first label with dyn.string |
superphil06 | 1:e3cb81b3cbea | 195 | |
superphil06 | 1:e3cb81b3cbea | 196 | sprintf (ma_chaine4,"%d",(int)fBat);// convert count as ascii string |
superphil06 | 1:e3cb81b3cbea | 197 | Html_Patch (tab_balise,2,ma_chaine4);// patch first label with dyn.string |
superphil06 | 1:e3cb81b3cbea | 198 | |
superphil06 | 1:e3cb81b3cbea | 199 | sprintf (ma_chaine4,"%d",(int)fIdc);// convert count as ascii string |
superphil06 | 1:e3cb81b3cbea | 200 | Html_Patch (tab_balise,3,ma_chaine4);// patch first label with dyn.string |
superphil06 | 1:e3cb81b3cbea | 201 | |
superphil06 | 1:e3cb81b3cbea | 202 | sprintf (ma_chaine4,"%d",(int)fTemp);// convert count as ascii string |
superphil06 | 1:e3cb81b3cbea | 203 | Html_Patch (tab_balise,4,ma_chaine4);// patch first label with dyn.string |
superphil06 | 1:e3cb81b3cbea | 204 | |
superphil06 | 1:e3cb81b3cbea | 205 | |
superphil06 | 1:e3cb81b3cbea | 206 | |
superphil06 | 1:e3cb81b3cbea | 207 | } |
superphil06 | 1:e3cb81b3cbea | 208 | |
superphil06 | 1:e3cb81b3cbea | 209 | |
superphil06 | 1:e3cb81b3cbea | 210 | /*********************** CAN BUS SECTION **********************/ |
superphil06 | 1:e3cb81b3cbea | 211 | |
superphil06 | 1:e3cb81b3cbea | 212 | |
superphil06 | 1:e3cb81b3cbea | 213 | |
superphil06 | 1:e3cb81b3cbea | 214 | void CAN_REC_THREAD(void const *args) |
superphil06 | 1:e3cb81b3cbea | 215 | { int iCount,iError; |
superphil06 | 1:e3cb81b3cbea | 216 | |
superphil06 | 1:e3cb81b3cbea | 217 | while (bCan_Active) |
superphil06 | 1:e3cb81b3cbea | 218 | {Thread::wait(100);// wait 100ms |
superphil06 | 1:e3cb81b3cbea | 219 | //printf("CAN_REC_Thread\n\r"); |
superphil06 | 1:e3cb81b3cbea | 220 | if(can_port.read(msg_receive)) //si on lit un message reçu */ |
superphil06 | 1:e3cb81b3cbea | 221 | //can_port.read(msg_receive); |
superphil06 | 1:e3cb81b3cbea | 222 | {iError=0; |
superphil06 | 1:e3cb81b3cbea | 223 | #ifdef _CAN_DEBUG |
superphil06 | 1:e3cb81b3cbea | 224 | printf("CAN Message received : %s\n id=%d\n\r", msg_receive.data,msg_receive.id); |
superphil06 | 1:e3cb81b3cbea | 225 | # endif |
superphil06 | 1:e3cb81b3cbea | 226 | switch (msg_receive.id) { |
superphil06 | 1:e3cb81b3cbea | 227 | case GAZ_CAN_ID: // received Gaz from can |
superphil06 | 1:e3cb81b3cbea | 228 | sscanf((char *)msg_receive.data,"%03d",&iGaz_Can);// read and convert gaz ref from can bus |
superphil06 | 1:e3cb81b3cbea | 229 | led4=!led4; |
superphil06 | 1:e3cb81b3cbea | 230 | #ifdef _CAN_DEBUG |
superphil06 | 1:e3cb81b3cbea | 231 | for (iCount=0; iCount<=5;iCount++) |
superphil06 | 1:e3cb81b3cbea | 232 | {led4=!led4; |
superphil06 | 1:e3cb81b3cbea | 233 | Thread::wait(100); |
superphil06 | 1:e3cb81b3cbea | 234 | } |
superphil06 | 1:e3cb81b3cbea | 235 | #endif |
superphil06 | 1:e3cb81b3cbea | 236 | break; |
superphil06 | 1:e3cb81b3cbea | 237 | |
superphil06 | 1:e3cb81b3cbea | 238 | } |
superphil06 | 1:e3cb81b3cbea | 239 | } |
superphil06 | 1:e3cb81b3cbea | 240 | } |
superphil06 | 1:e3cb81b3cbea | 241 | |
superphil06 | 1:e3cb81b3cbea | 242 | } |
superphil06 | 1:e3cb81b3cbea | 243 | |
superphil06 | 1:e3cb81b3cbea | 244 | |
superphil06 | 1:e3cb81b3cbea | 245 | |
superphil06 | 1:e3cb81b3cbea | 246 | |
superphil06 | 0:8871b0c9af3b | 247 | int main() { |
superphil06 | 0:8871b0c9af3b | 248 | |
superphil06 | 0:8871b0c9af3b | 249 | char cChoix=0; |
superphil06 | 1:e3cb81b3cbea | 250 | int iVal,iRefPWM; |
superphil06 | 0:8871b0c9af3b | 251 | |
superphil06 | 0:8871b0c9af3b | 252 | |
superphil06 | 0:8871b0c9af3b | 253 | Read_File_Data("/local/persist.txt"); // read persistent data from text file |
superphil06 | 1:e3cb81b3cbea | 254 | //Write_File_Data("/local/persist.txt"); // write persistent data to text file |
superphil06 | 1:e3cb81b3cbea | 255 | //***************************************** web section ********************************************/ |
superphil06 | 1:e3cb81b3cbea | 256 | Init_Web_Server(&CGI_Function); // create and initialize tcp server socket and pass function pointer to local CGI function |
superphil06 | 1:e3cb81b3cbea | 257 | Thread WebThread(Web_Server_Thread);// create and launch web server thread |
superphil06 | 1:e3cb81b3cbea | 258 | //******************************************* end web section ************************************* / |
superphil06 | 0:8871b0c9af3b | 259 | |
superphil06 | 0:8871b0c9af3b | 260 | |
superphil06 | 1:e3cb81b3cbea | 261 | //ma_chaine3 = Gen_HtmlCode_From_File("/local/pagecgi2.htm",tab_balise,5);// read and localise ^VARDEF[X] tag |
jlsalvat | 3:ac3990c4a479 | 262 | Gen_HtmlCode_From_File("/local/compteur.htm",tab_balise,2);// read and localise ^VARDEF[X] tag in empty html file |
superphil06 | 0:8871b0c9af3b | 263 | |
superphil06 | 0:8871b0c9af3b | 264 | IT_Timer_Gaz.attach_us(&MyITGaz, 10000);// install timer it each 10ms |
superphil06 | 0:8871b0c9af3b | 265 | IT_Speed.attach_us(&MyITSpeed, 100000);// install timer it each 10ms |
superphil06 | 0:8871b0c9af3b | 266 | TopHall.rise(&SpeedCount); |
superphil06 | 0:8871b0c9af3b | 267 | |
superphil06 | 0:8871b0c9af3b | 268 | pc.printf(" programme scooter mbed \n"); |
superphil06 | 0:8871b0c9af3b | 269 | MyPLD.write(0);// set initial PWM ref=0 |
superphil06 | 0:8871b0c9af3b | 270 | ValidPWM.write(1);// enable pwm generator |
superphil06 | 0:8871b0c9af3b | 271 | |
superphil06 | 1:e3cb81b3cbea | 272 | can_port.frequency(125000); //on impose une fréquence commune pour etre s’incroniser |
superphil06 | 1:e3cb81b3cbea | 273 | //can_port.attach(&CAN_REC_IRQ); // install CAN BUS IRQ on data received |
superphil06 | 1:e3cb81b3cbea | 274 | bCan_Active=true; |
superphil06 | 1:e3cb81b3cbea | 275 | Thread CanThread(CAN_REC_THREAD);// create and launch can receiver thread |
superphil06 | 1:e3cb81b3cbea | 276 | |
superphil06 | 1:e3cb81b3cbea | 277 | |
superphil06 | 0:8871b0c9af3b | 278 | while(cChoix!='q' and cChoix!='Q') |
jlsalvat | 3:ac3990c4a479 | 279 | {/*pc.printf(" veuillez saisir un choix parmi la liste proposee: \n"); |
superphil06 | 0:8871b0c9af3b | 280 | pc.printf(" a:saisie consigne pwm \n"); |
superphil06 | 0:8871b0c9af3b | 281 | pc.printf(" b:lecture registre PLD \n"); |
superphil06 | 0:8871b0c9af3b | 282 | pc.printf(" c:lecture ADC 4 voies \n"); |
superphil06 | 0:8871b0c9af3b | 283 | pc.printf(" d:calibration poignee Gaz \n"); |
superphil06 | 0:8871b0c9af3b | 284 | pc.printf(" e:affichage vitesse \n"); |
jlsalvat | 3:ac3990c4a479 | 285 | pc.printf(" q:quitter \n");*/ |
superphil06 | 1:e3cb81b3cbea | 286 | /************* multithreading : main thread need to sleep in order to allow web response */ |
superphil06 | 1:e3cb81b3cbea | 287 | while (pc.readable()==0) // determine if char availabler |
superphil06 | 0:8871b0c9af3b | 288 | {Thread::wait(10);} // wait 10 until char available on serial input |
superphil06 | 1:e3cb81b3cbea | 289 | /************* end of main thread sleep ****************/ |
superphil06 | 0:8871b0c9af3b | 290 | pc.scanf(" %c",&cChoix); |
superphil06 | 0:8871b0c9af3b | 291 | switch (cChoix){ |
superphil06 | 0:8871b0c9af3b | 292 | case 'a': pc.printf(" veuillez saisir une consigne pwm entre 0 et 255 \n"); |
superphil06 | 0:8871b0c9af3b | 293 | pc.scanf("%d",&iRefPWM); |
superphil06 | 0:8871b0c9af3b | 294 | if (iRefPWM>255) iRefPWM=255; |
superphil06 | 0:8871b0c9af3b | 295 | if (iRefPWM<0) iRefPWM=0; |
superphil06 | 0:8871b0c9af3b | 296 | MyPLD.write((unsigned char)iRefPWM);// update pwm ref on pld |
superphil06 | 0:8871b0c9af3b | 297 | break; |
superphil06 | 0:8871b0c9af3b | 298 | case 'b': iVal=MyPLD.read();// read PLd internal register |
superphil06 | 0:8871b0c9af3b | 299 | pc.printf("valeur lue dans le registre PLD: %02x \n",iVal); |
superphil06 | 0:8871b0c9af3b | 300 | pc.printf("secteur hall: %01d \n",iVal&0x07); |
superphil06 | 0:8871b0c9af3b | 301 | pc.printf("direction:%01d \n",(iVal&0x08)>>3); |
superphil06 | 0:8871b0c9af3b | 302 | pc.printf("flta:%01d \n",(iVal&0x10)>>4); |
superphil06 | 0:8871b0c9af3b | 303 | pc.printf("brake:%01d \n",(iVal&0x20)>>5); |
superphil06 | 0:8871b0c9af3b | 304 | pc.printf("overCurrent:%01d \n",(iVal&0x40)>>6); |
superphil06 | 0:8871b0c9af3b | 305 | break; |
superphil06 | 0:8871b0c9af3b | 306 | |
superphil06 | 0:8871b0c9af3b | 307 | case 'c': // lecture ADC 4 voies |
superphil06 | 0:8871b0c9af3b | 308 | fGaz=Gaz.read()*100; |
superphil06 | 0:8871b0c9af3b | 309 | fTemp=Temp.read()*100; |
superphil06 | 0:8871b0c9af3b | 310 | fBat=Bat.read()*100; |
superphil06 | 0:8871b0c9af3b | 311 | fIdc=Idc.read()*100; |
superphil06 | 0:8871b0c9af3b | 312 | pc.printf("valeur gaz:%3f Temperature:%3f Vbat:%3f Idc:%3f \n",fGaz,fTemp,fBat,fIdc); |
superphil06 | 1:e3cb81b3cbea | 313 | pc.printf("valeur temp:%3f \n\r",fTemp*5.1282-53.53); |
superphil06 | 0:8871b0c9af3b | 314 | break; |
superphil06 | 0:8871b0c9af3b | 315 | |
superphil06 | 0:8871b0c9af3b | 316 | case 'd': // calibration poignée gaz |
superphil06 | 0:8871b0c9af3b | 317 | Calibrate_Gaz(); |
superphil06 | 0:8871b0c9af3b | 318 | break; |
superphil06 | 0:8871b0c9af3b | 319 | case 'e': // display actual speed m/h |
superphil06 | 0:8871b0c9af3b | 320 | pc.printf("vitesse=%f m/h \n",fSpeed); |
superphil06 | 0:8871b0c9af3b | 321 | break; |
superphil06 | 0:8871b0c9af3b | 322 | |
superphil06 | 0:8871b0c9af3b | 323 | case 'q': break; |
superphil06 | 0:8871b0c9af3b | 324 | } |
superphil06 | 0:8871b0c9af3b | 325 | |
superphil06 | 0:8871b0c9af3b | 326 | /*for (iIndex=0;iIndex<=255;iIndex++) |
superphil06 | 0:8871b0c9af3b | 327 | {MyPLD.write((unsigned char) iIndex); |
superphil06 | 0:8871b0c9af3b | 328 | // iVal=MyPLD.read(); |
superphil06 | 0:8871b0c9af3b | 329 | |
superphil06 | 0:8871b0c9af3b | 330 | wait_ms(0.02); |
superphil06 | 0:8871b0c9af3b | 331 | }*/ |
superphil06 | 0:8871b0c9af3b | 332 | } |
superphil06 | 0:8871b0c9af3b | 333 | IT_Timer_Gaz.detach();// uninstall timer interrupt |
superphil06 | 0:8871b0c9af3b | 334 | IT_Speed.detach();// uninstall timer interrupt |
superphil06 | 0:8871b0c9af3b | 335 | MyPLD.write(0);// stop motor before exiting |
superphil06 | 0:8871b0c9af3b | 336 | ValidPWM.write(0);// disable pwm generator |
superphil06 | 1:e3cb81b3cbea | 337 | DeInit_Web_Server(); |
superphil06 | 1:e3cb81b3cbea | 338 | bCan_Active=false; |
superphil06 | 1:e3cb81b3cbea | 339 | CanThread=false;// close can received thread |
superphil06 | 0:8871b0c9af3b | 340 | pc.printf(" fin programme scooter mbed \n"); |
superphil06 | 0:8871b0c9af3b | 341 | } |