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_External.cpp
Views: 1798
1
#include "AP_Airspeed_External.h"
2
3
#if AP_AIRSPEED_EXTERNAL_ENABLED
4
5
AP_Airspeed_External::AP_Airspeed_External(AP_Airspeed &_frontend, uint8_t _instance) :
6
AP_Airspeed_Backend(_frontend, _instance)
7
{
8
set_bus_id(AP_HAL::Device::make_bus_id(AP_HAL::Device::BUS_TYPE_SERIAL,0,_instance,0));
9
}
10
11
// return the current differential_pressure in Pascal
12
bool AP_Airspeed_External::get_differential_pressure(float &pressure)
13
{
14
WITH_SEMAPHORE(sem);
15
if (press_count == 0) {
16
return false;
17
}
18
pressure = sum_pressure/press_count;
19
press_count = 0;
20
sum_pressure = 0;
21
return true;
22
}
23
24
// get last temperature
25
bool AP_Airspeed_External::get_temperature(float &temperature)
26
{
27
WITH_SEMAPHORE(sem);
28
if (temperature_count == 0) {
29
return false;
30
}
31
temperature = sum_temperature/temperature_count;
32
temperature_count = 0;
33
sum_temperature = 0;
34
return true;
35
}
36
37
void AP_Airspeed_External::handle_external(const AP_ExternalAHRS::airspeed_data_message_t &pkt)
38
{
39
WITH_SEMAPHORE(sem);
40
41
sum_pressure += pkt.differential_pressure;
42
press_count++;
43
if (press_count > 100) {
44
// prevent overflow
45
sum_pressure /= 2;
46
press_count /= 2;
47
}
48
49
sum_temperature += pkt.temperature;
50
temperature_count++;
51
if (temperature_count > 100) {
52
// prevent overflow
53
sum_temperature /= 2;
54
temperature_count /= 2;
55
}
56
}
57
58
#endif // AP_AIRSPEED_EXTERNAL_ENABLED
59
60