![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
mesure de l'angle sur AS5048 par SPI
main.cpp@0:5a1830df0b66, 2019-10-08 (annotated)
- Committer:
- PC2ROBOT
- Date:
- Tue Oct 08 14:59:11 2019 +0000
- Revision:
- 0:5a1830df0b66
- Child:
- 1:d92ff88de240
as5048
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
PC2ROBOT | 0:5a1830df0b66 | 1 | #include "mbed.h" |
PC2ROBOT | 0:5a1830df0b66 | 2 | #include "as5048spi.h" |
PC2ROBOT | 0:5a1830df0b66 | 3 | |
PC2ROBOT | 0:5a1830df0b66 | 4 | #define rayon_roue 0.0045 |
PC2ROBOT | 0:5a1830df0b66 | 5 | #define pi 3.14159 |
PC2ROBOT | 0:5a1830df0b66 | 6 | |
PC2ROBOT | 0:5a1830df0b66 | 7 | #define intervalle 0.005 |
PC2ROBOT | 0:5a1830df0b66 | 8 | |
PC2ROBOT | 0:5a1830df0b66 | 9 | As5048Spi sensor(PB_15, PB_14, PB_13, PB_12); //MOSI, MISO, SCKL, CS |
PC2ROBOT | 0:5a1830df0b66 | 10 | Serial pc(USBTX, USBRX); // tx, rx |
PC2ROBOT | 0:5a1830df0b66 | 11 | InterruptIn bouton(PC_13); |
PC2ROBOT | 0:5a1830df0b66 | 12 | Ticker timer; |
PC2ROBOT | 0:5a1830df0b66 | 13 | int angle, degrees_avant, degrees_maintenant, degrees_vitesse; |
PC2ROBOT | 0:5a1830df0b66 | 14 | float vitesse; |
PC2ROBOT | 0:5a1830df0b66 | 15 | |
PC2ROBOT | 0:5a1830df0b66 | 16 | void donnee_saisie() |
PC2ROBOT | 0:5a1830df0b66 | 17 | { |
PC2ROBOT | 0:5a1830df0b66 | 18 | const int* angles = sensor.read_angle(); |
PC2ROBOT | 0:5a1830df0b66 | 19 | angle = angles[0]; |
PC2ROBOT | 0:5a1830df0b66 | 20 | //Récupération de l'angle précédent |
PC2ROBOT | 0:5a1830df0b66 | 21 | degrees_avant = degrees_maintenant; |
PC2ROBOT | 0:5a1830df0b66 | 22 | |
PC2ROBOT | 0:5a1830df0b66 | 23 | //Aquisition du nouvel angle |
PC2ROBOT | 0:5a1830df0b66 | 24 | degrees_maintenant = sensor.degrees(angle)/100; |
PC2ROBOT | 0:5a1830df0b66 | 25 | |
PC2ROBOT | 0:5a1830df0b66 | 26 | //Calcul de la différence |
PC2ROBOT | 0:5a1830df0b66 | 27 | degrees_vitesse = (degrees_maintenant - degrees_avant) / intervalle; |
PC2ROBOT | 0:5a1830df0b66 | 28 | |
PC2ROBOT | 0:5a1830df0b66 | 29 | vitesse = (rayon_roue * degrees_vitesse * 2 * pi / 360) /*/ (5 + 0.01 / (2 * pi))*/; |
PC2ROBOT | 0:5a1830df0b66 | 30 | } |
PC2ROBOT | 0:5a1830df0b66 | 31 | |
PC2ROBOT | 0:5a1830df0b66 | 32 | void print_speed() |
PC2ROBOT | 0:5a1830df0b66 | 33 | { |
PC2ROBOT | 0:5a1830df0b66 | 34 | timer.detach(); |
PC2ROBOT | 0:5a1830df0b66 | 35 | //Affichage du résultat |
PC2ROBOT | 0:5a1830df0b66 | 36 | pc.printf("rotation = %d degrees/s, vitesse = %.4f mm/s \r", degrees_vitesse, vitesse * 1000); |
PC2ROBOT | 0:5a1830df0b66 | 37 | timer.attach(&donnee_saisie, intervalle); //Lancement de la fonction "donnee_saisie()" toutes les 1 sec |
PC2ROBOT | 0:5a1830df0b66 | 38 | } |
PC2ROBOT | 0:5a1830df0b66 | 39 | |
PC2ROBOT | 0:5a1830df0b66 | 40 | int main() { |
PC2ROBOT | 0:5a1830df0b66 | 41 | bouton.rise(&print_speed); |
PC2ROBOT | 0:5a1830df0b66 | 42 | timer.attach(&donnee_saisie, intervalle); //Lancement de la fonction "donnee_saisie()" toutes les 1 sec |
PC2ROBOT | 0:5a1830df0b66 | 43 | while(1) |
PC2ROBOT | 0:5a1830df0b66 | 44 | { |
PC2ROBOT | 0:5a1830df0b66 | 45 | |
PC2ROBOT | 0:5a1830df0b66 | 46 | } |
PC2ROBOT | 0:5a1830df0b66 | 47 | } |