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_MSP.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// MSP GPS driver17//18#include <AP_MSP/msp.h>19#include "AP_GPS_MSP.h"2021#if HAL_MSP_GPS_ENABLED2223// Reading does nothing in this class; we simply return whether or not24// the latest reading has been consumed. By calling this function we assume25// the caller is consuming the new data;26bool AP_GPS_MSP::read(void)27{28if (new_data) {29new_data = false;30return true;31}32return false;33}3435// handles an incoming msp message and sets36// corresponding gps data appropriately;37void AP_GPS_MSP::handle_msp(const MSP::msp_gps_data_message_t &pkt)38{39check_new_itow(pkt.ms_tow, sizeof(pkt));4041state.time_week = pkt.gps_week;42state.time_week_ms = pkt.ms_tow;43state.status = (AP_GPS::GPS_Status)pkt.fix_type;44state.num_sats = pkt.satellites_in_view;4546Location loc = {};47loc.lat = pkt.latitude;48loc.lng = pkt.longitude;49loc.alt = pkt.msl_altitude;5051state.location = loc;52state.hdop = pkt.hdop;53state.vdop = GPS_UNKNOWN_DOP;5455state.have_vertical_velocity = true;56Vector3f vel;57vel.x = pkt.ned_vel_north * 0.01;58vel.y = pkt.ned_vel_east * 0.01;59vel.z = pkt.ned_vel_down * 0.01;60state.velocity = vel;6162velocity_to_speed_course(state);6364state.have_speed_accuracy = true;65state.have_horizontal_accuracy = true;66state.have_vertical_accuracy = true;67state.have_vertical_velocity = true;6869state.horizontal_accuracy = pkt.horizontal_pos_accuracy * 0.01;70state.vertical_accuracy = pkt.vertical_pos_accuracy * 0.01;71state.speed_accuracy = pkt.horizontal_vel_accuracy * 0.01;7273state.last_gps_time_ms = AP_HAL::millis();7475if (pkt.true_yaw != 65535) {76state.gps_yaw = wrap_360(pkt.true_yaw*0.01);77state.have_gps_yaw = true;78state.gps_yaw_time_ms = state.last_gps_time_ms;79}8081new_data = pkt.fix_type>0;82}8384/*85return velocity lag in seconds86*/87bool AP_GPS_MSP::get_lag(float &lag_sec) const88{89// measured on Matek M8Q90lag_sec = 0.11;91return true;92}9394#endif // HAL_MSP_GPS_ENABLED959697