PX4 Firmware
PX4 Autopilot Software http://px4.io
MS5525.hpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2017 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 #ifndef DRIVERS_MS5525_AIRSPEED_HPP_
35 #define DRIVERS_MS5525_AIRSPEED_HPP_
36 
38 #include <math.h>
40 #include <px4_platform_common/getopt.h>
41 
42 /* The MS5525DSO address is 111011Cx, where C is the complementary value of the pin CSB */
43 static constexpr uint8_t I2C_ADDRESS_1_MS5525DSO = 0x76;
44 
45 static constexpr const char PATH_MS5525[] = "/dev/ms5525";
46 
47 /* Measurement rate is 100Hz */
48 static constexpr unsigned MEAS_RATE = 100;
49 static constexpr float MEAS_DRIVER_FILTER_FREQ = 1.2f;
50 static constexpr int64_t CONVERSION_INTERVAL = (1000000 / MEAS_RATE); /* microseconds */
51 
52 class MS5525 : public Airspeed
53 {
54 public:
55  MS5525(uint8_t bus, uint8_t address = I2C_ADDRESS_1_MS5525DSO, const char *path = PATH_MS5525) :
56  Airspeed(bus, address, CONVERSION_INTERVAL, path)
57  {
58  }
59 
60  ~MS5525() override = default;
61 
62 private:
63 
64  /**
65  * Perform a poll cycle; collect from the previous measurement
66  * and start a new one.
67  */
68  void Run() override;
69 
70  int measure() override;
71  int collect() override;
72 
73  // temperature is read once every 10 cycles
75 
76  static constexpr uint8_t CMD_RESET = 0x1E; // ADC reset command
77  static constexpr uint8_t CMD_ADC_READ = 0x00; // ADC read command
78 
79  static constexpr uint8_t CMD_PROM_START = 0xA0; // Prom read command (first)
80 
81  // D1 - pressure convert commands
82  // Convert D1 (OSR=256) 0x40
83  // Convert D1 (OSR=512) 0x42
84  // Convert D1 (OSR=1024) 0x44
85  // Convert D1 (OSR=2048) 0x46
86  // Convert D1 (OSR=4096) 0x48
87  static constexpr uint8_t CMD_CONVERT_PRES = 0x44;
88 
89  // D2 - temperature convert commands
90  // Convert D2 (OSR=256) 0x50
91  // Convert D2 (OSR=512) 0x52
92  // Convert D2 (OSR=1024) 0x54
93  // Convert D2 (OSR=2048) 0x56
94  // Convert D2 (OSR=4096) 0x58
95  static constexpr uint8_t CMD_CONVERT_TEMP = 0x54;
96 
97  uint8_t _current_cmd{CMD_CONVERT_PRES};
98 
99  unsigned _pressure_count{0};
100 
101  // Qx Coefficients Matrix by Pressure Range
102  // 5525DSO-pp001DS (Pmin = -1, Pmax = 1)
103  static constexpr uint8_t Q1 = 15;
104  static constexpr uint8_t Q2 = 17;
105  static constexpr uint8_t Q3 = 7;
106  static constexpr uint8_t Q4 = 5;
107  static constexpr uint8_t Q5 = 7;
108  static constexpr uint8_t Q6 = 21;
109 
110  // calibration coefficients from prom
111  uint16_t C1{0};
112  uint16_t C2{0};
113  uint16_t C3{0};
114  uint16_t C4{0};
115  uint16_t C5{0};
116  uint16_t C6{0};
117 
118  int64_t Tref{0};
119 
120  // last readings for D1 (uncompensated pressure) and D2 (uncompensated temperature)
121  uint32_t D1{0};
122  uint32_t D2{0};
123 
124  bool init_ms5525();
125  bool _inited{false};
126 
127  uint8_t prom_crc4(uint16_t n_prom[]) const;
128 
129 };
130 
131 #endif /* DRIVERS_MS5525_AIRSPEED_HPP_ */
uint16_t C5
Definition: MS5525.hpp:115
uint32_t D2
Definition: MS5525.hpp:122
uint16_t C6
Definition: MS5525.hpp:116
static constexpr unsigned MEAS_RATE
Definition: MS5525.hpp:48
static constexpr uint8_t Q3
Definition: MS5525.hpp:105
uint16_t C4
Definition: MS5525.hpp:114
static constexpr float MEAS_DRIVER_FILTER_FREQ
Definition: MS5525.hpp:49
~MS5525() override=default
static constexpr uint8_t CMD_ADC_READ
Definition: MS5525.hpp:77
int collect() override
Definition: MS5525.cpp:170
math::LowPassFilter2p _filter
Definition: MS5525.hpp:74
MS5525(uint8_t bus, uint8_t address=I2C_ADDRESS_1_MS5525DSO, const char *path=PATH_MS5525)
Definition: MS5525.hpp:55
static constexpr uint8_t Q5
Definition: MS5525.hpp:107
bool _inited
Definition: MS5525.hpp:125
static constexpr uint8_t CMD_CONVERT_TEMP
Definition: MS5525.hpp:95
static constexpr uint8_t CMD_PROM_START
Definition: MS5525.hpp:79
static constexpr uint8_t Q2
Definition: MS5525.hpp:104
int measure() override
Definition: MS5525.cpp:37
void Run() override
Perform a poll cycle; collect from the previous measurement and start a new one.
Definition: MS5525.cpp:275
uint8_t prom_crc4(uint16_t n_prom[]) const
Definition: MS5525.cpp:132
static constexpr int64_t CONVERSION_INTERVAL
Definition: MS5525.hpp:50
static constexpr uint8_t CMD_RESET
Definition: MS5525.hpp:76
uint8_t _current_cmd
Definition: MS5525.hpp:97
unsigned _pressure_count
Definition: MS5525.hpp:99
bool init_ms5525()
Definition: MS5525.cpp:62
static constexpr uint8_t I2C_ADDRESS_1_MS5525DSO
Definition: MS5525.hpp:43
static constexpr uint8_t CMD_CONVERT_PRES
Definition: MS5525.hpp:87
static constexpr uint8_t Q6
Definition: MS5525.hpp:108
static constexpr uint8_t Q1
Definition: MS5525.hpp:103
int64_t Tref
Definition: MS5525.hpp:118
uint16_t C2
Definition: MS5525.hpp:112
static constexpr const char PATH_MS5525[]
Definition: MS5525.hpp:45
uint16_t C1
Definition: MS5525.hpp:111
static constexpr uint8_t Q4
Definition: MS5525.hpp:106
uint32_t D1
Definition: MS5525.hpp:121
uint16_t C3
Definition: MS5525.hpp:113