Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_GPS/AP_GPS_ExternalAHRS.cpp
9568 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
//
17
// ExternalAHRS GPS driver
18
//
19
#include <AP_ExternalAHRS/AP_ExternalAHRS.h>
20
#include "AP_GPS_ExternalAHRS.h"
21
22
#if AP_EXTERNAL_AHRS_ENABLED
23
24
// Reading does nothing in this class; we simply return whether or not
25
// the latest reading has been consumed. By calling this function we assume
26
// the caller is consuming the new data;
27
bool AP_GPS_ExternalAHRS::read(void)
28
{
29
if (new_data) {
30
new_data = false;
31
return true;
32
}
33
return false;
34
}
35
36
// handles an incoming ExternalAHRS message and sets
37
// corresponding gps data appropriately;
38
void AP_GPS_ExternalAHRS::handle_external(const AP_ExternalAHRS::gps_data_message_t &pkt)
39
{
40
check_new_itow(pkt.ms_tow, sizeof(pkt));
41
42
state.time_week = pkt.gps_week;
43
state.time_week_ms = pkt.ms_tow;
44
if (pkt.fix_type == AP_GPS_FixType::NO_GPS) {
45
state.status = AP_GPS::NO_FIX;
46
} else {
47
state.status = (AP_GPS::GPS_Status)pkt.fix_type;
48
}
49
state.num_sats = pkt.satellites_in_view;
50
51
const Location loc {
52
pkt.latitude,
53
pkt.longitude,
54
pkt.msl_altitude,
55
Location::AltFrame::ABSOLUTE
56
};
57
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
58
if (!loc.initialised() && state.status >= AP_GPS::GPS_Status::GPS_OK_FIX_2D) {
59
AP_HAL::panic("Invalid location passed to AP_GPS_ExternalAHRS");
60
}
61
#endif
62
63
state.location = loc;
64
state.hdop = pkt.hdop;
65
state.vdop = pkt.vdop;
66
67
state.have_vertical_velocity = true;
68
state.velocity.x = pkt.ned_vel_north;
69
state.velocity.y = pkt.ned_vel_east;
70
state.velocity.z = pkt.ned_vel_down;
71
72
velocity_to_speed_course(state);
73
74
state.have_speed_accuracy = true;
75
state.have_horizontal_accuracy = true;
76
state.have_vertical_accuracy = true;
77
state.have_vertical_velocity = true;
78
79
state.horizontal_accuracy = pkt.horizontal_pos_accuracy;
80
state.vertical_accuracy = pkt.vertical_pos_accuracy;
81
state.speed_accuracy = pkt.horizontal_vel_accuracy;
82
83
state.last_gps_time_ms = AP_HAL::millis();
84
85
new_data = true;
86
}
87
88
/*
89
return velocity lag in seconds
90
*/
91
bool AP_GPS_ExternalAHRS::get_lag(float &lag_sec) const
92
{
93
// fixed assumed lag
94
lag_sec = 0.11;
95
return true;
96
}
97
98
#endif // AP_EXTERNAL_AHRS_ENABLED
99
100
101