Line data Source code
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 693 : bool AP_GPS_MSP::read(void) 28 : { 29 693 : if (new_data) { 30 64 : new_data = false; 31 64 : return true; 32 : } 33 629 : return false; 34 : } 35 : 36 : // handles an incoming msp message and sets 37 : // corresponding gps data appropriately; 38 64 : void AP_GPS_MSP::handle_msp(const MSP::msp_gps_data_message_t &pkt) 39 : { 40 64 : check_new_itow(pkt.ms_tow, sizeof(pkt)); 41 : 42 64 : state.time_week = pkt.gps_week; 43 64 : state.time_week_ms = pkt.ms_tow; 44 64 : state.status = (AP_GPS_FixType)pkt.fix_type; 45 64 : state.num_sats = pkt.satellites_in_view; 46 128 : state.location = { 47 64 : pkt.latitude, 48 64 : pkt.longitude, 49 64 : pkt.msl_altitude, 50 : Location::AltFrame::ABSOLUTE 51 : }; 52 64 : state.hdop = pkt.hdop; 53 64 : state.vdop = GPS_UNKNOWN_DOP; 54 : 55 64 : state.have_vertical_velocity = true; 56 64 : Vector3f vel; 57 64 : vel.x = pkt.ned_vel_north * 0.01; 58 64 : vel.y = pkt.ned_vel_east * 0.01; 59 64 : vel.z = pkt.ned_vel_down * 0.01; 60 64 : state.velocity = vel; 61 : 62 64 : velocity_to_speed_course(state); 63 : 64 64 : state.have_speed_accuracy = true; 65 64 : state.have_horizontal_accuracy = true; 66 64 : state.have_vertical_accuracy = true; 67 64 : state.have_vertical_velocity = true; 68 : 69 64 : state.horizontal_accuracy = pkt.horizontal_pos_accuracy * 0.01; 70 64 : state.vertical_accuracy = pkt.vertical_pos_accuracy * 0.01; 71 64 : state.speed_accuracy = pkt.horizontal_vel_accuracy * 0.01; 72 : 73 64 : state.last_gps_time_ms = AP_HAL::millis(); 74 : 75 64 : if (pkt.true_yaw != 65535) { 76 64 : state.gps_yaw = wrap_360(pkt.true_yaw*0.01); 77 64 : state.have_gps_yaw = true; 78 64 : state.gps_yaw_time_ms = state.last_gps_time_ms; 79 : } 80 : 81 64 : new_data = pkt.fix_type>0; 82 64 : } 83 : 84 : /* 85 : return velocity lag in seconds 86 : */ 87 15928 : bool AP_GPS_MSP::get_lag(float &lag_sec) const 88 : { 89 : // measured on Matek M8Q 90 15928 : lag_sec = 0.11; 91 15928 : return true; 92 : } 93 : 94 : #endif // HAL_MSP_GPS_ENABLED