CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Airspeed/AP_Airspeed_Backend.h
Views: 1798
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].use_zero_offset = true;
93
}
94
95
// set to no zero cal, which makes sense for some sensors
96
void set_skip_cal(void) {
97
#ifndef HAL_BUILD_AP_PERIPH
98
frontend.param[instance].skip_cal.set(1);
99
#endif
100
}
101
102
// set zero offset
103
void set_offset(float ofs) {
104
#ifndef HAL_BUILD_AP_PERIPH
105
frontend.param[instance].offset.set(ofs);
106
#endif
107
}
108
109
// set use
110
void set_use(int8_t use) {
111
#ifndef HAL_BUILD_AP_PERIPH
112
frontend.param[instance].use.set(use);
113
#endif
114
}
115
116
// set bus ID of this instance, for ARSPD_DEVID parameters
117
void set_bus_id(uint32_t id);
118
119
enum class DevType {
120
SITL = 0x01,
121
MS4525 = 0x02,
122
MS5525 = 0x03,
123
DLVR = 0x04,
124
MSP = 0x05,
125
SDP3X = 0x06,
126
UAVCAN = 0x07,
127
ANALOG = 0x08,
128
NMEA = 0x09,
129
ASP5033 = 0x0A,
130
};
131
132
private:
133
AP_Airspeed &frontend;
134
uint8_t instance;
135
};
136
137
#endif // AP_AIRSPEED_ENABLED
138
139