Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_GPS/AP_GPS_MSP.cpp
9447 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
// 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
state.location = {
47
pkt.latitude,
48
pkt.longitude,
49
pkt.msl_altitude,
50
Location::AltFrame::ABSOLUTE
51
};
52
state.hdop = pkt.hdop;
53
state.vdop = GPS_UNKNOWN_DOP;
54
55
state.have_vertical_velocity = true;
56
Vector3f vel;
57
vel.x = pkt.ned_vel_north * 0.01;
58
vel.y = pkt.ned_vel_east * 0.01;
59
vel.z = pkt.ned_vel_down * 0.01;
60
state.velocity = vel;
61
62
velocity_to_speed_course(state);
63
64
state.have_speed_accuracy = true;
65
state.have_horizontal_accuracy = true;
66
state.have_vertical_accuracy = true;
67
state.have_vertical_velocity = true;
68
69
state.horizontal_accuracy = pkt.horizontal_pos_accuracy * 0.01;
70
state.vertical_accuracy = pkt.vertical_pos_accuracy * 0.01;
71
state.speed_accuracy = pkt.horizontal_vel_accuracy * 0.01;
72
73
state.last_gps_time_ms = AP_HAL::millis();
74
75
if (pkt.true_yaw != 65535) {
76
state.gps_yaw = wrap_360(pkt.true_yaw*0.01);
77
state.have_gps_yaw = true;
78
state.gps_yaw_time_ms = state.last_gps_time_ms;
79
}
80
81
new_data = pkt.fix_type>0;
82
}
83
84
/*
85
return velocity lag in seconds
86
*/
87
bool AP_GPS_MSP::get_lag(float &lag_sec) const
88
{
89
// measured on Matek M8Q
90
lag_sec = 0.11;
91
return true;
92
}
93
94
#endif // HAL_MSP_GPS_ENABLED
95
96