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_Baro/AP_Baro_ExternalAHRS.cpp
Views: 1798
1
#include "AP_Baro_ExternalAHRS.h"
2
3
#if AP_BARO_EXTERNALAHRS_ENABLED
4
5
AP_Baro_ExternalAHRS::AP_Baro_ExternalAHRS(AP_Baro &baro, uint8_t port) :
6
AP_Baro_Backend(baro)
7
{
8
instance = _frontend.register_sensor();
9
set_bus_id(instance, AP_HAL::Device::make_bus_id(AP_HAL::Device::BUS_TYPE_SERIAL,port,0,0));
10
}
11
12
// Read the sensor
13
void AP_Baro_ExternalAHRS::update(void)
14
{
15
if (count) {
16
WITH_SEMAPHORE(_sem);
17
_copy_to_frontend(instance, sum_pressure/count, sum_temp/count);
18
sum_pressure = sum_temp = 0;
19
count = 0;
20
}
21
}
22
23
void AP_Baro_ExternalAHRS::handle_external(const AP_ExternalAHRS::baro_data_message_t &pkt)
24
{
25
if (pkt.instance != 0) {
26
// not for us
27
return;
28
}
29
WITH_SEMAPHORE(_sem);
30
sum_pressure += pkt.pressure_pa;
31
sum_temp += pkt.temperature;
32
count++;
33
}
34
35
#endif // AP_BARO_EXTERNALAHRS_ENABLED
36
37