2013-05-29 20:52:21 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2013-08-29 02:34:34 -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/>.
|
|
|
|
*/
|
|
|
|
|
2010-11-19 01:42:47 -04:00
|
|
|
//
|
|
|
|
// Hardware in the loop gps class.
|
|
|
|
// Code by James Goppert
|
|
|
|
//
|
|
|
|
// GPS configuration : Custom protocol per "DIYDrones Custom Binary Sentence Specification V1.1"
|
|
|
|
//
|
|
|
|
|
2012-09-27 02:18:44 -03:00
|
|
|
#include <AP_HAL.h>
|
2010-11-19 01:42:47 -04:00
|
|
|
#include "AP_GPS_HIL.h"
|
|
|
|
|
2013-11-23 03:30:27 -04:00
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
2010-11-19 01:42:47 -04:00
|
|
|
// Public Methods //////////////////////////////////////////////////////////////
|
2012-12-17 22:31:05 -04:00
|
|
|
void AP_GPS_HIL::init(AP_HAL::UARTDriver *s, enum GPS_Engine_Setting nav_setting)
|
2011-10-28 15:52:50 -03:00
|
|
|
{
|
2012-12-17 22:31:05 -04:00
|
|
|
_port = s;
|
2010-11-19 01:42:47 -04:00
|
|
|
}
|
|
|
|
|
2010-12-24 02:35:09 -04:00
|
|
|
bool AP_GPS_HIL::read(void)
|
2010-11-19 01:42:47 -04:00
|
|
|
{
|
2013-11-23 03:30:27 -04:00
|
|
|
if ((hal.scheduler->millis() - last_fix_time) < 200) {
|
|
|
|
// simulate a 5Hz GPS
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-17 03:19:44 -03:00
|
|
|
bool result = _updated;
|
2010-11-19 01:42:47 -04:00
|
|
|
|
2011-10-28 15:52:50 -03:00
|
|
|
// return true once for each update pushed in
|
2013-11-23 03:30:27 -04:00
|
|
|
new_data = true;
|
2011-10-28 15:52:50 -03:00
|
|
|
_updated = false;
|
|
|
|
return result;
|
2010-11-19 01:42:47 -04:00
|
|
|
}
|
|
|
|
|
2013-10-23 08:13:48 -03:00
|
|
|
void AP_GPS_HIL::setHIL(uint64_t _time_epoch_ms, float _latitude, float _longitude, float _altitude,
|
2011-10-28 15:52:50 -03:00
|
|
|
float _ground_speed, float _ground_course, float _speed_3d, uint8_t _num_sats)
|
2010-11-19 01:42:47 -04:00
|
|
|
{
|
2013-10-23 08:13:48 -03:00
|
|
|
time_week = _time_epoch_ms / (86400*7*(uint64_t)1000);
|
|
|
|
time_week_ms = _time_epoch_ms - time_week*(86400*7*(uint64_t)1000);
|
2013-01-10 14:42:24 -04:00
|
|
|
latitude = _latitude*1.0e7f;
|
|
|
|
longitude = _longitude*1.0e7f;
|
2013-07-10 01:01:53 -03:00
|
|
|
altitude_cm = _altitude*1.0e2f;
|
|
|
|
ground_speed_cm = _ground_speed*1.0e2f;
|
|
|
|
ground_course_cd = _ground_course*1.0e2f;
|
|
|
|
speed_3d_cm = _speed_3d*1.0e2f;
|
2012-08-17 03:19:44 -03:00
|
|
|
num_sats = _num_sats;
|
2013-03-25 04:24:14 -03:00
|
|
|
fix = FIX_3D;
|
2013-11-23 03:30:27 -04:00
|
|
|
hdop = 200;
|
2012-08-17 03:19:44 -03:00
|
|
|
_updated = true;
|
2010-11-19 01:42:47 -04:00
|
|
|
}
|
|
|
|
|