Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
OxygenSensor.cpp
00001 #include "OxygenSensor.h" 00002 #include <cmath> 00003 00004 static const float DEG2RAD = 3.141592654 / 180.; 00005 00006 /** 00007 * constructs an OxygenSensor object. 00008 */ 00009 OxygenSensor::OxygenSensor(const float temp0, 00010 const float temp100, 00011 const float phase0, 00012 const float phase100, 00013 const float pressure, 00014 const float salinity) 00015 : m_temp0(temp0), m_temp100(temp100), m_phase0(phase0), 00016 m_phase100(phase100), m_pressure(pressure), m_salinity(salinity) { 00017 } 00018 00019 /** 00020 * calculates the percent of oxygen air saturation. 00021 * 00022 * @param temp temperature, in degrees Celsius. 00023 * @param phase measured phase angle. 00024 * @return percentage of air saturated with oxygen. 00025 */ 00026 float 00027 OxygenSensor::calculate(const float temp, const float phase) const { 00028 const float f1 = 0.808; 00029 const float delphik = -0.0803; 00030 const float delksvk = 0.000433; 00031 const float m = 29.87; 00032 00033 const float tanphi0_100 = std::tan((m_phase0 + delphik*(m_temp100 - m_temp0)) 00034 * DEG2RAD); 00035 const float tanphi0_m = std::tan((m_phase0 + delphik*( temp - m_temp0)) 00036 * DEG2RAD); 00037 const float tanphi100_100 = std::tan(m_phase100 * DEG2RAD); 00038 const float tanphim_m = std::tan( phase * DEG2RAD); 00039 00040 const float A = tanphi100_100 / tanphi0_100 / m * 100*100; 00041 const float B = (tanphi100_100 / tanphi0_100 00042 + tanphi100_100 / tanphi0_100 / m 00043 - f1 / m - 1 + f1) * 100; 00044 const float C = tanphi100_100 / tanphi0_100 - 1; 00045 00046 const float ksv100 = (-B + std::sqrt(B*B - 4*A*C)) / (2 * A); 00047 const float ksvm = ksv100 + delksvk*(temp - m_temp100); 00048 00049 const float a = tanphim_m / tanphi0_m / m * ksvm * ksvm; 00050 const float b = (tanphim_m / tanphi0_m 00051 + tanphim_m / tanphi0_m / m 00052 - f1 / m - 1 + f1) * ksvm; 00053 const float c = tanphim_m / tanphi0_m - 1; 00054 00055 // const float chlorinity = (m_salinity - 0.03) / 1.805; 00056 00057 const float airsat = (-b + std::sqrt(b*b - 4*a*c)) / (2 * a); 00058 00059 return airsat; 00060 }
Generated on Tue Sep 27 2022 18:47:00 by
1.7.2