Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Airspeed/AP_Airspeed_SDP3X.h
9872 views
1
/*
2
This program is free software: you can redistribute it and/or modify
3
it under the terms of the GNU General Public License as published by
4
the Free Software Foundation, either version 3 of the License, or
5
(at your option) any later version.
6
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
11
12
You should have received a copy of the GNU General Public License
13
along with this program. If not, see <http://www.gnu.org/licenses/>.
14
*/
15
#pragma once
16
17
#include "AP_Airspeed_config.h"
18
19
#if AP_AIRSPEED_SDP3X_ENABLED
20
21
/*
22
backend driver for airspeed from I2C
23
*/
24
25
#include <AP_HAL/AP_HAL.h>
26
#include <AP_HAL/I2CDevice.h>
27
#include <utility>
28
29
#include "AP_Airspeed_Backend.h"
30
#include "AP_Airspeed.h"
31
32
/*
33
* Thanks to PX4 for registers definitions
34
*/
35
36
class AP_Airspeed_SDP3X : public AP_Airspeed_Backend
37
{
38
public:
39
40
using AP_Airspeed_Backend::AP_Airspeed_Backend;
41
42
~AP_Airspeed_SDP3X() {
43
delete _dev;
44
}
45
46
// probe and initialise the sensor
47
bool init() override;
48
49
// return the current differential_pressure in Pascal
50
bool get_differential_pressure(float &pressure) override;
51
52
// return the current temperature in degrees C, if available
53
bool get_temperature(float &temperature) override;
54
55
private:
56
void _timer();
57
bool _send_command(uint16_t cmd);
58
bool _crc(const uint8_t data[], uint8_t size, uint8_t checksum);
59
float _correct_pressure(float press);
60
61
float _temp;
62
float _press;
63
uint16_t _temp_count;
64
uint16_t _press_count;
65
float _temp_sum;
66
float _press_sum;
67
uint32_t _last_sample_time_ms;
68
uint16_t _scale;
69
70
AP_HAL::I2CDevice *_dev;
71
};
72
73
74
#endif // AP_AIRSPEED_SDP3X_ENABLED
75
76