MAV'RIC
|
00001 /******************************************************************************* 00002 * Copyright (c) 2009-2016, MAV'RIC Development Team 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 00011 * 2. Redistributions in binary form must reproduce the above copyright notice, 00012 * this list of conditions and the following disclaimer in the documentation 00013 * and/or other materials provided with the distribution. 00014 * 00015 * 3. Neither the name of the copyright holder nor the names of its contributors 00016 * may be used to endorse or promote products derived from this software without 00017 * specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00023 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00024 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00025 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00026 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00027 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00028 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00029 * POSSIBILITY OF SUCH DAMAGE. 00030 ******************************************************************************/ 00031 00032 /******************************************************************************* 00033 * \file barometer_ms5611.hpp 00034 * 00035 * \author MAV'RIC Team 00036 * \author Julien Lecoeur 00037 * 00038 * \brief Driver for the MS5611 barometer 00039 * 00040 ******************************************************************************/ 00041 00042 00043 #ifndef MS5611_HPP_ 00044 #define MS5611_HPP_ 00045 00046 #include <cstdint> 00047 #include <cstdbool> 00048 00049 #include "drivers/barometer.hpp" 00050 #include "hal/common/i2c.hpp" 00051 00055 class Barometer_MS5611: public Barometer 00056 { 00057 public: 00061 enum class state_t 00062 { 00063 INIT, 00064 IDLE, 00065 GET_TEMPERATURE, 00066 GET_PRESSURE, 00067 }; 00068 00072 enum class address_t 00073 { 00074 ADDR_CSBLOW = 0x77, 00075 ADDR_CSBHIGH = 0x76, 00076 }; 00077 00081 enum class oversampling_ratio_t 00082 { 00083 OSR_256 = 0x00, 00084 OSR_512 = 0x01, 00085 OSR_1024 = 0x02, 00086 OSR_2048 = 0x03, 00087 OSR_4096 = 0x04, 00088 }; 00089 00090 struct calibration_data_t 00091 { 00092 uint16_t SENS_T1; 00093 uint16_t OFF_T1; 00094 uint16_t TCS; 00095 uint16_t TCO; 00096 uint16_t T_REF; 00097 uint16_t TEMPSENS; 00098 }; 00099 00100 static const uint8_t COMMAND_RESET = 0x1E; 00101 static const uint8_t COMMAND_GET_CALIBRATION = 0xA2; 00102 static const uint8_t COMMAND_START_PRESSURE_CONV = 0x40; 00103 static const uint8_t COMMAND_START_TEMPERATURE_CONV = 0x50; 00104 static const uint8_t COMMAND_GET_DATA = 0x00; 00105 00109 struct conf_t 00110 { 00111 address_t address; 00112 oversampling_ratio_t oversampling_ratio_pressure; 00113 oversampling_ratio_t oversampling_ratio_temperature; 00114 }; 00115 00121 static inline conf_t default_config(void); 00122 00128 Barometer_MS5611(I2c& i2c, conf_t config = default_config()); 00129 00130 00136 bool init(void); 00137 00138 00145 bool update(void); 00146 00147 00153 uint64_t last_update_us(void) const; 00154 00155 00161 float pressure(void) const; 00162 00163 00171 float altitude_gf(void) const; 00172 00173 00181 float altitude_gf_raw(void) const; 00182 00183 00191 float vertical_speed_lf(void) const; 00192 00193 00201 float vertical_speed_lf_raw(void) const; 00202 00203 00209 float temperature(void) const; 00210 00211 00212 private: 00213 I2c& i2c_; 00214 conf_t config_; 00215 state_t state_; 00216 00217 calibration_data_t calib_; 00218 uint8_t i2c_address; 00219 00220 uint32_t time_sampling_start_ms_; 00221 00222 float last_state_update_us_; 00223 float last_update_us_; 00224 float dt_s_; 00225 float pressure_; 00226 float temperature_; 00227 float altitude_gf_; 00228 float speed_lf_; 00229 00230 float last_altitudes_[3]; 00231 00237 bool start_temperature_sampling(void); 00238 00244 bool read_temperature(void); 00245 00251 bool start_pressure_sampling(void); 00252 00258 bool read_pressure(void); 00259 }; 00260 00261 00267 Barometer_MS5611::conf_t Barometer_MS5611::default_config(void) 00268 { 00269 Barometer_MS5611::conf_t config = {}; 00270 00271 config.address = address_t::ADDR_CSBLOW; 00272 // config.oversampling_ratio_pressure = oversampling_ratio_t::OSR_4096; 00273 // config.oversampling_ratio_temperature = oversampling_ratio_t::OSR_4096; 00274 00275 config.oversampling_ratio_pressure = oversampling_ratio_t::OSR_256; 00276 config.oversampling_ratio_temperature = oversampling_ratio_t::OSR_256; 00277 00278 return config; 00279 } 00280 00281 #endif /* BMP085_HPP_ */