pitot tube strain gauge

Dependencies:   mbed ADS1015 SDFileSystem

Committer:
nakumur
Date:
Mon Mar 23 05:57:30 2020 +0000
Revision:
0:cf0be1174e43
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nakumur 0:cf0be1174e43 1 #include "mbed.h"
nakumur 0:cf0be1174e43 2 #include "Adafruit_ADS1015.h"
nakumur 0:cf0be1174e43 3 #include "SDFileSystem.h"
nakumur 0:cf0be1174e43 4 #define ADS1115_ADDR 0b1001000
nakumur 0:cf0be1174e43 5
nakumur 0:cf0be1174e43 6 Serial pc(USBTX, USBRX, 115200);
nakumur 0:cf0be1174e43 7 I2C i2c(p28, p27);
nakumur 0:cf0be1174e43 8 Adafruit_ADS1115 ads1115(&i2c, ADS1115_ADDR);
nakumur 0:cf0be1174e43 9 SDFileSystem sd_file_system(p5, p6, p7, p8, "sd");
nakumur 0:cf0be1174e43 10 Timer sd_timer;
nakumur 0:cf0be1174e43 11
nakumur 0:cf0be1174e43 12 FILE *sd;
nakumur 0:cf0be1174e43 13 char file_name[64];
nakumur 0:cf0be1174e43 14 char f_sd;
nakumur 0:cf0be1174e43 15 int16_t val[4] = {};
nakumur 0:cf0be1174e43 16 float voltage[4] = {};
nakumur 0:cf0be1174e43 17 float sum[4] = {};
nakumur 0:cf0be1174e43 18 float v_ave[4] = {};
nakumur 0:cf0be1174e43 19 float strain_v[4] = {};
nakumur 0:cf0be1174e43 20
nakumur 0:cf0be1174e43 21 int main()
nakumur 0:cf0be1174e43 22 {
nakumur 0:cf0be1174e43 23 ads1115.setGain(GAIN_TWOTHIRDS);
nakumur 0:cf0be1174e43 24
nakumur 0:cf0be1174e43 25 char file_name_format[] = "/sd/IZU2020_MISSION_%d.dat";
nakumur 0:cf0be1174e43 26 int file_number = 1;
nakumur 0:cf0be1174e43 27 while(1) {
nakumur 0:cf0be1174e43 28 sprintf(file_name, file_name_format, file_number);
nakumur 0:cf0be1174e43 29 sd = fopen(file_name, "r");
nakumur 0:cf0be1174e43 30 if(sd != NULL) {
nakumur 0:cf0be1174e43 31 fclose(sd);
nakumur 0:cf0be1174e43 32 file_number++;
nakumur 0:cf0be1174e43 33 } else {
nakumur 0:cf0be1174e43 34 sprintf(file_name, "/sd/IZU2020_MISSION_%d.dat", file_number);
nakumur 0:cf0be1174e43 35 break;
nakumur 0:cf0be1174e43 36 }
nakumur 0:cf0be1174e43 37 }
nakumur 0:cf0be1174e43 38 sd = fopen(file_name, "w");
nakumur 0:cf0be1174e43 39 sd_timer.start();
nakumur 0:cf0be1174e43 40 if(sd) {
nakumur 0:cf0be1174e43 41 fprintf(sd, "f_sd, ");
nakumur 0:cf0be1174e43 42 fprintf(sd, "speed[m/s],");
nakumur 0:cf0be1174e43 43 fprintf(sd, "sigma1,");
nakumur 0:cf0be1174e43 44 fprintf(sd, "sigma2,");
nakumur 0:cf0be1174e43 45 fprintf(sd, "taumax[MPa],");
nakumur 0:cf0be1174e43 46 fprintf(sd, "\r\n");
nakumur 0:cf0be1174e43 47 }
nakumur 0:cf0be1174e43 48
nakumur 0:cf0be1174e43 49 for(int i = 0; i < 10; i ++ ) {
nakumur 0:cf0be1174e43 50 val[0] = ads1115.readADC_SingleEnded(0);
nakumur 0:cf0be1174e43 51 val[1] = ads1115.readADC_SingleEnded(1);
nakumur 0:cf0be1174e43 52 val[2] = ads1115.readADC_SingleEnded(2);
nakumur 0:cf0be1174e43 53 val[3] = ads1115.readADC_SingleEnded(3);
nakumur 0:cf0be1174e43 54 voltage[0] = val[0] / 32768.0 * 6.144;
nakumur 0:cf0be1174e43 55 voltage[1] = val[1] / 32768.0 * 6.144;
nakumur 0:cf0be1174e43 56 voltage[2] = val[2] / 32768.0 * 6.144;
nakumur 0:cf0be1174e43 57 voltage[3] = val[3] / 32768.0 * 6.144;
nakumur 0:cf0be1174e43 58 sum[0] += voltage[0];
nakumur 0:cf0be1174e43 59 sum[1] += voltage[1];
nakumur 0:cf0be1174e43 60 sum[2] += voltage[2];
nakumur 0:cf0be1174e43 61 sum[3] += voltage[3];
nakumur 0:cf0be1174e43 62 }
nakumur 0:cf0be1174e43 63 v_ave[0] = sum[0] / 10.0;
nakumur 0:cf0be1174e43 64 v_ave[1] = sum[1] / 10.0;
nakumur 0:cf0be1174e43 65 v_ave[2] = sum[2] / 10.0;
nakumur 0:cf0be1174e43 66 v_ave[3] = sum[3] / 10.0;
nakumur 0:cf0be1174e43 67
nakumur 0:cf0be1174e43 68 while(1) {
nakumur 0:cf0be1174e43 69 val[0] = ads1115.readADC_SingleEnded(0);
nakumur 0:cf0be1174e43 70 val[1] = ads1115.readADC_SingleEnded(1);
nakumur 0:cf0be1174e43 71 val[2] = ads1115.readADC_SingleEnded(2);
nakumur 0:cf0be1174e43 72 val[3] = ads1115.readADC_SingleEnded(3);
nakumur 0:cf0be1174e43 73 voltage[0] = val[0] / 32768.0 * 6.144;
nakumur 0:cf0be1174e43 74 voltage[1] = val[1] / 32768.0 * 6.144;
nakumur 0:cf0be1174e43 75 voltage[2] = val[2] / 32768.0 * 6.144;
nakumur 0:cf0be1174e43 76 voltage[3] = val[3] / 32768.0 * 6.144;
nakumur 0:cf0be1174e43 77 pc.printf("%d, r%d, g%d, w%d\r\n", val[0], val[1], val[2], val[3]);
nakumur 0:cf0be1174e43 78 pc.printf("%f, r%f, g%f, w%f [V]\r\n", voltage[0], voltage[1], voltage[2], voltage[3]);
nakumur 0:cf0be1174e43 79
nakumur 0:cf0be1174e43 80 /*pitot_tube
nakumur 0:cf0be1174e43 81 -------------------------------------------------*/
nakumur 0:cf0be1174e43 82 float pitot_v = voltage[0] - v_ave[0] + 1;
nakumur 0:cf0be1174e43 83 //P = ((Vout / Vs) - 0.2) / 0.2
nakumur 0:cf0be1174e43 84 float pitot_Pa = (pitot_v / 5.0 - 0.2) / 0.2;
nakumur 0:cf0be1174e43 85 printf("pressure %f[kPa]\r\n", pitot_Pa);
nakumur 0:cf0be1174e43 86 float density = 1.3;
nakumur 0:cf0be1174e43 87 //v = root(2 * P / ρ)
nakumur 0:cf0be1174e43 88 float pitot_speed = sqrt(2 * pitot_Pa * 1000 / density);
nakumur 0:cf0be1174e43 89 printf("speed %f[m/s]\r\n", pitot_speed);
nakumur 0:cf0be1174e43 90 printf("speed %f[km/h]\r\n", pitot_speed * 3600 / 1000.0);
nakumur 0:cf0be1174e43 91
nakumur 0:cf0be1174e43 92 /*strain_gauge
nakumur 0:cf0be1174e43 93 ----------------------------------------------------*/
nakumur 0:cf0be1174e43 94 strain_v[1] = voltage[1] - v_ave[1];
nakumur 0:cf0be1174e43 95 strain_v[2] = voltage[2] - v_ave[2];
nakumur 0:cf0be1174e43 96 strain_v[3] = voltage[3] - v_ave[3];
nakumur 0:cf0be1174e43 97 //VOUT – VREF = G(VIN+ – VIN–)
nakumur 0:cf0be1174e43 98 //VREF = GND
nakumur 0:cf0be1174e43 99 //G = (49.4kΩ/RG) + 1
nakumur 0:cf0be1174e43 100 //straun = 2/3.3*V
nakumur 0:cf0be1174e43 101 float G = (49.4 * 1000 / 120.0) + 1;
nakumur 0:cf0be1174e43 102 float V1 = strain_v[1] / G;
nakumur 0:cf0be1174e43 103 float strain1 = 2 / 3.3 * V1 * 1000000.0;
nakumur 0:cf0be1174e43 104 float V2 = strain_v[2] / G;
nakumur 0:cf0be1174e43 105 float strain2 = 2 / 3.3 * V2 * 1000000.0;
nakumur 0:cf0be1174e43 106 float V3 = strain_v[3] / G;
nakumur 0:cf0be1174e43 107 float strain3 = 2 / 3.3 * V3 * 1000000.0;
nakumur 0:cf0be1174e43 108 printf("strain r %f g %f w %f [uε]\r\n", strain1, strain2, strain3);
nakumur 0:cf0be1174e43 109
nakumur 0:cf0be1174e43 110 float E = 2.5;//Al 72GPa
nakumur 0:cf0be1174e43 111 float nu = 0.3;//ポアソン比
nakumur 0:cf0be1174e43 112 float g = E / 2 / (1 + nu); //横弾性係数
nakumur 0:cf0be1174e43 113 float sigmax = E / (1 - nu * nu) * (strain1 + nu * strain3) / 1000.0;
nakumur 0:cf0be1174e43 114 float sigmay = E / (1 - nu * nu) * (nu * strain1 + strain3) / 1000.0;
nakumur 0:cf0be1174e43 115 float gammaxy = 2 * strain2 - strain1 - strain3;
nakumur 0:cf0be1174e43 116 float tauxy = g * gammaxy / 1000.0;
nakumur 0:cf0be1174e43 117 float sigma1 = (sigmax + sigmay) + sqrt((sigmax - sigmay) * (sigmax - sigmay) + 4 * tauxy * tauxy);
nakumur 0:cf0be1174e43 118 float sigma2 = (sigmax + sigmay) - sqrt((sigmax - sigmay) * (sigmax - sigmay) + 4 * tauxy * tauxy);
nakumur 0:cf0be1174e43 119 float taumax = (sigma1 - sigma2) / 2.0;
nakumur 0:cf0be1174e43 120 printf("sigmax %f sigmay %f tauxy %f [MPa]\r\n", sigmax, sigmay, tauxy);
nakumur 0:cf0be1174e43 121 printf("sigma1 %f sigma2 %f taumax %f [MPa]\r\n", sigma1, sigma2, taumax);
nakumur 0:cf0be1174e43 122
nakumur 0:cf0be1174e43 123 /*sd
nakumur 0:cf0be1174e43 124 --------------------------------------------------------*/
nakumur 0:cf0be1174e43 125 f_sd = bool(sd);
nakumur 0:cf0be1174e43 126 if(sd) {
nakumur 0:cf0be1174e43 127 fprintf(sd, "%d,", f_sd);
nakumur 0:cf0be1174e43 128 fprintf(sd, "%f,", pitot_speed);
nakumur 0:cf0be1174e43 129 fprintf(sd, "%f,", sigma1);
nakumur 0:cf0be1174e43 130 fprintf(sd, "%f,", sigma2);
nakumur 0:cf0be1174e43 131 fprintf(sd, "%f,", taumax);
nakumur 0:cf0be1174e43 132 fprintf(sd, "\r\n");
nakumur 0:cf0be1174e43 133 }
nakumur 0:cf0be1174e43 134 if(sd_timer.read_ms() >= 60*1000) {
nakumur 0:cf0be1174e43 135 sd_timer.reset();
nakumur 0:cf0be1174e43 136 sd_timer.start();
nakumur 0:cf0be1174e43 137 if(sd) {
nakumur 0:cf0be1174e43 138 fclose(sd);
nakumur 0:cf0be1174e43 139 sd = fopen(file_name, "a");
nakumur 0:cf0be1174e43 140 }
nakumur 0:cf0be1174e43 141 }
nakumur 0:cf0be1174e43 142
nakumur 0:cf0be1174e43 143 /*test
nakumur 0:cf0be1174e43 144 ----------------------------------------------------*/
nakumur 0:cf0be1174e43 145 float P = 5.0 * 9.8;
nakumur 0:cf0be1174e43 146 float A = 14.5 * 3.0;
nakumur 0:cf0be1174e43 147 float sigma = P / A;
nakumur 0:cf0be1174e43 148 pc.printf("test %f\r\n", sigma);
nakumur 0:cf0be1174e43 149
nakumur 0:cf0be1174e43 150 wait(0.5);
nakumur 0:cf0be1174e43 151 }
nakumur 0:cf0be1174e43 152 }