cette fois faites import plutot que modifier direct bande de gredins
Dependencies: GYRO_DISCO_L476VG mbed BSP_DISCO_L476VG COMPASS_DISCO_L476VG
main.cpp@7:4d02d2486949, 2020-06-12 (annotated)
- Committer:
- Leonnn
- Date:
- Fri Jun 12 12:49:53 2020 +0000
- Revision:
- 7:4d02d2486949
- Parent:
- 6:df81f0a821d8
- Child:
- 8:97589b322a4f
Gyr angle avec offset auto
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:5432bdf904f9 | 1 | #include "mbed.h" |
bcostm | 0:5432bdf904f9 | 2 | #include "GYRO_DISCO_L476VG.h" |
bcostm | 0:5432bdf904f9 | 3 | |
bcostm | 0:5432bdf904f9 | 4 | GYRO_DISCO_L476VG gyro; |
Leonnn | 5:a50ff92004e0 | 5 | Serial pc(SERIAL_TX, SERIAL_RX); |
Leonnn | 7:4d02d2486949 | 6 | Ticker tick_mesure; |
Leonnn | 7:4d02d2486949 | 7 | |
Leonnn | 7:4d02d2486949 | 8 | volatile bool flag_mesure = 0; |
Leonnn | 7:4d02d2486949 | 9 | |
Leonnn | 7:4d02d2486949 | 10 | void mesure(void){flag_mesure = 1;} |
bcostm | 0:5432bdf904f9 | 11 | |
bcostm | 0:5432bdf904f9 | 12 | int main() |
bcostm | 0:5432bdf904f9 | 13 | { |
Leonnn | 7:4d02d2486949 | 14 | float GyroBuffer[3], offset, GyrY; |
Leonnn | 7:4d02d2486949 | 15 | offset = 0; |
Leonnn | 7:4d02d2486949 | 16 | wait(0.5); |
Leonnn | 7:4d02d2486949 | 17 | for(int i=0; i<100; i++){ |
Leonnn | 7:4d02d2486949 | 18 | gyro.GetXYZ(GyroBuffer); |
Leonnn | 7:4d02d2486949 | 19 | offset = offset + GyroBuffer[1]; |
Leonnn | 7:4d02d2486949 | 20 | wait(0.01); |
Leonnn | 7:4d02d2486949 | 21 | } |
Leonnn | 7:4d02d2486949 | 22 | offset = offset/100; |
Leonnn | 7:4d02d2486949 | 23 | |
Leonnn | 7:4d02d2486949 | 24 | tick_mesure.attach(&mesure, 0.01); |
Leonnn | 5:a50ff92004e0 | 25 | pc.baud(115200); |
Leonnn | 7:4d02d2486949 | 26 | float angle = 0; |
Leonnn | 7:4d02d2486949 | 27 | unsigned int count = 0; |
bcostm | 0:5432bdf904f9 | 28 | |
Leonnn | 7:4d02d2486949 | 29 | while(1) { |
Leonnn | 7:4d02d2486949 | 30 | if(flag_mesure){ |
Leonnn | 7:4d02d2486949 | 31 | gyro.GetXYZ(GyroBuffer); |
Leonnn | 7:4d02d2486949 | 32 | GyrY = GyroBuffer[1]-offset; |
Leonnn | 7:4d02d2486949 | 33 | angle = angle + GyrY/100; |
Leonnn | 7:4d02d2486949 | 34 | |
Leonnn | 7:4d02d2486949 | 35 | if(count > 9){ |
Leonnn | 7:4d02d2486949 | 36 | pc.printf("$%f %f;", offset/1000, angle/1000); |
Leonnn | 7:4d02d2486949 | 37 | count = 0; |
Leonnn | 7:4d02d2486949 | 38 | } |
Leonnn | 7:4d02d2486949 | 39 | else |
Leonnn | 7:4d02d2486949 | 40 | count++; |
Leonnn | 7:4d02d2486949 | 41 | flag_mesure = 0; |
Leonnn | 7:4d02d2486949 | 42 | } |
Leonnn | 7:4d02d2486949 | 43 | //wait(0.1); |
bcostm | 0:5432bdf904f9 | 44 | } |
bcostm | 0:5432bdf904f9 | 45 | } |