-
Notifications
You must be signed in to change notification settings - Fork 7
/
0004-v0.0.18-adding-vxi11.patch
469 lines (445 loc) · 18.5 KB
/
0004-v0.0.18-adding-vxi11.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
From 4e9aa525d3a3db138f2a4fe1fbaa67469e6e08e2 Mon Sep 17 00:00:00 2001
From: Gwenhael Goavec-Merou <[email protected]>
Date: Fri, 28 Jul 2023 16:55:39 +0200
Subject: [PATCH 4/4] adding vxi11
Signed-off-by: Gwenhael Goavec-Merou <[email protected]>
---
src/algorithms/PVT/adapters/rtklib_pvt.cc | 11 +-
src/algorithms/PVT/adapters/rtklib_pvt.h | 7 +
.../PVT/gnuradio_blocks/CMakeLists.txt | 5 +
.../PVT/gnuradio_blocks/rtklib_pvt_gs.cc | 200 +++++++++++++++++-
.../PVT/gnuradio_blocks/rtklib_pvt_gs.h | 51 ++++-
.../adapters/uhd_signal_source.cc | 8 +-
.../adapters/uhd_signal_source.h | 2 +-
7 files changed, 270 insertions(+), 14 deletions(-)
diff --git a/src/algorithms/PVT/adapters/rtklib_pvt.cc b/src/algorithms/PVT/adapters/rtklib_pvt.cc
index 9ce402bcc..39fb51fc1 100644
--- a/src/algorithms/PVT/adapters/rtklib_pvt.cc
+++ b/src/algorithms/PVT/adapters/rtklib_pvt.cc
@@ -57,6 +57,15 @@ Rtklib_Pvt::Rtklib_Pvt(const ConfigurationInterface* configuration,
const std::string default_nmea_dump_devname("/dev/tty1");
const std::string default_rtcm_dump_devname("/dev/pts/1");
DLOG(INFO) << "role " << role;
+
+ PPS_Kp=configuration->property(role + ".PPS_Kp", 15000.);
+ PPS_Ki=configuration->property(role + ".PPS_Ki", 5000.);
+ SMA_internal_source_clock=configuration->property(role + ".SMA_internal_source_clock",true);
+ LO_external_frequ=configuration->property(role + ".LO_external_frequ",10000000);
+ PPS_correction=configuration->property(role + ".PPS_correction",false);
+ PPS_estimator_selected=configuration->property(role + ".PPS_estimator_selected",false);
+ SMA_IP_address=configuration->property(role + ".SMA_IP_address",std::string("192.168.1.69"));
+
pvt_output_parameters.dump = configuration->property(role + ".dump", false);
pvt_output_parameters.dump_filename = configuration->property(role + ".dump_filename", default_dump_filename);
pvt_output_parameters.dump_mat = configuration->property(role + ".dump_mat", true);
@@ -887,7 +896,7 @@ Rtklib_Pvt::Rtklib_Pvt(const ConfigurationInterface* configuration,
pvt_output_parameters.use_unhealthy_sats = configuration->property(role + ".use_unhealthy_sats", pvt_output_parameters.use_unhealthy_sats);
// make PVT object
- pvt_ = rtklib_make_pvt_gs(in_streams_, pvt_output_parameters, rtk);
+ pvt_ = rtklib_make_pvt_gs(in_streams_, pvt_output_parameters, rtk, PPS_Kp, PPS_Ki,SMA_internal_source_clock,LO_external_frequ,PPS_correction,PPS_estimator_selected,SMA_IP_address);
DLOG(INFO) << "pvt(" << pvt_->unique_id() << ")";
if (out_streams_ > 0)
{
diff --git a/src/algorithms/PVT/adapters/rtklib_pvt.h b/src/algorithms/PVT/adapters/rtklib_pvt.h
index 57fb22c4c..429049f30 100644
--- a/src/algorithms/PVT/adapters/rtklib_pvt.h
+++ b/src/algorithms/PVT/adapters/rtklib_pvt.h
@@ -226,6 +226,13 @@ private:
std::string role_;
unsigned int in_streams_;
unsigned int out_streams_;
+ double PPS_Kp;
+ double PPS_Ki;
+ bool SMA_internal_source_clock;
+ double LO_external_frequ;
+ bool PPS_correction;
+ bool PPS_estimator_selected;
+ std::string SMA_IP_address;
};
/** \} */
diff --git a/src/algorithms/PVT/gnuradio_blocks/CMakeLists.txt b/src/algorithms/PVT/gnuradio_blocks/CMakeLists.txt
index ae1b728bf..6d3a77427 100644
--- a/src/algorithms/PVT/gnuradio_blocks/CMakeLists.txt
+++ b/src/algorithms/PVT/gnuradio_blocks/CMakeLists.txt
@@ -32,6 +32,11 @@ target_link_libraries(pvt_gr_blocks
Boost::serialization
)
+# ADD VXI11 LIBRARY (JMF)
+find_library(VXI11 libvxi11.so.1 REQUIRED)
+ target_link_libraries( pvt_gr_blocks PRIVATE ${VXI11})
+# END ADD VXI11 LIBRARY (JMF)
+
if(GNURADIO_USES_STD_POINTERS)
target_compile_definitions(pvt_gr_blocks
PUBLIC -DGNURADIO_USES_STD_POINTERS=1
diff --git a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc
index 8f6f1648a..a9407d3a2 100644
--- a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc
+++ b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc
@@ -108,20 +108,59 @@ namespace wht = boost;
namespace wht = std;
#endif
+//------------ To access B210
+
+#include "uhd/convert.hpp"
+#include "uhd/usrp/multi_usrp.hpp"
+#include "uhd/utils/safe_main.hpp"
+#include <stdint.h>
+#include <stdlib.h>
+#include <iostream>
+
+static const std::string GPIO_DEFAULT_GPIO = "FP0";
+uhd::usrp::multi_usrp::sptr uhd_source_;
+
+//-------------R&S SMA
+#include "vxi11_user.h"
+#pragma message "With VXI11"
+#define BUF_LEN 1000
+// VXI11_CLINK *d_clink;
+//-------------R&S SMA end
+
rtklib_pvt_gs_sptr rtklib_make_pvt_gs(uint32_t nchannels,
const Pvt_Conf& conf_,
- const rtk_t& rtk)
+ const rtk_t& rtk,
+ const double PPS_Kp,
+ const double PPS_Ki,
+ const bool SMA_internal_source_clock,
+ double LO_external_frequ,
+ const bool PPS_correction,
+ const bool PPS_estimator_selected,
+ const std::string SMA_IP_address)
{
return rtklib_pvt_gs_sptr(new rtklib_pvt_gs(nchannels,
conf_,
- rtk));
+ rtk,
+ PPS_Kp,
+ PPS_Ki,
+ SMA_internal_source_clock,
+ LO_external_frequ,
+ PPS_correction,
+ PPS_estimator_selected,
+ SMA_IP_address));
}
rtklib_pvt_gs::rtklib_pvt_gs(uint32_t nchannels,
const Pvt_Conf& conf_,
- const rtk_t& rtk)
- : gr::sync_block("rtklib_pvt_gs",
+ const rtk_t& rtk,
+ const double PPS_Kp,
+ const double PPS_Ki,
+ const bool SMA_internal_source_clock,
+ double LO_external_frequ,
+ const bool PPS_correction,
+ const bool PPS_estimator_selected,
+ const std::string SMA_IP_address) : gr::sync_block("rtklib_pvt_gs",
gr::io_signature::make(nchannels, nchannels, sizeof(Gnss_Synchro)),
gr::io_signature::make(0, 0, 0)),
d_dump_filename(conf_.dump_filename),
@@ -182,6 +221,90 @@ rtklib_pvt_gs::rtklib_pvt_gs(uint32_t nchannels,
d_use_has_corrections(conf_.use_has_corrections),
d_use_unhealthy_sats(conf_.use_unhealthy_sats)
{
+ char* device_name = NULL;
+ char buf[BUF_LEN];
+ long bytes_returned;
+ char cmd[256];
+ d_PPS_correction=PPS_correction;
+ if (d_PPS_correction)
+ {
+ d_PPS_estimator_selected=PPS_estimator_selected;
+ d_PPS_Kp=PPS_Kp;
+ d_PPS_Ki=PPS_Ki;
+ d_LO_external_frequ=LO_external_frequ;
+ d_SMA_IP_address=SMA_IP_address;
+
+ std::cout
+ << std::setprecision(9)
+ << "Kp: " << d_PPS_Kp
+ << " Ki: " << d_PPS_Ki
+ << " LO: " << d_LO_external_frequ << "[Hz]" << '\n';
+
+ LOG(INFO) << "vxi11 init\n";
+ std::cout
+ << "SMA IP address: "
+ << d_SMA_IP_address << '\n';
+
+ vxi11_open_device(&d_clink, d_SMA_IP_address.c_str(), device_name);
+ sprintf (cmd, "*IDN?\n");
+ vxi11_send (d_clink, cmd,strlen(cmd));
+ bytes_returned=vxi11_receive (d_clink, buf, BUF_LEN);
+ LOG(INFO) << buf ;
+ if (SMA_internal_source_clock)
+ {
+ sprintf (cmd, "ROSC:SOUR INT");
+ vxi11_send (d_clink, cmd,strlen(cmd));
+ std::cout << "SMA Internal source clock selected\n";
+ }
+ else
+ {
+ sprintf (cmd, "ROSC:SOUR EXT");
+ vxi11_send (d_clink, cmd,strlen(cmd));
+ sprintf (cmd, "ROSC:EXT:FREQ 10MHz");
+ vxi11_send (d_clink, cmd,strlen(cmd));
+ std::cout << "SMA External source clock selected\n";
+ }
+
+ sprintf(cmd, "FREQ %0.3fHz",d_LO_external_frequ);
+ vxi11_send (d_clink, cmd,strlen(cmd));
+
+
+
+//uhd not used yet
+
+
+ // variables to be set by po
+ std::string args;
+ uint32_t rb;
+ std::string gpio=GPIO_DEFAULT_GPIO; // FP0
+ uint32_t ddr;
+ uint32_t ctrl;
+ uint32_t mask;
+ // create a uhd_source_ device
+ std::cout << std::endl;
+ std::cout << boost::format("Creating the uhd_source_ device with: %s...") % args
+ << std::endl;
+ uhd_source_ = uhd::usrp::multi_usrp::make(args);
+
+//uhd_source_
+ std::cout << boost::format("Using Device: %s") % uhd_source_->get_pp_string() << std::endl;
+ std::cout << "Using GPIO bank: " << gpio << std::endl;
+
+ ddr=0x00;
+ ctrl=0x00;
+ mask=0xff;
+ // writing config
+ uhd_source_->set_gpio_attr(gpio, "DDR", ddr, mask); // set data direction register (DDR)
+ uhd_source_->set_gpio_attr(gpio, "CTRL", ctrl, mask); // set control register
+ uhd_source_->set_gpio_attr(gpio, "OUT", 0x00, mask); // set control register
+ uhd_source_->set_gpio_attr(gpio, "ATR_0X", 0x00, mask); // set ATR registers
+ // reading back
+ rb= uhd_source_->get_gpio_attr(gpio, "DDR") & mask;
+ std::cout << "DDR:" << rb << std::endl;
+ rb= uhd_source_->get_gpio_attr(gpio, "CTRL") & mask;
+ std::cout << "CTRL:" << rb << std::endl;
+ }
+
// Send feedback message to observables block with the receiver clock offset
this->message_port_register_out(pmt::mp("pvt_to_observables"));
// Experimental: VLT commands from PVT to tracking channels
@@ -580,6 +703,11 @@ rtklib_pvt_gs::rtklib_pvt_gs(uint32_t nchannels,
rtklib_pvt_gs::~rtklib_pvt_gs()
{
DLOG(INFO) << "PVT block destructor called.";
+ if (d_PPS_correction)
+ {
+ vxi11_close_device(d_clink, d_SMA_IP_address.c_str());
+ }
+
if (d_sysv_msqid != -1)
{
msgctl(d_sysv_msqid, IPC_RMID, nullptr);
@@ -2201,8 +2329,6 @@ int rtklib_pvt_gs::work(int noutput_items, gr_vector_const_void_star& input_item
if (current_RX_time_ms % d_output_rate_ms == 0)
{
flag_compute_pvt_output = true;
- // std::cout.precision(17);
- // std::cout << "current_RX_time: " << current_RX_time_ms << " map time: " << d_gnss_observables_map.begin()->second.RX_time << '\n';
}
flag_pvt_valid = true;
}
@@ -2315,11 +2441,28 @@ int rtklib_pvt_gs::work(int noutput_items, gr_vector_const_void_star& input_item
{
if (d_show_local_time_zone)
{
+
const boost::posix_time::ptime time_first_solution = d_user_pvt_solver->get_position_UTC_time() + d_utc_diff_time;
std::cout << "First position fix at " << time_first_solution << d_local_time_str;
+ if(d_PPS_correction)
+ {
+ d_pps_init_offset=d_user_pvt_solver->get_time_offset_s();
+ d_pps_prev_error=0.;
+ d_estimator=0.;
+ LOG(INFO) << "init offset: " << d_pps_init_offset << "\n";
+ d_LO_external_frequ_init=d_LO_external_frequ;
+ }
}
else
{
+ if(d_PPS_correction)
+ {
+ d_pps_init_offset=d_user_pvt_solver->get_time_offset_s();
+ d_pps_prev_error=0.;
+ d_estimator=0.;
+ LOG(INFO) << "init offset: " << d_pps_init_offset << "\n";
+ d_LO_external_frequ_init=d_LO_external_frequ;
+ }
std::cout << "First position fix at " << d_user_pvt_solver->get_position_UTC_time() << " UTC";
}
std::cout << " is Lat = " << d_user_pvt_solver->get_latitude() << " [deg], Long = " << d_user_pvt_solver->get_longitude()
@@ -2414,8 +2557,49 @@ int rtklib_pvt_gs::work(int noutput_items, gr_vector_const_void_star& input_item
<< " [deg], Height = " << d_user_pvt_solver->get_height() << " [m]" << TEXT_RESET << '\n';
std::cout << std::setprecision(ss);
- DLOG(INFO) << "RX clock offset: " << d_user_pvt_solver->get_time_offset_s() << "[s]";
-
+ if (d_PPS_correction)
+ {
+ if (d_PPS_estimator_selected)
+ {
+ d_estimator_prev=d_estimator;
+ d_pps_offset=d_internal_pvt_solver->get_time_offset_s();
+ d_estimator=d_estimator*0.9+5.5e-8*(d_LO_external_frequ-d_LO_external_frequ_init)+0.1*(d_pps_offset-d_pps_init_offset);
+ d_FREQU_correction=d_estimator*(d_PPS_Kp+d_PPS_Ki)-d_estimator_prev*d_PPS_Kp;
+ }
+ else
+ {
+ d_pps_prev_error=d_pps_offset-d_pps_init_offset;
+ d_pps_offset=d_internal_pvt_solver->get_time_offset_s();
+ d_FREQU_correction=(d_pps_offset-d_pps_init_offset)*(d_PPS_Kp+d_PPS_Ki)-d_pps_prev_error*d_PPS_Kp;
+ }
+ if (d_FREQU_correction>0.074) //max 0.074 Hz
+ {
+ d_FREQU_correction=0.074;
+ std::cout << "sat\n";
+ }
+ if (d_FREQU_correction<-0.074) //max 0.074 Hz
+ {
+ d_FREQU_correction=-0.074;
+ std::cout << "SAT\n";
+ }
+ std::cout
+ << "Estimator selected: " << std::boolalpha << d_PPS_estimator_selected << " value: " << d_estimator << '\n';
+ std::cout
+ << std::fixed << std::setprecision(12)
+ << "RX clock offset: " << d_pps_offset << " [s] "
+ << "diff offset: " << d_pps_offset-d_pps_init_offset << " [s] "
+ << "Frequ correction: " << d_FREQU_correction << " [Hz]" << '\n';
+
+ char cmd[256];
+ d_LO_external_frequ=d_LO_external_frequ-d_FREQU_correction;
+
+ std::cout
+ << std::fixed << std::setprecision(3)
+ << "LO Frequency: " << d_LO_external_frequ << " [Hz]" << '\n';
+
+ sprintf(cmd, "FREQ %0.3fHz",d_LO_external_frequ);
+ vxi11_send (d_clink, cmd,strlen(cmd));
+ }
std::cout
<< TEXT_BOLD_GREEN
<< "Velocity: " << std::fixed << std::setprecision(3)
diff --git a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.h b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.h
index 747c31c65..f58bf2bc6 100644
--- a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.h
+++ b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.h
@@ -45,6 +45,8 @@
* \{ */
+#include "vxi11_user.h"
+
class Beidou_Dnav_Almanac;
class Beidou_Dnav_Ephemeris;
class Galileo_Almanac;
@@ -71,7 +73,14 @@ using rtklib_pvt_gs_sptr = gnss_shared_ptr<rtklib_pvt_gs>;
rtklib_pvt_gs_sptr rtklib_make_pvt_gs(uint32_t nchannels,
const Pvt_Conf& conf_,
- const rtk_t& rtk);
+ const rtk_t& rtk,
+ const double PPS_Kp,
+ const double PPS_Ki,
+ const bool SMA_internal_source_clock,
+ double LO_external_frequ,
+ const bool PPS_correction,
+ const bool PPS_estimator_selected,
+ const std::string SMA_IP_address);
/*!
* \brief This class implements a block that computes the PVT solution using the RTKLIB integrated library
@@ -132,11 +141,26 @@ public:
private:
friend rtklib_pvt_gs_sptr rtklib_make_pvt_gs(uint32_t nchannels,
const Pvt_Conf& conf_,
- const rtk_t& rtk);
+ const rtk_t& rtk,
+ const double PPS_Kp,
+ const double PPS_Ki,
+ const bool SMA_internal_source_clock,
+ double LO_external_frequ,
+ const bool PPS_correction,
+ const bool PPS_estimator_selected,
+ const std::string SMA_IP_address);
rtklib_pvt_gs(uint32_t nchannels,
const Pvt_Conf& conf_,
- const rtk_t& rtk);
+ const rtk_t& rtk,
+ const double PPS_Kp,
+ const double PPS_Ki,
+ const bool SMA_internal_source_clock,
+ double LO_external_frequ,
+ const bool PPS_correction,
+ const bool PPS_estimator_selected,
+ const std::string SMA_IP_address);
+
void log_source_timetag_info(double RX_time_ns, double TAG_time_ns);
@@ -279,6 +303,27 @@ private:
bool d_use_e6_for_pvt;
bool d_use_has_corrections;
bool d_use_unhealthy_sats;
+
+ bool d_PPS_correction;
+ bool d_PPS_estimator_selected;
+ double d_PPS_Kp;
+ double d_PPS_Ki;
+ double d_LO_external_frequ;
+ double d_LO_external_frequ_init;
+
+ std::string d_SMA_IP_address;
+ VXI11_CLINK *d_clink;
+
+
+//-------------1PPS variables
+
+ double d_FREQU_correction;
+ double d_pps_prev_error;
+ double d_estimator;
+ double d_estimator_prev;
+ double d_pps_init_offset;
+ double d_pps_offset;
+
};
diff --git a/src/algorithms/signal_source/adapters/uhd_signal_source.cc b/src/algorithms/signal_source/adapters/uhd_signal_source.cc
index 72cc743c1..ecde6bcfc 100644
--- a/src/algorithms/signal_source/adapters/uhd_signal_source.cc
+++ b/src/algorithms/signal_source/adapters/uhd_signal_source.cc
@@ -233,7 +233,8 @@ UhdSignalSource::UhdSignalSource(const ConfigurationInterface* configuration,
}
// 1.2 Make the UHD source object
- uhd_source_ = gr::uhd::usrp_source::make(dev_addr, uhd_stream_args_);
+
+ uhd_source_ = gr::uhd::usrp_source::make(dev_addr, uhd_stream_args_, true); // jmfriedt 201026 true added to issue stream (now + 0.1 s)
// Set subdevice specification string for USRP family devices. It is composed of:
// <motherboard slot name>:<daughterboard frontend name>
@@ -328,6 +329,11 @@ UhdSignalSource::UhdSignalSource(const ConfigurationInterface* configuration,
{
LOG(ERROR) << "This implementation only supports one output stream";
}
+// ajout 201026 : delayed start
+uhd::time_spec_t curr_hw_time = uhd_source_->get_time_last_pps();
+uhd_source_->set_time_next_pps(uhd::time_spec_t(1.0) + curr_hw_time);
+// sleep(1.0)
+uhd_source_->set_start_time(uhd::time_spec_t(2.01) + curr_hw_time);
}
diff --git a/src/algorithms/signal_source/adapters/uhd_signal_source.h b/src/algorithms/signal_source/adapters/uhd_signal_source.h
index b97cd45ab..036c0655c 100644
--- a/src/algorithms/signal_source/adapters/uhd_signal_source.h
+++ b/src/algorithms/signal_source/adapters/uhd_signal_source.h
@@ -58,8 +58,8 @@ public:
gr::basic_block_sptr get_right_block() override;
gr::basic_block_sptr get_right_block(int RF_channel) override;
-private:
gr::uhd::usrp_source::sptr uhd_source_;
+private:
gnss_shared_ptr<gr::block> spoofing_detect_;
gnss_shared_ptr<gr::block> jamming_sgd_;
gnss_shared_ptr<gr::block> jamming_xcorr_;
--
2.41.0