AresENSEA-CDF2020
/
AresCDFMainCode_capteur_US
Capteur_US
odo_asserv.cpp@12:2c312916a621, 2020-09-11 (annotated)
- Committer:
- plmir
- Date:
- Fri Sep 11 13:47:56 2020 +0000
- Revision:
- 12:2c312916a621
- Parent:
- 11:e62133022f88
- Child:
- 13:a72b0752aa6f
Odometrie
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nanaud | 2:094c09903a9c | 1 | //Nom du fichier : odo_asserv.cpp |
Nanaud | 2:094c09903a9c | 2 | #include "pins.h" |
Nanaud | 2:094c09903a9c | 3 | |
Nanaud | 6:ea6b30c4bb01 | 4 | ///// VARIABLES |
Nanaud | 10:0714feaaaee1 | 5 | |
plmir | 12:2c312916a621 | 6 | Ticker ticker_odo; |
plmir | 12:2c312916a621 | 7 | |
Nanaud | 10:0714feaaaee1 | 8 | // Coeff à définir empiriquement |
Nanaud | 10:0714feaaaee1 | 9 | const double coeffGLong = 5.956, coeffDLong = -5.956; // constantes permettant la transformation tic/millimètre |
Nanaud | 11:e62133022f88 | 10 | //const double coeffGAngl = 12.4516203705, coeffDAngl = 12.725; // constantes permettant la transformation tic/degré |
Nanaud | 11:e62133022f88 | 11 | const double coeffGAngl = 12*2*Pi*53791, coeffDAngl = 12*2*Pi*54972; // constantes permettant la transformation tic/radian |
Nanaud | 6:ea6b30c4bb01 | 12 | |
Nanaud | 6:ea6b30c4bb01 | 13 | long comptG = 0, comptD = 0; // nb de tics comptés pour chaque codeur |
Nanaud | 6:ea6b30c4bb01 | 14 | |
Nanaud | 6:ea6b30c4bb01 | 15 | ///// INTERRUPTIONS CODEURS |
Nanaud | 6:ea6b30c4bb01 | 16 | |
Nanaud | 6:ea6b30c4bb01 | 17 | void cdgaRise() |
Nanaud | 6:ea6b30c4bb01 | 18 | { |
Nanaud | 6:ea6b30c4bb01 | 19 | if(cdgB) comptG++; |
Nanaud | 6:ea6b30c4bb01 | 20 | else comptG--; |
Nanaud | 6:ea6b30c4bb01 | 21 | } |
Nanaud | 2:094c09903a9c | 22 | |
Nanaud | 6:ea6b30c4bb01 | 23 | void cddaRise() |
Nanaud | 6:ea6b30c4bb01 | 24 | { |
Nanaud | 6:ea6b30c4bb01 | 25 | if(cddB) comptD++; |
Nanaud | 6:ea6b30c4bb01 | 26 | else comptD--; |
Nanaud | 6:ea6b30c4bb01 | 27 | } |
Nanaud | 6:ea6b30c4bb01 | 28 | |
Nanaud | 10:0714feaaaee1 | 29 | ///// ODOMÉTRIE |
Nanaud | 2:094c09903a9c | 30 | |
Nanaud | 10:0714feaaaee1 | 31 | // Variables et constantes |
Nanaud | 10:0714feaaaee1 | 32 | #define NbPulseCodeur 1000 |
Nanaud | 10:0714feaaaee1 | 33 | #define entraxe 245 |
Nanaud | 6:ea6b30c4bb01 | 34 | |
Nanaud | 10:0714feaaaee1 | 35 | float x = 0, y = 0, phi = 0; |
plmir | 12:2c312916a621 | 36 | float phi_deg; |
Nanaud | 10:0714feaaaee1 | 37 | float x0 = 0, y0 = 0, phi0 = 0; |
Nanaud | 10:0714feaaaee1 | 38 | float dDist = 0, dAngl = 0; |
Nanaud | 10:0714feaaaee1 | 39 | float distG = 0, distD = 0; // Distance parcourue par chaque roue |
Nanaud | 6:ea6b30c4bb01 | 40 | |
Nanaud | 10:0714feaaaee1 | 41 | void odometrie() |
Nanaud | 10:0714feaaaee1 | 42 | { |
Nanaud | 10:0714feaaaee1 | 43 | x0 = x; |
Nanaud | 10:0714feaaaee1 | 44 | y0 = y; |
Nanaud | 10:0714feaaaee1 | 45 | phi0 = phi; |
Nanaud | 6:ea6b30c4bb01 | 46 | |
plmir | 12:2c312916a621 | 47 | dDist = ((comptG / coeffGLong) + (comptD / coeffDLong)) / 2; |
plmir | 12:2c312916a621 | 48 | dAngl = ((comptD / coeffDAngl) - (comptG / coeffGAngl)) / entraxe; |
Nanaud | 10:0714feaaaee1 | 49 | |
plmir | 12:2c312916a621 | 50 | x = x0 + dDist * cos(phi0); |
plmir | 12:2c312916a621 | 51 | y = y0 + dDist * sin(phi0); |
Nanaud | 10:0714feaaaee1 | 52 | phi = phi0 + dAngl; |
plmir | 12:2c312916a621 | 53 | phi_deg = phi*180/Pi; |
plmir | 12:2c312916a621 | 54 | |
plmir | 12:2c312916a621 | 55 | |
plmir | 12:2c312916a621 | 56 | comptG = 0; |
plmir | 12:2c312916a621 | 57 | comptD = 0; |
Nanaud | 6:ea6b30c4bb01 | 58 | } |
Nanaud | 6:ea6b30c4bb01 | 59 | |
Nanaud | 10:0714feaaaee1 | 60 | |
Nanaud | 10:0714feaaaee1 | 61 | ///// CONSIGNE ANGLE |
Nanaud | 10:0714feaaaee1 | 62 | |
Nanaud | 10:0714feaaaee1 | 63 | void angle() |
Nanaud | 10:0714feaaaee1 | 64 | { |
Nanaud | 10:0714feaaaee1 | 65 | |
Nanaud | 10:0714feaaaee1 | 66 | } |