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
main.cpp@5:bbca34b60427, 2019-05-19 (annotated)
- Committer:
- Coconara
- Date:
- Sun May 19 20:09:32 2019 +0000
- Revision:
- 5:bbca34b60427
- Parent:
- 4:deef042e9c02
asser
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Coconara | 0:6ca63d45f0ee | 1 | #include "mbed.h" |
| Coconara | 0:6ca63d45f0ee | 2 | |
| Coconara | 0:6ca63d45f0ee | 3 | #include "hardware.h" |
| Coconara | 0:6ca63d45f0ee | 4 | #include "odometrie.h" |
| Coconara | 0:6ca63d45f0ee | 5 | #include "reglages.h" |
| GuillaumeCH | 2:5764f89a27f6 | 6 | #include "commande_moteurs.h" |
| GuillaumeCH | 3:1dba6eca01ad | 7 | #include "deplacement.h" |
| Coconara | 0:6ca63d45f0ee | 8 | |
| Coconara | 5:bbca34b60427 | 9 | #define TAILLEWRITE 22 |
| Coconara | 5:bbca34b60427 | 10 | #define TAILLEREAD 20 |
| Coconara | 5:bbca34b60427 | 11 | Serial serial(PC_10,PC_11,115200); |
| Coconara | 5:bbca34b60427 | 12 | Serial pc(SERIAL_TX, SERIAL_RX, 115200); |
| Coconara | 5:bbca34b60427 | 13 | event_callback_t receptionCallback; |
| Coconara | 5:bbca34b60427 | 14 | bool consigne = false; |
| Coconara | 5:bbca34b60427 | 15 | |
| Coconara | 5:bbca34b60427 | 16 | char bufferWrite[TAILLEWRITE] = "3.1415/15000/50000"; |
| Coconara | 5:bbca34b60427 | 17 | char bufferRead[TAILLEREAD]; |
| Coconara | 5:bbca34b60427 | 18 | |
| Coconara | 5:bbca34b60427 | 19 | void recupererConsigne(int events); |
| Coconara | 5:bbca34b60427 | 20 | |
| Coconara | 5:bbca34b60427 | 21 | void envoyerPosition() |
| Coconara | 5:bbca34b60427 | 22 | { |
| Coconara | 5:bbca34b60427 | 23 | serial.printf("%s", bufferWrite); |
| Coconara | 5:bbca34b60427 | 24 | } |
| Coconara | 5:bbca34b60427 | 25 | |
| Coconara | 0:6ca63d45f0ee | 26 | int main() |
| Coconara | 0:6ca63d45f0ee | 27 | { |
| GuillaumeCH | 4:deef042e9c02 | 28 | //ini |
| Coconara | 0:6ca63d45f0ee | 29 | init_odometrie(); |
| Coconara | 0:6ca63d45f0ee | 30 | init_hardware(); |
| GuillaumeCH | 2:5764f89a27f6 | 31 | srand(time(NULL)); |
| GuillaumeCH | 2:5764f89a27f6 | 32 | motors_on(); |
| GuillaumeCH | 4:deef042e9c02 | 33 | AnalogIn Ain(A0); |
| GuillaumeCH | 4:deef042e9c02 | 34 | if(Ain.read()<0.5){ |
| GuillaumeCH | 4:deef042e9c02 | 35 | return 0; |
| GuillaumeCH | 4:deef042e9c02 | 36 | } |
| GuillaumeCH | 3:1dba6eca01ad | 37 | /*DigitalIn depart(USER_BUTTON); |
| GuillaumeCH | 2:5764f89a27f6 | 38 | //Pause pour sauver le robot et l'ordi |
| GuillaumeCH | 3:1dba6eca01ad | 39 | while(depart);*/ |
| GuillaumeCH | 3:1dba6eca01ad | 40 | deplacement robot; |
| GuillaumeCH | 3:1dba6eca01ad | 41 | robot.bouton(); |
| GuillaumeCH | 3:1dba6eca01ad | 42 | Ticker asser; |
| GuillaumeCH | 3:1dba6eca01ad | 43 | Timer t; |
| GuillaumeCH | 3:1dba6eca01ad | 44 | t.start(); |
| GuillaumeCH | 4:deef042e9c02 | 45 | //asser.attach(callback(&robot,&deplacement::asservissement),0.01); |
| GuillaumeCH | 4:deef042e9c02 | 46 | //robot.ligne_droite_v2(210000); |
| GuillaumeCH | 4:deef042e9c02 | 47 | |
| Coconara | 5:bbca34b60427 | 48 | Ticker t; |
| Coconara | 5:bbca34b60427 | 49 | t.attach(&envoyerPosition, 0.1f); |
| Coconara | 5:bbca34b60427 | 50 | |
| Coconara | 5:bbca34b60427 | 51 | receptionCallback.attach(recupererConsigne); |
| Coconara | 5:bbca34b60427 | 52 | serial.read((uint8_t*)bufferRead, TAILLEREAD, receptionCallback, SERIAL_EVENT_RX_COMPLETE); |
| GuillaumeCH | 3:1dba6eca01ad | 53 | |
| Coconara | 5:bbca34b60427 | 54 | float vitesseD; |
| Coconara | 5:bbca34b60427 | 55 | float vitesseG; |
| Coconara | 5:bbca34b60427 | 56 | |
| Coconara | 5:bbca34b60427 | 57 | while(1) |
| Coconara | 5:bbca34b60427 | 58 | { |
| Coconara | 5:bbca34b60427 | 59 | pc.printf("Consigne lu : %s\n\r", bufferRead); |
| Coconara | 5:bbca34b60427 | 60 | conversion(&vitesseD, &vitesseG); |
| Coconara | 5:bbca34b60427 | 61 | commande_vitesse(), |
| Coconara | 5:bbca34b60427 | 62 | } |
| GuillaumeCH | 4:deef042e9c02 | 63 | |
| GuillaumeCH | 4:deef042e9c02 | 64 | //printf("x : %lf,y : %lf,angle : %lf\n",get_x_actuel(),get_y_actuel(),get_angle());*/ |
| Coconara | 0:6ca63d45f0ee | 65 | return 0; |
| Coconara | 0:6ca63d45f0ee | 66 | } |
| Coconara | 5:bbca34b60427 | 67 | |
| Coconara | 5:bbca34b60427 | 68 | |
| Coconara | 5:bbca34b60427 | 69 | |
| Coconara | 5:bbca34b60427 | 70 | void recupererConsigne(int events) |
| Coconara | 5:bbca34b60427 | 71 | { |
| Coconara | 5:bbca34b60427 | 72 | consigne = true; |
| Coconara | 5:bbca34b60427 | 73 | serial.read((uint8_t*)bufferRead, TAILLEREAD, receptionCallback, SERIAL_EVENT_RX_COMPLETE); |
| Coconara | 5:bbca34b60427 | 74 | |
| Coconara | 5:bbca34b60427 | 75 | } |
| Coconara | 5:bbca34b60427 | 76 | |
| Coconara | 5:bbca34b60427 | 77 | void conversion(float *vd, float *vg) |
| Coconara | 5:bbca34b60427 | 78 | { |
| Coconara | 5:bbca34b60427 | 79 | const char seps[2] = "/"; |
| Coconara | 5:bbca34b60427 | 80 | int i = 1; |
| Coconara | 5:bbca34b60427 | 81 | const char sepv[2] = ","; |
| Coconara | 5:bbca34b60427 | 82 | float aux1 = 0; |
| Coconara | 5:bbca34b60427 | 83 | float aux2 = 0; |
| Coconara | 5:bbca34b60427 | 84 | int j=0; |
| Coconara | 5:bbca34b60427 | 85 | |
| Coconara | 5:bbca34b60427 | 86 | float aux = bufferRead[0]; |
| Coconara | 5:bbca34b60427 | 87 | while(bufferRead[i] != sepv[0]) |
| Coconara | 5:bbca34b60427 | 88 | { |
| Coconara | 5:bbca34b60427 | 89 | aux *= 10; |
| Coconara | 5:bbca34b60427 | 90 | aux = bufferRead[i] - 48; |
| Coconara | 5:bbca34b60427 | 91 | i++; |
| Coconara | 5:bbca34b60427 | 92 | } |
| Coconara | 5:bbca34b60427 | 93 | j=i; |
| Coconara | 5:bbca34b60427 | 94 | i++; |
| Coconara | 5:bbca34b60427 | 95 | while(bufferRead[i] != seps[0]) |
| Coconara | 5:bbca34b60427 | 96 | { |
| Coconara | 5:bbca34b60427 | 97 | aux1 = bufferRead[i] - 48; |
| Coconara | 5:bbca34b60427 | 98 | aux1 = aux1/(pow(10,(i-j))); |
| Coconara | 5:bbca34b60427 | 99 | aux2 = aux1+aux2; |
| Coconara | 5:bbca34b60427 | 100 | i++; |
| Coconara | 5:bbca34b60427 | 101 | } |
| Coconara | 5:bbca34b60427 | 102 | *vd = aux + aux2; |
| Coconara | 5:bbca34b60427 | 103 | |
| Coconara | 5:bbca34b60427 | 104 | printf("vd : %lf",&vd); |
| Coconara | 5:bbca34b60427 | 105 | |
| Coconara | 5:bbca34b60427 | 106 | i++; |
| Coconara | 5:bbca34b60427 | 107 | float aux = bufferRead[i]; |
| Coconara | 5:bbca34b60427 | 108 | i++; |
| Coconara | 5:bbca34b60427 | 109 | aux1, aux2 = 0, 0; |
| Coconara | 5:bbca34b60427 | 110 | while(bufferRead[i] != sepv[0]) |
| Coconara | 5:bbca34b60427 | 111 | { |
| Coconara | 5:bbca34b60427 | 112 | aux *= 10; |
| Coconara | 5:bbca34b60427 | 113 | aux = bufferRead[i] - 48; |
| Coconara | 5:bbca34b60427 | 114 | i++; |
| Coconara | 5:bbca34b60427 | 115 | } |
| Coconara | 5:bbca34b60427 | 116 | j=i; |
| Coconara | 5:bbca34b60427 | 117 | i++; |
| Coconara | 5:bbca34b60427 | 118 | while(bufferRead[i] != seps[0]) |
| Coconara | 5:bbca34b60427 | 119 | { |
| Coconara | 5:bbca34b60427 | 120 | aux1 = bufferRead[i] - 48; |
| Coconara | 5:bbca34b60427 | 121 | aux1 = aux1/(pow(10,(i-j))); |
| Coconara | 5:bbca34b60427 | 122 | aux2 = aux1+aux2; |
| Coconara | 5:bbca34b60427 | 123 | i++; |
| Coconara | 5:bbca34b60427 | 124 | } |
| Coconara | 5:bbca34b60427 | 125 | *vg = aux + aux2; |
| Coconara | 5:bbca34b60427 | 126 | |
| Coconara | 5:bbca34b60427 | 127 | printf("vg : %lf",&vg); |
| Coconara | 5:bbca34b60427 | 128 | } |