Search code examples
pythonc++python-3.xgnuradiognuradio-companion

AttributeError: module 'tutorial' has no attribute 'my_qpsk_demod_cb' given by Gnuradio Companion


I have another question. I have been following a tutorial for creating a QPSK demodulator. Here is the link: https://wiki.gnuradio.org/index.php/Guided_Tutorial_GNU_Radio_in_C%2B%2B I was able to fix a different issue and fixed a warning that I was receiving but, a new problem has come about and I can't seem to fix it. Here is the error:

Traceback (most recent call last):
File "/home/mariom/gr-tutorial/build/top_block.py", line 191, in <module> 
 main()
File "/home/mariom/gr-tutorial/build/top_block.py", line 167, in main 
 tb = top_block_cls()
File "/home/mariom/gr-tutorial/build/top_block.py", line 82, in __init__
 self.tutorial_my_qpsk_demod_cb_0 = tutorial.my_qpsk_demod_cb(True)
AttributeError: module 'tutorial' has no attribute 'my_qpsk_demod_cb'

Noramlly when I see this error, I think I know how to fix this and go find the module tutorial and add the my_qpsk_demod_cb. This time, I seem to be running into the problem that I can't seem to find the right area or maybe I am in the right area. I understand that the issue is from the block I made from the tutorial so any thought? Here is block codes.

My_qpsk_demod_cb_impl.cc

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

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

namespace gr {
 namespace tutorial {

   my_qpsk_demod_cb::sptr
   my_qpsk_demod_cb::make(bool gray_code)
  {
    return gnuradio::get_initial_sptr
      (new my_qpsk_demod_cb_impl(gray_code));
  }

  /*
   * The private constructor
   */
  my_qpsk_demod_cb_impl::my_qpsk_demod_cb_impl(bool gray_code)
    : gr::block("my_qpsk_demod_cb",
            gr::io_signature::make(1, 1, sizeof(gr_complex)),
            gr::io_signature::make(1, 1, sizeof(char))),
      d_gray_code(gray_code)
  {
  }

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

  void
  my_qpsk_demod_cb_impl::forecast(int noutput_items,
                   gr_vector_int &ninput_items_required)
  {
  unsigned ninputs = ninput_items_required.size ();
  for(unsigned i = 0; i < ninputs; i++)
    ninput_items_required[i] = noutput_items;
  }

  unsigned char
  my_qpsk_demod_cb_impl::get_minimum_distances(const gr_complex &sample)
  {
    if (d_gray_code) {
      unsigned char bit0 = 0;
      unsigned char bit1 = 0;
      // The two left quadrants (quadrature component < 0) have this bit set to 1
      if (sample.real() < 0) {
        bit0 = 0x01;
      }
      // The two lower quadrants (in-phase component < 0) have this bit set to 1
      if (sample.imag() < 0) {
        bit1 = 0x01 << 1;
      }
      return bit0 | bit1;
      } else {
      // For non-gray code, we can't simply decide on signs, so we check every single 
    quadrant.
     if (sample.imag() >= 0 and sample.real() >= 0) {
        return 0x00;
     }
     else if (sample.imag() >= 0 and sample.real() < 0) {
       return 0x01;
     }
     else if (sample.imag() < 0 and sample.real() < 0) {
      return 0x02;
     }
     else if (sample.imag() < 0 and sample.real() >= 0) {
      return 0x03;
     }
   }
   return 0;
 }

 int
 my_qpsk_demod_cb_impl::general_work (int noutput_items,
                    gr_vector_int &ninput_items,
                    gr_vector_const_void_star &input_items,
                    gr_vector_void_star &output_items)
 {
     const gr_complex *in = (const gr_complex *) input_items[0];
        unsigned char *out = (unsigned char *) output_items[0];
        gr_complex origin = gr_complex(0,0);
        // Perform ML decoding over the input iq data to generate alphabets
        for(int i = 0; i < noutput_items; i++)
        {
                // ML decoder, determine the minimum distance from all constellation points
                out[i] = get_minimum_distances(in[i]);
        }
        // Tell runtime system how many input items we consumed on
        // each input stream.
        consume_each (noutput_items);
        // Tell runtime system how many output items we produced.
        return noutput_items;
    }
  } /* namespace tutorial */
} /* namespace gr */

my_qpsk_demod_cb_impl.h

#ifndef INCLUDED_TUTORIAL_MY_QPSK_DEMOD_CB_IMPL_H
#define INCLUDED_TUTORIAL_MY_QPSK_DEMOD_CB_IMPL_H

#include <tutorial/my_qpsk_demod_cb.h>

namespace gr {
  namespace tutorial {

    class my_qpsk_demod_cb_impl : public my_qpsk_demod_cb
    {
    private:
      bool d_gray_code;

    public:
      my_qpsk_demod_cb_impl(bool gray_code);
      ~my_qpsk_demod_cb_impl();
      unsigned char get_minimum_distances(const gr_complex &sample);

      // Where all the action really happens
      void forecast (int noutput_items, gr_vector_int &ninput_items_required);

      int general_work(int noutput_items,
           gr_vector_int &ninput_items,
           gr_vector_const_void_star &input_items,
           gr_vector_void_star &output_items);
    };

  } // namespace tutorial
} // namespace gr

#endif /* INCLUDED_TUTORIAL_MY_QPSK_DEMOD_CB_IMPL_H */

Solution

  • I think you are missing swig/dependencies or PYTHONPATH. I had the same issue, and was able to resolve it by following these fixes:

    1. Install dependencies specific to your environment (including swig): https://wiki.gnuradio.org/index.php/UbuntuInstall#Bionic_Beaver_.2818.04.29_through_Eoan_Ermine_.2819.10.29
    2. Configure PYTHONPATH and/or LD_LIBRARY_PATH according to these steps: https://wiki.gnuradio.org/index.php/ModuleNotFoundError

    (Note that order may matter according to this case: https://lists.gnu.org/archive/html/discuss-gnuradio/2016-03/msg00065.html)