2013-08-02 16:00:12 +00:00
|
|
|
/*!
|
|
|
|
* \file front_end_cal.cc
|
|
|
|
* \brief Implementation of the Front-end calibration program.
|
|
|
|
* \author Javier Arribas, 2013. jarribas(at)cttc.es
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2014-03-17 20:01:32 +00:00
|
|
|
* Copyright (C) 2010-2014 (see AUTHORS file for a list of contributors)
|
2013-08-02 16:00:12 +00:00
|
|
|
*
|
|
|
|
* GNSS-SDR is a software defined Global Navigation
|
|
|
|
* Satellite Systems receiver
|
|
|
|
*
|
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
|
|
|
* GNSS-SDR 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.
|
|
|
|
*
|
|
|
|
* GNSS-SDR 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 GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
2013-07-05 17:00:48 +00:00
|
|
|
|
2014-03-16 19:58:29 +00:00
|
|
|
#include "front_end_cal.h"
|
|
|
|
#include <cmath>
|
|
|
|
#include <ctime>
|
|
|
|
#include <memory>
|
2013-07-05 17:00:48 +00:00
|
|
|
#include <exception>
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
#include <gflags/gflags.h>
|
|
|
|
#include <glog/logging.h>
|
|
|
|
#include <boost/thread/mutex.hpp>
|
|
|
|
#include <boost/thread/thread.hpp>
|
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include "gps_navigation_message.h"
|
|
|
|
#include "gps_ephemeris.h"
|
|
|
|
#include "gps_almanac.h"
|
|
|
|
#include "gps_iono.h"
|
|
|
|
#include "gps_utc_model.h"
|
|
|
|
#include "gnss_sdr_supl_client.h"
|
|
|
|
|
2013-08-02 16:00:12 +00:00
|
|
|
extern concurrent_map<Gps_Ephemeris> global_gps_ephemeris_map;
|
|
|
|
extern concurrent_map<Gps_Iono> global_gps_iono_map;
|
|
|
|
extern concurrent_map<Gps_Utc_Model> global_gps_utc_model_map;
|
|
|
|
extern concurrent_map<Gps_Almanac> global_gps_almanac_map;
|
|
|
|
extern concurrent_map<Gps_Acq_Assist> global_gps_acq_assist_map;
|
2013-07-05 17:00:48 +00:00
|
|
|
|
|
|
|
FrontEndCal::FrontEndCal()
|
2013-08-02 16:00:12 +00:00
|
|
|
{}
|
2013-07-05 17:00:48 +00:00
|
|
|
|
|
|
|
FrontEndCal::~FrontEndCal()
|
2013-08-02 16:00:12 +00:00
|
|
|
{}
|
2013-07-05 17:00:48 +00:00
|
|
|
|
|
|
|
bool FrontEndCal::read_assistance_from_XML()
|
|
|
|
{
|
2013-08-02 16:00:12 +00:00
|
|
|
gnss_sdr_supl_client supl_client_ephemeris_;
|
|
|
|
std::string eph_xml_filename = "gps_ephemeris.xml";
|
2014-03-17 20:01:32 +00:00
|
|
|
std::cout << "SUPL: Trying to read GPS ephemeris from XML file " << eph_xml_filename << std::endl;
|
|
|
|
LOG(INFO) << "SUPL: Trying to read GPS ephemeris from XML file " << eph_xml_filename;
|
2013-08-02 16:00:12 +00:00
|
|
|
if (supl_client_ephemeris_.load_ephemeris_xml(eph_xml_filename) == true)
|
|
|
|
{
|
|
|
|
std::map<int,Gps_Ephemeris>::iterator gps_eph_iter;
|
|
|
|
for(gps_eph_iter = supl_client_ephemeris_.gps_ephemeris_map.begin();
|
|
|
|
gps_eph_iter != supl_client_ephemeris_.gps_ephemeris_map.end();
|
|
|
|
gps_eph_iter++)
|
|
|
|
{
|
|
|
|
std::cout << "SUPL: Read XML Ephemeris for GPS SV " << gps_eph_iter->first << std::endl;
|
2014-03-17 20:01:32 +00:00
|
|
|
LOG(INFO) << "SUPL: Read XML Ephemeris for GPS SV " << gps_eph_iter->first;
|
|
|
|
LOG(INFO) << "New Ephemeris record inserted with Toe=" << gps_eph_iter->second.d_Toe << " and GPS Week=" << gps_eph_iter->second.i_GPS_week;
|
2013-08-02 16:00:12 +00:00
|
|
|
global_gps_ephemeris_map.write(gps_eph_iter->second.i_satellite_PRN, gps_eph_iter->second);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-17 20:01:32 +00:00
|
|
|
std::cout << "ERROR: SUPL client error reading XML" << std::endl;
|
|
|
|
LOG(WARNING) << "ERROR: SUPL client error reading XML";
|
2013-08-02 16:00:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-07-05 17:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int FrontEndCal::Get_SUPL_Assist()
|
|
|
|
{
|
2014-03-17 20:01:32 +00:00
|
|
|
//######### GNSS Assistance #################################
|
2013-08-02 16:00:12 +00:00
|
|
|
gnss_sdr_supl_client supl_client_acquisition_;
|
|
|
|
gnss_sdr_supl_client supl_client_ephemeris_;
|
|
|
|
int supl_mcc; // Current network MCC (Mobile country code), 3 digits.
|
|
|
|
int supl_mns; //Current network MNC (Mobile Network code), 2 or 3 digits.
|
|
|
|
int supl_lac; // Current network LAC (Location area code),16 bits, 1-65520 are valid values.
|
|
|
|
int supl_ci; // Cell Identity (16 bits, 0-65535 are valid values).
|
2014-03-17 20:01:32 +00:00
|
|
|
|
2013-08-02 16:00:12 +00:00
|
|
|
// GNSS Assistance configuration
|
|
|
|
int error = 0;
|
|
|
|
bool enable_gps_supl_assistance = configuration_->property("GNSS-SDR.SUPL_gps_enabled", false);
|
|
|
|
if (enable_gps_supl_assistance == true)
|
|
|
|
//SUPL SERVER TEST. Not operational yet!
|
|
|
|
{
|
2014-03-17 20:01:32 +00:00
|
|
|
LOG(INFO) << "SUPL RRLP GPS assistance enabled!";
|
2013-08-02 16:00:12 +00:00
|
|
|
std::string default_acq_server = "supl.nokia.com";
|
|
|
|
std::string default_eph_server = "supl.google.com";
|
|
|
|
supl_client_ephemeris_.server_name = configuration_->property("GNSS-SDR.SUPL_gps_ephemeris_server", default_acq_server);
|
|
|
|
supl_client_acquisition_.server_name = configuration_->property("GNSS-SDR.SUPL_gps_acquisition_server", default_eph_server);
|
|
|
|
supl_client_ephemeris_.server_port = configuration_->property("GNSS-SDR.SUPL_gps_ephemeris_port", 7275);
|
|
|
|
supl_client_acquisition_.server_port = configuration_->property("GNSS-SDR.SUPL_gps_acquisition_port", 7275);
|
|
|
|
supl_mcc = configuration_->property("GNSS-SDR.SUPL_MCC", 244);
|
|
|
|
supl_mns = configuration_->property("GNSS-SDR.SUPL_MNS", 5);
|
|
|
|
|
|
|
|
std::string default_lac = "0x59e2";
|
|
|
|
std::string default_ci = "0x31b0";
|
|
|
|
try
|
|
|
|
{
|
|
|
|
supl_lac = boost::lexical_cast<int>(configuration_->property("GNSS-SDR.SUPL_LAC", default_lac));
|
|
|
|
}
|
|
|
|
catch(boost::bad_lexical_cast &)
|
|
|
|
{
|
|
|
|
supl_lac = 0x59e2;
|
|
|
|
}
|
|
|
|
try
|
|
|
|
{
|
|
|
|
supl_ci = boost::lexical_cast<int>(configuration_->property("GNSS-SDR.SUPL_CI", default_ci));
|
|
|
|
}
|
|
|
|
catch(boost::bad_lexical_cast &)
|
|
|
|
{
|
|
|
|
supl_ci = 0x31b0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SUPL_read_gps_assistance_xml = configuration_->property("GNSS-SDR.SUPL_read_gps_assistance_xml", false);
|
|
|
|
if (SUPL_read_gps_assistance_xml == true)
|
|
|
|
{
|
|
|
|
// read assistance from file
|
|
|
|
read_assistance_from_XML();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Request ephemeris from SUPL server
|
|
|
|
supl_client_ephemeris_.request = 1;
|
2014-03-17 20:01:32 +00:00
|
|
|
LOG(INFO) << "SUPL: Trying to read GPS ephemeris from SUPL server...";
|
|
|
|
std::cout << "SUPL: Trying to read GPS ephemeris from SUPL server..." << std::endl;
|
2013-08-02 16:00:12 +00:00
|
|
|
error = supl_client_ephemeris_.get_assistance(supl_mcc, supl_mns, supl_lac, supl_ci);
|
|
|
|
if (error == 0)
|
|
|
|
{
|
|
|
|
std::map<int,Gps_Ephemeris>::iterator gps_eph_iter;
|
|
|
|
for(gps_eph_iter = supl_client_ephemeris_.gps_ephemeris_map.begin();
|
|
|
|
gps_eph_iter != supl_client_ephemeris_.gps_ephemeris_map.end();
|
|
|
|
gps_eph_iter++)
|
|
|
|
{
|
2014-03-17 20:01:32 +00:00
|
|
|
LOG(INFO) << "SUPL: Received Ephemeris for GPS SV " << gps_eph_iter->first;
|
|
|
|
std::cout << "SUPL: Received Ephemeris for GPS SV " << gps_eph_iter->first << std::endl;
|
|
|
|
LOG(INFO) << "New Ephemeris record inserted with Toe=" << gps_eph_iter->second.d_Toe << " and GPS Week=" << gps_eph_iter->second.i_GPS_week;
|
2013-08-02 16:00:12 +00:00
|
|
|
global_gps_ephemeris_map.write(gps_eph_iter->second.i_satellite_PRN, gps_eph_iter->second);
|
|
|
|
}
|
|
|
|
//Save ephemeris to XML file
|
|
|
|
std::string eph_xml_filename = "gps_ephemeris.xml";
|
|
|
|
if (supl_client_ephemeris_.save_ephemeris_xml(eph_xml_filename) == true)
|
|
|
|
{
|
2014-03-17 20:01:32 +00:00
|
|
|
LOG(INFO) << "SUPL: XML Ephemeris file created.";
|
2013-08-02 16:00:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-17 20:01:32 +00:00
|
|
|
LOG(WARNING) << "ERROR: SUPL client for Ephemeris returned " << error;
|
|
|
|
std::cout << "ERROR in SUPL client. Please check your Internet connection and SUPL server configuration" << std::endl;
|
2013-08-02 16:00:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Request almanac , IONO and UTC Model
|
|
|
|
supl_client_ephemeris_.request = 0;
|
2014-03-17 20:01:32 +00:00
|
|
|
LOG(INFO) << "SUPL: Try read Almanac, Iono, Utc Model, Ref Time and Ref Location from SUPL server...";
|
2013-08-02 16:00:12 +00:00
|
|
|
error = supl_client_ephemeris_.get_assistance(supl_mcc, supl_mns, supl_lac, supl_ci);
|
|
|
|
if (error == 0)
|
|
|
|
{
|
|
|
|
std::map<int,Gps_Almanac>::iterator gps_alm_iter;
|
|
|
|
for(gps_alm_iter = supl_client_ephemeris_.gps_almanac_map.begin();
|
|
|
|
gps_alm_iter != supl_client_ephemeris_.gps_almanac_map.end();
|
|
|
|
gps_alm_iter++)
|
|
|
|
{
|
2014-03-17 20:01:32 +00:00
|
|
|
LOG(INFO) << "SUPL: Received Almanac for GPS SV " << gps_alm_iter->first;
|
|
|
|
std::cout << "SUPL: Received Almanac for GPS SV " << gps_alm_iter->first << std::endl;
|
2013-08-02 16:00:12 +00:00
|
|
|
global_gps_almanac_map.write(gps_alm_iter->first, gps_alm_iter->second);
|
|
|
|
}
|
|
|
|
if (supl_client_ephemeris_.gps_iono.valid == true)
|
|
|
|
{
|
2014-03-17 20:01:32 +00:00
|
|
|
LOG(INFO) << "SUPL: Received GPS Iono";
|
|
|
|
std::cout << "SUPL: Received GPS Iono" << std::endl;
|
2013-08-02 16:00:12 +00:00
|
|
|
global_gps_iono_map.write(0,supl_client_ephemeris_.gps_iono);
|
|
|
|
}
|
|
|
|
if (supl_client_ephemeris_.gps_utc.valid == true)
|
|
|
|
{
|
2014-03-17 20:01:32 +00:00
|
|
|
LOG(INFO) << "SUPL: Received GPS UTC Model";
|
|
|
|
std::cout << "SUPL: Received GPS UTC Model" << std::endl;
|
2013-08-02 16:00:12 +00:00
|
|
|
global_gps_utc_model_map.write(0, supl_client_ephemeris_.gps_utc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-17 20:01:32 +00:00
|
|
|
LOG(WARNING) << "ERROR: SUPL client for Almanac returned " << error;
|
|
|
|
std::cout << "ERROR in SUPL client. Please check your Internet connection and SUPL server configuration" << std::endl;
|
2013-08-02 16:00:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Request acquisition assistance
|
|
|
|
supl_client_acquisition_.request = 2;
|
2014-03-17 20:01:32 +00:00
|
|
|
LOG(INFO) << "SUPL: Trying to read Acquisition assistance from SUPL server...";
|
|
|
|
std::cout << "SUPL: Trying to read Acquisition assistance from SUPL server..." << std::endl;
|
2013-08-02 16:00:12 +00:00
|
|
|
|
|
|
|
error = supl_client_acquisition_.get_assistance(supl_mcc, supl_mns, supl_lac, supl_ci);
|
|
|
|
if (error == 0)
|
|
|
|
{
|
|
|
|
std::map<int,Gps_Acq_Assist>::iterator gps_acq_iter;
|
|
|
|
for(gps_acq_iter = supl_client_acquisition_.gps_acq_map.begin();
|
|
|
|
gps_acq_iter != supl_client_acquisition_.gps_acq_map.end();
|
|
|
|
gps_acq_iter++)
|
|
|
|
{
|
2014-03-17 20:01:32 +00:00
|
|
|
LOG(INFO) << "SUPL: Received Acquisition assistance for GPS SV " << gps_acq_iter->first;
|
|
|
|
std::cout << "SUPL: Received Acquisition assistance for GPS SV " << gps_acq_iter->first << std::endl;
|
|
|
|
LOG(INFO) << "New acq assist record inserted";
|
2013-08-02 16:00:12 +00:00
|
|
|
global_gps_acq_assist_map.write(gps_acq_iter->second.i_satellite_PRN, gps_acq_iter->second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-17 20:01:32 +00:00
|
|
|
LOG(WARNING) << "ERROR: SUPL client for Acquisition assistance returned " << error;
|
|
|
|
std::cout << "ERROR in SUPL client. Please check your Internet connection and SUPL server configuration" << std::endl;
|
2013-08-02 16:00:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return error;
|
2013-07-05 17:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-03 21:59:14 +00:00
|
|
|
void FrontEndCal::set_configuration(std::shared_ptr<ConfigurationInterface> configuration)
|
2013-07-05 17:00:48 +00:00
|
|
|
{
|
2013-08-02 16:00:12 +00:00
|
|
|
configuration_ = configuration;
|
2013-07-05 17:00:48 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 16:00:12 +00:00
|
|
|
|
2013-07-30 10:53:45 +00:00
|
|
|
bool FrontEndCal::get_ephemeris()
|
2013-07-05 17:00:48 +00:00
|
|
|
{
|
2014-03-17 20:01:32 +00:00
|
|
|
bool read_ephemeris_from_xml = configuration_->property("GNSS-SDR.read_eph_from_xml", false);
|
2013-08-02 16:00:12 +00:00
|
|
|
|
|
|
|
if (read_ephemeris_from_xml == true)
|
|
|
|
{
|
|
|
|
std::cout << "Trying to read ephemeris from XML file..." << std::endl;
|
2014-03-17 20:01:32 +00:00
|
|
|
LOG(INFO) << "Trying to read ephemeris from XML file...";
|
2013-08-02 16:00:12 +00:00
|
|
|
if (read_assistance_from_XML() == false)
|
|
|
|
{
|
2014-03-17 20:01:32 +00:00
|
|
|
std::cout << "ERROR: Could not read Ephemeris file: Trying to get ephemeris from SUPL server..." << std::endl;
|
|
|
|
LOG(INFO) << "ERROR: Could not read Ephemeris file: Trying to get ephemeris from SUPL server...";
|
2013-08-02 16:00:12 +00:00
|
|
|
if (Get_SUPL_Assist() == 1)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-17 20:01:32 +00:00
|
|
|
std::cout << "Trying to read ephemeris from SUPL server..." << std::endl;
|
|
|
|
LOG(INFO) << "Trying to read ephemeris from SUPL server...";
|
2013-08-02 16:00:12 +00:00
|
|
|
if (Get_SUPL_Assist() == 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-07-05 17:00:48 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 16:00:12 +00:00
|
|
|
|
2013-07-05 17:00:48 +00:00
|
|
|
arma::vec FrontEndCal::lla2ecef(arma::vec lla)
|
|
|
|
{
|
2013-08-02 16:00:12 +00:00
|
|
|
// WGS84 flattening
|
2014-03-17 20:01:32 +00:00
|
|
|
double f = 1/298.257223563;
|
2013-07-05 17:00:48 +00:00
|
|
|
|
2013-08-02 16:00:12 +00:00
|
|
|
// WGS84 equatorial radius
|
2014-03-17 20:01:32 +00:00
|
|
|
double R = 6378137;
|
2013-07-05 17:00:48 +00:00
|
|
|
|
2013-08-02 16:00:12 +00:00
|
|
|
arma::vec ellipsoid = "0.0 0.0";
|
2014-03-17 20:01:32 +00:00
|
|
|
double phi = (lla(0)/360.0) * GPS_TWO_PI;
|
|
|
|
double lambda = (lla(1)/360.0) * GPS_TWO_PI;
|
2013-07-05 17:00:48 +00:00
|
|
|
|
2013-08-02 16:00:12 +00:00
|
|
|
ellipsoid(0) = R;
|
|
|
|
ellipsoid(1) = sqrt(1-(1-f)*(1-f));
|
2013-07-05 17:00:48 +00:00
|
|
|
|
2013-08-02 16:00:12 +00:00
|
|
|
arma::vec ecef = "0.0 0.0 0.0 0.0";
|
|
|
|
ecef = geodetic2ecef(phi, lambda, lla(3), ellipsoid);
|
2013-07-05 17:00:48 +00:00
|
|
|
|
2013-08-02 16:00:12 +00:00
|
|
|
return ecef;
|
2013-07-05 17:00:48 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 16:00:12 +00:00
|
|
|
|
2013-07-05 17:00:48 +00:00
|
|
|
arma::vec FrontEndCal::geodetic2ecef(double phi, double lambda, double h, arma::vec ellipsoid)
|
|
|
|
{
|
2014-03-17 20:01:32 +00:00
|
|
|
double a = ellipsoid(0);
|
|
|
|
double e2 = ellipsoid(1)*ellipsoid(1);
|
|
|
|
double sinphi = sin(phi);
|
|
|
|
double cosphi = cos(phi);
|
|
|
|
double N = a / sqrt(1 - e2 * sinphi*sinphi);
|
2013-08-02 16:00:12 +00:00
|
|
|
arma::vec ecef = "0.0 0.0 0.0 0.0";
|
2013-07-05 17:00:48 +00:00
|
|
|
|
2013-08-02 16:00:12 +00:00
|
|
|
ecef(0) = (N + h) * cosphi * cos(lambda);
|
|
|
|
ecef(1) = (N + h) * cosphi * sin(lambda);
|
|
|
|
ecef(2) = (N*(1 - e2) + h) * sinphi;
|
2013-07-05 17:00:48 +00:00
|
|
|
|
2013-08-02 16:00:12 +00:00
|
|
|
return ecef;
|
2013-07-05 17:00:48 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 16:00:12 +00:00
|
|
|
|
2013-07-05 17:00:48 +00:00
|
|
|
double FrontEndCal::estimate_doppler_from_eph(unsigned int PRN, double TOW, double lat, double lon, double height)
|
|
|
|
{
|
2013-08-02 16:00:12 +00:00
|
|
|
int num_secs = 10;
|
|
|
|
double step_secs = 0.5;
|
|
|
|
|
2014-03-17 20:01:32 +00:00
|
|
|
// Observer position ECEF
|
2013-08-02 16:00:12 +00:00
|
|
|
arma::vec obs_ecef = "0.0 0.0 0.0 0.0";
|
|
|
|
arma::vec lla = "0.0 0.0 0.0 0.0";
|
|
|
|
lla(0) = lat;
|
|
|
|
lla(1) = lon;
|
|
|
|
lla(2) = height;
|
|
|
|
obs_ecef = lla2ecef(lla);
|
|
|
|
|
2014-03-17 20:01:32 +00:00
|
|
|
// Satellite positions ECEF
|
2013-08-02 16:00:12 +00:00
|
|
|
std::map<int,Gps_Ephemeris> eph_map;
|
|
|
|
eph_map = global_gps_ephemeris_map.get_map_copy();
|
|
|
|
|
|
|
|
std::map<int,Gps_Ephemeris>::iterator eph_it;
|
|
|
|
eph_it = eph_map.find(PRN);
|
|
|
|
|
|
|
|
if (eph_it!=eph_map.end())
|
|
|
|
{
|
|
|
|
arma::vec SV_pos_ecef = "0.0 0.0 0.0 0.0";
|
|
|
|
double obs_time_start, obs_time_stop;
|
|
|
|
obs_time_start = TOW - num_secs/2;
|
|
|
|
obs_time_stop = TOW + num_secs/2;
|
|
|
|
int n_points = round((obs_time_stop - obs_time_start)/step_secs);
|
|
|
|
arma::vec ranges = arma::zeros(n_points, 1);
|
|
|
|
double obs_time = obs_time_start;
|
|
|
|
for (int i=0; i<n_points; i++)
|
|
|
|
{
|
|
|
|
eph_it->second.satellitePosition(obs_time);
|
|
|
|
SV_pos_ecef(0) = eph_it->second.d_satpos_X;
|
|
|
|
SV_pos_ecef(1) = eph_it->second.d_satpos_Y;
|
|
|
|
SV_pos_ecef(2) = eph_it->second.d_satpos_Z;
|
|
|
|
// SV distances to observer (true range)
|
2014-03-17 20:01:32 +00:00
|
|
|
ranges(i) = arma::norm(SV_pos_ecef - obs_ecef, 2);
|
2013-08-02 16:00:12 +00:00
|
|
|
obs_time += step_secs;
|
|
|
|
}
|
|
|
|
// Observer to satellite radial velocity
|
|
|
|
// Numeric derivative: Positive slope means that the distance from obs to
|
|
|
|
// satellite is increasing
|
|
|
|
arma::vec obs_to_sat_velocity;
|
2014-03-17 20:01:32 +00:00
|
|
|
obs_to_sat_velocity = (ranges.subvec(1, (n_points - 1)) - ranges.subvec(0, (n_points - 2)))/step_secs;
|
2013-08-02 16:00:12 +00:00
|
|
|
// Doppler equations are formulated accounting for positive velocities if the
|
|
|
|
// tx and rx are approaching to each other. So, the satellite velocity must
|
|
|
|
// be redefined as:
|
|
|
|
obs_to_sat_velocity = -obs_to_sat_velocity;
|
|
|
|
|
|
|
|
//Doppler estimation
|
|
|
|
arma::vec Doppler_Hz;
|
|
|
|
Doppler_Hz = (obs_to_sat_velocity/GPS_C_m_s)*GPS_L1_FREQ_HZ;
|
|
|
|
double mean_Doppler_Hz;
|
|
|
|
mean_Doppler_Hz = arma::mean(Doppler_Hz);
|
|
|
|
return mean_Doppler_Hz;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw(1);
|
|
|
|
}
|
2013-07-05 17:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-02 16:00:12 +00:00
|
|
|
void FrontEndCal::GPS_L1_front_end_model_E4000(double f_bb_true_Hz, double f_bb_meas_Hz, double fs_nominal_hz, double *estimated_fs_Hz, double *estimated_f_if_Hz, double *f_osc_err_ppm)
|
|
|
|
{
|
2014-03-17 20:01:32 +00:00
|
|
|
const double f_osc_n = 28.8e6;
|
2013-08-02 16:00:12 +00:00
|
|
|
//PLL registers settings (according to E4000 datasheet)
|
2014-03-17 20:01:32 +00:00
|
|
|
const double N = 109;
|
|
|
|
const double Y = 65536;
|
|
|
|
const double X = 26487;
|
|
|
|
const double R = 2;
|
2013-08-02 16:00:12 +00:00
|
|
|
|
|
|
|
// Obtained RF center frequency
|
2014-03-17 20:01:32 +00:00
|
|
|
double f_rf_pll = (f_osc_n*(N+X/Y))/R;
|
|
|
|
|
2013-08-02 16:00:12 +00:00
|
|
|
// RF frequency error caused by fractional PLL roundings
|
2014-03-17 20:01:32 +00:00
|
|
|
double f_bb_err_pll = GPS_L1_FREQ_HZ - f_rf_pll;
|
2013-08-02 16:00:12 +00:00
|
|
|
|
|
|
|
// Measured F_rf error
|
2014-03-17 20:01:32 +00:00
|
|
|
double f_rf_err = (f_bb_meas_Hz - f_bb_true_Hz) - f_bb_err_pll;
|
|
|
|
double f_osc_err_hz = (f_rf_err*R)/(N+X/Y);
|
2013-08-02 16:00:12 +00:00
|
|
|
|
|
|
|
// OJO,segun los datos gnss, la IF positiva hace disminuir la fs!!
|
|
|
|
f_osc_err_hz = -f_osc_err_hz;
|
|
|
|
*f_osc_err_ppm = f_osc_err_hz/(f_osc_n/1e6);
|
|
|
|
|
2014-03-17 20:01:32 +00:00
|
|
|
double frac = fs_nominal_hz/f_osc_n;
|
2013-08-02 16:00:12 +00:00
|
|
|
*estimated_fs_Hz = frac*(f_osc_n + f_osc_err_hz);
|
|
|
|
*estimated_f_if_Hz = f_rf_err;
|
2013-07-05 17:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|