Skip to content
Snippets Groups Projects
Commit 947f8856 authored by Javier Laplaza Galindo's avatar Javier Laplaza Galindo
Browse files

Added static function to get fix

parent ffb6ace3
No related branches found
No related tags found
1 merge request!2Resolve "Enable Standard Point Positioning (SPP) computation"
This commit is part of merge request !2. Comments created here will be created in the context of that merge request.
#ifndef GNSS_UTILS_H
#define GNSS_UTILS_H
#include <vector>
#include <iostream>
#include <memory>
#include "observations.h"
#include "navigation.h"
extern "C"
{
#include "../deps/RTKLIB/src/rtklib.h"
}
namespace GNSSUtils
{
static int getPos(Observations obs, Navigation nav, sol_t sol);
}
#endif
#ifndef GNSS_UTILS_H
#define GNSS_UTILS_H
#include <vector>
#include <iostream>
#include <memory>
#include "observations.h"
#include "navigation.h"
extern "C"
{
#include "../deps/RTKLIB/src/rtklib.h"
}
namespace GNSSUtils
{
class Receiver
{
public:
// Public objects
// Constructor & Destructor
Receiver();
~Receiver();
// Public methods
const std::shared_ptr<GNSSUtils::Observations> getObs();
const std::shared_ptr<GNSSUtils::Navigation> getNav();
/* - Processing Options - */
void clearOptions();
void setOptions(prcopt_t opt);
prcopt_t getOptions();
/* - Solution - */
void clearSolution();
void setSolution(sol_t sol);
sol_t getSolution();
/* - Satellite status - */
void clearSatStatus();
void setSatStatus(ssat_t ssat);
ssat_t getSatStatus();
/* - Compute Fix - */
int computeSPP(double *azel, char *msg);
protected:
// Private objects
// GNSSUtils::Observation attribute to represent the different observation msgs for a given epoch
std::shared_ptr<GNSSUtils::Observations> obs_ptr_;
// GNSSUtils::Navigation attribute to represent the different navigation msgs for a given epoch
std::shared_ptr<GNSSUtils::Navigation> nav_ptr_;
// rtklib-like attribute to represent the different options for a given epoch
prcopt_t _opt;
// rtklib-like attribute to represent the solution for a given epoch
sol_t _sol;
// rtklib-like attribute to represent the satellite status for a given epoch
ssat_t _ssat;
// Private methods
};
}
#endif
...@@ -9,115 +9,101 @@ ...@@ -9,115 +9,101 @@
extern "C" extern "C"
{ {
#include "../deps/RTKLIB/src/rinex.c" #include "/home/jlaplaza/RTKLIB/src/rinex.c"
} }
using namespace GNSSUtils; using namespace GNSSUtils;
int createObsAndNav(Observations* observations, char* obs_path, Navigation* navigation, char* nav_path)
Observations createObs()
{ {
/* create an Observations object */ // Time
Observations observations; double ts_d[] = {2018, 5, 17, 14, 1, 2};
gtime_t ts = epoch2time(ts_d);
/* set _obsVector attribute */
int year=2018, month=5, day=17, hour=14, min=1, seconds=2;
double seconds_frac=0.002;
time_t te = {0};
gtime_t time = {te, seconds_frac};
obsd_t observation;
observation.time = time;
observation.sat = 25;
observation.rcv = 1;
observation.SNR[0] = 45;
observation.LLI[0] = 0; //??????????
observation.code[0] = 0; //?????????
observation.L[0] = 117441226.71621;
observation.P[0] = 22348322.550;
observation.D[0] = -3039.055;
observations.pushObservation(observation);
observation.time = time;
observation.sat = 29;
observation.rcv = 1;
observation.SNR[0] = 23;
observation.LLI[0] = 0; //??????????
observation.code[0] = 0; //?????????
// observation.L[0] = ;
observation.P[0] = 20873167.574;
observation.D[0] = -2449.652;
observations.pushObservation(observation);
observation.time = time;
observation.sat = 31;
observation.rcv = 1;
observation.SNR[0] = 39;
observation.LLI[0] = 0; //??????????
observation.code[0] = 0; //?????????
observation.L[0] = 109939061.00922;
observation.P[0] = 20920707.830;
observation.D[0] = -1587.315;
observations.pushObservation(observation);
observation.time = time;
observation.sat = 21;
observation.rcv = 1;
observation.SNR[0] = 37;
observation.LLI[0] = 0; //??????????
observation.code[0] = 0; //?????????
observation.L[0] = 113496465.14223;
observation.P[0] = 21597659.275;
observation.D[0] = 1343.465;
observations.pushObservation(observation);
return observations;
}
double te_d[] = {2018, 5, 17, 14, 42, 8};
gtime_t te = epoch2time(te_d);
double tint = 0.1;
Navigation createNav(char * nav_path) // Create options container
{ char* opt = "-SYS=G";
/* create a Navigation object */
Navigation navigation;
/* Load _nav attribute into nav variable */ // Create receiver identifier
nav_t nav = navigation.getNavigation(); int rcv = 1;
/* Open navigation file */ // Create object types
FILE *fp = fopen(nav_path,"r"); rnxopt_t rnx_opt;
/* Set constellation mask -SYS=sys[,sys...]: select navi systems (sys=G:GPS,R:GLO,E:GAL,J:QZS,C:BDS,S:SBS) */ // Create obsd_t object to hold the observations
char* opt = "-SYS=G"; obs_t obs;
obs.data = (obsd_t *) malloc(sizeof(obsd_t)*MAXSAT);
if (readrnx(obs_path, rcv, opt, &obs, NULL, NULL))
{
obs.data[0].P[0] = 22352029.710;
obs.data[1].P[0] = 20876138.578;
obs.data[2].P[0] = 20922649.533;
obs.data[3].P[0] = 24736002.147;
obs.data[4].P[0] = 21596022.619;
std::cout << "Obs number: " << obs.n << std::endl;
sortobs(&obs);
}
else
{
std::cout << "Couldn't load provided observation file" << std::endl;
return 0;
}
for (int i=0; i < obs.n; i++)
{
std::cout << "time: " << obs.data[i].time.time << " | sat: " << int(obs.data[i].sat) << " | rcv: " << obs.data[i].rcv <<
" | SNR: " << obs.data[i].SNR[0] << " | LLI: " << obs.data[i].LLI[0] << " | code: " << obs.data[i].code[0] <<
" | L: " << obs.data[i].L[0] << " | P: " << obs.data[i].P[0] << " | D: " << obs.data[i].D[0] << std::endl;
observations->pushObservation(obs.data[i]);
}
free(obs.data);
/* Read navigation file, SYS can be SYS_ALL, SYS_GPS, SYS_SBS, SYS_GLO, SYS_GAL, ... */
if (readrnxnav(fp, opt, 3.03, SYS_ALL, &nav)){ /* Load _nav attribute into nav variable */
nav_t nav = navigation->getNavigation();
if (readrnx(nav_path, rcv, opt, NULL, &nav, NULL))
{
std::cout << "Navigation file loaded" << std::endl; std::cout << "Navigation file loaded" << std::endl;
std::cout << "GPS satellites: " << nav.n << std::endl; std::cout << "GPS satellites: " << nav.n << std::endl;
std::cout << "GLONASS satellites: " << nav.ng << std::endl; std::cout << "GLONASS satellites: " << nav.ng << std::endl;
std::cout << "SBAS satellites: " << nav.ns << std::endl; std::cout << "SBAS satellites: " << nav.ns << std::endl;
std::cout << "Almanac satellites: " << nav.na << std::endl; std::cout << "Almanac satellites: " << nav.na << std::endl;
uniqnav(&nav);
} }
else { else
{
std::cout << "Couldn't load provided navigation file" << std::endl; std::cout << "Couldn't load provided navigation file" << std::endl;
return 0;
} }
/* Print Constellation Satellites ids */ /* Print Constellation Satellites ids */
for (int i=0;i<nav.n;i++) for (int i=0;i<nav.n;i++)
{ {
std::cout << i << "GPS/GAL Sat Id: " << nav.eph[i].sat << std::endl; std::cout << i << " GPS Sat Id: " << nav.eph[i].sat << std::endl;
} }
for (int i=0;i<nav.ng;i++) for (int i=0;i<nav.ng;i++)
{ {
std::cout << i << "GLONASS Sat Id: " << nav.geph[i].sat << std::endl; std::cout << i << " GLONASS Sat Id: " << nav.geph[i].sat << std::endl;
} }
for (int i=0;i<nav.ns;i++) for (int i=0;i<nav.ns;i++)
...@@ -126,18 +112,22 @@ Navigation createNav(char * nav_path) ...@@ -126,18 +112,22 @@ Navigation createNav(char * nav_path)
} }
navigation.setNavigation(nav); navigation->setNavigation(nav);
std::cout << "Navigation message loaded to Navigation class." << std::endl; std::cout << "Navigation message loaded to Navigation class." << std::endl;
//std::cout << navigation.getNavigation()->ns << std::endl;
return navigation;
return 1;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
/* header */ /* header */
...@@ -145,19 +135,24 @@ int main(int argc, char *argv[]) ...@@ -145,19 +135,24 @@ int main(int argc, char *argv[])
std::cout << "GNSS Utils Library Example" << std::endl; std::cout << "GNSS Utils Library Example" << std::endl;
std::cout << "--------------------------" << std::endl; std::cout << "--------------------------" << std::endl;
// Create Observations object
Observations observations = createObs();
std::cout << "_obsVector size: " << observations.getObservations().size() << std::endl; // create Observations object
Observations observations;
// create Navigation object
Navigation navigation;
// Create Navigation object createObsAndNav(&observations, "/home/jlaplaza/gitlab/gnss_utils/src/examples/raw_201805171357.obs" ,&navigation, "/home/jlaplaza/gitlab/gnss_utils/src/examples/raw_201805171357.nav");
Navigation navigation = createNav("../src/examples/raw_201805171357.nav");
//readrnx()
/* Set processing options */
prcopt_t prcopt = prcopt_default; nav_t nav2 = navigation.getNavigation();
std::cout << "Navigation eph number " << nav2.n << std::endl;
/* Set processing options */
prcopt_t prcopt = prcopt_default;
prcopt.mode = PMODE_SINGLE; prcopt.mode = PMODE_SINGLE;
prcopt.soltype = 0; prcopt.soltype = 0;
prcopt.nf = 1; prcopt.nf = 1;
...@@ -166,13 +161,18 @@ int main(int argc, char *argv[]) ...@@ -166,13 +161,18 @@ int main(int argc, char *argv[])
prcopt.sateph = EPHOPT_BRDC; prcopt.sateph = EPHOPT_BRDC;
prcopt.ionoopt = IONOOPT_OFF; prcopt.ionoopt = IONOOPT_OFF;
prcopt.tropopt = TROPOPT_OFF; prcopt.tropopt = TROPOPT_OFF;
prcopt.dynamics = 0;
prcopt.tidecorr = 0;
prcopt.sbascorr = SBSOPT_FCORR; prcopt.sbascorr = SBSOPT_FCORR;
prcopt.ru[0] = 4789374.0336;
prcopt.ru[1] = 177048.3292;
prcopt.ru[2] = 4194542.6444;
std::cout << "Processing options defined." << std::endl; std::cout << "Processing options defined" << std::endl;
//Compute fix //Compute fix
int stat; int stat;
sol_t solb={{0}}; sol_t solb={{0}};
...@@ -181,9 +181,13 @@ int main(int argc, char *argv[]) ...@@ -181,9 +181,13 @@ int main(int argc, char *argv[])
std::vector<obsd_t> obs = observations.getObservations(); std::vector<obsd_t> obs = observations.getObservations();
std::cout << "obs: " << obs[0].P[0] << std::endl;
nav_t nav = navigation.getNavigation(); nav_t nav = navigation.getNavigation();
stat = pntpos(&obs[0], obs.size(), &nav, &prcopt, &solb, NULL, NULL, msg); stat = pntpos(&(obs[0]), obs.size(), &nav, &prcopt, &solb, NULL, NULL, msg);
std::cout << "msg: " << msg << std::endl;
std::cout << "Stat: " << stat << std::endl; std::cout << "Stat: " << stat << std::endl;
......
src/getPos.cpp 0 → 100644
#include "../include/gnss_utils.h"
using namespace GNSSUtils;
static int getPos(Observations observations, Navigation navigation, sol_t sol)
{
// Define observations
std::vector<obsd_t> obs = observations.getObservations();
// Define navigation
nav_t nav = navigation.getNavigation();
// Define processing options
prcopt_t prcopt = prcopt_default;
prcopt.mode = PMODE_SINGLE;
prcopt.soltype = 0;
prcopt.nf = 1;
prcopt.navsys = SYS_GPS;
prcopt.elmin = 1.05; // 60 degrees = 1.05 rad
prcopt.sateph = EPHOPT_BRDC;
prcopt.ionoopt = IONOOPT_OFF;
prcopt.tropopt = TROPOPT_OFF;
prcopt.dynamics = 0;
prcopt.tidecorr = 0;
prcopt.sbascorr = SBSOPT_FCORR;
// Define solution
sol_t solb={{0}};
// Define error msg
char msg[128]="";
int stat = pntpos(&(obs[0]), obs.size(), &nav, &prcopt, &solb, NULL, NULL, msg);
return stat;
}
#include "../include/gnss_utils.h"
using namespace GNSSUtils;
/******************************* RECEIVER CLASS *******************************************/
Receiver::Receiver()
{
obs_ptr_ = std::make_shared<GNSSUtils::Observations>();
nav_ptr_ = std::make_shared<GNSSUtils::Navigation>();
}
Receiver::~Receiver()
{
}
const std::shared_ptr<GNSSUtils::Observations> Receiver::getObs()
{
// return obs_ptr_;
}
const std::shared_ptr<GNSSUtils::Navigation> Receiver::getNav()
{
// return nav_ptr_;
}
/* - Processing options - */
void Receiver::clearOptions()
{
//_opt = NULL;
}
void Receiver::setOptions(prcopt_t opt)
{
_opt = opt;
}
prcopt_t Receiver::getOptions()
{
return this->_opt;
}
/* - Solution - */
void Receiver::clearSolution()
{
//_sol = NULL;
}
void Receiver::setSolution(sol_t sol)
{
_sol = sol;
}
sol_t Receiver::getSolution()
{
return this->_sol;
}
/* - Satellite Status - */
void Receiver::clearSatStatus()
{
//_ssat = NULL;
}
void Receiver::setSatStatus(ssat_t ssat)
{
_ssat = ssat;
}
ssat_t Receiver::getSatStatus()
{
return this->_ssat;
}
/* - Compute Fix - */
int Receiver::computeSPP(double *azel, char *msg)
{
/*
const obsd_t *obs = &this->_obsVector[0];
int n = this->_obsVector.size();
const nav_t *nav = this->_nav;
const prcopt_t *opt = this->_opt;
sol_t *sol = this->_sol;
ssat_t *ssat = this->_ssat;
*/
// return pntpos(obs, n, &_nav, &_opt, &_sol, azel, &_ssat, msg);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment