Hello,
I am using a Gnuradio Python Block in my GRC signal processing and am having problems initializing my parameters. My system has a number of vector parameters to be initialized at startup. I will provide the gist of my goal in a scaled down version of my work.
1. In the def __init__(self, start = True) method, "start" is the parameter that will be used in the program to run the initialization process and is set as follows:
self.start = start
2. In the work(self, input_items, output_items) method, I have the following at the start of the method:
if self.start == True:
v = self.my_init() # go initialize all vectors
output_items[0][:] = in0*v[0] + in1*v[1] + in2*v[2] #computation using v
# with 3-inputs to the block
3. In the my_init(self) method I have:
self.start = False # set start to False
v = np.array([1., 2., 3.]) #hypothetical to make this simple
return v
When I run the GRC model, it tells me that "v" is referenced before assignment. I am confused because I thought that the method my_init() would have been called before the computation and would return the values for "v". On the other hand if I do the assignment in the work(...) method as
v = np.array([1., 2., 3.]), it works perfectly.
Question: Why was the my_init() method not called properly to get the values for the numpy array v?
Thanks for the help!
Regards,
George