richard misi
/
STM32F303-ESSAI-DS3231-16102018
Essai ds3132
Revision 0:13c98588f2fc, committed 2018-10-17
- Comitter:
- RCMISbed
- Date:
- Wed Oct 17 12:01:00 2018 +0000
- Commit message:
- essai ds3132
Changed in this revision
diff -r 000000000000 -r 13c98588f2fc ds3231.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ds3231.lib Wed Oct 17 12:01:00 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/Maxim-Integrated/code/ds3231/#11630748e2f2
diff -r 000000000000 -r 13c98588f2fc essai-ds3231.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/essai-ds3231.cpp Wed Oct 17 12:01:00 2018 +0000 @@ -0,0 +1,642 @@ + + +#include "mbed.h" +#include <stdio.h> +#include <stdlib.h> +#include <string> +#include "objet.h" +#include "ds3231.h" + +using namespace std; + +//0- Definition/ Parametres/ Configuration/ Materiel +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +string target = "STM32F303"; +DigitalIn SW0(PB_5); // Digitale/ In/ SWITCH +DigitalIn SW1(PA_7) ; // Digitale/ In/ SWITCH +DigitalIn SW2(PB_0); // Digitale/ In/ SWITCH +DigitalIn SW3(PA_8); // Digitale/ In/ SWITCH +DigitalOut RXLED(PB_3); // Digitale/ Out/ lumineux/ Led Verte Intégrée +DigitalOut BLED(PA_4); // Digitale/ Out/ lumineux/ Led Bleu +DigitalOut GLED(PA_3); // Digitale/ Out/ lumineux/ Led Verte +DigitalOut RLED(PF_1); // Digitale/ Out/ lumineux/ Led Rouge +DigitalOut SOUND(PB_4); // Digitale/ Out/ Son +AnalogIn padX(PA_0); //Analogique/ pad/ voie X +AnalogIn padY(PA_1); //Analogique/ pad/ voie Y + +Serial usb(USBTX, USBRX); // Liaison UART/ Dispositif USB +Serial uart(PA_9, PA_10); // Liaison UART/ Dispositif UART + +I2C i2c (PB_7, PB_6); // Liaison I2C/ Dispositif Afficheur + +//CAN bCAN(p30, p29); // Liaison CAN/ Dispositif Communication Inter Systeme + + +//1- Definition/ Constantes Programme +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +#define vDEBUG true // Validation Mode DEBUG +#define vACC false // Validation Accelero +#define vSON true // Validation SON + +// Definition/ Constantes/ Generale +#define ON false +#define OFF true + +// Definition/ Constantes/ Caracteres Alphanumeriques ASCII +#define LF 10 // Line Feed \n +#define CR 13 // Carriage Return \r +#define BS 127 // Back Space + +//Definition/ Constantes Orientation +#define bARRET 0 +#define bGAUCHE 1 +#define bDROITE 2 +#define bAVANT 3 + +// Definition/ Constantes KEYBOARD +#define noKEY 0 // Clavier/ no KEY +#define lKEY 1 // Clavier/ left KEY +#define mKEY 2 // Clavier/ middle KEY +#define rKEY 4 // Clavier/ right KEY +#define razKEY 64 // Clavier/ az KEY + +// Definition/ Affichage/ OLED +#define oled_addr 0x78 + + +// Definition/ Identification/ produit +#define productName "Controleur Distant/ bluetooth" +#define versionName "v1.3" + +// Definition/ Identification/ PAD +#define padName "Joystick Analogique" +#define padNbAxe 2 // PAD/ Nb Axe MAX +#define padNbSW 3 // PAD/ Nb SW +#define XAxeName "Roulis" +#define YAxeName "Tangage" + +// Definition/ Identification/ TRAME +#define wdtTXMAX 100 // Watchdog Emission Trame MAX (periode) +#define wdtRXMAX 1000 // Watchdog Reception Trame MAX + +// Definition/ ADC/ Dynamique Signal +#define Adcm 0 // Convertisseur ADC/ Valeur Min +#define AdcM 1023 // Convertisseur ADC/ Valeur Max +#define Adc0 512 // Convertisseur ADC/ Valeur Mediane + +// Definition/ PAD/ Dynamique variable +#define Dynm -1000 // Dynamique signal/ Valeur Min +#define DynM 1000 // Dynamique signal/ Valeur Max +#define Dyn0 0 // Dynamique signal/ Valeur Moyenne + +// Definition/ PAD/ nombre max géré +#define nbAxesMAX 2 + +// Definition/ PAD/ parametres loi de pilotage +#define dzmin 0 // Dead Zone/ valeur minimale +#define dzMAX 100 // Dead Zone/ valeur Maximale +#define znlmin 0 // Zone Non Linearite/ valeur minimale +#define znlMax 100 // Zone Non Linearite/ valeur Maximale +#define ctfmin 0.05 // Kpmin: Gain min poportionnel +#define ctfMAX 5 // KpMax: Gain Max poportionnel +#define ctimin 0.0003 // KiMax: Gain Max integral (Constante de temps Integration Max) +#define ctiMAX 0.003 // KiMax: Gain Max integral (Constante de temps Integration Max) + +#define CtR 0.00003 // Constante de temps filtrage commande (filtre passe bas) + +//Definition/ Constantes temporelles +#define TSample 0.01 // Periode Echantillonnage Process ( 10 ms ) +#define secWDTMAX 1/ TSample // Watchdog Seconde +#define wledWDTMAX 30 // Watchdog MAX/ Led WIFI +#define ledWDTMAX 100 // Watchdog MAX/ Led +#define sonWDTMAX 500 // Watchdog MAX/ signal sonore +#define imuWDTMAX 10 // Watchdog MAX/ process IMU +#define trameWDTMAX 300 // Watchdog MAX/ Duree de vie de la Trame +#define keyWDTMAX 50 // Watchdog MAX/ Durée de vie info touche sur trame + +// Definition/ Constantes materiel communication +#define usbBR 115200 // Communication/ port Serie/ UART USB Baut Rate +#define uartBR 9600 // Communication/ port Serie/ UART Baut Rate (Bluetooth) +#define i2cBR 400000 // Communication/ port Serie/ frequence bus I2C + +// Definition/ Parametres Protocole Trame +#define idNULL 0 +#define idMOBILE 120 +#define idMOBILE1 122 +#define idMOTOR 123 +#define idBALANCE 543 +#define idIMU 888 + + +//2- Definition/ Type de donnees +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +// Voir fichier: objet.h + + + +//3- Definition/ Variables Globales +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +int16_t periode= 10; + +int16_t wledWDT = 0; +int16_t rxledWDT = 0; +int16_t rledWDT = 0; +int16_t gledWDT = 0; +int16_t bledWDT = 0; +int16_t secWDT = secWDTMAX; +int16_t sonWDT = 0; +int16_t sw0WDT = 0; +int16_t sw1WDT = 0; +int16_t sw2WDT = 0; +int16_t sw3WDT = 0; +int16_t sw0MASK = 0; +int16_t sw1MASK = 0; +int16_t sw2MASK = 0; +int16_t sw3MASK = 0; +int16_t sw = 0; + +int16_t pTX = 0; +int16_t pRX = 0; +int16_t op[10]; +bool fINPUT = true; + +int heure = 0; +int minute = 0; +int seconde = 0; +time_t epoch_time; + + +bool fSB = false; +bool fEB = false; +char startB = '$'; +char dlB = ','; +char endB = '*'; +char rx[wBUFFER]; +int pcar = 0; + + +int pUSBRx = 0; +int pUSBTx = 0; + +string sUSBRx = " "; + + +Ds3231 rtc(PB_7, PB_6); + +PAD_t pad; +TRAME_t trame; +Ticker process; + + +long int nbTRM = 0; + + +//4- Definition/ Macro +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +#define RX_LED_OFF RXLED = 0; +#define RX_LED_ON RXLED = 1; + +#define R_LED_OFF RLED = 1; +#define R_LED_ON RLED = 0; + +#define G_LED_OFF GLED = 1; +#define G_LED_ON GLED = 0; + +#define B_LED_OFF BLED = 1; +#define B_LED_ON BLED = 0; + +#define SON_OFF SOUND = 0; +#define SON_ON SOUND = 1; + + + +//5- Definition/ Procedures +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +//5.1- Definition/ Procedure/ Reception UART USB (interruption) +void rx_usb_isr(){ + char car; + int count = 0; + + car= usb.getc(); + + switch((int)car){ + + case 97: //Touche 'a' + break; + case 122: //Touche 'z' + break; + + case BS://Touche 'Back Space' + if(sUSBRx.length()> 0){ + sUSBRx.erase(sUSBRx.length()-1,1); + while(count< sUSBRx.length()){usb.printf(" ");++count;}; + usb.printf("\r%s",sUSBRx); + }; + break; + case LF: // Touche Line Feed '\n' + break; + case CR: //Touche Carriage Return '\r' + sUSBRx+= "\r\n"; + usb.printf("\r\n"); + sUSBRx= ""; + break; + default: //Touche Caractere ASCII + sUSBRx+= car; + usb.printf("%c",car); + break; + }; // fin switch((int)car){ + + } + + + + +//5.2- Definition/ Procedure/ Reception UART BT (interruption) +void rx_uart_isr(){ + // __disable_irq(); + + char RxCar; + char stB; + string str; + int identifier; + + RxCar= uart.getc(); + +// if(vDEBUG == true){ usb.printf("%c",RxCar); }; // DEBUG/ USB +// bledWDT= 3; + + if((RxCar== startB )&& (fEB== false)){pcar= 0; fSB = true; fEB= false;}; // Synchronisation Trame (Start Beacon) + if(fSB== true){rx[pcar]= RxCar; ++pcar;}; + if((RxCar== endB )&& (fSB== true)){fEB= true;}; + if(pcar>= wBUFFER){fSB= false; fEB= false; pcar= 0;}; + if((fSB== true)&& (fEB== true)){ // Synchronisation OK + fSB= false; fEB= false; + // usb.printf("%s\r\n", rx); + + sscanf(rx,"%c,%i",&stB, &identifier); + switch(identifier){ + case idMOBILE: // Trame idMOBILE + trame.wdtRX = 100; + sscanf(rx,"%c,%i,%i,%i,%i,%i,%i,%c",&trame.sb, &trame.r[0], &trame.r[1], &trame.r[2], &trame.r[3], &trame.r[4], &trame.r[5], &trame.eb); // Réception Données Trame + usb.printf("Rx from MOBILE : %s %s\r\n", rx, ctime(&epoch_time)); + switch(trame.r[3]){ // Traitement rMODE + case mSTP: // mode STOP + bledWDT= 30; gledWDT= 0; rledWDT= 0; + break; + case mMAN: // mode MANUEL + bledWDT= 0; gledWDT= 30; rledWDT= 0; + break; + case mPA : // mode PA + bledWDT= 0; gledWDT= 0; rledWDT= 30; + break; + + default :break; + }; // fin switch(trame.r[3]){ + rxledWDT= 3; + break; + + default : break; + }; // fin switch(identifier){ + }; // fin if((fSRx== true)&& (fERx== true)){ + // __enable_irq(); + + } + + + +//5.3- Definition/ Procedure/ Process (interruption) +void process_isr(){ + float aP, aI; + int ctn; + int8_t key; + + // --ledWDT; if(ledWDT<= 0){ledWDT= ledWDTMAX; RX_LED_OFF; SON_OFF;}; if(ledWDT< 5){RX_LED_ON; SON_ON;}; + + --sw0WDT; if(sw0WDT<= 0){sw0WDT= 0;}; // wdt SW0 + --sw1WDT; if(sw1WDT<= 0){sw1WDT= 0;}; // wdt SW1 + --sw2WDT; if(sw2WDT<= 0){sw2WDT= 0;}; // wdt SW2 + --sw3WDT; if(sw3WDT<= 0){sw3WDT= 0;}; // wdt SW3 + + --rxledWDT; if(rxledWDT<= 0){rxledWDT= 0; RX_LED_OFF;}else{RX_LED_ON;}; // wdt LED INTEGREE + + --rledWDT; if(rledWDT<= 0){rledWDT= 0; R_LED_OFF;}else{R_LED_ON;}; // wdt LED ROUGE + --gledWDT; if(gledWDT<= 0){gledWDT= 0; G_LED_OFF;}else{G_LED_ON;}; // wdt LED VERTE + --bledWDT; if(bledWDT<= 0){bledWDT= 0; B_LED_OFF;}else{B_LED_ON;}; // wdt LED VERTE + + --sonWDT; if(sonWDT<= 0){sonWDT= 0; SON_OFF;}else{SON_ON;}; // wdt son + + --trame.wdtTX; if(trame.wdtTX < 0) {trame.wdtTX = 0;}; // wdt TX TRAME (periode emission) + + --trame.wdtRX; if(trame.wdtRX <= 0) {trame.wdtRX = 0; ;}; // wdt RX TRAME + if(trame.wdtRX == 1 ) {ctn= wBUFFER- 1; + while(ctn>= 0){trame.rx[ctn]= '+'; --ctn;}; + ctn= wBUFFER- 3; trame.rx[ctn]= '\r'; + ctn= wBUFFER- 2; trame.rx[ctn]= '\n'; + sonWDT= 25; + }; + + --secWDT; if(secWDT<= 0){secWDT= 0;}; // wdt Seconde + + // a- Process/ Gestion CLAVIER + key = noKEY; + if(SW1== 1){key= lKEY;}; // appui touche RIGHT + if(SW2== 1){key= mKEY;}; // appui touche MIDDLE + if(SW3== 1){key= rKEY;}; // appui touche LEFT + if(SW0== 0){key= razKEY;}; // appui touche RAZ (touche inversée) + + // b- Process/ Gestion LED + switch(key){ + case lKEY : if(fINPUT== true){sonWDT= 3; sw1WDT= keyWDTMAX ; bledWDT= 10; fINPUT= false;}; break; + case mKEY : if(fINPUT== true){sonWDT= 3; sw2WDT= keyWDTMAX ; gledWDT= 10; fINPUT= false;}; break; + case rKEY : if(fINPUT== true){sonWDT= 3; sw3WDT= keyWDTMAX ; rledWDT= 10; fINPUT= false;}; break; + case razKEY : if(fINPUT== true){sonWDT= 3; sw0WDT= keyWDTMAX ; + bledWDT= 5; gledWDT= 5; rledWDT= 5; fINPUT= false;}; break; + case noKEY : fINPUT= true; break; + default : break; + }; + + // c- Process/ Gestion PAD + // c.1- Process/ Gestion PAD/ SW + ctn= 0; + while(ctn<= padNbSW){ + switch(ctn){ + case 0: // Gestion SW(0]: RAZ loi + pad.sw[0].value= OFF; if(key== razKEY){pad.sw[0].value= ON;}; + if(pad.sw[0].value== ON){ + pad.axe[1].in= Dyn0; pad.axe[1].i0= Dyn0; pad.axe[1].i= 0; pad.axe[1].out= 0; + pad.axe[0].in= Dyn0; pad.axe[0].i0= Dyn0; pad.axe[0].i= 0; pad.axe[0].out= 0; + }; + break; + case 1: // Gestion SW(1] + break; + case 2: // Gestion SW(2] + break; + case 3: // Gestion SW(3] + break; + case 4: // Gestion SW(4] + break; + default:break; + }; + ++ctn; + }; // fin while(ctn<= padNbSW){ + + + // c.2- Process/ Gestion SW + sw= mSTB; + if(sw0WDT> 0){sw= mRAZ;}; + if(sw1WDT> 0){sw= mSTP;}; + if(sw2WDT> 0){sw= mMAN;}; + if(sw3WDT> 0){sw= mPA; }; + + + // c.2- Process/ Gestion PAD + // c.2- Process/ Gestion PAD/ axe 1 + pad.axe[0].out = 2*padX- 1; + if(pad.axe[0].out< -1){pad.axe[0].out= -1;}; + if(pad.axe[0].out> 1){pad.axe[0].out= 1;}; + + // c.2.3- Process/ Gestion PAD/ axe Tangage + pad.axe[1].out = 2*padY- 1; + if(pad.axe[1].out< -1){pad.axe[1].out= -1;}; + if(pad.axe[1].out> 1){pad.axe[1].out= 1;}; + + + --periode; + if(periode<= 0){ + sprintf(trame.tx,"%c,%d,%d,%d,%d,%d,%d,%c %d \r\n", startB, trame.id, (int)(DynM* pad.axe[1].out), (int)(DynM* pad.axe[0].out), sw, 0, 0, endB, epoch_time); + uart.printf("%s",trame.tx); + // usb.printf("Tx to MOBILE : %s",trame.tx); + + periode= 10; + }; + +} + + + + + + +//5.4- Definition/ Procedures/ Initialisation +int InitProcess(void){ + + int cmpt= 0, ctn= 0, status= 0; + + pTX= 0; + RX_LED_OFF; + R_LED_OFF; + G_LED_OFF; + B_LED_OFF; + SON_OFF; + + usb.printf("\r\n\r\n\r\n"); + if(vDEBUG== true){usb.printf("%s/ Initialisation ..... %s \r\n", productName, versionName); wait(1);}; + + + // Signal Sonore et Lumineux de Bienvenue + SON_ON; wait(0.1); SON_OFF; + R_LED_ON; G_LED_ON; B_LED_ON; + + // if(vDEBUG== true){usb.println(" "); usb.print(productName); usb.print(" nb axes: "); usb.println(padNbAxe);delay(10);}; + cmpt= 0; + while(cmpt< padNbAxe){ +// if(vDEBUG== true){usb.print("-"); delay(500);}; + switch(cmpt){ + case 0:// Axe Latteral (Roulis) +// pad.axe[cmpt].nom = XAxeName; // "Roulis"; // Axe/ Designation + pad.axe[cmpt].scB = 100; // Mode Commande : 100 (%: 100 -> Proportionnelle pure, 0 -> Integrale Pure) + pad.axe[cmpt].dzB = 7; // Dead Zone : 5 (% plage) + pad.axe[cmpt].znlB = 25; // Zone Non Linearite: 50 (% plage) + pad.axe[cmpt].ctfB= 20; // Gain Proportionnel: 20 (% plage) + pad.axe[cmpt].ctiB= 0; // Gain Integral : 0 (% plage) + pad.axe[cmpt].gainI= 20; // Gain Integration deuxieme zone lineaire/ Valeure + // RAZ filtre moyenneur +// pad.axe[cmpt].fm[0]= 0; pad.axe[cmpt].fm[1]= 0; pad.axe[cmpt].fm[2]= 0; pad.axe[cmpt].fm[3]= 0; pad.axe[cmpt].fm[4]= 0; + break; + + case 1:// Axe Antero posterieur (Tangage) + // pad.axe[cmpt].nom = YAxeName; //"Tangage";// Axe/ Designation + pad.axe[cmpt].scB = 100; // Mode Commande : 100 (%: 100 -> Proportionnelle pure, 0 -> Integrale Pure) // Commande Integrale Pure + pad.axe[cmpt].dzB = 5; // Dead Zone : 10 (% plage) + pad.axe[cmpt].znlB = 70; // Zone Non Linearite: 40 (% plage) + pad.axe[cmpt].ctfB= 20; // Gain Proportionnel: 20 (% plage) + pad.axe[cmpt].ctiB= 0; // Gain Integral : 0 (% plage) + pad.axe[cmpt].gainI= 25; // Gain Integration deuxieme zone lineaire/ Valeure + // RAZ filtre moyenneur +// pad.axe[cmpt].fm[0]= 0; pad.axe[cmpt].fm[1]= 0; pad.axe[cmpt].fm[2]= 0; pad.axe[cmpt].fm[3]= 0; pad.axe[cmpt].fm[4]= 0; + break; + default: break; + }; // fin switch(cmpt){ + + pad.axe[cmpt].sc = pad.axe[cmpt].scB/ 100; + pad.axe[cmpt].dzm = pad.axe[cmpt].dzB; pad.axe[cmpt].dzm/= 100; // Dead Zone/ Valeur min + pad.axe[cmpt].dzm*= -1; + pad.axe[cmpt].dzM = pad.axe[cmpt].dzB; pad.axe[cmpt].dzM/= 100; // Dead Zone/ Valeur MAX + pad.axe[cmpt].znlm= pad.axe[cmpt].znlB; pad.axe[cmpt].znlm/= 100; // Zone Non Linearite/ Valeur min + pad.axe[cmpt].znlm*= -1; + pad.axe[cmpt].znlM= pad.axe[cmpt].znlB; pad.axe[cmpt].znlM/= 100; // Zone Non Linearite/ Valeur MAX + pad.axe[cmpt].ctf = ctfmin+ (((pad.axe[cmpt].ctfB*(ctfMAX- ctfmin))/100)); // Gain Proportionnel/ Valeur nominale + pad.axe[cmpt].cti = ctimin+ (((pad.axe[cmpt].ctiB*(ctiMAX- ctimin))/100)); // Gain Integral/ Valeur nominale + pad.axe[cmpt].l = 0; + pad.axe[cmpt].i = 0; + pad.axe[cmpt].p = 0; + pad.axe[cmpt].i0 = 0; + pad.axe[cmpt].in = 0; + pad.axe[cmpt].out = 0; + pad.axe[cmpt].x= 0; pad.axe[cmpt].dX= 0; pad.axe[cmpt].X= 0; + + ++cmpt; + }; // fin while(cmpt<= padNbAxe){ + + +// if(vDEBUG== true){usb.println(" "); delay(10);}; + + // Initialisation/ Module/ PAD/ SW +// if(vDEBUG== true){usb.print(productName); usb.print("/ Initialisation/ PAD/ SW "); delay(10);}; + cmpt= 0; + while(cmpt<= padNbSW){ +// if(vDEBUG== true){usb.print("-"); delay(10);}; + switch(cmpt){ + case 0:// Switch SW0: RAZ + pad.sw[0].value = OFF; + break; + default: break; + }; // fin switch(cmpt){ + ++cmpt; + }; // fin while(cmpt<= padNbSW){ + + + // Initialisation/ Module/ Trame emission et reception UART + // if(vDEBUG== true){usb.print(productName); usb.print("/ Initialisation/ PAD/ Trame "); delay(10);}; + trame.wdtTX = wdtTXMAX; + trame.wdtRX = wdtRXMAX; + ctn= wBUFFER- 1; while(ctn>= 0){trame.rx[ctn]= ' '; --ctn;}; + trame.pcar = -1; + trame.fSB = false; + trame.fEB = false; + trame.sb = startB; + trame.eb = endB; + trame.dlb = dlB; + trame.id = idMOBILE; + + //Initialisation/ Materiel/ DS3231 + // ds3231_time_t time = {12,0,0,0,1}; + // int16_t ret_val= rtc.set_time(time); + + + //Initialisation/ Materiel/ Communication/ UART USB + usb.baud(usbBR); wait(0.3); + usb.attach(&rx_usb_isr, Serial::RxIrq); +// USB.attach(&Tx_USB_Isr, Serial::TxIrq); + pUSBRx= 0; pUSBTx= 0; + + //Initialisation/ Materiel/ Communication/ UART BT + uart.baud(uartBR); wait(0.3); + uart.attach(&rx_uart_isr, Serial::RxIrq); +// uart.attach(&Tx_uart_Isr, Serial::TxIrq); + + //Initialisation/ Materiel/ Communication/ I2C + i2c.frequency(i2cBR); wait(0.2); + + + //Initialisation/ Materiel/ Communication/ RTC +// epoch_time = rtc.get_epoch(); // ds3231 + + // Signal Sonore et Lumineux de Sortie + SON_ON; wait(0.1); SON_OFF; + R_LED_OFF; G_LED_OFF; B_LED_OFF; + + //Initialisation/ Materiel/ Interruption principale + if(status ==0){process.attach(&process_isr, TSample);}; + + return status; +} + + + + + + +//5.6- Definition/ Procedure/ Alarme +void alarme(void){ + while(1){ + B_LED_OFF; G_LED_OFF; R_LED_OFF; wait(0.3); + B_LED_ON; G_LED_OFF; R_LED_OFF; wait(0.3); + B_LED_OFF; G_LED_ON; R_LED_OFF; wait(0.3); + B_LED_OFF; G_LED_OFF; R_LED_ON; wait(0.3); + B_LED_OFF; G_LED_OFF; R_LED_OFF; wait(0.3); + }; + } + + + +//5.6- Definition/ Procedure/ Principale +int main(){ + int statusInit= 0; + string svalue = ""; + + statusInit= InitProcess(); // Processus Principal/ Initialisation + if(statusInit== -1){ alarme();}; // Processus Principal/ Initialisation/ Probleme/ ARRET + + usb.printf("\r\n\r\n--------------------------------------------------------\r\n\r\n"); + usb.printf("%s/ %s version : %s \r\n", target, productName, versionName); + usb.printf("\r\n\r\n"); + + usb.printf("Parametre/ TSample (ms) : %d \r\n", (int)(1000*TSample)); + usb.printf("Parametre/ USB Baud Rate : %d \r\n", usbBR); + usb.printf("\r\n"); + usb.printf("%s/ STATUS : Running ... \r\n\r\n", productName); + + // Processus principal + while(true){ + + if(secWDT<= 0){ + epoch_time = rtc.get_epoch(); + rledWDT= 5; + secWDT= secWDTMAX; + }; + + /* + // 5.15.1- Gestion Bus I2C + tmp1= 888; + tmp2= 999; + tmp1= power.read_bus_voltage(); + tmp2= power.read_current(); + eTENSION= tmp1; + eCOURANT= tmp2; + + // 5.15.2- Gestion Bus CAN + // 5.15.2.1- CAN Emission + if(sndCAN== true){ // CAN/ Emission + // CANTx.clear(); + switch(processCAN){ + case 0: CANTx.id= idMOBILE; processCAN= 1;break; // CAN/ demande info IMU + case 1: CANTx.id= idIMU; processCAN= 0;break; + default: break; + }; // fin switch(processCAN){ + CANTx.len= 1; + CANTx.data[0]= 0; + bCAN.write(CANTx); + sndCAN= false; + }; // fin if(sndCAN== true){ + + // 5.15.2.2- CAN Reception + if(rcvCAN== true){ // CAN/ Reception + switch(CANRx.id){ + case idIMU : // imuWDT= 100; + // led(1, d20ms); + break; + default : break; + }; // fin swith(CANRx.id){ + rcvCAN= false; + }; // fin if(rcvCAN== true){ + */ + }; // fin while(true){ + + } // Fin int main() { + +
diff -r 000000000000 -r 13c98588f2fc mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Oct 17 12:01:00 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/aa5281ff4a02 \ No newline at end of file
diff -r 000000000000 -r 13c98588f2fc objet.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/objet.h Wed Oct 17 12:01:00 2018 +0000 @@ -0,0 +1,317 @@ + +#include <string> + +//1- Definition/ Constantes +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +#define wBUFFER 300 // Processus principal/ Trame/ Profondeur MAX du buffer de donnees (exprimé en caracteres) +#define wDTRAME 6 // Processus principal/ Trame/ Nombre de donnees MAX par trame +// Definition/ Constante/ Nombre d'objet Event MAX +#define nbEVENTMAX 12 + +// Definition/ Constante/ Nombre de LED intégrées MAX +#define nbLEDMAX 4 // Carte/ nombre Max LED + +// Definition/ Constante/ Nombre de Moteurs MAX +#define nbMOTORMAX 2 + +// Definition/ Constante/ Nombre de SERVO MAX +#define nbSERVOMAX 2 + +//Definition/ Parametrage/ GPS/ Parcours/ Nombre maximal de WP +#define nbWPMAX 100 // Parcours GPS/ Nombre de Way Point Maximum enregistrés + +//Definition/ Constante/ Nombre d'objet PID MAX +#define nbPIDMAX 2 + +//Definition/ Constante/ Nombre d'objet commande.axe +#define nbAXEMAX 2 + +//Definition/ Constante/ ojet PAD/ nb axe MAX et nb SW MAX +#define padNBAXEMAX 2 +#define padNBSWMAX 4 + +//Definition/ Constante/ Nombre Parametres MAX +#define nbPARAMAX 11 + + +// Definition/ Protocole/ Constantes/ Mode +#define mSTB 0 // Mode/ STANDBY +#define mSTP 1 // Mode/ STOP +#define mMAN 2 // Mode/ MANUAL +#define mPA 4 // Mode/ Pilote Automatique +#define mWP 8 // Mode/ Enregistrement WP +#define mRAZ 64 // Mode/ Remise à 0 des commandes +#define mCHG 128 // Mode/ recharge Accumulateurs + + + +//2- Definition/ Type de donnees +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +//2.1- Definition/ Type/ global/ data/ objet GLOBAL +typedef struct{ + bool fValid; // Validation module + string designation; // Identification produit + string version; // Version produit (v.xx/yy , xx: annee, yy: semaine dans l'annee) + bool debug; // Activation du mode DEBUG + int nbLED; // Nombre LED integrées + int tBATT; // Batterie/ Structure Chimique + int NbElement; // Batterie/ Nombre Elements + int Dynmin; // Variables/ dynamique minimum + int DynMAX; // Variables/ dynamique MAXIMUM + float TSample; // Periode d'echantillonnage du processus (exprimée en secondes) + int TPWM; // periode PWM (exprimée en micro secondes) + int USBBaud; // UART sur USB BaudRate + int UART1Baud; // UART 1 BaudRate + int UART2Baud; // UART 2 BaudRate + int I2CBaud; // Frequence bus I2C + int CANBaud; // Frequence bus CAN + struct{ // Event + bool fValid; // Event/ Validité + bool fPeriode; // Event/ Periodicité + int wdt; // Event/ WatchDog + int wdtMAX; // Event/ WatchDog MAX + }event[nbEVENTMAX]; + } GLOBAL_t; + + +//2.2- Definition/ Type/ objet TRAME +typedef struct{ + bool fValid; // Validation module + int wdtTX; // WatchDog Emission + int wdtRX; // WatchDog Reception + int pcar; // Pointeur de caracteres + char sb; // Protocole communication/ Start Beacon: + char dlb; // Protocole communication/ Delimiter Beacon + char eb; // Protocole communication/ End Beacon + int id; // Mot identificateur de trame + char rx[wBUFFER]; // tableau des caracteres recus + char tx[wBUFFER]; // tableau des caracteres envoyés + bool fSB, fEB; // status startB et endB + int c[wDTRAME]; // Data Consigne + int r[wDTRAME]; // Data Reponse + int nbdata; // Nombre de Data sur la Trame + } TRAME_t; + + + +//2.3- Definition/ Type/ objet COMMANDE +typedef struct{ + struct{ + bool fValid; // Validation Module + float in; // Variable Entree + float out; // Variable Sortie + float dzm; // Valeur Dead Zone inferieure (0..1) + float dzM; // Valeur Dead Zone supérieure (0..1) + float cti; // Valeur Constante de temps Integrale (0..1) + float ctf; // Valeur Constante de temps Proportionnelle (0..1) + float ctg; // Valeur Constante de Temps Filtre de sortie + float cgg; // Valeur Gain Filtre de sortie + float l; // Valeur calcul loi non lineaire + float i, i0; // Valeur calcul integral + float p; // Valeur calcul proportionnelle + float c; // Valeur calcul proportionnelle - integrale + float x, dx; // Valeur filtre passe bas + }axe[nbAXEMAX]; + } COMMANDE_t; + + + + + +//2.4- Definition/ Type/ objet MUX (multiplexeur) +typedef struct{ + bool fValid; // Validation Module + float in0x, in0y, in1x, in1y, in2x, in2y, // Variables d'état d'entree du module: variables d'entree + outx, outy; // Variables d'état de sortie du module: variables de sortie + unsigned char sel; // Variables d'état d'entree du module: selection de la variable d'entrée + unsigned char Status; // Variables Status du module s0:, s1:, s2:, s3:, s4:, s5:, s6:, s7: + }MUX_t; + + + +//2.5- Definition/ Type/ objet ENERGIE +typedef struct{ + bool fValid, fCHARGE, fVhigh, fVlow, fIhigh, fIlow, fFailed; + unsigned char tBATT; // Type de batterie (1: LEAD, 2: NIMH, 2: LION, 3: LIPO) // Definition/ Parametres/ Type de batterie + unsigned char NbElement; // Nombre Element en Serie + int seqPointer; // Sequenceur du processus de charge + float tension, courant; // Variables differentielles Energie, Tension, Courant Acquisition + float dE,dV,dI; // Variables differentielles Energie, Tension, Courant Filtrage + float E, E0, V, I; // Variables Energie, Tension, Courant + float VMax, Vmin, IMax, Imin; // Parametres internes + int wPWM, pPWM; // Largeur Impulsion, Periode PWM (chargeur) + unsigned char Status; // Variables Status du module s0: fValid, s1: fCharge, s2:fVlow, s3:fVhigh, s4:fIlow, s5:fIhigh, s6: NA, s7: fFailed + } ENERGY_t; + + +//2.6- Definition/ Type/ objet GPS +typedef struct{ + bool fValid, fLocked, fFailed; // Validation Module, Trame Valide + int baud; // BaudRate + int TSample; // Periode rafraichissement des trames + int dop; // Variable Indice Dilution Satellites + double utc, lng, lat, hdg, spd; // Variables: Temps Universel (UTC), Longitude (LNG), Latitude (LAT), Cap (HDG), Vitesse Air (SPD) + int speedmin; + unsigned char Status; //Variables Status du module s0:fValid, s1:fLocked, s2:na, s3:na, s4:na, s5:na, s6:na, s7:fFailed + } GPS_t; + + +//2.7- Definition/ Type/ objet IMU +typedef struct{ + bool fValid, fFailed; // Validation module + float roll, pitch, yaw, temp; // Variables attitude; Roulis, Tangage, Lacet, Temperature + float q0, q1, q2, q3; // Variables attitude/ Quarternions + float liax, liay, liaz; // Variables acceleration lineaire x, y, z + float grvx, grvy, grvz; // Variables gravité + float gyrox, gyroy, gyroz; // Variables gyroscopiques x, y, z + float magx, magy, magz; // Variables magnetometriques x, y, z + unsigned char Status; // Variables Status module. s0:fValid, s1:fLocked, s2:na, s3:na, s4:na, s5:na, s6:na, s7:fFailed + } IMU_t; + + +//2.8- Definition/ Type/ objet PA (pilote automatique) +typedef struct{ + bool fValid, fGPSLocked, fWPLocked, fDmin, fDMax, fFailed; + double wLNG, wLAT, // Variables d'état d'entree du module: Coordonnnees Consigne (WayPoint à rejoindre) + mLNG, mLAT; // Variables d'état d'entree du module: Coordonnees reponse (mesure GPS) + float mSPD, // Variables d'état d'entree du module: Vitesse (km/h) (mesure GPS) + mHDG, // Variables d'état d'entree du module: Cap (deg) (mesure GPS) + CtG, // Cap à suivre au WP (calculé) + DtG, // Distance à parcourir au WP (calculée) + cPowerMax, // Niveau de puissance Max (0 .. 1) + Dmin, DMax, // Distance Max et minau WP + Kp, // Correction/ Gain Proportionnel (exprimé en % 0..300) + outx, outy; // Variables d'état de sortie du module + unsigned char Status; // Variables Status du module s0: fValid, s1: fGPSLocked, s2: fWPLocked, s3:fDmin, s4:fDMax, s5: NA, s6: NA,s7: fFailed + } PA_t; + + +//2.9- Definition/ Type/ objet DIGITAL (Accessoire) +typedef struct{ + bool fValid; // Validation Module + unsigned int cDigital; // Variables d'état d'entree du module (c0: Klaxon, c1: Phare) + unsigned int rDigital; // Variables d'état de sortie du module (c0: Klaxon, c1: Phare) + unsigned char Status; // Variable Status du module s0:, s1:, s2:, s3:, s4:, s5:, s6:, s7: + }DIGITAL_t; + + +//2.10- Definition/ Type/ objet SERVO +typedef struct{ + bool fValid; // Validation Module + int c; // Variables d'état d'entree du module/ Variable (0 .. 1) + float x, dx, tSERVO; // Variables d'état Filtre x, dx/ constante de temps du filtre + int r; // Variables d'état de sortie du module/ Variable (0 .. 1) + int pmin; // Constante/ valeur position minimum + int pmax; // Constante/ valeur position maximum + unsigned char Status; // Variable Status du module s0:, s1:, s2:, s3:, s4:, s5:, s6:, s7: + } SERVO_t; + +//2.11- Definition/ Type/ objet LOI + typedef struct{ + bool fValid; // Validation Module + float inx; // Variable/ Entree/ Power + float iny; // Variable/ Entree/ Teta + float outx; // Variable/ Sortie/ Gauche + float outy; // Variable/ Sortie/ Droit + unsigned char Status; // Variable Status du module s0:, s1:, s2:, s3:, s4:, s5:, s6:, s7: + } LAW_t; + + + +//2.12- Definition/ Type/ objet filtre PID +typedef struct{ + bool fValid; // Filtre PID/ Validite + float inc; // Filtre PID/ Variable/ Consigne + float inr; // Filtre PID/ Variable/ FeedBack + float eM; // Filtre PID/ Variable/ Erreur (Consigne- Feedback) + float eMp; + float eMd; + float eMd0; + float uMi; + float uMi0; + float uMd; + float uMd0; + float out; // Filtre PID/ Variable/ Sortie + float cPID1; // Filtre PID/ Constante/1/ + float cPID2; // Filtre PID/ Constante/2/ + float cPID3; // Filtre PID/ Constante/3/ + float cPID4; // Filtre PID/ Constante/4/ + float cPID5; // Filtre PID/ Constante/5/ + float cPID6; // Filtre PID/ Constante/6/ + unsigned char Status; // Filtre PID/ Variable Status du module s0:, s1:, s2:, s3:, s4:, s5:, s6:, s7: + } PID_t; + + +//2.13- Definition/ Type/ objet MOTEUR +typedef struct{ + bool fValid; // Validite Module + float in; // Variable d'état/ entrée/ puissance (0..1) + float dx, x; // Variables d'etat/ interne / Filtre Passe Bas + float out; // Variables d'état/ sortie / puissance (0.. 1) + float tMOTOR; // Constante de temps/ Filtre Passe Bas + float gMOTOR; // Constante/ Gain/ Filtre Passe Bas + unsigned char Status; // Variable Status du module s0:, s1:, s2:, s3:, s4:, s5:, s6:, s7: + } MOTOR_t; + + + +//2.14- Definition/ Type/ objet TRACK +typedef struct{ + bool fValid; // TRACK/ validite/ module + bool fRecord; // TRACK/ Acquisition/ En cours + int nbWP; // TRACK/ nombre WP + int pWP; // TRACK/ pointeur WP + struct{ // TRACK/ structure WP + bool fValid; // wp/ valide + double lat, lng; // wp/ Coordonnees Geographiques + }wp[nbWPMAX]; + int Status; // wp/ status + } TRACK_t; + + + +//2.15- Definition/ Type/ objet MOBILE +typedef struct{ + bool fValid; // Mobile/ Validite + int cWDTRX; // Mobile/ Contante/ WatchDog RX + float inx, iny, outx, outy; // Mobile/ Commande: Niveau de puissance vectorielle: Amplidude/ Phase exprimé de 0 à 100% + int cMODE, rMODE; // Mobile/ Mode de Fonctionnement + double lng, lat, alt, speed, head; // Mobile/ Variables localisation (GPS) + float roll, pitch, yaw, altitude; // Mobile/ Variables attitude (IMU) + int Status; // Mobile/ Status Module + } MOBILE_t; + + +//2.16- Definition/ objet PAD +typedef struct{ + bool fValid; + struct{ + float in; // Variable Entree + float out; // Variable Sortie + int scB; // Pourcentage Proportionnal- Integral (0..100) sc=0: Commande Integrale pure .... sc= 100: Commande Proportionnelle pure + int dzB; // Pourcentage Dead Zone (0..100) + int znlB; // Pourcentage Zone Non Lineaire (0..100) + float ctiB; // Pourcentage Constante de temps loi integrale (0..100) + float gainI; // Gain Integrale deuxieme zone lineaire + float ctfB; // Pourcentage Constante de temps loi proportionnelle (0..100) + float sc; // Valeur Proportionnel Integral + float dzm; // Valeur Dead Zone inferieure + float dzM; // Valeur Dead Zone supérieure + float znlm; // Valeur Non Linearite inferieure + float znlM; // Valeur Non Linearite supérieure + float cti; // Valeur Constante de temps Integrale + float ctf; // Valeur Constante de temps Proportionnelle + float l; // Valeur calcul loi non lineaire + float i, i0; // Valeur calcul integral + float p; // Valeur calcul proportionnelle +// float fm[5]; // Valeur filtre moyenneur + float x, dX, X; // Valeur filtre passe bas + }axe[padNBAXEMAX]; + struct{ + bool value; + }sw[padNBSWMAX]; + +// float roulis, tangage; +} PAD_t;