2016-05-19 20:24:08 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//
|
|
|
|
// MAVLINK GPS driver
|
|
|
|
//
|
|
|
|
#include "AP_GPS_MAV.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
// Reading does nothing in this class; we simply return whether or not
|
|
|
|
// the latest reading has been consumed. By calling this function we assume
|
|
|
|
// the caller is consuming the new data;
|
2016-07-12 03:44:19 -03:00
|
|
|
bool AP_GPS_MAV::read(void)
|
2016-05-19 20:24:08 -03:00
|
|
|
{
|
|
|
|
if (_new_data) {
|
|
|
|
_new_data = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handles an incoming mavlink message (HIL_GPS) and sets
|
|
|
|
// corresponding gps data appropriately;
|
2019-04-30 07:22:48 -03:00
|
|
|
void AP_GPS_MAV::handle_msg(const mavlink_message_t &msg)
|
2016-05-19 20:24:08 -03:00
|
|
|
{
|
2019-04-30 07:22:48 -03:00
|
|
|
switch (msg.msgid) {
|
2016-12-06 20:53:28 -04:00
|
|
|
|
|
|
|
case MAVLINK_MSG_ID_GPS_INPUT: {
|
|
|
|
mavlink_gps_input_t packet;
|
2019-04-30 07:22:48 -03:00
|
|
|
mavlink_msg_gps_input_decode(&msg, &packet);
|
2016-12-06 20:53:28 -04:00
|
|
|
|
|
|
|
bool have_alt = ((packet.ignore_flags & GPS_INPUT_IGNORE_FLAG_ALT) == 0);
|
|
|
|
bool have_hdop = ((packet.ignore_flags & GPS_INPUT_IGNORE_FLAG_HDOP) == 0);
|
|
|
|
bool have_vdop = ((packet.ignore_flags & GPS_INPUT_IGNORE_FLAG_VDOP) == 0);
|
|
|
|
bool have_vel_h = ((packet.ignore_flags & GPS_INPUT_IGNORE_FLAG_VEL_HORIZ) == 0);
|
|
|
|
bool have_vel_v = ((packet.ignore_flags & GPS_INPUT_IGNORE_FLAG_VEL_VERT) == 0);
|
|
|
|
bool have_sa = ((packet.ignore_flags & GPS_INPUT_IGNORE_FLAG_SPEED_ACCURACY) == 0);
|
|
|
|
bool have_ha = ((packet.ignore_flags & GPS_INPUT_IGNORE_FLAG_HORIZONTAL_ACCURACY) == 0);
|
|
|
|
bool have_va = ((packet.ignore_flags & GPS_INPUT_IGNORE_FLAG_VERTICAL_ACCURACY) == 0);
|
2019-08-09 04:29:19 -03:00
|
|
|
bool have_yaw = (packet.yaw != 0);
|
2016-12-06 20:53:28 -04:00
|
|
|
|
|
|
|
state.time_week = packet.time_week;
|
|
|
|
state.time_week_ms = packet.time_week_ms;
|
|
|
|
state.status = (AP_GPS::GPS_Status)packet.fix_type;
|
|
|
|
|
|
|
|
Location loc = {};
|
|
|
|
loc.lat = packet.lat;
|
|
|
|
loc.lng = packet.lon;
|
|
|
|
if (have_alt) {
|
2016-12-07 20:36:41 -04:00
|
|
|
loc.alt = packet.alt * 100; // convert to centimeters
|
2016-12-06 20:53:28 -04:00
|
|
|
}
|
|
|
|
state.location = loc;
|
|
|
|
|
|
|
|
if (have_hdop) {
|
|
|
|
state.hdop = packet.hdop * 100; // convert to centimeters
|
|
|
|
}
|
|
|
|
|
|
|
|
if (have_vdop) {
|
|
|
|
state.vdop = packet.vdop * 100; // convert to centimeters
|
|
|
|
}
|
|
|
|
|
|
|
|
if (have_vel_h) {
|
|
|
|
Vector3f vel(packet.vn, packet.ve, 0);
|
2018-03-01 03:00:15 -04:00
|
|
|
if (have_vel_v) {
|
2016-12-06 20:53:28 -04:00
|
|
|
vel.z = packet.vd;
|
2018-03-01 03:00:15 -04:00
|
|
|
state.have_vertical_velocity = true;
|
|
|
|
}
|
2016-12-06 20:53:28 -04:00
|
|
|
|
|
|
|
state.velocity = vel;
|
|
|
|
state.ground_course = wrap_360(degrees(atan2f(vel.y, vel.x)));
|
2021-09-11 07:31:17 -03:00
|
|
|
state.ground_speed = vel.xy().length();
|
2016-12-06 20:53:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (have_sa) {
|
|
|
|
state.speed_accuracy = packet.speed_accuracy;
|
2017-03-08 02:22:20 -04:00
|
|
|
state.have_speed_accuracy = true;
|
2016-12-06 20:53:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (have_ha) {
|
|
|
|
state.horizontal_accuracy = packet.horiz_accuracy;
|
2017-03-08 02:22:20 -04:00
|
|
|
state.have_horizontal_accuracy = true;
|
2016-12-06 20:53:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (have_va) {
|
|
|
|
state.vertical_accuracy = packet.vert_accuracy;
|
2017-03-08 02:22:20 -04:00
|
|
|
state.have_vertical_accuracy = true;
|
2016-12-06 20:53:28 -04:00
|
|
|
}
|
|
|
|
|
2021-07-20 04:36:45 -03:00
|
|
|
const uint32_t now_ms = AP_HAL::millis();
|
|
|
|
|
2019-08-09 04:29:19 -03:00
|
|
|
if (have_yaw) {
|
|
|
|
state.gps_yaw = wrap_360(packet.yaw*0.01);
|
2021-07-20 04:36:45 -03:00
|
|
|
state.gps_yaw_time_ms = now_ms;
|
2019-08-09 04:29:19 -03:00
|
|
|
state.have_gps_yaw = true;
|
2021-05-11 03:26:06 -03:00
|
|
|
state.gps_yaw_configured = true;
|
2019-08-09 04:29:19 -03:00
|
|
|
}
|
|
|
|
|
2019-09-13 05:50:18 -03:00
|
|
|
if (packet.fix_type >= 3 && packet.time_week > 0) {
|
|
|
|
/*
|
|
|
|
use the millisecond timestamp from the GPS_INPUT
|
|
|
|
packet into jitter correction to get a local
|
|
|
|
timestamp corrected for transport jitter
|
|
|
|
*/
|
|
|
|
if (first_week == 0) {
|
|
|
|
first_week = packet.time_week;
|
|
|
|
}
|
|
|
|
uint32_t timestamp_ms = (packet.time_week - first_week) * AP_MSEC_PER_WEEK + packet.time_week_ms;
|
2021-07-20 04:36:45 -03:00
|
|
|
uint32_t corrected_ms = jitter.correct_offboard_timestamp_msec(timestamp_ms, now_ms);
|
2019-09-13 05:50:18 -03:00
|
|
|
state.uart_timestamp_ms = corrected_ms;
|
2021-07-20 04:36:45 -03:00
|
|
|
if (have_yaw) {
|
|
|
|
state.gps_yaw_time_ms = corrected_ms;
|
|
|
|
}
|
2019-09-13 05:50:18 -03:00
|
|
|
}
|
|
|
|
|
2016-12-06 20:53:28 -04:00
|
|
|
state.num_sats = packet.satellites_visible;
|
2021-07-20 04:36:45 -03:00
|
|
|
state.last_gps_time_ms = now_ms;
|
2016-12-06 20:53:28 -04:00
|
|
|
_new_data = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MAVLINK_MSG_ID_HIL_GPS: {
|
|
|
|
mavlink_hil_gps_t packet;
|
2019-04-30 07:22:48 -03:00
|
|
|
mavlink_msg_hil_gps_decode(&msg, &packet);
|
2016-12-06 20:53:28 -04:00
|
|
|
|
|
|
|
state.time_week = 0;
|
|
|
|
state.time_week_ms = packet.time_usec/1000;
|
|
|
|
state.status = (AP_GPS::GPS_Status)packet.fix_type;
|
|
|
|
|
|
|
|
Location loc = {};
|
|
|
|
loc.lat = packet.lat;
|
|
|
|
loc.lng = packet.lon;
|
2018-04-02 21:07:53 -03:00
|
|
|
loc.alt = packet.alt * 0.1f;
|
2016-12-06 20:53:28 -04:00
|
|
|
state.location = loc;
|
2017-05-24 16:19:10 -03:00
|
|
|
state.hdop = MIN(packet.eph, GPS_UNKNOWN_DOP);
|
|
|
|
state.vdop = MIN(packet.epv, GPS_UNKNOWN_DOP);
|
2016-12-06 20:53:28 -04:00
|
|
|
if (packet.vel < 65535) {
|
2021-05-11 11:08:27 -03:00
|
|
|
state.ground_speed = packet.vel * 0.01f;
|
2016-12-06 20:53:28 -04:00
|
|
|
}
|
2021-05-11 11:08:27 -03:00
|
|
|
Vector3f vel(packet.vn*0.01f, packet.ve*0.01f, packet.vd*0.01f);
|
2016-12-06 20:53:28 -04:00
|
|
|
state.velocity = vel;
|
2018-04-04 16:36:57 -03:00
|
|
|
if (packet.vd != 0) {
|
|
|
|
state.have_vertical_velocity = true;
|
|
|
|
}
|
2016-12-07 20:37:03 -04:00
|
|
|
if (packet.cog < 36000) {
|
2021-05-11 11:08:27 -03:00
|
|
|
state.ground_course = packet.cog * 0.01f;
|
2016-12-06 20:53:28 -04:00
|
|
|
}
|
2017-03-08 02:22:20 -04:00
|
|
|
state.have_speed_accuracy = false;
|
2018-04-04 16:36:57 -03:00
|
|
|
state.have_horizontal_accuracy = false;
|
|
|
|
state.have_vertical_accuracy = false;
|
2016-12-07 20:37:03 -04:00
|
|
|
if (packet.satellites_visible < 255) {
|
|
|
|
state.num_sats = packet.satellites_visible;
|
|
|
|
}
|
2016-12-06 20:53:28 -04:00
|
|
|
state.last_gps_time_ms = AP_HAL::millis();
|
|
|
|
_new_data = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// ignore all other messages
|
|
|
|
break;
|
2016-07-12 03:44:19 -03:00
|
|
|
}
|
2016-05-19 20:24:08 -03:00
|
|
|
}
|