1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-15 12:40:35 +00:00

Modify sample counter

This commit is contained in:
Antonio Ramos 2018-02-13 18:16:03 +01:00
parent 057d19d98e
commit 8885333aa7
8 changed files with 287 additions and 264 deletions

View File

@ -33,39 +33,38 @@
#include "gnss_synchro.h"
#include <gnuradio/io_signature.h>
gnss_sdr_sample_counter::gnss_sdr_sample_counter () : gr::sync_block("sample_counter",
gr::io_signature::make(1, 1, sizeof(Gnss_Synchro)),
gr::io_signature::make(0,0,0))
gnss_sdr_sample_counter::gnss_sdr_sample_counter (double _fs) : gr::sync_decimator("sample_counter",
gr::io_signature::make(1, 1, sizeof(gr_complex)),
gr::io_signature::make(1, 1, sizeof(Gnss_Synchro)), floor(_fs*0.001))
{
this->message_port_register_out(pmt::mp("sample_counter"));
last_T_rx_s = 0;
report_interval_s = 1;//default reporting 1 second
current_T_rx_ms = 0;
report_interval_ms = 1000;//default reporting 1 second
flag_enable_send_msg = false; //enable it for reporting time with asynchronous message
}
gnss_sdr_sample_counter_sptr gnss_sdr_make_sample_counter ()
gnss_sdr_sample_counter_sptr gnss_sdr_make_sample_counter (double _fs)
{
gnss_sdr_sample_counter_sptr sample_counter_(new gnss_sdr_sample_counter());
gnss_sdr_sample_counter_sptr sample_counter_(new gnss_sdr_sample_counter(_fs));
return sample_counter_;
}
int gnss_sdr_sample_counter::work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items __attribute__((unused)))
int gnss_sdr_sample_counter::work (int noutput_items __attribute__((unused)),
gr_vector_const_void_star &input_items __attribute__((unused)),
gr_vector_void_star &output_items)
{
const Gnss_Synchro *in = reinterpret_cast<const Gnss_Synchro *>(input_items[0]); // input
double current_T_rx_s = in[noutput_items - 1].Tracking_sample_counter / static_cast<double>(in[noutput_items - 1].fs);
if ((current_T_rx_s - last_T_rx_s) > report_interval_s)
Gnss_Synchro* out = reinterpret_cast<Gnss_Synchro*>(output_items[0]);
out[0] = Gnss_Synchro();
if ((current_T_rx_ms % report_interval_ms) == 0)
{
std::cout << "Current receiver time: " << static_cast<double>(current_T_rx_ms) / 1000.0 << " [s]" << std::endl;
if(flag_enable_send_msg == true)
{
std::cout << "Current receiver time: " << floor(current_T_rx_s) << " [s]" << std::endl;
if(flag_enable_send_msg == true)
{
this->message_port_pub(pmt::mp("receiver_time"), pmt::from_double(current_T_rx_s));
}
last_T_rx_s = current_T_rx_s;
this->message_port_pub(pmt::mp("receiver_time"), pmt::from_double(static_cast<double>(current_T_rx_ms) / 1000.0));
}
return noutput_items;
}
current_T_rx_ms++;
return 1;
}

View File

@ -31,7 +31,7 @@
#ifndef GNSS_SDR_sample_counter_H_
#define GNSS_SDR_sample_counter_H_
#include <gnuradio/sync_block.h>
#include <gnuradio/sync_decimator.h>
#include <boost/shared_ptr.hpp>
@ -39,14 +39,14 @@ class gnss_sdr_sample_counter;
typedef boost::shared_ptr<gnss_sdr_sample_counter> gnss_sdr_sample_counter_sptr;
gnss_sdr_sample_counter_sptr gnss_sdr_make_sample_counter ();
gnss_sdr_sample_counter_sptr gnss_sdr_make_sample_counter (double _fs);
class gnss_sdr_sample_counter : public gr::sync_block
class gnss_sdr_sample_counter : public gr::sync_decimator
{
friend gnss_sdr_sample_counter_sptr gnss_sdr_make_sample_counter();
gnss_sdr_sample_counter ();
double last_T_rx_s;
double report_interval_s;
friend gnss_sdr_sample_counter_sptr gnss_sdr_make_sample_counter(double _fs);
gnss_sdr_sample_counter (double _fs);
long long int current_T_rx_ms;
int report_interval_ms;
bool flag_enable_send_msg;
public:

View File

@ -57,10 +57,10 @@ HybridObservables::HybridObservables(ConfigurationInterface* configuration,
}
else
{
default_depth = 500;
default_depth = 100;
}
unsigned int history_deep = configuration->property(role + ".history_depth", default_depth);
observables_ = hybrid_make_observables_cc(in_streams_, dump_, dump_filename_, history_deep);
observables_ = hybrid_make_observables_cc(in_streams_, out_streams_, dump_, dump_filename_, history_deep);
DLOG(INFO) << "pseudorange(" << observables_->unique_id() << ")";
}

View File

@ -47,19 +47,19 @@
using google::LogMessage;
hybrid_observables_cc_sptr hybrid_make_observables_cc(unsigned int nchannels, bool dump, std::string dump_filename, unsigned int deep_history)
hybrid_observables_cc_sptr hybrid_make_observables_cc(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, std::string dump_filename, unsigned int deep_history)
{
return hybrid_observables_cc_sptr(new hybrid_observables_cc(nchannels, dump, dump_filename, deep_history));
return hybrid_observables_cc_sptr(new hybrid_observables_cc(nchannels_in, nchannels_out, dump, dump_filename, deep_history));
}
hybrid_observables_cc::hybrid_observables_cc(unsigned int nchannels, bool dump, std::string dump_filename, unsigned int deep_history) :
gr::block("hybrid_observables_cc", gr::io_signature::make(nchannels, nchannels, sizeof(Gnss_Synchro)),
gr::io_signature::make(nchannels, nchannels, sizeof(Gnss_Synchro)))
hybrid_observables_cc::hybrid_observables_cc(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, std::string dump_filename, unsigned int deep_history) :
gr::block("hybrid_observables_cc", gr::io_signature::make(nchannels_in, nchannels_in, sizeof(Gnss_Synchro)),
gr::io_signature::make(nchannels_out, nchannels_out, sizeof(Gnss_Synchro)))
{
// initialize internal vars
d_dump = dump;
d_nchannels = nchannels;
d_nchannels = nchannels_out;
d_dump_filename = dump_filename;
history_deep = deep_history;
T_rx_s = 0.0;
@ -328,21 +328,13 @@ bool Hybrid_valueCompare_gnss_synchro_d_TOW(const Gnss_Synchro& a, double b)
void hybrid_observables_cc::forecast (int noutput_items __attribute__((unused)), gr_vector_int &ninput_items_required)
{
bool zero_samples = true;
for(unsigned int i = 0; i < d_nchannels; i++)
{
int items = detail()->input(i)->items_available();
if (items > 0) zero_samples = false;
ninput_items_required[i] = items; // set the required available samples in each call
}
if (zero_samples == true)
{
for(unsigned int i = 0; i < d_nchannels; i++)
{
ninput_items_required[i] = 1; // set the required available samples in each call
}
}
{
ninput_items_required[i] = 0;
//std::cout << "IN buffer "<< i << ". Number of items " << detail()->input(i)->items_available() << std::endl;
}
//std::cout << "SC buffer. Number of items " << detail()->input(d_nchannels)->items_available() << std::endl;
ninput_items_required[d_nchannels] = 1; // set the required available samples in each call
}
@ -360,239 +352,252 @@ int hybrid_observables_cc::general_work (int noutput_items ,
Gnss_Synchro current_gnss_synchro[d_nchannels];
Gnss_Synchro aux = Gnss_Synchro();
for(unsigned int i = 0; i < d_nchannels; i++)
{
current_gnss_synchro[i] = aux;
}
{
current_gnss_synchro[i] = aux;
}
/*
* 1. Read the GNSS SYNCHRO objects from available channels.
* Multi-rate GNURADIO Block. Read how many input items are avaliable in each channel
* Record all synchronization data into queues
*/
for (unsigned int i = 0; i < d_nchannels; i++)
{
n_consume[i] = ninput_items[i]; // full throttle
for (int j = 0; j < n_consume[i]; j++)
{
n_consume[i] = ninput_items[i]; // full throttle
for (int j = 0; j < n_consume[i]; j++)
{
d_gnss_synchro_history_queue[i].push_back(in[i][j]);
}
d_gnss_synchro_history_queue[i].push_back(in[i][j]);
}
}
bool channel_history_ok;
do
{
channel_history_ok = true;
for (unsigned int i = 0; i < d_nchannels; i++)
{
channel_history_ok = true;
if (d_gnss_synchro_history_queue[i].size() < history_deep && !d_gnss_synchro_history_queue[i].empty())
{
channel_history_ok = false;
}
}
if (channel_history_ok == true)
{
std::map<int,Gnss_Synchro>::const_iterator gnss_synchro_map_iter;
std::deque<Gnss_Synchro>::const_iterator gnss_synchro_deque_iter;
// 1. If the RX time is not set, set the Rx time
if (T_rx_s == 0)
{
// 0. Read a gnss_synchro snapshot from the queue and store it in a map
std::map<int,Gnss_Synchro> gnss_synchro_map;
for (unsigned int i = 0; i < d_nchannels; i++)
{
if (!d_gnss_synchro_history_queue[i].empty())
{
gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(d_gnss_synchro_history_queue[i].front().Channel_ID,
d_gnss_synchro_history_queue[i].front()));
}
}
if (gnss_synchro_map.empty()) break;
gnss_synchro_map_iter = min_element(gnss_synchro_map.cbegin(),
gnss_synchro_map.cend(),
Hybrid_pairCompare_gnss_synchro_sample_counter);
T_rx_s = static_cast<double>(gnss_synchro_map_iter->second.Tracking_sample_counter) / static_cast<double>(gnss_synchro_map_iter->second.fs);
T_rx_s = floor(T_rx_s * 1000.0) / 1000.0; // truncate to ms
T_rx_s += past_history_s; // increase T_rx to have a minimum past history to interpolate
}
// 2. Realign RX time in all valid channels
std::map<int,Gnss_Synchro> realigned_gnss_synchro_map; // container for the aligned set of observables for the selected T_rx
std::map<int,Gnss_Synchro> adjacent_gnss_synchro_map; // container for the previous observable values to interpolate
// shift channels history to match the reference TOW
for (unsigned int i = 0; i < d_nchannels; i++)
{
if (!d_gnss_synchro_history_queue[i].empty())
{
if (d_gnss_synchro_history_queue[i].size() < history_deep)
gnss_synchro_deque_iter = std::lower_bound(d_gnss_synchro_history_queue[i].cbegin(),
d_gnss_synchro_history_queue[i].cend(),
T_rx_s,
Hybrid_valueCompare_gnss_synchro_receiver_time);
if (gnss_synchro_deque_iter != d_gnss_synchro_history_queue[i].cend())
{
if (gnss_synchro_deque_iter->Flag_valid_word == true)
{
channel_history_ok = false;
}
}
if (channel_history_ok == true)
{
std::map<int,Gnss_Synchro>::const_iterator gnss_synchro_map_iter;
std::deque<Gnss_Synchro>::const_iterator gnss_synchro_deque_iter;
double T_rx_channel = static_cast<double>(gnss_synchro_deque_iter->Tracking_sample_counter) / static_cast<double>(gnss_synchro_deque_iter->fs);
double delta_T_rx_s = T_rx_channel - T_rx_s;
// 1. If the RX time is not set, set the Rx time
if (T_rx_s == 0)
{
// 0. Read a gnss_synchro snapshot from the queue and store it in a map
std::map<int,Gnss_Synchro> gnss_synchro_map;
for (unsigned int i = 0; i < d_nchannels; i++)
// check that T_rx difference is less than a threshold (the correlation interval)
if (delta_T_rx_s * 1000.0 < static_cast<double>(gnss_synchro_deque_iter->correlation_length_ms))
{
// record the word structure in a map for pseudorange computation
// save the previous observable
int distance = std::distance(d_gnss_synchro_history_queue[i].cbegin(), gnss_synchro_deque_iter);
if (distance > 0)
{
gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(d_gnss_synchro_history_queue[i].front().Channel_ID,
d_gnss_synchro_history_queue[i].front()));
}
gnss_synchro_map_iter = min_element(gnss_synchro_map.cbegin(),
gnss_synchro_map.cend(),
Hybrid_pairCompare_gnss_synchro_sample_counter);
T_rx_s = static_cast<double>(gnss_synchro_map_iter->second.Tracking_sample_counter) / static_cast<double>(gnss_synchro_map_iter->second.fs);
T_rx_s = floor(T_rx_s * 1000.0) / 1000.0; // truncate to ms
T_rx_s += past_history_s; // increase T_rx to have a minimum past history to interpolate
}
// 2. Realign RX time in all valid channels
std::map<int,Gnss_Synchro> realigned_gnss_synchro_map; // container for the aligned set of observables for the selected T_rx
std::map<int,Gnss_Synchro> adjacent_gnss_synchro_map; // container for the previous observable values to interpolate
// shift channels history to match the reference TOW
for (unsigned int i = 0; i < d_nchannels; i++)
{
gnss_synchro_deque_iter = std::lower_bound(d_gnss_synchro_history_queue[i].cbegin(),
d_gnss_synchro_history_queue[i].cend(),
T_rx_s,
Hybrid_valueCompare_gnss_synchro_receiver_time);
if (gnss_synchro_deque_iter != d_gnss_synchro_history_queue[i].cend())
{
if (gnss_synchro_deque_iter->Flag_valid_word == true)
if (d_gnss_synchro_history_queue[i].at(distance - 1).Flag_valid_word)
{
double T_rx_channel_prev = static_cast<double>(d_gnss_synchro_history_queue[i].at(distance - 1).Tracking_sample_counter) / static_cast<double>(gnss_synchro_deque_iter->fs);
double delta_T_rx_s_prev = T_rx_channel_prev - T_rx_s;
if (fabs(delta_T_rx_s_prev) < fabs(delta_T_rx_s))
{
double T_rx_channel = static_cast<double>(gnss_synchro_deque_iter->Tracking_sample_counter) / static_cast<double>(gnss_synchro_deque_iter->fs);
double delta_T_rx_s = T_rx_channel - T_rx_s;
// check that T_rx difference is less than a threshold (the correlation interval)
if (delta_T_rx_s * 1000.0 < static_cast<double>(gnss_synchro_deque_iter->correlation_length_ms))
{
// record the word structure in a map for pseudorange computation
// save the previous observable
int distance = std::distance(d_gnss_synchro_history_queue[i].cbegin(), gnss_synchro_deque_iter);
if (distance > 0)
{
if (d_gnss_synchro_history_queue[i].at(distance - 1).Flag_valid_word)
{
double T_rx_channel_prev = static_cast<double>(d_gnss_synchro_history_queue[i].at(distance - 1).Tracking_sample_counter) / static_cast<double>(gnss_synchro_deque_iter->fs);
double delta_T_rx_s_prev = T_rx_channel_prev - T_rx_s;
if (fabs(delta_T_rx_s_prev) < fabs(delta_T_rx_s))
{
realigned_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(d_gnss_synchro_history_queue[i].at(distance - 1).Channel_ID,
d_gnss_synchro_history_queue[i].at(distance - 1)));
adjacent_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(gnss_synchro_deque_iter->Channel_ID, *gnss_synchro_deque_iter));
}
else
{
realigned_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(gnss_synchro_deque_iter->Channel_ID, *gnss_synchro_deque_iter));
adjacent_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(d_gnss_synchro_history_queue[i].at(distance - 1).Channel_ID,
d_gnss_synchro_history_queue[i].at(distance - 1)));
}
}
}
else
{
realigned_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(gnss_synchro_deque_iter->Channel_ID, *gnss_synchro_deque_iter));
}
}
realigned_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(d_gnss_synchro_history_queue[i].at(distance - 1).Channel_ID,
d_gnss_synchro_history_queue[i].at(distance - 1)));
adjacent_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(gnss_synchro_deque_iter->Channel_ID, *gnss_synchro_deque_iter));
}
else
{
realigned_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(gnss_synchro_deque_iter->Channel_ID, *gnss_synchro_deque_iter));
adjacent_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(d_gnss_synchro_history_queue[i].at(distance - 1).Channel_ID,
d_gnss_synchro_history_queue[i].at(distance - 1)));
}
}
}
if(!realigned_gnss_synchro_map.empty())
{
/*
* 2.1 Use CURRENT set of measurements and find the nearest satellite
* common RX time algorithm
*/
// what is the most recent symbol TOW in the current set? -> this will be the reference symbol
gnss_synchro_map_iter = max_element(realigned_gnss_synchro_map.cbegin(),
realigned_gnss_synchro_map.cend(),
Hybrid_pairCompare_gnss_synchro_d_TOW);
double ref_fs_hz = static_cast<double>(gnss_synchro_map_iter->second.fs);
// compute interpolated TOW value at T_rx_s
int ref_channel_key = gnss_synchro_map_iter->second.Channel_ID;
Gnss_Synchro adj_obs;
adj_obs = adjacent_gnss_synchro_map.at(ref_channel_key);
double ref_adj_T_rx_s = static_cast<double>(adj_obs.Tracking_sample_counter) / ref_fs_hz + adj_obs.Code_phase_samples / ref_fs_hz;
double d_TOW_reference = gnss_synchro_map_iter->second.TOW_at_current_symbol_s;
double d_ref_T_rx_s = static_cast<double>(gnss_synchro_map_iter->second.Tracking_sample_counter) / ref_fs_hz + gnss_synchro_map_iter->second.Code_phase_samples / ref_fs_hz;
double selected_T_rx_s = T_rx_s;
// two points linear interpolation using adjacent (adj) values: y=y1+(x-x1)*(y2-y1)/(x2-x1)
double ref_TOW_at_T_rx_s = adj_obs.TOW_at_current_symbol_s +
(selected_T_rx_s - ref_adj_T_rx_s) * (d_TOW_reference - adj_obs.TOW_at_current_symbol_s) / (d_ref_T_rx_s - ref_adj_T_rx_s);
// Now compute RX time differences due to the PRN alignment in the correlators
double traveltime_ms;
double pseudorange_m;
double channel_T_rx_s;
double channel_fs_hz;
double channel_TOW_s;
for(gnss_synchro_map_iter = realigned_gnss_synchro_map.cbegin(); gnss_synchro_map_iter != realigned_gnss_synchro_map.cend(); gnss_synchro_map_iter++)
{
channel_fs_hz = static_cast<double>(gnss_synchro_map_iter->second.fs);
channel_TOW_s = gnss_synchro_map_iter->second.TOW_at_current_symbol_s;
channel_T_rx_s = static_cast<double>(gnss_synchro_map_iter->second.Tracking_sample_counter) / channel_fs_hz + gnss_synchro_map_iter->second.Code_phase_samples / channel_fs_hz;
// compute interpolated observation values
// two points linear interpolation using adjacent (adj) values: y=y1+(x-x1)*(y2-y1)/(x2-x1)
// TOW at the selected receiver time T_rx_s
int element_key = gnss_synchro_map_iter->second.Channel_ID;
try{
adj_obs = adjacent_gnss_synchro_map.at(element_key);
}catch(const std::exception & ex)
{
continue;
}
double adj_T_rx_s = static_cast<double>(adj_obs.Tracking_sample_counter) / channel_fs_hz + adj_obs.Code_phase_samples / channel_fs_hz;
double channel_TOW_at_T_rx_s = adj_obs.TOW_at_current_symbol_s + (selected_T_rx_s - adj_T_rx_s) * (channel_TOW_s - adj_obs.TOW_at_current_symbol_s) / (channel_T_rx_s - adj_T_rx_s);
// Doppler and Accumulated carrier phase
double Carrier_phase_lin_rads = adj_obs.Carrier_phase_rads + (selected_T_rx_s - adj_T_rx_s) * (gnss_synchro_map_iter->second.Carrier_phase_rads - adj_obs.Carrier_phase_rads) / (channel_T_rx_s - adj_T_rx_s);
double Carrier_Doppler_lin_hz = adj_obs.Carrier_Doppler_hz + (selected_T_rx_s - adj_T_rx_s) * (gnss_synchro_map_iter->second.Carrier_Doppler_hz - adj_obs.Carrier_Doppler_hz) / (channel_T_rx_s - adj_T_rx_s);
// compute the pseudorange (no rx time offset correction)
traveltime_ms = (ref_TOW_at_T_rx_s - channel_TOW_at_T_rx_s) * 1000.0 + GPS_STARTOFFSET_ms;
// convert to meters
pseudorange_m = traveltime_ms * GPS_C_m_ms; // [m]
// update the pseudorange object
current_gnss_synchro[gnss_synchro_map_iter->second.Channel_ID] = gnss_synchro_map_iter->second;
current_gnss_synchro[gnss_synchro_map_iter->second.Channel_ID].Pseudorange_m = pseudorange_m;
current_gnss_synchro[gnss_synchro_map_iter->second.Channel_ID].Flag_valid_pseudorange = true;
// Save the estimated RX time (no RX clock offset correction yet!)
current_gnss_synchro[gnss_synchro_map_iter->second.Channel_ID].RX_time = ref_TOW_at_T_rx_s + GPS_STARTOFFSET_ms / 1000.0;
current_gnss_synchro[gnss_synchro_map_iter->second.Channel_ID].Carrier_phase_rads = Carrier_phase_lin_rads;
current_gnss_synchro[gnss_synchro_map_iter->second.Channel_ID].Carrier_Doppler_hz = Carrier_Doppler_lin_hz;
}
if(d_dump == true)
else
{
// MULTIPLEXED FILE RECORDING - Record results to file
try
{
double tmp_double;
for (unsigned int i = 0; i < d_nchannels; i++)
{
tmp_double = current_gnss_synchro[i].RX_time;
d_dump_file.write(reinterpret_cast<char*>(&tmp_double), sizeof(double));
tmp_double = current_gnss_synchro[i].TOW_at_current_symbol_s;
d_dump_file.write(reinterpret_cast<char*>(&tmp_double), sizeof(double));
tmp_double = current_gnss_synchro[i].Carrier_Doppler_hz;
d_dump_file.write(reinterpret_cast<char*>(&tmp_double), sizeof(double));
tmp_double = current_gnss_synchro[i].Carrier_phase_rads / GPS_TWO_PI;
d_dump_file.write(reinterpret_cast<char*>(&tmp_double), sizeof(double));
tmp_double = current_gnss_synchro[i].Pseudorange_m;
d_dump_file.write(reinterpret_cast<char*>(&tmp_double), sizeof(double));
tmp_double = current_gnss_synchro[i].PRN;
d_dump_file.write(reinterpret_cast<char*>(&tmp_double), sizeof(double));
tmp_double = static_cast<double>(current_gnss_synchro[i].Flag_valid_pseudorange);
d_dump_file.write(reinterpret_cast<char*>(&tmp_double), sizeof(double));
}
}
catch (const std::ifstream::failure& e)
{
LOG(WARNING) << "Exception writing observables dump file " << e.what();
}
realigned_gnss_synchro_map.insert(std::pair<int, Gnss_Synchro>(gnss_synchro_deque_iter->Channel_ID, *gnss_synchro_deque_iter));
}
for (unsigned int i = 0; i < d_nchannels; i++)
{
out[i][n_outputs] = current_gnss_synchro[i];
}
n_outputs++;
}
// Move RX time
T_rx_s = T_rx_s + T_rx_step_s;
// pop old elements from queue
for (unsigned int i = 0; i < d_nchannels; i++)
{
while (static_cast<double>(d_gnss_synchro_history_queue[i].front().Tracking_sample_counter) / static_cast<double>(d_gnss_synchro_history_queue[i].front().fs) < (T_rx_s - past_history_s))
{
d_gnss_synchro_history_queue[i].pop_front();
}
}
}
}
}
} while(channel_history_ok == true && noutput_items > n_outputs);
}
if(!realigned_gnss_synchro_map.empty())
{
/*
* 2.1 Use CURRENT set of measurements and find the nearest satellite
* common RX time algorithm
*/
// what is the most recent symbol TOW in the current set? -> this will be the reference symbol
gnss_synchro_map_iter = max_element(realigned_gnss_synchro_map.cbegin(),
realigned_gnss_synchro_map.cend(),
Hybrid_pairCompare_gnss_synchro_d_TOW);
double ref_fs_hz = static_cast<double>(gnss_synchro_map_iter->second.fs);
// compute interpolated TOW value at T_rx_s
int ref_channel_key = gnss_synchro_map_iter->second.Channel_ID;
Gnss_Synchro adj_obs;
adj_obs = adjacent_gnss_synchro_map.at(ref_channel_key);
double ref_adj_T_rx_s = static_cast<double>(adj_obs.Tracking_sample_counter) / ref_fs_hz + adj_obs.Code_phase_samples / ref_fs_hz;
double d_TOW_reference = gnss_synchro_map_iter->second.TOW_at_current_symbol_s;
double d_ref_T_rx_s = static_cast<double>(gnss_synchro_map_iter->second.Tracking_sample_counter) / ref_fs_hz + gnss_synchro_map_iter->second.Code_phase_samples / ref_fs_hz;
double selected_T_rx_s = T_rx_s;
// two points linear interpolation using adjacent (adj) values: y=y1+(x-x1)*(y2-y1)/(x2-x1)
double ref_TOW_at_T_rx_s = adj_obs.TOW_at_current_symbol_s +
(selected_T_rx_s - ref_adj_T_rx_s) * (d_TOW_reference - adj_obs.TOW_at_current_symbol_s) / (d_ref_T_rx_s - ref_adj_T_rx_s);
// Now compute RX time differences due to the PRN alignment in the correlators
double traveltime_ms;
double pseudorange_m;
double channel_T_rx_s;
double channel_fs_hz;
double channel_TOW_s;
for(gnss_synchro_map_iter = realigned_gnss_synchro_map.cbegin(); gnss_synchro_map_iter != realigned_gnss_synchro_map.cend(); gnss_synchro_map_iter++)
{
channel_fs_hz = static_cast<double>(gnss_synchro_map_iter->second.fs);
channel_TOW_s = gnss_synchro_map_iter->second.TOW_at_current_symbol_s;
channel_T_rx_s = static_cast<double>(gnss_synchro_map_iter->second.Tracking_sample_counter) / channel_fs_hz + gnss_synchro_map_iter->second.Code_phase_samples / channel_fs_hz;
// compute interpolated observation values
// two points linear interpolation using adjacent (adj) values: y=y1+(x-x1)*(y2-y1)/(x2-x1)
// TOW at the selected receiver time T_rx_s
int element_key = gnss_synchro_map_iter->second.Channel_ID;
try{
adj_obs = adjacent_gnss_synchro_map.at(element_key);
}catch(const std::exception & ex)
{
continue;
}
double adj_T_rx_s = static_cast<double>(adj_obs.Tracking_sample_counter) / channel_fs_hz + adj_obs.Code_phase_samples / channel_fs_hz;
double channel_TOW_at_T_rx_s = adj_obs.TOW_at_current_symbol_s + (selected_T_rx_s - adj_T_rx_s) * (channel_TOW_s - adj_obs.TOW_at_current_symbol_s) / (channel_T_rx_s - adj_T_rx_s);
// Doppler and Accumulated carrier phase
double Carrier_phase_lin_rads = adj_obs.Carrier_phase_rads + (selected_T_rx_s - adj_T_rx_s) * (gnss_synchro_map_iter->second.Carrier_phase_rads - adj_obs.Carrier_phase_rads) / (channel_T_rx_s - adj_T_rx_s);
double Carrier_Doppler_lin_hz = adj_obs.Carrier_Doppler_hz + (selected_T_rx_s - adj_T_rx_s) * (gnss_synchro_map_iter->second.Carrier_Doppler_hz - adj_obs.Carrier_Doppler_hz) / (channel_T_rx_s - adj_T_rx_s);
// compute the pseudorange (no rx time offset correction)
traveltime_ms = (ref_TOW_at_T_rx_s - channel_TOW_at_T_rx_s) * 1000.0 + GPS_STARTOFFSET_ms;
// convert to meters
pseudorange_m = traveltime_ms * GPS_C_m_ms; // [m]
// update the pseudorange object
current_gnss_synchro[gnss_synchro_map_iter->second.Channel_ID] = gnss_synchro_map_iter->second;
current_gnss_synchro[gnss_synchro_map_iter->second.Channel_ID].Pseudorange_m = pseudorange_m;
current_gnss_synchro[gnss_synchro_map_iter->second.Channel_ID].Flag_valid_pseudorange = true;
// Save the estimated RX time (no RX clock offset correction yet!)
current_gnss_synchro[gnss_synchro_map_iter->second.Channel_ID].RX_time = ref_TOW_at_T_rx_s + GPS_STARTOFFSET_ms / 1000.0;
current_gnss_synchro[gnss_synchro_map_iter->second.Channel_ID].Carrier_phase_rads = Carrier_phase_lin_rads;
current_gnss_synchro[gnss_synchro_map_iter->second.Channel_ID].Carrier_Doppler_hz = Carrier_Doppler_lin_hz;
}
if(d_dump == true)
{
// MULTIPLEXED FILE RECORDING - Record results to file
try
{
double tmp_double;
for (unsigned int i = 0; i < d_nchannels; i++)
{
tmp_double = current_gnss_synchro[i].RX_time;
d_dump_file.write(reinterpret_cast<char*>(&tmp_double), sizeof(double));
tmp_double = current_gnss_synchro[i].TOW_at_current_symbol_s;
d_dump_file.write(reinterpret_cast<char*>(&tmp_double), sizeof(double));
tmp_double = current_gnss_synchro[i].Carrier_Doppler_hz;
d_dump_file.write(reinterpret_cast<char*>(&tmp_double), sizeof(double));
tmp_double = current_gnss_synchro[i].Carrier_phase_rads / GPS_TWO_PI;
d_dump_file.write(reinterpret_cast<char*>(&tmp_double), sizeof(double));
tmp_double = current_gnss_synchro[i].Pseudorange_m;
d_dump_file.write(reinterpret_cast<char*>(&tmp_double), sizeof(double));
tmp_double = current_gnss_synchro[i].PRN;
d_dump_file.write(reinterpret_cast<char*>(&tmp_double), sizeof(double));
tmp_double = static_cast<double>(current_gnss_synchro[i].Flag_valid_pseudorange);
d_dump_file.write(reinterpret_cast<char*>(&tmp_double), sizeof(double));
}
}
catch (const std::ifstream::failure& e)
{
LOG(WARNING) << "Exception writing observables dump file " << e.what();
}
}
for (unsigned int i = 0; i < d_nchannels; i++)
{
out[i][n_outputs] = current_gnss_synchro[i];
}
n_outputs++;
}
// Move RX time
T_rx_s = T_rx_s + T_rx_step_s;
// pop old elements from queue
for (unsigned int i = 0; i < d_nchannels; i++)
{
if (!d_gnss_synchro_history_queue[i].empty())
{
while (static_cast<double>(d_gnss_synchro_history_queue[i].front().Tracking_sample_counter) / static_cast<double>(d_gnss_synchro_history_queue[i].front().fs) < (T_rx_s - past_history_s))
{
d_gnss_synchro_history_queue[i].pop_front();
}
}
}
}
} while(channel_history_ok == true && noutput_items > n_outputs);
// Multi-rate consume!
for (unsigned int i = 0; i < d_nchannels; i++)
{
consume(i, n_consume[i]); // which input, how many items
}
{
consume(i, n_consume[i]); // which input, how many items
}
//consume monitor channel always
consume(d_nchannels, 1);
return n_outputs;
}

View File

@ -44,7 +44,7 @@ class hybrid_observables_cc;
typedef boost::shared_ptr<hybrid_observables_cc> hybrid_observables_cc_sptr;
hybrid_observables_cc_sptr
hybrid_make_observables_cc(unsigned int n_channels, bool dump, std::string dump_filename, unsigned int deep_history);
hybrid_make_observables_cc(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, std::string dump_filename, unsigned int deep_history);
/*!
* \brief This class implements a block that computes Galileo observables
@ -58,8 +58,8 @@ public:
void forecast (int noutput_items, gr_vector_int &ninput_items_required);
private:
friend hybrid_observables_cc_sptr
hybrid_make_observables_cc(unsigned int nchannels, bool dump, std::string dump_filename, unsigned int deep_history);
hybrid_observables_cc(unsigned int nchannels, bool dump, std::string dump_filename, unsigned int deep_history);
hybrid_make_observables_cc(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, std::string dump_filename, unsigned int deep_history);
hybrid_observables_cc(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, std::string dump_filename, unsigned int deep_history);
//Tracking observable history
std::vector<std::deque<Gnss_Synchro>> d_gnss_synchro_history_queue;

View File

@ -248,7 +248,15 @@ std::unique_ptr<GNSSBlockInterface> GNSSBlockFactory::GetObservables(std::shared
GPS_channels += configuration->property("Channels_2S.count", 0);
GPS_channels += configuration->property("Channels_L5.count", 0);
unsigned int Glonass_channels = configuration->property("Channels_1G.count", 0);
return GetBlock(configuration, "Observables", implementation, Galileo_channels + GPS_channels + Glonass_channels, Galileo_channels + GPS_channels + Glonass_channels);
unsigned int extra_channels = 1; // For monitor channel sample counter
return GetBlock(configuration, "Observables", implementation,
Galileo_channels +
GPS_channels +
Glonass_channels +
extra_channels,
Galileo_channels +
GPS_channels +
Glonass_channels);
}

View File

@ -248,6 +248,24 @@ void GNSSFlowgraph::connect()
}
DLOG(INFO) << "Signal source connected to signal conditioner";
//connect the signal source to sample counter
//connect the sample counter to Observables
try
{
double fs = static_cast<double>(configuration_->property("GNSS-SDR.internal_fs_sps", 0));
ch_out_sample_counter = gnss_sdr_make_sample_counter(fs);
top_block_->connect(sig_conditioner_.at(0)->get_right_block(), 0, ch_out_sample_counter, 0);
top_block_->connect(ch_out_sample_counter, 0, observables_->get_left_block(), channels_count_); //extra port for the sample counter pulse
}
catch (const std::exception & e)
{
LOG(WARNING) << "Can't connect sample counter";
LOG(ERROR) << e.what();
top_block_->disconnect_all();
return;
}
// Signal conditioner (selected_signal_source) >> channels (i) (dependent of their associated SignalSource_ID)
int selected_signal_conditioner_ID;
for (unsigned int i = 0; i < channels_count_; i++)
@ -296,13 +314,6 @@ void GNSSFlowgraph::connect()
{
LOG(INFO) << "Channel " << i << " connected to observables in standby mode";
}
//connect the sample counter to the channel 0
if (i == 0)
{
ch_out_sample_counter = gnss_sdr_make_sample_counter();
top_block_->connect(channels_.at(i)->get_right_block(), 0, ch_out_sample_counter, 0);
}
}
/*

View File

@ -74,7 +74,7 @@ const double GPS_STARTOFFSET_ms = 68.802; //[ms] Initial sign. travel time (this
// OBSERVABLE HISTORY DEEP FOR INTERPOLATION
const int GPS_L1_CA_HISTORY_DEEP = 500;
const int GPS_L1_CA_HISTORY_DEEP = 100;
// NAVIGATION MESSAGE DEMODULATION AND DECODING