Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed X_NUCLEO_IHM02A1
Revision 5:bbca34b60427, committed 2019-05-19
- Comitter:
- Coconara
- Date:
- Sun May 19 20:09:32 2019 +0000
- Parent:
- 4:deef042e9c02
- Commit message:
- asser
Changed in this revision
--- a/X_NUCLEO_IHM02A1.lib Wed May 08 20:46:46 2019 +0000 +++ b/X_NUCLEO_IHM02A1.lib Sun May 19 20:09:32 2019 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/teams/AREM-CDFR-2019/code/asser1/#612e6272cf09 +https://developer.mbed.org/teams/ST/code/X_NUCLEO_IHM02A1/#ff67801d7cd7
--- a/deplacement.cpp Wed May 08 20:46:46 2019 +0000 +++ b/deplacement.cpp Sun May 19 20:09:32 2019 +0000 @@ -102,7 +102,7 @@ consigne_tab[19][1]=0;*/ } -void deplacement::commande_vitesse(float vitesse_G,float vitesse_D){ //fonction pour commander les moteurs sans avoir à utiliser set_PWM +void deplacement::commande_vitesse(float vitesse_G,float vitesse_D){ //fonction pour commander les moteurs sans avoir à utiliser set_PWM, en ticks/ms int sens_G=signe(vitesse_G); int sens_D=signe(vitesse_D);
--- a/main.cpp Wed May 08 20:46:46 2019 +0000 +++ b/main.cpp Sun May 19 20:09:32 2019 +0000 @@ -6,6 +6,23 @@ #include "commande_moteurs.h" #include "deplacement.h" +#define TAILLEWRITE 22 +#define TAILLEREAD 20 +Serial serial(PC_10,PC_11,115200); +Serial pc(SERIAL_TX, SERIAL_RX, 115200); +event_callback_t receptionCallback; +bool consigne = false; + +char bufferWrite[TAILLEWRITE] = "3.1415/15000/50000"; +char bufferRead[TAILLEREAD]; + +void recupererConsigne(int events); + +void envoyerPosition() +{ + serial.printf("%s", bufferWrite); +} + int main() { //ini @@ -28,22 +45,84 @@ //asser.attach(callback(&robot,&deplacement::asservissement),0.01); //robot.ligne_droite_v2(210000); - //robot.ligne_droite_v2(210000); - robot.commande_vitesse(500,0); - //robot.ligne_droite_v2(150000); - //robot.test_rotation_rel(90); - //robot.ligne_droite_v2(40000); - //robot.poussette(); - //robot.reculer_un_peu(-50000); - //robot.test(); - //asser.detach(); - //robot.vitesse_nulle_G(0); - //robot.vitesse_nulle_D(0); - //wait(0.2); - //motors_stop(); - //robot.printftab(); + Ticker t; + t.attach(&envoyerPosition, 0.1f); + + receptionCallback.attach(recupererConsigne); + serial.read((uint8_t*)bufferRead, TAILLEREAD, receptionCallback, SERIAL_EVENT_RX_COMPLETE); + float vitesseD; + float vitesseG; + + while(1) + { + pc.printf("Consigne lu : %s\n\r", bufferRead); + conversion(&vitesseD, &vitesseG); + commande_vitesse(), + } //printf("x : %lf,y : %lf,angle : %lf\n",get_x_actuel(),get_y_actuel(),get_angle());*/ return 0; } + + + +void recupererConsigne(int events) +{ + consigne = true; + serial.read((uint8_t*)bufferRead, TAILLEREAD, receptionCallback, SERIAL_EVENT_RX_COMPLETE); + +} + +void conversion(float *vd, float *vg) +{ + const char seps[2] = "/"; + int i = 1; + const char sepv[2] = ","; + float aux1 = 0; + float aux2 = 0; + int j=0; + + float aux = bufferRead[0]; + while(bufferRead[i] != sepv[0]) + { + aux *= 10; + aux = bufferRead[i] - 48; + i++; + } + j=i; + i++; + while(bufferRead[i] != seps[0]) + { + aux1 = bufferRead[i] - 48; + aux1 = aux1/(pow(10,(i-j))); + aux2 = aux1+aux2; + i++; + } + *vd = aux + aux2; + + printf("vd : %lf",&vd); + + i++; + float aux = bufferRead[i]; + i++; + aux1, aux2 = 0, 0; + while(bufferRead[i] != sepv[0]) + { + aux *= 10; + aux = bufferRead[i] - 48; + i++; + } + j=i; + i++; + while(bufferRead[i] != seps[0]) + { + aux1 = bufferRead[i] - 48; + aux1 = aux1/(pow(10,(i-j))); + aux2 = aux1+aux2; + i++; + } + *vg = aux + aux2; + + printf("vg : %lf",&vg); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uart.cpp Sun May 19 20:09:32 2019 +0000 @@ -0,0 +1,44 @@ +#include "mbed.h" + +#define TAILLEWRITE 22 +#define TAILLEREAD 20 +Serial serial(PC_10,PC_11,115200); +Serial pc(SERIAL_TX, SERIAL_RX, 115200); +event_callback_t receptionCallback; +bool consigne = false; + +char bufferWrite[TAILLEWRITE] = "3.1415/15000/50000"; +char bufferRead[TAILLEREAD]; + +void recupererConsigne(int events); + +void envoyerPosition() +{ + serial.printf("%s", bufferWrite); +} + +int main() { + + Ticker t; + t.attach(&envoyerPosition, 0.1f); + + receptionCallback.attach(recupererConsigne); + serial.read((uint8_t*)bufferRead, TAILLEREAD, receptionCallback, SERIAL_EVENT_RX_COMPLETE); + while(1) + { + pc.printf("Consigne lu : %s\n\r", bufferRead); + if(consigne == true) + { + //pc.printf("Consigne lu : %s\n\r", bufferRead); + consigne = false; + } + } +} + + +void recupererConsigne(int events) +{ + consigne = true; + serial.read((uint8_t*)bufferRead, TAILLEREAD, receptionCallback, SERIAL_EVENT_RX_COMPLETE); + +} \ No newline at end of file