Triggering USRP at given GPS time from GNU Radio

Hi all,

Whenever I want to trigger USRP with at given time with use of a GPSDO
I’m adding something like this at the end of a constructor of a topblock
generated by gnuradio-companion:

    if start_time!="":
        self.start_time_epoch =

time.mktime(time.strptime(start_time,’%d.%m.%Y %H:%M:%S’))

self.uhd_usrp_source_0.set_start_time(uhd.time_spec_t(self.start_time_epoch))

where start_time is a string parameter containing the time at which the
device should start reception.

The snippet might be useful for others trying to do the same thing.

I want to ask you if there is a way to do better than that and generate
directly in gnuradio-companion a flowgraph that use GPSDO of USRP to
trigger it without having to edit anything manually?

Best Regards,
Piotr K.

On 23-02-15 21:33, Piotr K. wrote:

self.uhd_usrp_source_0.set_start_time(uhd.time_spec_t(self.start_time_epoch))

where start_time is a string parameter containing the time at which the
device should start reception.

The snippet might be useful for others trying to do the same thing.
This is usefull to me indeed. Thanks.

I want to ask you if there is a way to do better than that and generate
directly in gnuradio-companion a flowgraph that use GPSDO of USRP to
trigger it without having to edit anything manually?
I have not found a way yet.
I always edit manually and add a few lines of code, like you seem to do.
(See the end of this mail)

For this application it would be helpfull if you could set the
start_time from grc.

In general it would be very helpfull if you could add your own python
code to grc without having to edit it manually after generating.

A “codeblock” in a similar way the import block is implemented would be
very helpful. Just a block where you can add code. You should probably
be able to choose where the code is added.

at the top of the file after all imports
at the beginning of the constructor of the flowgraph
at the end of the constructor of the flow_graph
as a seperate method of the flowgraph
at the start of main
at the end of main.

We could make it a feature request.
Or maybe I should just implement it.

Here follows my code snippet to set the start of capturing in the near
future. This also works if you do not have a GPSDO
You need to set a start_time in the near future which I do like this:

     # In grc add a parameter delay (in seconds) with type float and

default 0.5
# at the end of def init () of the generated flowgrapg
add the following code:
#
self.init_timed_streaming(self.delay)

 def init_timed_streaming(self, delay):
     # You can optionally set the time in the usrp to zero or to

something else
# with set_time_now() or if you have a GPSDO with
set_time_unknown_pps()
# or set_time_next_pps()
#self.uhd_usrp_source.set_time_next_pps(uhd.time_spec_t(0))
#self.uhd_usrp_source.set_time_unknown_pps(uhd.time_spec_t(0))
#time.sleep(2)

     # Now get the time from the usrp before streaming has started .
     # You can use either uhd_usrp_source or uhd_usrp_sink to get

the time now.
tnow = self.uhd_usrp_source.get_time_now()

     # If you have a GPSDO installed tnow is the absolute time
     # locked to the GPS time it received.
     # If you do not have a GPSDO time then this time is just a
     # meaningless number which started somewhere in the past.
     # tnow is of type uhd.time_spec_t

     self.reasonable_delay = delay
     # delay in seconds into the future, this should be at least
     # an order of magnitude larger then the round trip time to USRP

     # capture and transmit will start at t0
     self.t0  = tnow + uhd.time_spec_t(self.reasonable_delay)
     self.t0_secs = self.t0.get_real_secs() # the time in secs (full
  • fractional) as a floating point number
    print "tnow secs = ", tnow.get_real_secs()
    print "t0_secs = ", self.t0_secs

       #Now you can set the start time of the uhd_usrp_source and/or
    

of the uhd_usrp_sink
# If you set the start_time of both then you can build a system
# where source and sink start at the exact same moment. This
# can be usefull in several situations.
self.uhd_usrp_source.set_start_time (self.t0 )
self.uhd_usrp_sink.set_start_time (self.t0 )

Best regards,

Martin Dudok van Heel

W dniu 24.02.2015 o 10:59, Martin pisze:

at the top of the file after all imports
at the beginning of the constructor of the flowgraph
at the end of the constructor of the flow_graph
as a seperate method of the flowgraph
at the start of main
at the end of main.

We could make it a feature request.
Or maybe I should just implement it.

Martin,

The solution proposed by you would be very good to give to the user
ability to do something more sophisticated than gnuradio-companion
supports at any point in the future.

However in my opinion ability to trigger USRP at a specified time is
quite basic feature of the device. Maybe it would be better to add the
start_time parameter in gnuradio-companion UHD blocks (source and sink)
that would be parsed into appropriate python code. To keep it simple to
implement the value given could be as a float in seconds that would be
directly converted into USRP’s clock value like this:

uhd.time_spec_t(start_time)

and it would be user task to assign proper value like:

start_time: time.mktime(time.strptime(time_string,’%d.%m.%Y
%H:%M:%S’)) #if he uses GPSDO

or

start_time:   self.uhd_usrp_source.get_time_now()+4 #if he just to

start 4 seconds from now

The examples of how to use this parameter could be documented in the
description of the blocks so each user wouldn’t have to find this out on
his own.

The other advantage of this approach - it would also give a simple way
to synchronize UHD source and sink from gnuradio-companion.

Best Regards,
Piotr K.