Flying Sea Glider / Mbed 2 deprecated 2019_10may_firstflight_jcw_nosd

Dependencies:   mbed MODSERIAL FATFileSystem

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers omegaPX209.cpp Source File

omegaPX209.cpp

00001 /*
00002 This class wraps an Omega pressure transducer.
00003 Author: Matthew, October 24th, 2013
00004 Modified: Dan, 2017-10-30
00005 
00006 WIP: Troy
00007 - added the ability to read the counts from this class directly
00008 - had to fix the class to have the header guard in the header file (#ifndef, #define, #endif)
00009 */
00010 
00011 #include "mbed.h"
00012 #include "omegaPX209.hpp"
00013 #include "StaticDefs.hpp"       //pins and other hardware (new)
00014 
00015 omegaPX209::omegaPX209(PinName pin): 
00016     _adc(pin)   //leaving function as is for now
00017 {
00018     _psi = 14.7;                    // pressure [psi]
00019     _zeroPsi = 14.7;                // atmospheric pressure at sea level [psi]
00020     _adcVoltage = 5.24;              // Troy: I'm not sure this is the right name for this multiplier... [V] (was 3.3 before)
00021     _fullscale = 50;                // value of sensor at full scale (*confirm with Stearns*) [psi]
00022     _psi_per_volt_cal = _fullscale/5.0;          // psi per volt calibration [psi/V]
00023     _PSI_reading = 0;
00024 }
00025 
00026 // nothing to initialize, but you can call this function if it makes you feel better.
00027 void omegaPX209::init() {
00028 }
00029 
00030 // lets user set a different ambient pressure [psi]
00031 void omegaPX209::setZero(float zeroPsi) {
00032     _zeroPsi = zeroPsi;    
00033 }
00034 
00035 // returns the internal ambient pressure [psi]
00036 float omegaPX209::getZero() {
00037     return _zeroPsi;
00038 }
00039 
00040 // reads from ADC system and does math for converting to psi
00041 float omegaPX209::getPsi() {
00042     // filter by over-sampling
00043     float add = 0;
00044     float adc_reading = 0;
00045     
00046     _PSI_reading = 0;   //reset each time
00047     
00048     for (int i = 0; i < OVERSAMPLE; i++) {
00049         // analog input _adc is float 0.0 to 1.0
00050         // multiplying by _adcVoltage converts percentage to a voltage
00051         // multiplying by _cal converts voltage to a pressure
00052         adc_reading = adc().readCh4()/4095.0;
00053         
00054         _PSI_reading = adc_reading * _adcVoltage * _psi_per_volt_cal;    //Note: real_voltage_reading = adc_reading * _adcVoltage
00055         
00056         add += _PSI_reading;    //replaced _adc.read()
00057     }
00058     
00059     // use over-sampled
00060     _psi = (add/OVERSAMPLE);
00061 
00062     return _psi;
00063 }
00064 
00065 // reads the ADC system and returns depth in feet
00066 float omegaPX209::getDepthFt() {
00067     float psi = getPsi() - _zeroPsi; // read the sensor and remove atmospheric bias
00068     float Pa = psi2Pa * psi; // convert psi to Pascals
00069     float depth_m = Pa / (water_density_kg_m3 * grav_m_s2); // convert Pa to fluid depth in meters
00070     float depth_ft = m2ft * depth_m; // convert meters to feet
00071 
00072     return depth_ft;
00073 }
00074 float omegaPX209::getDepthM() {
00075     float psi = getPsi() - _zeroPsi; // read the sensor and remove atmospheric bias
00076     float Pa = psi2Pa * psi; // convert psi to Pascals
00077     float depth_m = Pa / (water_density_kg_m3 * grav_m_s2); // convert Pa to fluid depth in meters
00078     // float depth_ft = m2ft * depth_m; // convert meters to feet
00079 
00080     return depth_m;
00081 }
00082 
00083 // call this if you want to tare to zero
00084 void omegaPX209::tare() {
00085     setZero(getPsi());
00086 }
00087 
00088 // 06/06/2018
00089 
00090 int omegaPX209::readADCCounts() {
00091     //return _adc.read();
00092     return adc().readCh4();
00093 }
00094 
00095 float omegaPX209::readVoltage() {
00096     float pressure_voltage = adc().readCh4()/4095.0 * _adcVoltage;
00097     return pressure_voltage;
00098 }
00099 
00100 float omegaPX209::getRawPSI() {
00101     return _PSI_reading;
00102 }