For test
Embed:
(wiki syntax)
Show/hide line numbers
calculate.cpp
00001 00002 #include "calculate.h" 00003 00004 00005 const float lm57_mv_table[71] = { 00006 1152, 1147, 1142, 1137, 1132, 1127, 1122, 1117, 1112, 1106, 00007 1101, 1096, 1091, 1086, 1081, 1076, 1071, 1066, 1061, 1055, 00008 1050, 1045, 1040, 1035, 1030, 1025, 1020, 1015, 1009, 1004, 00009 999, 994, 989, 984, 979, 973, 968, 963, 958, 953, 00010 948, 942, 937, 932, 927, 922, 917, 911, 906, 901, 00011 896, 891, 885, 880, 875, 870, 865, 859, 854, 849, 00012 844, 839, 833, 828, 823, 818, 812, 807, 802, 797, 791 00013 }; 00014 00015 /* linterp ----------------------------------------------------------- 00016 00017 Performs linear interpolation on a data array. The argument X array must be ascending. 00018 If supplied X value is outside the X data array, the function performs extrapolation 00019 by two last data points. 00020 00021 Input: val waiting to find 00022 size >= 2 size of X & Y data arrays 00023 _x[size] >>ascending<< X data array 00024 _y[size] Y data array 00025 00026 Return: Y value 00027 00028 */ 00029 float Calculate::linterp(const float* _x, const float* _y, float val, unsigned char size) 00030 { 00031 // take care the value is within range 00032 if (size < 2) return _y[0]; // on illegal call, return first element in Y array 00033 // val = constrain(val, _in[0], _in[size-1]); 00034 if (val <= _x[0]) return _y[0]; 00035 if (val >= _x[size-1]) return _y[size-1]; 00036 00037 // search right interval 00038 unsigned char pos = 1; // _x[0] allready tested 00039 while(val > _x[pos]) pos++; 00040 00041 // this will handle all exact "points" in the _in array 00042 if (val == _x[pos]) return _y[pos]; 00043 00044 // interpolate in the right segment for the rest 00045 return ((val - _x[pos-1]) * (_y[pos] - _y[pos-1]) / (_x[pos] - _x[pos-1]) + _y[pos-1]); 00046 } 00047 00048 //===================================================================================================================== 00049 // Calculate the value of IR target temperature. Temperature unit is 0.1*S 00050 // 00051 void Calculate::calcu_Tir_oS(float * targTempS, float PSdOut, float ambTempC, const struct CalibrationConstants CalConst, float emissivity) 00052 { 00053 const float Ofs = CalConst.Ofs; // PSdOfs for gain 1 00054 const float * const En = CalConst.En; // Table of energy of target, gain 1 00055 const float * const ToS = CalConst.ToS; //Table of temperature 00056 const float * const TempCo = CalConst.TempCo; // Det tempco (alpha) 00057 const float Td0 = CalConst.Td0; // Cal det temp 00058 00059 00060 float Td; // Temperature and energy of the detector itself 00061 float T; // Target temperature all gains 00062 00063 float TempCo_C; 00064 00065 Td = ambTempC; 00066 if(Td > Td0) 00067 TempCo_C = (1 + TempCo[0] * (Td - Td0)) * (1 + TempCo[1] * (Td - Td0)); 00068 else 00069 TempCo_C = (1 + TempCo[0] * (Td0 - Td)) * (1 + TempCo[1] * (Td - Td0)); 00070 00071 PSdOut = (PSdOut * TempCo_C - Ofs) / emissivity; 00072 00073 T = linterp(En,ToS,PSdOut,CALI_CONST_IR_TAB_NUM); // PSd1(T1) to T1, temperature of the target, gain 1, in 0.1*S 00074 00075 *targTempS = T / 10.0; // Return temperature 00076 } 00077 00078 float Calculate::get_Tamb_oC(float N_Tamb) 00079 { 00080 float lm57_oC[71]; 00081 float mV[71]; 00082 float T_mV = -N_Tamb * 1200 / 16777215; 00083 for (int i = 0; i < 71; i++) { 00084 lm57_oC[i] = -10 + i; 00085 mV[i] = -lm57_mv_table[i]; 00086 } 00087 return linterp(mV, lm57_oC, T_mV, 71); ; 00088 }
Generated on Thu Jul 14 2022 14:25:06 by
1.7.2