Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Compass/AP_Compass_ExternalAHRS.cpp
9383 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
16
#include <AP_HAL/AP_HAL.h>
17
#include "AP_Compass_ExternalAHRS.h"
18
19
#if AP_COMPASS_EXTERNALAHRS_ENABLED
20
21
AP_Compass_Backend *AP_Compass_ExternalAHRS::probe(uint8_t port)
22
{
23
auto devid = AP_HAL::Device::make_bus_id(AP_HAL::Device::BUS_TYPE_SERIAL,port,0,0);
24
auto *ret = NEW_NOTHROW AP_Compass_ExternalAHRS();
25
if (ret == nullptr) {
26
return nullptr;
27
}
28
if (!ret->register_compass(devid)) {
29
delete ret;
30
return nullptr;
31
}
32
ret->set_external(true);
33
return ret;
34
}
35
36
void AP_Compass_ExternalAHRS::handle_external(const AP_ExternalAHRS::mag_data_message_t &pkt)
37
{
38
Vector3f field = pkt.field;
39
accumulate_sample(field);
40
}
41
42
void AP_Compass_ExternalAHRS::read(void)
43
{
44
drain_accumulated_samples();
45
}
46
47
#endif // AP_COMPASS_EXTERNALAHRS_ENABLED
48
49