Corentin Courtot / Mbed 2 deprecated Asserve

Dependencies:   mbed X_NUCLEO_IHM02A1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 #include "hardware.h"
00004 #include "odometrie.h"
00005 #include "reglages.h"
00006 #include "commande_moteurs.h"
00007 #include "deplacement.h"
00008 
00009 #define TAILLEWRITE 22
00010 #define TAILLEREAD  20
00011 Serial serial(PC_10,PC_11,115200);
00012 Serial pc(SERIAL_TX, SERIAL_RX, 115200);
00013 event_callback_t receptionCallback;
00014 bool consigne = false;
00015 
00016 char bufferWrite[TAILLEWRITE] = "3.1415/15000/50000";
00017 char bufferRead[TAILLEREAD]; 
00018 
00019 void recupererConsigne(int events);
00020 
00021 void envoyerPosition()
00022 {
00023     serial.printf("%s", bufferWrite);   
00024 }
00025 
00026 int main()
00027 {
00028     //ini
00029     init_odometrie();
00030     init_hardware();
00031     srand(time(NULL));
00032     motors_on();
00033     AnalogIn Ain(A0);
00034     if(Ain.read()<0.5){
00035           return 0;
00036     }
00037     /*DigitalIn depart(USER_BUTTON);
00038     //Pause pour sauver le robot et l'ordi
00039     while(depart);*/
00040     deplacement robot;
00041     robot.bouton();
00042     Ticker asser;
00043     Timer t;
00044     t.start();
00045     //asser.attach(callback(&robot,&deplacement::asservissement),0.01);
00046     //robot.ligne_droite_v2(210000);
00047 
00048     Ticker t;
00049     t.attach(&envoyerPosition, 0.1f);
00050     
00051     receptionCallback.attach(recupererConsigne); 
00052     serial.read((uint8_t*)bufferRead, TAILLEREAD, receptionCallback, SERIAL_EVENT_RX_COMPLETE);
00053     
00054     float vitesseD;
00055     float vitesseG;
00056     
00057     while(1)
00058     {
00059         pc.printf("Consigne lu : %s\n\r", bufferRead);
00060         conversion(&vitesseD, &vitesseG);
00061         commande_vitesse(),
00062     }
00063     
00064     //printf("x : %lf,y : %lf,angle : %lf\n",get_x_actuel(),get_y_actuel(),get_angle());*/
00065     return 0;
00066 }
00067 
00068 
00069 
00070 void recupererConsigne(int events)
00071 {
00072     consigne = true;
00073     serial.read((uint8_t*)bufferRead, TAILLEREAD, receptionCallback, SERIAL_EVENT_RX_COMPLETE);
00074     
00075 }
00076 
00077 void conversion(float *vd, float *vg)
00078 {
00079     const char seps[2] = "/";
00080     int i = 1;
00081     const char sepv[2] = ",";
00082     float aux1 = 0;
00083     float aux2 = 0;
00084     int j=0;
00085     
00086     float aux = bufferRead[0];
00087     while(bufferRead[i] != sepv[0])
00088     {
00089         aux *= 10;
00090         aux = bufferRead[i] - 48;
00091         i++;
00092     }
00093     j=i;
00094     i++;
00095     while(bufferRead[i] != seps[0])
00096     {
00097         aux1 = bufferRead[i] - 48;
00098         aux1 = aux1/(pow(10,(i-j)));
00099         aux2 = aux1+aux2;
00100         i++;
00101     }
00102     *vd = aux + aux2;
00103     
00104     printf("vd : %lf",&vd);
00105     
00106     i++;    
00107     float aux = bufferRead[i];
00108     i++;
00109     aux1, aux2 = 0, 0;
00110     while(bufferRead[i] != sepv[0])
00111     {
00112         aux *= 10;
00113         aux = bufferRead[i] - 48;
00114         i++;
00115     }
00116     j=i;
00117     i++;
00118     while(bufferRead[i] != seps[0])
00119     {
00120         aux1 = bufferRead[i] - 48;
00121         aux1 = aux1/(pow(10,(i-j)));
00122         aux2 = aux1+aux2;
00123         i++;
00124     }
00125     *vg = aux + aux2;
00126     
00127     printf("vg : %lf",&vg);
00128 }