2016-02-26 65 views
0

我使用GNU Radio Companion來構建我的OOT模塊來執行順序能量檢測。我安裝了它成功的,但是當我在流圖中運行它有一個錯誤:GNU Radio ValueError:無法強制端點

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文件中添加這一部分:

    浮動β()const的{返回d_beta; }

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

    爲什麼我們需要添加此零件?只是因爲beta是一個私有變量,我們需要在impl.cc文件中使用它?

  • int和size_t是否有區別?我可以將'size_t number'更改爲'int number'嗎?

+0

我很困惑。你的問題標題說明了與實際問題不同的內容。現在它是什麼,「不能強制端點」或「AttributeError」? –

+0

我很抱歉,這是「無法強制終結點」。 – Betty

+0

還要添加ValueError發生的行; Python應該告訴你哪一行是,以及一些周圍的代碼。 –

回答

0

「無法強制端點」通常意味着您忘記連接所有輸入和輸出,或試圖連接到一個輸入或不存在的輸出。錯誤地嘗試連接一些完全不是塊的東西也很常見。

看看你生成的(Python)代碼。在該行發生值錯誤,您應該在connect呼叫。檢查你在那裏連接的東西:你真的連接正確的東西嗎?

+0

但爲什麼我再次連接流圖,它出現'沒有屬性'seq_energy''?非常感謝。 – Betty