GNU Radio ValueError:无法强制端点

时间:2016-02-26 18:57:27

标签: c++ gnuradio

我正在使用GNU Radio Companion构建我的OOT块以进行顺序能量检测。我成功安装了它,但是当我在流程图中运行它时出现错误:

ValueError:无法强制终结

但是在我再次连接流程图之后,又出现了另一个错误:

Using Volk machine: avx_64_mmx_orc

Traceback (most recent call last):

  File "/home/mint/Documents/test_sensor/energy_de/seq_energy.py", line 92, in <module>

    tb = seq_energy()

  File "/home/mint/Documents/test_sensor/energy_de/seq_energy.py", line 62, in __init__

    self.sensing_seq_energy_0 = sensing.seq_energy(256, 20, 0.01, 0.1, 0.084)
AttributeError: 'module' object has no attribute 'seq_energy'

seq_energy.py:

from gnuradio import analog
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio import wxgui
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from gnuradio.wxgui import scopesink2
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import sensing
import wx

class seq_energy(grc_wxgui.top_block_gui):

    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Seq Energy")
        _icon_path = "/home/mint/.local/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 2000000
        self.freq = freq = 250000

        ##################################################
        # Blocks
        ##################################################
        self.wxgui_scopesink2_1_0_0_0 = scopesink2.scope_sink_f(
            self.GetWin(),
            title="Scope Plot2",
            sample_rate=samp_rate,
            v_scale=0,
            v_offset=0,
            t_scale=0,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=wxgui.TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.Add(self.wxgui_scopesink2_1_0_0_0.win)
        self.sensing_seq_energy_0 = sensing.seq_energy(256, 20, 0.01, 0.1, 0.084)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True)
        self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 1000, 1, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_throttle_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.sensing_seq_energy_0, 0))    
        self.connect((self.sensing_seq_energy_0, 0), (self.wxgui_scopesink2_1_0_0_0, 0))    


    def get_samp_rate(self):
        return self.samp_rate

    def set_samp_rate(self, samp_rate):
        self.samp_rate = samp_rate
        self.blocks_throttle_0.set_sample_rate(self.samp_rate)
        self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)
        self.wxgui_scopesink2_1_0_0_0.set_sample_rate(self.samp_rate)

    def get_freq(self):
        return self.freq

    def set_freq(self, freq):
        self.freq = freq

if __name__ == '__main__':
    parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
    (options, args) = parser.parse_args()
    tb = seq_energy()
    tb.Start(True)
    tb.Wait()

我创建了包含四个文件的块'seq_energy':

1.seq_energy.h

#ifndef INCLUDED_SENSING_SEQ_ENERGY_H
#define INCLUDED_SENSING_SEQ_ENERGY_H

#include <sensing/api.h>
#include <gnuradio/sync_block.h>

namespace gr {
  namespace sensing {

    /*!
     * \brief <+description of block+>
     * \ingroup sensing
     *
     */
    class SENSING_API seq_energy : virtual public gr::sync_block
    {
     public:
      typedef boost::shared_ptr<seq_energy> sptr;

      /*!
       * \brief Return a shared_ptr to a new instance of sensing::seq_energy.
       *
       * To avoid accidental use of raw pointers, sensing::seq_energy's
       * constructor is in a private implementation
       * class. sensing::seq_energy::make is the public interface for
       * creating new instances.
       */
      static sptr make(size_t number, int slots,float beta,float alpha, float noise);

      virtual float beta() const = 0;
      virtual void set_beta(float beta) = 0;
      virtual float alpha() const = 0;
      virtual void set_alpha(float alpha) = 0;
      virtual float noise() const = 0;
      virtual void set_noise(float noise) = 0;
    };

  } // namespace sensing
} // namespace gr

2.seq_energy_impl.h

#ifndef INCLUDED_SENSING_SEQ_ENERGY_IMPL_H
#define INCLUDED_SENSING_SEQ_ENERGY_IMPL_H

#include <sensing/seq_energy.h>

namespace gr {
  namespace sensing {

    class seq_energy_impl : public seq_energy
    {
     private:
      size_t d_number;
      int d_slots;
      float d_beta, d_alpha, d_noise;

     public:
      seq_energy_impl(size_t number, int slots,float beta,float alpha, float noise);
      ~seq_energy_impl();

      void forecast (int noutput_items, gr_vector_int &ninput_items_required);
      float beta() const { return d_beta; }
      void set_beta(float beta) { d_beta = beta; }
      float alpha() const { return d_alpha; }
      void set_alpha(float alpha) { d_alpha = alpha; }
      float noise() const { return d_noise; }
      void set_noise(float noise) { d_noise = noise; }

      // Where all the action really happens
      int work(int noutput_items,
           gr_vector_const_void_star &input_items,
           gr_vector_void_star &output_items);
    };

  } // namespace sensing
} // namespace gr

3.seq_energy_impl.cc

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gnuradio/io_signature.h>
#include "seq_energy_impl.h"

namespace gr {
  namespace sensing {

    seq_energy::sptr
    seq_energy::make(size_t number, int slots,float beta,float alpha, float noise)
    {
      return gnuradio::get_initial_sptr
        (new seq_energy_impl(number, slots, beta, alpha, noise));
    }

    /*
     * The private constructor
     */
    seq_energy_impl::seq_energy_impl(size_t number, int slots,float beta,float alpha, float noise)
      : gr::sync_block("seq_energy",
              gr::io_signature::make(1, 1, number*sizeof(float)),
              gr::io_signature::make(1, 1, sizeof(float))),
        d_number(number),d_slots(slots),d_beta(beta),d_alpha(alpha),d_noise(noise)
    {}

    /*
     * Our virtual destructor.
     */
    seq_energy_impl::~seq_energy_impl()
    {
    }

    int
    seq_energy_impl::work(int noutput_items,
              gr_vector_const_void_star &input_items,
              gr_vector_void_star &output_items)
    {
        const float *in = (const float *) input_items[0];
        float *out = (float *) output_items[0];


        for(int i = 0; i < noutput_items; i++){
            float sum[i];
            for(int j = 0; j < (int)d_number;j++){
                sum[i] += in[i*d_number];
            }
            if(sum[i] > d_alpha){
              out[i] =1.0;
            }
            else if(sum[i] < d_beta){
              out[i] = 0.0;
            }
            else if(sum[i] > d_noise){
              out[i] = 1.0;
            }
            else{
              out[i] = 0.0;
            }
        }
        return noutput_items;
    }

  } /* namespace sensing */
} /* namespace gr */

4.enery_impl.xml

<?xml version="1.0"?>
<block>
  <name>seq_energy</name>
  <key>sensing_seq_energy</key>
  <category>sensing</category>
  <import>import sensing</import>
  <make>sensing.seq_energy($number, $slots, $beta, $alpha, $noise)</make>
  <callback>set_beta($beta)</callback>
  <callback>set_alpha($alpha)</callback>
  <callback>set_noise($noise)</callback>

  <param>
    <name>Number of samples</name>
    <key>number</key>
    <type>int</type>
  </param>
 <param>
    <name>Maximum sensing slots</name>
    <key>slots</key>
    <type>int</type>
  </param>
 <param>
    <name>Beta threshold</name>
    <key>beta</key>
    <type>float</type>
  </param>
 <param>
    <name>Alpha threshold</name>
    <key>alpha</key>
    <type>float</type>
  </param>
 <param>
    <name>Estimated noise power</name>
    <key>noise</key>
    <type>float</type>
  </param>

  <sink>
    <name>in</name>
    <type>float</type>
  </sink>


  <source>
    <name>out</name>
    <type>float</type>
  </source>
</block>

此外,我想知道

  • 是否需要在impl.h文件中添加此部分:

    float beta()const {return d_beta; }

    void set_beta(float beta){d_beta = beta; }

    为什么我们需要添加这部分?只是因为beta是一个私有变量,我们需要在impl.cc文件中使用它?

  • int和size_t之间有什么区别吗?我可以将'size_t number'更改为'int number'吗?

1 个答案:

答案 0 :(得分:0)

&#34;无法强制终点&#34;通常意味着您忘记连接所有输入和输出,或者尝试连接到不存在的输入或输出。错误地尝试连接不是块的东西也很常见。

查看您生成的(Python)代码。在该行抛出值错误,您应该进行connect调用。检查你在那里连接的东西:你真的连接正确的东西吗?