PX4飞控学习与开发(三)-PX4+ROS开发环境搭建

PX4开发环境搭建

主要步骤如下:

  1. 第一步,设置用户组。在终端输入命令: sudo usermod -a -G dialout $USER,然后登出,重启;
  2. 第二步,Pixhawk固件1.8.2下载:参考网页PX4飞控,工具链下载安装:ubuntu_sim_nuttx.sh参考网页PX4工具链下载网址,或者从我的CSDN资源中下载,分了三个脚本文件,为:
  1. 第三步,打开终端,通过cd指令进入配置文件 ubuntu_sim_nuttx.sh所在的文件夹,如果是在官网下载的脚本,可在终端运行指令: source ubuntu_sim_nuttx.sh;官网下载或可能失败,可在第二步中提供的资源中下载需要三个文件,则需输入三次脚本运行指令,依次为source ubuntu_deps.shsource ubuntu_sim.shsource ubuntu_sim_nuttx.sh安装好了之后重启电脑;
  2. 第三步,安装jinja2(编译时需要),新开一个终端,运行: sudo pip install jinja2;
  3. 第四步,安装串口驱动(下载固件时需要),在新终端里,运行: sudo pip install pyserial,如果安装了Python3,也可以是 sudo pip3 install pyserial;
  4. 第五步,cd进入Firmware文件夹,运行: make px4fmu-v2_default;,即编译固件;
  5. 第六步,连接飞控板和电脑,运行 make px4fmu-v2_default upload.视情况中间可能需要插拔下USB线。

下载成功界面如下:
下载成功界面
PS:编译可能遇到以下问题在这里插入图片描述
这是因为tools里有些文件没有添加权限,在目录~/Firmware/platforms/nuttx/Nuttx/nuttx/下打开终端,输入以下指令:

chmod -R 777 tools/

如下图所示:
在这里插入图片描述
然后再编译,就能成功:
在这里插入图片描述

ROS开发环境搭建

按上述搭建的PX4开发环境可能无法运行QGC地面站,需要将系统ubuntu升级到18.0版本(在设置里找到详细信息-系统检查更新)。升级之后装ROS时,注意要安装ROS Melodic版本不是ROS kinetic,可参考 这篇博客
成功安装后,通过source ubuntu_sim_ros_gazebo.sh脚本文件安装mavros,脚本文件内容为:

#!/bin/bash


cd ~/catkin_ws

## Build MAVROS
### Get source (upstream - released)
rosinstall_generator --upstream mavros | tee /tmp/mavros.rosinstall
### Get latest released mavlink package
rosinstall_generator mavlink | tee -a /tmp/mavros.rosinstall
### Setup workspace & install deps
wstool merge -t src /tmp/mavros.rosinstall
wstool update -t src
if ! rosdep install --from-paths src --ignore-src --rosdistro melodic -y; then
    # (Use echo to trim leading/trailing whitespaces from the unsupported OS name
    unsupported_os=$(echo $(rosdep db 2>&1| grep Unsupported | awk -F: '{print $2}'))
    rosdep install --from-paths src --ignore-src --rosdistro melodic -y --os ubuntu:xenial
fi
## Build!
catkin build
## Re-source environment to reflect new packages/build environment
catkin_ws_source="source ~/catkin_ws/devel/setup.bash"
if grep -Fxq "$catkin_ws_source" ~/.bashrc; then echo ROS catkin_ws setup.bash already in .bashrc; 
else echo "$catkin_ws_source" >> ~/.bashrc; fi
eval $catkin_ws_source

echo "Downloading dependent script 'install_geographiclib_datasets.sh'"
# Source the install_geographiclib_datasets.sh script directly from github
install_geo=$(wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh -O -)
wget_return_code=$?
# If there was an error downloading the dependent script, we must warn the user and exit at this point.
if [[ $wget_return_code -ne 0 ]]; then echo "Error downloading 'install_geographiclib_datasets.sh'. Sorry but I cannot proceed further :("; exit 1; fi
# Otherwise source the downloaded script.
sudo bash -c "$install_geo"

# Go to the firmware directory
cd $clone_dir/Firmware

if [[ ! -z $unsupported_os ]]; then
    >&2 echo -e "\033[31mYour OS ($unsupported_os) is unsupported. Assumed an Ubuntu 18.04 installation,"
    >&2 echo -e "and continued with the installation, but if things are not working as"
    >&2 echo -e "expected you have been warned."
fi

~/catkin_ws内运行catkin build检查mavros是否正确编译,可能会出现以下错误:
在这里插入图片描述此时运行指令:

sudo apt-get install ros-melodic-mavros ros-melodic-mavros-extras

即可将缺少的包安装上。再次运行catkin build,出现以下结果即编译成功:
在这里插入图片描述

  • 10
    点赞
  • 48
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值