Exemplo n.º 1
0
    def test_001_t(self):
        # set up message

        msg1 = pmt.list3(pmt.string_to_symbol('id'),
                         pmt.string_to_symbol('int'), pmt.from_long(42))
        msg2 = pmt.list3(pmt.string_to_symbol('value'),
                         pmt.string_to_symbol('float'), pmt.from_float(3.1416))
        #msg3 = pmt.list3(pmt.string_to_symbol('text'),pmt.string_to_symbol('string'),pmt.string_to_symbol('some text'))
        msg = pmt.list2(msg1, msg2)

        # set up sql connection

        host = '127.0.0.1'
        port = 0  # default
        user = '******'
        password = '******'
        database = 'my_db'
        table = 'my_table'

        # set up flowgraph

        if 0:  # Enable and disable here
            msg_src = blocks.message_strobe(msg, 100)
            sql_connector = sql.msg_to_table(user, password, database, table,
                                             host, port)

            self.tb.msg_connect(msg_src, 'strobe', sql_connector, 'Msg in')

        # run flowgraph

        self.tb.start()
        sleep(0.2)
        self.tb.stop()
        self.tb.wait()
Exemplo n.º 2
0
    def test_001_t (self):
        # set up message

        msg1 = pmt.list3(pmt.string_to_symbol('id'),pmt.string_to_symbol('int'),pmt.from_long(42))
        msg2 = pmt.list3(pmt.string_to_symbol('value'),pmt.string_to_symbol('float'),pmt.from_float(3.1416))
        #msg3 = pmt.list3(pmt.string_to_symbol('text'),pmt.string_to_symbol('string'),pmt.string_to_symbol('some text'))
        msg = pmt.list2(msg1,msg2)

        # set up sql connection

        host = '127.0.0.1'
        port = 0 # default
        user = '******'
        password = '******'
        database = 'my_db'
        table = 'my_table'

        # set up flowgraph

        if 0: # Enable and disable here
            msg_src = blocks.message_strobe(msg,100)
            sql_connector = sql.msg_to_table(user,password,database,table,host,port)

            self.tb.msg_connect(msg_src,'strobe',sql_connector,'Msg in')

        # run flowgraph

        self.tb.start()
        sleep(0.2)
        self.tb.stop()
        self.tb.wait()
Exemplo n.º 3
0
	def test_001_t (self):
		# set up fg
		num_mean = 1
		center_freq = 1
		antenna_gain_tx = 1
		antenna_gain_rx = 1
		usrp_gain_rx = 1
		amplitude = 1
		corr_factor = 1
		exponent = 1

		Range = (10, 20, 30)
		power = (15, 30, 45)

		pmt_range = pmt.list2(pmt.string_to_symbol('range'),pmt.init_f32vector(len(Range),Range))
		pmt_power = pmt.list2(pmt.string_to_symbol('power'),pmt.init_f32vector(len(power),power))
		pmt_misc = pmt.list2(pmt.string_to_symbol('misc'),pmt.init_f32vector(3,(1,2,3)))
		pmt_in = pmt.list3(pmt_misc,pmt_range,pmt_power)

		src = blocks.message_strobe(pmt_in, 300)
		est = radar.estimator_rcs(num_mean, center_freq, antenna_gain_tx, antenna_gain_rx, usrp_gain_rx, amplitude, corr_factor, exponent)
		snk = blocks.message_debug()
		self.tb.msg_connect(src,"strobe",est,"Msg in")
		self.tb.msg_connect(est,"Msg out",snk,"store")
		self.tb.msg_connect(est,"Msg out",snk,"print")
		
		self.tb.start()
		sleep(0.5)
		self.tb.stop()
		self.tb.wait()

		# check data

		msg = snk.get_message(0)

		wavel = 3e8/center_freq
		d_antenna_gain_abs_rx = 10**(antenna_gain_rx/10)
		d_antenna_gain_abs_tx = 10**(antenna_gain_tx/10)
		power_rx = power[0]**exponent / 10**(usrp_gain_rx/10);
		power_tx = amplitude

		rcs_ref = (4*math.pi)**(3)/(d_antenna_gain_abs_rx*d_antenna_gain_abs_tx*wavel**2)*Range[0]**4*power_rx/power_tx*corr_factor

		self.assertAlmostEqual( rcs_ref, pmt.f32vector_ref(pmt.nth(1,(pmt.nth(0,msg))),0), 4 ) # check rcs value
	def test_001_t (self):
		# set up fg
		Range = (10, 20, 30)
		power = (15, 30, 45)
		block_time = 100

		pmt_range = pmt.list2(pmt.string_to_symbol('range'),pmt.init_f32vector(len(Range),Range))
		pmt_power = pmt.list2(pmt.string_to_symbol('power'),pmt.init_f32vector(len(power),power))
		pmt_misc = pmt.list2(pmt.string_to_symbol('misc'),pmt.init_f32vector(3,(1,2,3)))
		pmt_in = pmt.list3(pmt_misc,pmt_range,pmt_power)

		src = blocks.message_strobe(pmt_in, 100)
		test = radar.trigger_command("echo test_command",("Range","power"),(5, 10),(35, 50), block_time)
		
		self.tb.msg_connect(src,"strobe",test,"Msg in")
		
		self.tb.start()
		sleep(0.5)
		self.tb.stop()
		self.tb.wait()
	def test_001_t (self):
		# create input data
		steps = 200
		vec_time = np.linspace(0,20,steps);
		vec_velocity = np.linspace(5,5,steps)
		vec_range = np.linspace(100,1,steps)
		vec_velocity_real = [0]*steps
		vec_range_real = [0]*steps
		for k in range(steps):
			vec_velocity_real[k] = vec_velocity[k]
			vec_range_real[k] = vec_range[k]
		
		# random data on trajectory
		mu = 0
		sigma_vel = 0.5
		sigma_rge = 7
		for k in range(len(vec_velocity)):
			vec_velocity[k] = vec_velocity[k] + random.gauss(mu,sigma_vel)
			vec_range[k] = vec_range[k] + random.gauss(mu,sigma_rge)
		
		# set up pmts with zero points
		target_pmts = [0]*len(vec_velocity)
		#zero_points = (5,12,17)
		zero_points = ()
		for k in range(len(vec_velocity)):
			pmt_time = pmt.list2(pmt.string_to_symbol("rx_time"),pmt.make_tuple(pmt.from_long(int(vec_time[k])),pmt.from_double(vec_time[k]-int(vec_time[k]))))
			if k in zero_points:
				vec = [0]
				pmt_velocity = pmt.list2(pmt.string_to_symbol("velocity"),pmt.init_f32vector(1,vec))
				pmt_range = pmt.list2(pmt.string_to_symbol("range"),pmt.init_f32vector(1,vec))
			else:
				pmt_velocity = pmt.list2(pmt.string_to_symbol("velocity"),pmt.init_f32vector(1,(vec_velocity[k],)))
				pmt_range = pmt.list2(pmt.string_to_symbol("range"),pmt.init_f32vector(1,(vec_range[k],)))
			target_pmts[k] = pmt.list3(pmt_time,pmt_velocity,pmt_range)
		
		# set up fg
		test_duration = 1000 # ms, do not change!
		
		num_particle = 300
		std_range_meas = sigma_rge
		std_velocity_meas = sigma_vel
		std_accel_sys = 0.1
		threshold_track = 0.001
		threshold_lost = 4
		tracking_filter = "particle"
		#tracking_filter = "kalman"
		
		# connect multiple strobes for different msgs
		src = [0]*len(target_pmts)
		for k in range(len(target_pmts)):
			src[k] = blocks.message_strobe(target_pmts[k], test_duration-400+400/len(target_pmts)*k)
		tracking = radar.tracking_singletarget(num_particle, std_range_meas, std_velocity_meas, std_accel_sys, threshold_track, threshold_lost, tracking_filter)
		snk = blocks.message_debug()
		
		for k in range(len(target_pmts)):
			self.tb.msg_connect(src[k],"strobe",tracking,"Msg in")
		self.tb.msg_connect(tracking,"Msg out",snk,"store")
		
		self.tb.start()
		sleep(test_duration/1000.0)
		self.tb.stop()
		self.tb.wait
		()
		# check data
#		show_data = False # Toggle visibility of single messages # broken
		msg_num = snk.num_messages()
		vec_out_range = []
		vec_out_velocity = []
		for k in range(msg_num):
			msg_part = snk.get_message(k)
			tme = pmt.nth(0,msg_part) # not used
			vel = pmt.nth(1,msg_part)
			rgn = pmt.nth(2,msg_part)
			vec_out_range.append(pmt.f32vector_elements(pmt.nth(1,rgn))[0])
			vec_out_velocity.append(pmt.f32vector_elements(pmt.nth(1,vel))[0])
#			if show_data:
#				print "msg:", k
#				print pmt.symbol_to_string(pmt.nth(0,vel)), pmt.f32vector_elements(pmt.nth(1,vel))[0]
#				print pmt.symbol_to_string(pmt.nth(0,rgn)), pmt.f32vector_elements(pmt.nth(1,rgn))[0]
#				print 
#		print "RANGE:"
#		print vec_out_range
#		print "VELOCITY:"
#		print vec_out_velocity
		
		# make plots
		show_plots = False # Toggle visibility of plots
		if show_plots:
			time = range(len(vec_range))
			time_out = range(len(vec_out_range))
			plt.figure(1)
			
			plt.subplot(211)
			marker = '-o'
			p1 = plt.plot(time,vec_velocity_real,marker,time,vec_velocity,marker,time_out,vec_out_velocity,marker)
			plt.legend(p1,["IN velocity real", "IN velocity", "OUT velocity"])
			plt.title("VELOCITY")
			plt.xlabel('time')
			
			plt.subplot(212)
			marker = '-o'
			p1 = plt.plot(time,vec_range_real,marker,time,vec_range,marker,time_out,vec_out_range,marker)
			plt.legend(p1,["IN range real","IN range","OUT range"])
			plt.title("RANGE")
			plt.xlabel('time')
			
			plt.show()
    def test_001_t(self):
        # create input data
        steps = 200
        vec_time = np.linspace(0, 20, steps)
        vec_velocity = np.linspace(5, 5, steps)
        vec_range = np.linspace(100, 1, steps)
        vec_velocity_real = [0] * steps
        vec_range_real = [0] * steps
        for k in range(steps):
            vec_velocity_real[k] = vec_velocity[k]
            vec_range_real[k] = vec_range[k]

        # random data on trajectory
        mu = 0
        sigma_vel = 0.5
        sigma_rge = 7
        for k in range(len(vec_velocity)):
            vec_velocity[k] = vec_velocity[k] + random.gauss(mu, sigma_vel)
            vec_range[k] = vec_range[k] + random.gauss(mu, sigma_rge)

        # set up pmts with zero points
        target_pmts = [0] * len(vec_velocity)
        #zero_points = (5,12,17)
        zero_points = ()
        for k in range(len(vec_velocity)):
            pmt_time = pmt.list2(
                pmt.string_to_symbol("rx_time"),
                pmt.make_tuple(pmt.from_long(int(vec_time[k])),
                               pmt.from_double(vec_time[k] -
                                               int(vec_time[k]))))
            if k in zero_points:
                vec = [0]
                pmt_velocity = pmt.list2(pmt.string_to_symbol("velocity"),
                                         pmt.init_f32vector(1, vec))
                pmt_range = pmt.list2(pmt.string_to_symbol("range"),
                                      pmt.init_f32vector(1, vec))
            else:
                pmt_velocity = pmt.list2(
                    pmt.string_to_symbol("velocity"),
                    pmt.init_f32vector(1, (vec_velocity[k], )))
                pmt_range = pmt.list2(pmt.string_to_symbol("range"),
                                      pmt.init_f32vector(1, (vec_range[k], )))
            target_pmts[k] = pmt.list3(pmt_time, pmt_velocity, pmt_range)

        # set up fg
        test_duration = 1000  # ms, do not change!

        num_particle = 300
        std_range_meas = sigma_rge
        std_velocity_meas = sigma_vel
        std_accel_sys = 0.1
        threshold_track = 0.001
        threshold_lost = 4
        tracking_filter = "particle"
        #tracking_filter = "kalman"

        # connect multiple strobes for different msgs
        src = [0] * len(target_pmts)
        for k in range(len(target_pmts)):
            src[k] = blocks.message_strobe(
                target_pmts[k],
                test_duration - 400 + 400 / len(target_pmts) * k)
        tracking = radar.tracking_singletarget(num_particle, std_range_meas,
                                               std_velocity_meas,
                                               std_accel_sys, threshold_track,
                                               threshold_lost, tracking_filter)
        snk = blocks.message_debug()

        for k in range(len(target_pmts)):
            self.tb.msg_connect(src[k], "strobe", tracking, "Msg in")
        self.tb.msg_connect(tracking, "Msg out", snk, "store")

        self.tb.start()
        sleep(test_duration / 1000.0)
        self.tb.stop()
        self.tb.wait
        ()
        # check data
        #		show_data = False # Toggle visibility of single messages # broken
        msg_num = snk.num_messages()
        vec_out_range = []
        vec_out_velocity = []
        for k in range(msg_num):
            msg_part = snk.get_message(k)
            tme = pmt.nth(0, msg_part)  # not used
            vel = pmt.nth(1, msg_part)
            rgn = pmt.nth(2, msg_part)
            vec_out_range.append(pmt.f32vector_elements(pmt.nth(1, rgn))[0])
            vec_out_velocity.append(pmt.f32vector_elements(pmt.nth(1, vel))[0])


#			if show_data:
#				print "msg:", k
#				print pmt.symbol_to_string(pmt.nth(0,vel)), pmt.f32vector_elements(pmt.nth(1,vel))[0]
#				print pmt.symbol_to_string(pmt.nth(0,rgn)), pmt.f32vector_elements(pmt.nth(1,rgn))[0]
#				print
#		print "RANGE:"
#		print vec_out_range
#		print "VELOCITY:"
#		print vec_out_velocity

# make plots
        show_plots = False  # Toggle visibility of plots
        if show_plots:
            time = range(len(vec_range))
            time_out = range(len(vec_out_range))
            plt.figure(1)

            plt.subplot(211)
            marker = '-o'
            p1 = plt.plot(time, vec_velocity_real, marker, time, vec_velocity,
                          marker, time_out, vec_out_velocity, marker)
            plt.legend(p1, ["IN velocity real", "IN velocity", "OUT velocity"])
            plt.title("VELOCITY")
            plt.xlabel('time')

            plt.subplot(212)
            marker = '-o'
            p1 = plt.plot(time, vec_range_real, marker, time, vec_range,
                          marker, time_out, vec_out_range, marker)
            plt.legend(p1, ["IN range real", "IN range", "OUT range"])
            plt.title("RANGE")
            plt.xlabel('time')

            plt.show()