树莓派或ubuntu安装mavros

这篇文章介绍源码安装mavros的方法,ubuntu和树莓派基本相同,如下:
1、安装依赖

sudo apt-get install python-catkin-tools python-rosinstall-generator -y

2、创建工作空间

mkdir -p ~/mavros_ws/src
cd ~/mavros_ws
catkin init
wstool init src

3、安装mavlink和mavros

rosinstall_generator --rosdistro kinetic mavlink | tee /tmp/mavros.rosinstall
rosinstall_generator --upstream mavros | tee -a /tmp/mavros.rosinstall

4、设置工作空间并安装

wstool merge -t src /tmp/mavros.rosinstall
wstool update -t src -j4
rosdep install --from-paths src --ignore-src -y

在这个过程中会出现一些问题:
(1)
在这里插入图片描述
这个问题就是还没安全包,继续执行:

rosinstall_generator --rosdistro kinetic "所缺的包" | tee -a /tmp/mavros.rosinstall

其中"所缺的包"由报错里中括号里的包替换,如上图中的trajectory_msgs、tf2_eigen等。安装完后重新执行:

wstool merge -t src /tmp/mavros.rosinstall
wstool update -t src -j4
rosdep install --from-paths src --ignore-src -y

可能还会出现上述错误,就是还有新的包没安装,再去安装,重复执行直到没有报错即可。
(2)安装出错,总是连不上,返回connection refused。
这个错误一般重新安装即可,但是可能会一直连不上,试成千上万次试到自闭,这里改一下本地hosts文件来提速:

sudo vim /etc/hosts

在该文件最后添加:

192.30.253.112 github.com
192.30.253.118 gist.github.com
151.101.112.133 assets-cdn.github.com
151.101.184.133 raw.githubusercontent.com

然后重启网络服务:

sudo /etc/init.d/networking restart

之后再重新安装,发现不会发生连不上的问题了hhhh
5、安装GeographicLib datasets(这个用时可能会比较长,耐心等)

sudo ./src/mavros/mavros/scripts/install_geographiclib_datasets.sh

6、catkin编译
在编译前应把交换文件大小调大,防止编译时出现交换空间不足的错误:
打开文件/etc/dphys-swapfile,将CONF_SWAPSIZE改为1024或2048(原来是100),然后保存退出,执行下面的命令让它生效:

sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start

之后再进行编译

catkin build

在catkin build时,可能会出现各种各样的错误,下面列举我出现的错误以及解决方案:
(1)出现找不到python解释器的错误,如图:
在这里插入图片描述
原因在于src/mavlink/CMakeLists里第27行:

find_package(Python${Py_VERSION} COMPONENTS Interpretator)

这里找的包名称为Python${Py_VERSION},而打开/usr/bin可以发现我的python解释器只有python、python2、python2.7,解决方案有两种,一是再建一个名为Python2的软链接,二是把这里的P改成小写:

find_package(python${Py_VERSION} COMPONENTS Interpretator)

编译成功
(2)“logError not in the scope”,“logWarn not in the scope”等错误
这是因为缺少logError等的宏定义导致的,直接在该文件下添加宏定义即可:
文件:/usr/include/console_bridge/console.h
添加:

#define logWarn CONSOLE_BRIDGE_logWarn
#define logError CONSOLE_BRIDGE_logError
#define logDebug CONSOLE_BRIDGE_logDebug
#define logInform CONSOLE_BRIDGE_logInform

重新编译,编译成功
(3)出现如下图所示错误:
在这里插入图片描述
这是因为新版的boost不允许部分函数在传参的时候进行自动类型转换,所以我们要手动进行类型转换。打开出错文件,将参数强制转换为long型,在这里我打开/home/pi/mavros_ws/src/actionlib/src/connection_monitor.cpp,将278行对应部分改为:

boost::posix_time::milliseconds((long)(time_left.toSec() * 1000.0f)));

编译成功

发布了11 篇原创文章 · 获赞 1 · 访问量 367

猜你喜欢

转载自blog.csdn.net/qq_43414059/article/details/104065219
今日推荐