Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Airspeed/AP_Airspeed_Backend.h
9743 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
/*
18
backend driver class for airspeed
19
*/
20
21
#include "AP_Airspeed_config.h"
22
23
#if AP_AIRSPEED_ENABLED
24
25
#include <AP_Common/AP_Common.h>
26
#include <AP_HAL/AP_HAL_Boards.h>
27
#include <AP_HAL/Semaphores.h>
28
#include "AP_Airspeed.h"
29
#include <AP_MSP/msp_sensors.h>
30
31
class AP_Airspeed_Backend {
32
public:
33
AP_Airspeed_Backend(AP_Airspeed &frontend, uint8_t instance);
34
virtual ~AP_Airspeed_Backend() {}
35
36
// probe and initialise the sensor
37
virtual bool init(void) = 0;
38
39
// return the current differential_pressure in Pascal
40
virtual bool get_differential_pressure(float &pressure) {return false;}
41
42
// return the current temperature in degrees C, if available
43
virtual bool get_temperature(float &temperature) = 0;
44
45
// true if sensor reads airspeed directly, not via pressure
46
virtual bool has_airspeed() {return false;}
47
48
// return airspeed in m/s if available
49
virtual bool get_airspeed(float& airspeed) {return false;}
50
51
virtual void handle_msp(const MSP::msp_airspeed_data_message_t &pkt) {}
52
#if AP_AIRSPEED_EXTERNAL_ENABLED
53
virtual void handle_external(const AP_ExternalAHRS::airspeed_data_message_t &pkt) {}
54
#endif
55
56
#if AP_AIRSPEED_HYGROMETER_ENABLE
57
// optional hygrometer support
58
virtual bool get_hygrometer(uint32_t &last_sample_ms, float &temperature, float &humidity) { return false; }
59
#endif
60
61
protected:
62
int8_t get_pin(void) const;
63
float get_psi_range(void) const;
64
uint8_t get_bus(void) const;
65
bool bus_is_configured(void) const;
66
uint8_t get_instance(void) const {
67
return instance;
68
}
69
70
// see if voltage correction should be disabled
71
bool disable_voltage_correction(void) const {
72
return (frontend._options.get() & AP_Airspeed::OptionsMask::DISABLE_VOLTAGE_CORRECTION) != 0;
73
}
74
75
AP_Airspeed::pitot_tube_order get_tube_order(void) const {
76
#ifndef HAL_BUILD_AP_PERIPH
77
return AP_Airspeed::pitot_tube_order(frontend.param[instance].tube_order.get());
78
#else
79
return AP_Airspeed::pitot_tube_order::PITOT_TUBE_ORDER_AUTO;
80
#endif
81
}
82
83
// semaphore for access to shared frontend data
84
HAL_Semaphore sem;
85
86
float get_airspeed_ratio(void) const {
87
return frontend.get_airspeed_ratio(instance);
88
}
89
90
// some sensors use zero offsets
91
void set_use_zero_offset(void) {
92
frontend.state[instance].cal.state = AP_Airspeed::CalibrationState::NOT_REQUIRED_ZERO_OFFSET;
93
#ifndef HAL_BUILD_AP_PERIPH
94
frontend.param[instance].offset.set(0.0);
95
#endif
96
}
97
98
// set use
99
void set_use(int8_t use) {
100
#ifndef HAL_BUILD_AP_PERIPH
101
frontend.param[instance].use.set(use);
102
#endif
103
}
104
105
// set bus ID of this instance, for ARSPD_DEVID parameters
106
void set_bus_id(uint32_t id);
107
108
enum class DevType {
109
SITL = 0x01,
110
MS4525 = 0x02,
111
MS5525 = 0x03,
112
DLVR = 0x04,
113
MSP = 0x05,
114
SDP3X = 0x06,
115
UAVCAN = 0x07,
116
ANALOG = 0x08,
117
NMEA = 0x09,
118
ASP5033 = 0x0A,
119
AUAV = 0x0B,
120
};
121
122
private:
123
AP_Airspeed &frontend;
124
uint8_t instance;
125
};
126
127
#endif // AP_AIRSPEED_ENABLED
128
129