Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_GPS/AP_GPS_MAV.cpp
Views: 1798
/*1This program is free software: you can redistribute it and/or modify2it under the terms of the GNU General Public License as published by3the Free Software Foundation, either version 3 of the License, or4(at your option) any later version.56This program is distributed in the hope that it will be useful,7but WITHOUT ANY WARRANTY; without even the implied warranty of8MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9GNU General Public License for more details.1011You should have received a copy of the GNU General Public License12along with this program. If not, see <http://www.gnu.org/licenses/>.13*/1415//16// MAVLINK GPS driver17//1819#include "AP_GPS_config.h"2021#if AP_GPS_MAV_ENABLED2223#include "AP_GPS_MAV.h"24#include <stdint.h>2526// Reading does nothing in this class; we simply return whether or not27// the latest reading has been consumed. By calling this function we assume28// the caller is consuming the new data;29bool AP_GPS_MAV::read(void)30{31if (_new_data) {32_new_data = false;33return true;34}3536return false;37}3839// handles an incoming mavlink message (HIL_GPS) and sets40// corresponding gps data appropriately;41void AP_GPS_MAV::handle_msg(const mavlink_message_t &msg)42{43switch (msg.msgid) {4445case MAVLINK_MSG_ID_GPS_INPUT: {46mavlink_gps_input_t packet;47mavlink_msg_gps_input_decode(&msg, &packet);4849// check if target instance belongs to incoming gps data.50if (state.instance != packet.gps_id) {51return;52}5354bool have_alt = ((packet.ignore_flags & GPS_INPUT_IGNORE_FLAG_ALT) == 0);55bool have_hdop = ((packet.ignore_flags & GPS_INPUT_IGNORE_FLAG_HDOP) == 0);56bool have_vdop = ((packet.ignore_flags & GPS_INPUT_IGNORE_FLAG_VDOP) == 0);57bool have_vel_h = ((packet.ignore_flags & GPS_INPUT_IGNORE_FLAG_VEL_HORIZ) == 0);58bool have_vel_v = ((packet.ignore_flags & GPS_INPUT_IGNORE_FLAG_VEL_VERT) == 0);59bool have_sa = ((packet.ignore_flags & GPS_INPUT_IGNORE_FLAG_SPEED_ACCURACY) == 0);60bool have_ha = ((packet.ignore_flags & GPS_INPUT_IGNORE_FLAG_HORIZONTAL_ACCURACY) == 0);61bool have_va = ((packet.ignore_flags & GPS_INPUT_IGNORE_FLAG_VERTICAL_ACCURACY) == 0);62bool have_yaw = (packet.yaw != 0);6364state.time_week = packet.time_week;65state.time_week_ms = packet.time_week_ms;66state.status = (AP_GPS::GPS_Status)packet.fix_type;6768Location loc = {};69loc.lat = packet.lat;70loc.lng = packet.lon;71if (have_alt) {72loc.alt = packet.alt * 100; // convert to centimeters73}74state.location = loc;7576if (have_hdop) {77state.hdop = packet.hdop * 100; // convert to centimeters78}7980if (have_vdop) {81state.vdop = packet.vdop * 100; // convert to centimeters82}8384if (have_vel_h) {85Vector3f vel(packet.vn, packet.ve, 0);86if (have_vel_v) {87vel.z = packet.vd;88state.have_vertical_velocity = true;89}9091state.velocity = vel;92velocity_to_speed_course(state);93}9495if (have_sa) {96state.speed_accuracy = packet.speed_accuracy;97state.have_speed_accuracy = true;98}99100if (have_ha) {101state.horizontal_accuracy = packet.horiz_accuracy;102state.have_horizontal_accuracy = true;103}104105if (have_va) {106state.vertical_accuracy = packet.vert_accuracy;107state.have_vertical_accuracy = true;108}109110const uint32_t now_ms = AP_HAL::millis();111112if (have_yaw) {113state.gps_yaw = wrap_360(packet.yaw*0.01);114state.gps_yaw_time_ms = now_ms;115state.have_gps_yaw = true;116state.gps_yaw_configured = true;117}118119if (packet.fix_type >= 3 && packet.time_week > 0) {120/*121use the millisecond timestamp from the GPS_INPUT122packet into jitter correction to get a local123timestamp corrected for transport jitter124*/125if (first_week == 0) {126first_week = packet.time_week;127}128uint32_t timestamp_ms = (packet.time_week - first_week) * AP_MSEC_PER_WEEK + packet.time_week_ms;129uint32_t corrected_ms = jitter.correct_offboard_timestamp_msec(timestamp_ms, now_ms);130state.last_corrected_gps_time_us = (corrected_ms * 1000ULL);131state.corrected_timestamp_updated = true;132if (state.last_corrected_gps_time_us) {133_last_itow_ms = state.time_week_ms;134_have_itow = true;135}136if (have_yaw) {137state.gps_yaw_time_ms = corrected_ms;138}139}140141state.num_sats = packet.satellites_visible;142state.last_gps_time_ms = now_ms;143_new_data = true;144break;145}146147default:148// ignore all other messages149break;150}151}152#endif153154155