PX4 Firmware
PX4 Autopilot Software http://px4.io
SDP3X.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 /**
35  * @file SDP3X.hpp
36  *
37  * Driver for Sensirion SDP3X Differential Pressure Sensor
38  *
39  * Datasheet: https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/8_Differential_Pressure/Sensirion_Differential_Pressure_Sensors_SDP3x_Digital_Datasheet_V0.8.pdf
40  */
41 
42 #ifndef DRIVERS_SDP3X_AIRSPEED_HPP_
43 #define DRIVERS_SDP3X_AIRSPEED_HPP_
44 
46 #include <math.h>
48 #include <px4_platform_common/getopt.h>
49 
50 #define I2C_ADDRESS_1_SDP3X 0x21
51 #define I2C_ADDRESS_2_SDP3X 0x22
52 #define I2C_ADDRESS_3_SDP3X 0x23
53 
54 #define SDP3X_SCALE_TEMPERATURE 200.0f
55 #define SDP3X_RESET_ADDR 0x00
56 #define SDP3X_RESET_CMD 0x06
57 #define SDP3X_CONT_MEAS_AVG_MODE 0x3615
58 
59 #define SDP3X_SCALE_PRESSURE_SDP31 60
60 #define SDP3X_SCALE_PRESSURE_SDP32 240
61 #define SDP3X_SCALE_PRESSURE_SDP33 20
62 
63 #define PATH_SDP3X "/dev/sdp3x"
64 
65 // Measurement rate is 20Hz
66 #define SPD3X_MEAS_RATE 100
67 #define SDP3X_MEAS_DRIVER_FILTER_FREQ 3.0f
68 #define CONVERSION_INTERVAL (1000000 / SPD3X_MEAS_RATE) /* microseconds */
69 
70 class SDP3X : public Airspeed
71 {
72 public:
73  SDP3X(int bus, int address = I2C_ADDRESS_1_SDP3X, const char *path = PATH_SDP3X) :
74  Airspeed(bus, address, CONVERSION_INTERVAL, path)
75  {
76  }
77 
78 private:
79 
80  /**
81  * Perform a poll cycle; collect from the previous measurement
82  * and start a new one.
83  */
84  void Run() override;
85  int measure() override { return 0; }
86  int collect() override;
87  int probe() override;
88 
90 
91  bool init_sdp3x();
92 
93  /**
94  * Calculate the CRC8 for the sensor payload data
95  */
96  bool crc(const uint8_t data[], unsigned size, uint8_t checksum);
97 
98  /**
99  * Write a command in Sensirion specific logic
100  */
101  int write_command(uint16_t command);
102 
103  uint16_t _scale{0};
104 };
105 
106 #endif /* DRIVERS_SDP3X_AIRSPEED_HPP_ */
bool init_sdp3x()
Definition: SDP3X.cpp:58
int measure() override
Definition: SDP3X.hpp:85
SDP3X(int bus, int address=I2C_ADDRESS_1_SDP3X, const char *path=PATH_SDP3X)
Definition: SDP3X.hpp:73
#define I2C_ADDRESS_1_SDP3X
Definition: SDP3X.hpp:50
#define SPD3X_MEAS_RATE
Definition: SDP3X.hpp:66
int write_command(uint16_t command)
Write a command in Sensirion specific logic.
Definition: SDP3X.cpp:49
#define SDP3X_MEAS_DRIVER_FILTER_FREQ
Definition: SDP3X.hpp:67
#define PATH_SDP3X
Definition: SDP3X.hpp:63
bool crc(const uint8_t data[], unsigned size, uint8_t checksum)
Calculate the CRC8 for the sensor payload data.
Definition: SDP3X.cpp:187
Definition: SDP3X.hpp:70
uint8_t * data
Definition: dataman.cpp:149
uint16_t _scale
Definition: SDP3X.hpp:103
int probe() override
Definition: SDP3X.cpp:44
#define CONVERSION_INTERVAL
Definition: SDP3X.hpp:68
int collect() override
Definition: SDP3X.cpp:122
math::LowPassFilter2p _filter
Definition: SDP3X.hpp:89
void Run() override
Perform a poll cycle; collect from the previous measurement and start a new one.
Definition: SDP3X.cpp:171