20160815 計器最新版

Dependencies:   SDFileSystem mbed

Fork of keiki2016verRtos by albatross

Committer:
taurin
Date:
Fri May 20 12:26:32 2016 +0000
Revision:
7:9415448ae9ca
Parent:
0:085b2c5e3254
5/20 ????;

Who changed what in which revision?

UserRevisionLine numberNew 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 7:9415448ae9ca 6
taurin 0:085b2c5e3254 7 #define AIR_K 0.14737
taurin 7:9415448ae9ca 8 #define AIR_N 1.12
taurin 0:085b2c5e3254 9 #define AIR_A 1.4314
taurin 0:085b2c5e3254 10 #define AIR_B 0.209
taurin 0:085b2c5e3254 11 #define AIR_SUM_NUM 20
taurin 0:085b2c5e3254 12 #define AIR_BUFFER 30
taurin 0:085b2c5e3254 13
taurin 0:085b2c5e3254 14 float airSpeed = 0.0;
taurin 0:085b2c5e3254 15 float airSpeed_ave = 0.0;
taurin 0:085b2c5e3254 16 float airSpeed_max = 0.0;
taurin 0:085b2c5e3254 17 int air_counter = 0;
taurin 0:085b2c5e3254 18 float air_sum[AIR_SUM_NUM] = {0.0};
taurin 0:085b2c5e3254 19
taurin 0:085b2c5e3254 20 class Fusokukei{
taurin 0:085b2c5e3254 21 protected:
taurin 0:085b2c5e3254 22
taurin 0:085b2c5e3254 23 public:
taurin 0:085b2c5e3254 24 float make_ave(float s[], int n){
taurin 0:085b2c5e3254 25 float p = 0;
taurin 0:085b2c5e3254 26 int i;
taurin 0:085b2c5e3254 27 for(i = 0; i < n; i++){
taurin 0:085b2c5e3254 28 p += s[i];
taurin 0:085b2c5e3254 29 }
taurin 0:085b2c5e3254 30 if(n != 0)
taurin 0:085b2c5e3254 31 return p / n;
taurin 0:085b2c5e3254 32 else
taurin 0:085b2c5e3254 33 return 0;
taurin 0:085b2c5e3254 34 }
taurin 0:085b2c5e3254 35
taurin 0:085b2c5e3254 36 void calcAirSpeed(float x){
taurin 0:085b2c5e3254 37 air_sum[air_counter % AIR_SUM_NUM] = (float)AIR_K * (float)pow((double)x, 1 / AIR_N);
taurin 0:085b2c5e3254 38 if(air_counter % AIR_SUM_NUM == 0)
taurin 0:085b2c5e3254 39 air_counter = 0;
taurin 0:085b2c5e3254 40 airSpeed_ave = make_ave(air_sum, AIR_SUM_NUM);
taurin 7:9415448ae9ca 41 //airSpeed = airSpeed_ave*AIR_A+AIR_B;
taurin 7:9415448ae9ca 42 airSpeed=airSpeed_ave;
taurin 0:085b2c5e3254 43 if(airSpeed > airSpeed_max)
taurin 0:085b2c5e3254 44 airSpeed_max = airSpeed;
taurin 0:085b2c5e3254 45 air_counter++;
taurin 0:085b2c5e3254 46 }
taurin 0:085b2c5e3254 47 };
taurin 0:085b2c5e3254 48 #endif