def test_001_t (self): # set up pmt in_2 = (-1,2,-3,4,5,0) in_3 = (1,2,3,4,5,0) in_4 = (1,-2.1,3,-4.2,5.9,0) pmt_1 = pmt.list2(pmt.string_to_symbol("rx_time"),pmt.from_long(0)) pmt_2 = pmt.list2(pmt.string_to_symbol("test"),pmt.init_f32vector(6,in_2)) pmt_3 = pmt.list2(pmt.string_to_symbol("velocity"),pmt.init_f32vector(6,in_3)) pmt_4 = pmt.list2(pmt.string_to_symbol("test2"),pmt.init_f32vector(6,in_4)) pmt_in = pmt.list4(pmt_1,pmt_2,pmt_3,pmt_4) # set up fg symbols = ("test", "test2") const_add = (1, -2) const_mult = (-5, 1) strobe = blocks.message_strobe(pmt_in,400); test = radar.msg_manipulator(symbols,const_add,const_mult) debug = blocks.message_debug() self.tb.msg_connect(strobe, "strobe", test, "Msg in") self.tb.msg_connect(test, "Msg out", debug, "store") self.tb.msg_connect(test, "Msg out", debug, "print") # run fg self.tb.start() sleep(0.5) self.tb.stop() self.tb.wait() # check data msg = debug.get_message(0) out_2 = pmt.f32vector_elements(pmt.nth(1,pmt.nth(1,msg))) out_3 = pmt.f32vector_elements(pmt.nth(1,pmt.nth(2,msg))) out_4 = pmt.f32vector_elements(pmt.nth(1,pmt.nth(3,msg))) ref_2 = [0]*6 ref_3 = [0]*6 ref_4 = [0]*6 for k in range(6): ref_2[k] = (in_2[k]+const_add[0])*const_mult[0] ref_3[k] = in_3[k] ref_4[k] = (in_4[k]+const_add[1])*const_mult[1] for k in range(6): # do asserts self.assertAlmostEqual(ref_2[k],out_2[k],3) self.assertAlmostEqual(ref_3[k],out_3[k],3) self.assertAlmostEqual(ref_4[k],out_4[k],3)
def test_001_t(self): # set up fg Range = (2, 4, 22, 23) velocity = (3, 12, 19, 19) power = (10, 10, 10, 1) # last value is thrown away with merging peaks pmt_time = pmt.list2( pmt.string_to_symbol('rx_time'), pmt.make_tuple(pmt.from_long(-1), pmt.from_double(0))) pmt_axisx = pmt.list2(pmt.string_to_symbol('axis_x'), pmt.init_f32vector(len(Range), Range)) pmt_axisy = pmt.list2(pmt.string_to_symbol('axis_y'), pmt.init_f32vector(len(velocity), velocity)) pmt_power = pmt.list2(pmt.string_to_symbol('power'), pmt.init_f32vector(len(power), power)) pmt_in = pmt.list4(pmt_time, pmt_axisx, pmt_axisy, pmt_power) src = blocks.message_strobe(pmt_in, 300) est = radar.estimator_ofdm('range', 30, (0, 40, -40, 10), 'velocity', 20, (-5, 5)) 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() # get ref data ref_range = (0 + 40 * 2 / 15.0, 0 + 40 * 4 / 15.0, -40 + 50 * (22 - 15) / 15.0) ref_velocity = (-5 + 10 * 3 / 20.0, -5 + 10 * 12 / 20.0, -5 + 10 * 19 / 20.0) # check data msg = snk.get_message(0) val_range = pmt.f32vector_elements(pmt.nth(1, pmt.nth(1, msg))) val_velocity = pmt.f32vector_elements(pmt.nth(1, pmt.nth(2, msg))) print val_range self.assertFloatTuplesAlmostEqual(val_velocity, ref_velocity, 4) self.assertFloatTuplesAlmostEqual(val_range, ref_range, 4)
def msg_handler(self, p): self.counter = self.counter + 1 if self.counter == self.d_period: self.counter = 0 #print "turning ", self.d_degrees_per_trigger, " degrees" self.angle += self.d_degrees_per_trigger if self.d_serial_port != "": self.ttctrl.move_to(self.angle) if self.angle > self.d_stop: print "Stopping execution now" #sys.exit(0) ang_key = pmt.string_to_symbol("angle") ang_value = pmt.init_f32vector(1, [self.angle]) ang_pack = pmt.list2(ang_key, ang_value) #m = pmt.list1(ang_pack) m = pmt.list4(pmt.nth(0, p), pmt.nth(1, p), pmt.nth(2, p), ang_pack) #pmt.list_add(m, p) self.message_port_pub(pmt.string_to_symbol("out"), m)