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_GPS/AP_GPS_ExternalAHRS.cpp
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
16
//
17
// ExternalAHRS GPS driver
18
//
19
#include <AP_ExternalAHRS/AP_ExternalAHRS.h>
20
#include "AP_GPS_ExternalAHRS.h"
21
22
#if HAL_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
Location loc = {};
52
loc.lat = pkt.latitude;
53
loc.lng = pkt.longitude;
54
loc.alt = pkt.msl_altitude;
55
56
state.location = loc;
57
state.hdop = pkt.hdop;
58
state.vdop = pkt.vdop;
59
60
state.have_vertical_velocity = true;
61
state.velocity.x = pkt.ned_vel_north;
62
state.velocity.y = pkt.ned_vel_east;
63
state.velocity.z = pkt.ned_vel_down;
64
65
velocity_to_speed_course(state);
66
67
state.have_speed_accuracy = true;
68
state.have_horizontal_accuracy = true;
69
state.have_vertical_accuracy = true;
70
state.have_vertical_velocity = true;
71
72
state.horizontal_accuracy = pkt.horizontal_pos_accuracy;
73
state.vertical_accuracy = pkt.vertical_pos_accuracy;
74
state.speed_accuracy = pkt.horizontal_vel_accuracy;
75
76
state.last_gps_time_ms = AP_HAL::millis();
77
78
new_data = true;
79
}
80
81
/*
82
return velocity lag in seconds
83
*/
84
bool AP_GPS_ExternalAHRS::get_lag(float &lag_sec) const
85
{
86
// fixed assumed lag
87
lag_sec = 0.11;
88
return true;
89
}
90
91
#endif // HAL_EXTERNAL_AHRS_ENABLED
92
93
94