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_MSP.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
// MSP GPS driver
18
//
19
#include <AP_MSP/msp.h>
20
#include "AP_GPS_MSP.h"
21
22
#if HAL_MSP_GPS_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_MSP::read(void)
28
{
29
if (new_data) {
30
new_data = false;
31
return true;
32
}
33
return false;
34
}
35
36
// handles an incoming msp message and sets
37
// corresponding gps data appropriately;
38
void AP_GPS_MSP::handle_msp(const MSP::msp_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
state.status = (AP_GPS::GPS_Status)pkt.fix_type;
45
state.num_sats = pkt.satellites_in_view;
46
47
Location loc = {};
48
loc.lat = pkt.latitude;
49
loc.lng = pkt.longitude;
50
loc.alt = pkt.msl_altitude;
51
52
state.location = loc;
53
state.hdop = pkt.hdop;
54
state.vdop = GPS_UNKNOWN_DOP;
55
56
state.have_vertical_velocity = true;
57
Vector3f vel;
58
vel.x = pkt.ned_vel_north * 0.01;
59
vel.y = pkt.ned_vel_east * 0.01;
60
vel.z = pkt.ned_vel_down * 0.01;
61
state.velocity = vel;
62
63
velocity_to_speed_course(state);
64
65
state.have_speed_accuracy = true;
66
state.have_horizontal_accuracy = true;
67
state.have_vertical_accuracy = true;
68
state.have_vertical_velocity = true;
69
70
state.horizontal_accuracy = pkt.horizontal_pos_accuracy * 0.01;
71
state.vertical_accuracy = pkt.vertical_pos_accuracy * 0.01;
72
state.speed_accuracy = pkt.horizontal_vel_accuracy * 0.01;
73
74
state.last_gps_time_ms = AP_HAL::millis();
75
76
if (pkt.true_yaw != 65535) {
77
state.gps_yaw = wrap_360(pkt.true_yaw*0.01);
78
state.have_gps_yaw = true;
79
state.gps_yaw_time_ms = state.last_gps_time_ms;
80
}
81
82
new_data = pkt.fix_type>0;
83
}
84
85
/*
86
return velocity lag in seconds
87
*/
88
bool AP_GPS_MSP::get_lag(float &lag_sec) const
89
{
90
// measured on Matek M8Q
91
lag_sec = 0.11;
92
return true;
93
}
94
95
#endif // HAL_MSP_GPS_ENABLED
96
97