艰辛的Gnuradio搭建之路——Ubuntu安装配置gnuradio
整理了一下Ubuntu18.04下的以及我遇到的几个常见和罕见的bug。
1.Gnuradio 安装
首先推荐一些依赖。
sudo apt-get -y install git swig cmake doxygen build-essential libboost-all-dev libtool libusb-1.0-0 libusb-1.0-0-dev libudev-dev libncurses5-dev libfftw3-bin libfftw3-dev libfftw3-doc libcppunit-1.14-0 libcppunit-dev libcppunit-doc ncurses-bin cpufrequtils python-numpy python-numpy-doc python-numpy-dbg python-scipy python-docutils qt4-bin-dbg qt4-default qt4-doc libqt4-dev libqt4-dev-bin python-qt4 python-qt4-dbg python-qt4-dev python-qt4-doc python-qt4-doc libqwt6abi1 libfftw3-bin libfftw3-dev libfftw3-doc ncurses-bin libncurses5 libncurses5-dev libncurses5-dbg libfontconfig1-dev libxrender-dev libpulse-dev swig g++ automake autoconf libtool python-dev libfftw3-dev libcppunit-dev libboost-all-dev libusb-dev libusb-1.0-0-dev fort77 libsdl1.2-dev python-wxgtk3.0 git libqt4-dev python-numpy ccache python-opengl libgsl-dev python-cheetah python-mako python-lxml doxygen qt4-default qt4-dev-tools libusb-1.0-0-dev libqwtplot3d-qt5-dev pyqt4-dev-tools python-qwt5-qt4 cmake git wget libxi-dev gtk2-engines-pixbuf r-base-dev python-tk liborc-0.4-0 liborc-0.4-dev libasound2-dev python-gtk2 libzmq3-dev libzmq5 python-requests python-sphinx libcomedi-dev python-zmq libqwt-dev libqwt6abi1 python-six libgps-dev libgps23 gpsd gpsd-clients python-gps python-setuptools
复制命令行中使用apt安装。
接下来官网推荐了两种安装方式,一种是通过apt,另一种是编译源码进行安装。
此处强烈推荐通过apt进行安装,非常省心。源码编译起来非常的慢!
不过默认的apt镜像以及几个国内镜像中一般会安装gnuradio3.7 版本(2021年04月26日00:46:12),因此我们需要按照官网上的步骤。

例如我们想安装3.8版本,则需要配置
sudo add-apt-repository ppa:gnuradio/gnuradio-releases-3.8
注意add-apt-repository 操作进行一次就可以了,否则如果添加多个仓库,再进行apt install之后应该会直接安装最高的版本。
/etc/apt/sources.list.d
如果不小心add了多个仓库,可以在如下路径中找到并且删除掉相应的仓库。如下图所示,经过添加仓库操作后,我们就可以再apt的配置目录中看到相应的文件。

添加仓库之后记得更新apt
apt update
以上命令如果权限不够,加sudo!!!
接下来
sudo apt install gnuradio
即可安装所需版本的gnuradio。
如果你想尝试手动编译安装,按照官网教程即可,此处不做赘述。
2.配置gr_modtool
理论上这里gr_modtool已经可以用了,但是如果这时候创建项目
gr_modtool newmod test
命令行很有可能看到一串报错,大概是关于UTF-8什么的,这时候运行
cd /usr/share/gnuradio/modtool/templates/gr-newmod
sudo py3clean .
接下来就可以正常使用gr_modtool命令了。
3.创建一个gr_modtool 项目实例
首先找一个空目录,我们计划把项目建在这里
gr_modtool newmod [项目名]
如图所示,我们创建一个名为liu(为了纪念我的好友),进入目录可以看到一个完整的工程目录。

接下来我们创建一个模块,依然用好友的英文名herry。

此时我们可以看到,gr_modtool自动为我们生成了两个文件,分别是grc/liu_herry.block.yml 和 python/herry.py两个文件。

其中yaml是一个配置文件,规定了该模块的输入输出类型以及模块内部的可变参数。我们将其修改为:
id: liu_herry
label: herry
category: '[liu]'templates:imports: import liumake: liu.herry()# Make one 'parameters' list entry for every parameter you want settable from the GUI.
# Keys include:
# * id (makes the value accessible as \$keyname, e.g. in the make entry)
# * label (label shown in the GUI)
# * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...)
parameters:# Make one 'inputs' list entry per input and one 'outputs' list entry per output.
# Keys include:
# * label (an identifier for the GUI)
# * domain (optional - stream or message. Default is stream)
# * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...)
# * vlen (optional - data stream vector length. Default is 1)
# * optional (optional - set to 1 for optional inputs. Default is 0)
inputs:
- label: herry_indtype: floatoutputs:
- label: herry_outdtype: float# 'file_format' specifies the version of the GRC yml format used in the file
# and should usually not be changed.
file_format: 1
然后再修改herry.py文件
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2021 gr-liu author.
#
# This is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#import numpy
from gnuradio import grclass herry(gr.sync_block):"""docstring for block herry"""def __init__(self):gr.sync_block.__init__(self,name="herry",in_sig=[numpy.float, ],out_sig=[numpy.float, ])def work(self, input_items, output_items):in0 = input_items[0]out = output_items[0]# <+signal processing here+>out[:] = in0return len(output_items[0])
最后编译安装
mkdir build
cd build
sudo cmake ../
sudo make -j8
sudo make install
sudo ldconfig
就可以在gnuradio中看到这个模块了。
注意这里可能有个bug,那就是如果你的gnuradio中能看到自定义模块,但是运行的时候报错为Module liu not found,则说明自定义模块安装有点问题。
这是因为gr项目在安装时,会创建一个项目名称liu的python模块,在运行时import liu。但是gnuradio可能找不到这个模块(这个bug可能比较罕见)。
我们可以观察运行sudo make install时的日志,找到这个python模块的安装目录,如果出现上述错误,一般这里就是因为安装到了
/usr/local/lib/python3/dist-packages/
这个目录了,而实际上python3的包目录一般在这里
/usr/lib/python3/dist-packages/
因此在上述步骤的cmake中,可以修改安装目录再进行后续安装步骤
cmake -DCMAKE_INSTALL_PREFIX=/usr ../
就可以正常安装了。
我们的实例模块讲复信号的实部单独抽出来(没什么具体功能,演示而已),按照上图构图,输出为

本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
