most functionality to splashdwon, find neutral and start mission. short timeouts still in code for testing, will adjust to go directly to sit_idle after splashdown
Dependencies: mbed MODSERIAL FATFileSystem
Diff: omegaPX209/omegaPX209.cpp
- Revision:
- 14:85b64a4d08e8
- Parent:
- 10:085ab7328054
- Child:
- 17:7c16b5671d0e
--- a/omegaPX209/omegaPX209.cpp Mon Oct 30 21:09:19 2017 +0000 +++ b/omegaPX209/omegaPX209.cpp Tue Oct 31 17:06:52 2017 +0000 @@ -1,35 +1,64 @@ /* -Matthew Kelly -October 24th, 2013 -The purpose of this class is to define a a data structure with all of the necessary information and member functions... -to fully describe a single ultrasonic transducer for use in a relative positioning system. +This class wraps an Omega pressure transducer. +Author: Matthew, October 24th, 2013 +Modified: Dan, 2017-10-30 */ #include "mbed.h" #include "omegaPX209.hpp" omegaPX209::omegaPX209(PinName pin): - depthP(pin) + _adc(pin) { + _psi = 14.7; // pressure [psi] + _zeroPsi = 14.7; // atmospheric pressure at sea level [psi] + _adcVoltage = 3.3; // mbed ADC system voltage [V] + _fullscale = 50; // value of sensor at full scale (*confirm with Stearns*) [psi] + _cal = _fullscale/5.0; // psi per volt calibration [psi/V] } -void omegaPX209::initialize() { - P = 0; // Pressure [psi] - cal = 12; // Volts per psi - multiplier = 3.3; // Maximum voltage in +// nothing to initialize, but you can call this function if it makes you feel better. +void omegaPX209::init() { +} + +// lets user set a different ambient pressure [psi] +void omegaPX209::setZero(float zeroPsi) { + _zeroPsi = zeroPsi; +} + +// returns the internal ambient pressure [psi] +float omegaPX209::getZero() { + return _zeroPsi; } +// reads from ADC system and does math for converting to psi float omegaPX209::getPsi() { - P = depthP*multiplier*cal; - return P; + // filter by over-sampling + float add = 0; + for (int i = 0; i < OVERSAMPLE; i++) { + // analog input _adc is float 0.0 to 1.0 + // multiplying by _adcVoltage converts percentage to a voltage + // multiplying by _cal converts voltage to a pressure + add += _adc.read() * _adcVoltage * _cal; + } + + // use over-sampled + _psi = (add/OVERSAMPLE); + + return _psi; } -// math sourced from http://www.kylesconverter.com/pressure/feet-of-water-to-pounds-per-square-inch -float omegaPX209::getDepth() { - P = getPsi(); // read the sensor - float pascals = (P * 6894.76) - (14.7 * 6894.76); // convert psi to Pascals - float depth_m = pascals / (density_of_water_g_cc * 1000 * 9.80665); // convert Pa to fluid depth in meters - float depth_ft = 3.28084 * depth_m; // convert meters to feet - +// reads the ADC system and returns depth in feet +float omegaPX209::getDepthFt() { + float psi = getPsi() - _zeroPsi; // read the sensor and remove atmospheric bias + float Pa = psi2Pa * psi; // convert psi to Pascals + float depth_m = Pa / (water_density_kg_m3 * grav_m_s2); // convert Pa to fluid depth in meters + float depth_ft = m2ft * depth_m; // convert meters to feet + return depth_ft; +} + +// call this if you want to tare to zero +float omegaPX209::tare() { + setZero(getPsi()); } \ No newline at end of file