PX4飞控学习与开发(三)-PX4+ROS开发环境搭建
Pixhawk固件1.8.2的下载与编译主要步骤如下:第一步,Pixhawk固件1.8.2下载:参考网页PX4飞控,工具链下载安装:ubuntu_sim_nuttx.sh参考网页PX4工具链下载网址;第二步,打开终端,通过 \textcolor{red}{cd}指令进入配置文件 ubuntu_sim_nuttx.sh所在的文件夹,在终端运行指令: source ubuntu_sim_nuttx.s
·
PX4开发环境搭建
主要步骤如下:
- 第一步,设置用户组。在终端输入命令:
sudo usermod -a -G dialout $USER
,然后登出,重启; - 第二步,Pixhawk固件1.8.2下载:参考网页PX4飞控,工具链下载安装:
ubuntu_sim_nuttx.sh
参考网页PX4工具链下载网址,或者从我的CSDN资源中下载,分了三个脚本文件,为:
- 第三步,打开终端,通过
cd
指令进入配置文件ubuntu_sim_nuttx.sh
所在的文件夹,如果是在官网下载的脚本,可在终端运行指令:source ubuntu_sim_nuttx.sh
;官网下载或可能失败,可在第二步中提供的资源中下载需要三个文件,则需输入三次脚本运行指令,依次为source ubuntu_deps.sh
、source ubuntu_sim.sh
、source ubuntu_sim_nuttx.sh
安装好了之后重启电脑; - 第三步,安装jinja2(编译时需要),新开一个终端,运行:
sudo pip install jinja2
; - 第四步,安装串口驱动(下载固件时需要),在新终端里,运行:
sudo pip install pyserial
,如果安装了Python3,也可以是sudo pip3 install pyserial
; - 第五步,cd进入Firmware文件夹,运行:
make px4fmu-v2_default
;,即编译固件; - 第六步,连接飞控板和电脑,运行
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
,出现以下结果即编译成功:
更多推荐
所有评论(0)