cette fois faites import plutot que modifier direct bande de gredins
Dependencies: GYRO_DISCO_L476VG mbed BSP_DISCO_L476VG COMPASS_DISCO_L476VG
main.cpp@8:97589b322a4f, 2020-06-12 (annotated)
- Committer:
- Leonnn
- Date:
- Fri Jun 12 13:48:55 2020 +0000
- Revision:
- 8:97589b322a4f
- Parent:
- 7:4d02d2486949
- Child:
- 9:187f56fa6db5
LA FUSION :O
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" |
Leonnn | 8:97589b322a4f | 3 | #include "COMPASS_DISCO_L476VG.h" |
Leonnn | 8:97589b322a4f | 4 | #define PI 3.14159265358979323846 |
bcostm | 0:5432bdf904f9 | 5 | |
Leonnn | 8:97589b322a4f | 6 | COMPASS_DISCO_L476VG compass; |
bcostm | 0:5432bdf904f9 | 7 | GYRO_DISCO_L476VG gyro; |
Leonnn | 8:97589b322a4f | 8 | |
Leonnn | 5:a50ff92004e0 | 9 | Serial pc(SERIAL_TX, SERIAL_RX); |
Leonnn | 7:4d02d2486949 | 10 | Ticker tick_mesure; |
Leonnn | 7:4d02d2486949 | 11 | |
Leonnn | 7:4d02d2486949 | 12 | volatile bool flag_mesure = 0; |
Leonnn | 7:4d02d2486949 | 13 | |
Leonnn | 8:97589b322a4f | 14 | void mesure(void){flag_mesure = 1;}// ISR mesure |
bcostm | 0:5432bdf904f9 | 15 | |
bcostm | 0:5432bdf904f9 | 16 | int main() |
bcostm | 0:5432bdf904f9 | 17 | { |
Leonnn | 7:4d02d2486949 | 18 | float GyroBuffer[3], offset, GyrY; |
Leonnn | 7:4d02d2486949 | 19 | offset = 0; |
Leonnn | 7:4d02d2486949 | 20 | wait(0.5); |
Leonnn | 8:97589b322a4f | 21 | for(int i=0; i<100; i++){// séquence de mise à 0 |
Leonnn | 7:4d02d2486949 | 22 | gyro.GetXYZ(GyroBuffer); |
Leonnn | 7:4d02d2486949 | 23 | offset = offset + GyroBuffer[1]; |
Leonnn | 7:4d02d2486949 | 24 | wait(0.01); |
Leonnn | 7:4d02d2486949 | 25 | } |
Leonnn | 8:97589b322a4f | 26 | offset = offset/100;//-----------------fin mise à 0 |
Leonnn | 7:4d02d2486949 | 27 | |
Leonnn | 7:4d02d2486949 | 28 | tick_mesure.attach(&mesure, 0.01); |
Leonnn | 5:a50ff92004e0 | 29 | pc.baud(115200); |
Leonnn | 8:97589b322a4f | 30 | |
Leonnn | 8:97589b322a4f | 31 | unsigned int count = 0; |
Leonnn | 8:97589b322a4f | 32 | float Gyr_angle = 0; |
Leonnn | 8:97589b322a4f | 33 | float Acc_angle; |
Leonnn | 8:97589b322a4f | 34 | int16_t AccBuffer[3]; |
bcostm | 0:5432bdf904f9 | 35 | |
Leonnn | 7:4d02d2486949 | 36 | while(1) { |
Leonnn | 8:97589b322a4f | 37 | if(flag_mesure){// mesure Gyro |
Leonnn | 7:4d02d2486949 | 38 | gyro.GetXYZ(GyroBuffer); |
Leonnn | 7:4d02d2486949 | 39 | GyrY = GyroBuffer[1]-offset; |
Leonnn | 8:97589b322a4f | 40 | Gyr_angle = Gyr_angle + GyrY/100; |
Leonnn | 8:97589b322a4f | 41 | Acc_angle = atan2((float)AccBuffer[0], (float)AccBuffer[2])*180.0/PI; |
Leonnn | 7:4d02d2486949 | 42 | |
Leonnn | 7:4d02d2486949 | 43 | if(count > 9){ |
Leonnn | 8:97589b322a4f | 44 | compass.AccGetXYZ(AccBuffer); |
Leonnn | 8:97589b322a4f | 45 | pc.printf("$%f %f;", Acc_angle, Gyr_angle/1000); |
Leonnn | 7:4d02d2486949 | 46 | count = 0; |
Leonnn | 7:4d02d2486949 | 47 | } |
Leonnn | 7:4d02d2486949 | 48 | else |
Leonnn | 7:4d02d2486949 | 49 | count++; |
Leonnn | 7:4d02d2486949 | 50 | flag_mesure = 0; |
Leonnn | 7:4d02d2486949 | 51 | } |
Leonnn | 7:4d02d2486949 | 52 | //wait(0.1); |
bcostm | 0:5432bdf904f9 | 53 | } |
bcostm | 0:5432bdf904f9 | 54 | } |