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.
main.cpp@3:e750507bf900, 2019-03-12 (annotated)
- Committer:
- Nilox
- Date:
- Tue Mar 12 16:07:01 2019 +0000
- Revision:
- 3:e750507bf900
- Parent:
- 2:656a20620e62
- Child:
- 5:7e152e2fe429
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Nilox | 0:f07bc5dab40d | 1 | #include "mbed.h" |
| Nilox | 0:f07bc5dab40d | 2 | #include <PwmIn.h> |
| karteck | 2:656a20620e62 | 3 | #include <stdio.h> |
| Nilox | 0:f07bc5dab40d | 4 | |
| Nilox | 0:f07bc5dab40d | 5 | DigitalIn mybutton(USER_BUTTON); |
| Nilox | 0:f07bc5dab40d | 6 | DigitalOut trig(PA_10); |
| Nilox | 0:f07bc5dab40d | 7 | Serial pc(USBTX,USBRX); |
| Nilox | 3:e750507bf900 | 8 | PwmOut servo(PB_5); |
| Nilox | 0:f07bc5dab40d | 9 | PwmIn LidarI(PB_3); |
| Nilox | 0:f07bc5dab40d | 10 | |
| Nilox | 0:f07bc5dab40d | 11 | float mes = 0; |
| karteck | 2:656a20620e62 | 12 | int arret = 0, n = 0, i = 0; |
| Nilox | 3:e750507bf900 | 13 | float A = 1.0f; |
| Nilox | 0:f07bc5dab40d | 14 | |
| Nilox | 0:f07bc5dab40d | 15 | float boucleM(){ |
| Nilox | 3:e750507bf900 | 16 | wait_ms(40); //Laisser le moteur arriver à sa position |
| Nilox | 3:e750507bf900 | 17 | trig = 1; |
| Nilox | 3:e750507bf900 | 18 | trig=0; // Déclenchement |
| Nilox | 3:e750507bf900 | 19 | wait_ms(10); //Attendre que le signal du LIDAR soit clair pour le microcontroleur et pas parasité par la baisse du déclenchement |
| Nilox | 3:e750507bf900 | 20 | mes = LidarI.pulsewidth() / 10; //Lecture du signal et enregistrement dans la variable mes |
| Nilox | 3:e750507bf900 | 21 | trig = 1; //Stop de la prise de mesure |
| Nilox | 3:e750507bf900 | 22 | pc.printf("Mesure : %f",mes); //Affichage de la mesure prise |
| Nilox | 3:e750507bf900 | 23 | //arret = !mybutton.read(); ------------------------------>Ne sert à rien de toute facon |
| Nilox | 3:e750507bf900 | 24 | return (mes); //Renvoi de la mesure |
| Nilox | 0:f07bc5dab40d | 25 | } |
| karteck | 2:656a20620e62 | 26 | |
| Nilox | 3:e750507bf900 | 27 | /*Procédure de rotation |
| karteck | 2:656a20620e62 | 28 | void rotation(float angle){ |
| karteck | 2:656a20620e62 | 29 | |
| karteck | 2:656a20620e62 | 30 | |
| karteck | 2:656a20620e62 | 31 | } |
| Nilox | 3:e750507bf900 | 32 | */ |
| Nilox | 0:f07bc5dab40d | 33 | |
| Nilox | 0:f07bc5dab40d | 34 | |
| Nilox | 0:f07bc5dab40d | 35 | int main() { |
| karteck | 2:656a20620e62 | 36 | float aireTotale = 0, aireTriangle = 0, angle; |
| Nilox | 3:e750507bf900 | 37 | float tabM[180]; |
| karteck | 2:656a20620e62 | 38 | |
| Nilox | 0:f07bc5dab40d | 39 | pc.printf("\nLancement du programme...\n"); |
| Nilox | 0:f07bc5dab40d | 40 | pc.printf("%d\n\n",n); |
| Nilox | 0:f07bc5dab40d | 41 | |
| Nilox | 3:e750507bf900 | 42 | angle = 1; // Angle de chaque rotation du moteur entre chaque prises de mesure |
| karteck | 2:656a20620e62 | 43 | |
| Nilox | 0:f07bc5dab40d | 44 | trig = 1; |
| Nilox | 3:e750507bf900 | 45 | servo.pulsewidth_us(A*1000); |
| karteck | 2:656a20620e62 | 46 | tabM[i]=boucleM(); |
| karteck | 2:656a20620e62 | 47 | i++; |
| Nilox | 3:e750507bf900 | 48 | wait(1); |
| Nilox | 3:e750507bf900 | 49 | while(A<=2.0f){ |
| Nilox | 3:e750507bf900 | 50 | //Fonction rotation moteur rotation; |
| Nilox | 3:e750507bf900 | 51 | servo.pulsewidth_us(A*1000); |
| Nilox | 3:e750507bf900 | 52 | A += (1.0f/180.0f); |
| Nilox | 0:f07bc5dab40d | 53 | tabM[i]=boucleM(); |
| Nilox | 3:e750507bf900 | 54 | |
| karteck | 2:656a20620e62 | 55 | |
| Nilox | 3:e750507bf900 | 56 | //Calcul de l'aire de chaque segment et de l'aire totale |
| karteck | 2:656a20620e62 | 57 | aireTriangle = (tabM[i - 1] * tabM[i] * sin(angle) ) / 2; |
| karteck | 2:656a20620e62 | 58 | aireTotale += aireTriangle; |
| Nilox | 3:e750507bf900 | 59 | |
| Nilox | 3:e750507bf900 | 60 | i++; |
| Nilox | 0:f07bc5dab40d | 61 | } |
| Nilox | 0:f07bc5dab40d | 62 | i=0; |
| Nilox | 3:e750507bf900 | 63 | servo.pulsewidth(0); |
| Nilox | 3:e750507bf900 | 64 | while(i<180){ |
| karteck | 2:656a20620e62 | 65 | pc.printf("M(%d):[%f]\n",i ,tabM[i]); |
| Nilox | 0:f07bc5dab40d | 66 | i=i++; |
| Nilox | 0:f07bc5dab40d | 67 | } |
| karteck | 2:656a20620e62 | 68 | |
| karteck | 2:656a20620e62 | 69 | pc.printf("\n Aire total : %f \n", aireTotale); |
| Nilox | 0:f07bc5dab40d | 70 | pc.printf("Arret du programme..."); |
| Nilox | 0:f07bc5dab40d | 71 | sleep(); |
| Nilox | 0:f07bc5dab40d | 72 | } |
| karteck | 2:656a20620e62 | 73 | |
| karteck | 2:656a20620e62 | 74 | |
| karteck | 2:656a20620e62 | 75 | |
| karteck | 2:656a20620e62 | 76 | |
| karteck | 2:656a20620e62 | 77 | |
| karteck | 2:656a20620e62 | 78 | |
| karteck | 2:656a20620e62 | 79 | |
| karteck | 2:656a20620e62 | 80 | /* DEUXIEME VERSION A METTRE DANS MAIN |
| karteck | 2:656a20620e62 | 81 | passe dans la tableau et calcule l'aire une fois que les mesures sont prises |
| karteck | 2:656a20620e62 | 82 | |
| karteck | 2:656a20620e62 | 83 | |
| karteck | 2:656a20620e62 | 84 | i = 1; |
| karteck | 2:656a20620e62 | 85 | while (i < n){ |
| karteck | 2:656a20620e62 | 86 | |
| karteck | 2:656a20620e62 | 87 | aireTriangle = (tabM[i - 1] * tabM[i] * sin(angle) ) / 2; |
| karteck | 2:656a20620e62 | 88 | aireTotale += aireTriangle; |
| karteck | 2:656a20620e62 | 89 | i++; |
| karteck | 2:656a20620e62 | 90 | } |
| karteck | 2:656a20620e62 | 91 | |
| karteck | 2:656a20620e62 | 92 | |
| karteck | 2:656a20620e62 | 93 | |
| karteck | 2:656a20620e62 | 94 | */ |
| karteck | 2:656a20620e62 | 95 | |
| karteck | 2:656a20620e62 | 96 | |
| karteck | 2:656a20620e62 | 97 | |
| karteck | 2:656a20620e62 | 98 | |
| karteck | 2:656a20620e62 | 99 | |
| karteck | 2:656a20620e62 | 100 | |
| karteck | 2:656a20620e62 | 101 | |
| karteck | 2:656a20620e62 | 102 | |
| Nilox | 0:f07bc5dab40d | 103 |