albatross / Mbed 2 deprecated keiki2018

Dependencies:   BufferedSoftSerial2 INA226_ver1 mbed-rtos mbed SDFileSystem-RTOS

Fork of keiki2017 by albatross

Committer:
tsumagari
Date:
Sat Jan 28 10:17:50 2017 +0000
Branch:
noThread2017ver.
Revision:
27:d2955f29a3aa
Parent:
15:6966299bea4c
Child:
51:f391d3a02397
Thread??ver.????????????????????????

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
tsumagari 27:d2955f29a3aa 7 #define AIR_K 4.70591884 //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){
tsumagari 27:d2955f29a3aa 37 air_sum[air_counter % AIR_SUM_NUM] = (float)AIR_K * (float)pow((double)(x/150.0), 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