5/13 計器プログラム
Dependencies: SDFileSystem mbed
Fork of keiki2016ver3 by
Fusokukei.h@0:085b2c5e3254, 2016-02-23 (annotated)
- Committer:
- taurin
- Date:
- Tue Feb 23 13:05:06 2016 +0000
- Revision:
- 0:085b2c5e3254
2/23 ??;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
taurin | 0:085b2c5e3254 | 1 | #ifndef FUSOKUKEI_H |
taurin | 0:085b2c5e3254 | 2 | #define FUSOKUKEI_H |
taurin | 0:085b2c5e3254 | 3 | |
taurin | 0:085b2c5e3254 | 4 | #include "mbed.h" |
taurin | 0:085b2c5e3254 | 5 | |
taurin | 0:085b2c5e3254 | 6 | #define AIR_K 0.14737 |
taurin | 0:085b2c5e3254 | 7 | #define AIR_N 1.19 |
taurin | 0:085b2c5e3254 | 8 | #define AIR_A 1.4314 |
taurin | 0:085b2c5e3254 | 9 | #define AIR_B 0.209 |
taurin | 0:085b2c5e3254 | 10 | #define AIR_SUM_NUM 20 |
taurin | 0:085b2c5e3254 | 11 | #define AIR_BUFFER 30 |
taurin | 0:085b2c5e3254 | 12 | |
taurin | 0:085b2c5e3254 | 13 | float airSpeed = 0.0; |
taurin | 0:085b2c5e3254 | 14 | float airSpeed_ave = 0.0; |
taurin | 0:085b2c5e3254 | 15 | float airSpeed_max = 0.0; |
taurin | 0:085b2c5e3254 | 16 | int air_counter = 0; |
taurin | 0:085b2c5e3254 | 17 | float air_sum[AIR_SUM_NUM] = {0.0}; |
taurin | 0:085b2c5e3254 | 18 | |
taurin | 0:085b2c5e3254 | 19 | class Fusokukei{ |
taurin | 0:085b2c5e3254 | 20 | protected: |
taurin | 0:085b2c5e3254 | 21 | |
taurin | 0:085b2c5e3254 | 22 | public: |
taurin | 0:085b2c5e3254 | 23 | float make_ave(float s[], int n){ |
taurin | 0:085b2c5e3254 | 24 | float p = 0; |
taurin | 0:085b2c5e3254 | 25 | int i; |
taurin | 0:085b2c5e3254 | 26 | for(i = 0; i < n; i++){ |
taurin | 0:085b2c5e3254 | 27 | p += s[i]; |
taurin | 0:085b2c5e3254 | 28 | } |
taurin | 0:085b2c5e3254 | 29 | if(n != 0) |
taurin | 0:085b2c5e3254 | 30 | return p / n; |
taurin | 0:085b2c5e3254 | 31 | else |
taurin | 0:085b2c5e3254 | 32 | return 0; |
taurin | 0:085b2c5e3254 | 33 | } |
taurin | 0:085b2c5e3254 | 34 | |
taurin | 0:085b2c5e3254 | 35 | void calcAirSpeed(float x){ |
taurin | 0:085b2c5e3254 | 36 | air_sum[air_counter % AIR_SUM_NUM] = (float)AIR_K * (float)pow((double)x, 1 / AIR_N); |
taurin | 0:085b2c5e3254 | 37 | if(air_counter % AIR_SUM_NUM == 0) |
taurin | 0:085b2c5e3254 | 38 | air_counter = 0; |
taurin | 0:085b2c5e3254 | 39 | airSpeed_ave = make_ave(air_sum, AIR_SUM_NUM); |
taurin | 0:085b2c5e3254 | 40 | airSpeed = airSpeed_ave*AIR_A+AIR_B; |
taurin | 0:085b2c5e3254 | 41 | if(airSpeed > airSpeed_max) |
taurin | 0:085b2c5e3254 | 42 | airSpeed_max = airSpeed; |
taurin | 0:085b2c5e3254 | 43 | air_counter++; |
taurin | 0:085b2c5e3254 | 44 | } |
taurin | 0:085b2c5e3254 | 45 | }; |
taurin | 0:085b2c5e3254 | 46 | #endif |