PX4无人机资料开发
1.1 Ubuntu系统的安装及相关工具使用
- ubuntu 系统安装以及简单使用以及git,markdown工具的使用
- 常用工具使用(git markdown)
ubuntu 系统安装以及基础使用
系统安装
-
准备一台电脑(8核,GPU,8G内存以上,固态硬盘),移动U盘(4G以上)
-
windows下使用虚拟机安装ubuntu
-
ubuntu单系统
-
windows与ubuntu双系统
-
双系统安装
uefi+gpt方式启动。
双系统安装教程
ubutnu系统最好安装到固态硬盘上
如果安装完毕,只能进入单个系统,而且重启后进入电脑boot manager,可以进去另一个系统。那么就需要进入ubuntu系统中来修改grub.cfg添加window启动引导项。
menuentry 'Windows 10' {
search --file --no-floppy --set=root /EFI/MICROSOFT/BOOT/BOOTMGFW.EFI
chainloader /EFI/MICROSOFT/BOOT/BOOTMGFW.EFI
}
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uRjBHdKU-1648797860413)(…/img/chap1/grubwindow.png)]
ubuntu基础使用
常用工具下载 vim typora chrome wps gpu驱动 source源修改 快捷键 搜狗在线翻译等
alt+ctrl+t :
中文输入法安装
-
使用
-
常用命令
tab 键自动补齐;
mv souce target 用target重命名source
cp souce target
ls -al 显示所有文件的详细信息
mkdir (make directories) 创建目录
rmdir(remove empty diretories) 删除空目录
rm -rf 删除文件夹
touch 创建空文件
cat 显示文件内容
find 搜索文件,find -name xx ;find -iname xx (不区分大小写);
which 搜索命令所在目录
whereis 搜索文件所在目录及帮助文档路径
grep 显示指定的文字 grep int main.c ; ls -al | grep xx.
cd - 进入上次访问的目录
cd … 返回上一目录
ps -aux 查看进程资源(快照)
top 实施显示进程资源
sudo chown -R bingo
chown -R bingo /filename/dir/ # 将 filename/dir 的所属用户改为 userA 用户 ,-R是递归指令,即dir下所有文件都改变
chgrp -R bingo /filename/dir/ # 将 filename/dir 的所属组改为 grpA 组,-R是递归指令,即dir下所有文件都改变
sudo usermod -a -G dialout $USER 添加用户到dialout组中
sudo chmod 774 /code/readme.txt 设置文件的权限 User : 7 = 111 表示具有 ” r , w , x” 权限 Group : 7 = 111 表示具有 ” r , w , x” 权限 Other : 4 = 100 表示只具有 ” r ” 权限,而没有 “w,x” 权限
VIM编辑常用命令
:wq 保存并退出
:q!强制退出且不保存
set nu 设置行号
dd 删除当前行
yy 复制当前行
8yy复制光标以下8行(包括光标所在行)
p 粘贴
gg 跳到文件的首行
G 跳到文件的尾行
0 、Home键 行首
¥ 、End键 行尾
/ xx 搜索字符串
u 撤销上一步
vim ~/.bashrc
export PATH=/path/to/your/dir:$PATH 添加环境变量
source ~/.bashrc是能变量有效
sudo nmcli networking off重启网络
sudo update-alternatives --config python 查看多个版本的python并提供切换
apt常用命令
apt-cache search package 搜索包
apt-cache show package 获取包的相关信息,如说明、大小、版本等
sudo apt-get install package 安装包
sudo apt-get remove package 删除包
sudo apt-get remove package - - purge 删除包,包括删除配置文件等
sudo apt-get update 更新源
sudo apt-get upgrade 更新已安装的包
apt-cache depends package 了解使用依赖
dpkg -l | grep gazebo 查看已安装包信息
常用工具使用
-
markdown
安装方法
git常用命令
git add xx
git checkout . 撤销工作区所有文件的修改
git add .
git commit -m"describe" 添加与上传xx文件
git status 获取当前文件的状态
git diff xx 若文件modified,查看修改内容
git log ( --pretty=oneline) 查看版本信息
git reset --hard HEAD^ 返回上一个版本
git reflog 来查看每一次命令的记录
git reset --hard HEAD~20返回20个版本之前
git reset --hard HEAD^^ 返回上上一个版本
git reset --hard commit_id 返回id时commit_id文件
git clean -xf 删除未被跟踪的文件
git tag -l 查看所有tag
git checkout tag 切换到指定tag
git reflog 查看每次的命令
git checkout – 文件 回到最新版本
git reset HEAD xx 撤销暂缓区的修改
git rm xx 把文件从版本库中删除
git remote rm origin 删除远程仓库源 git remote add origin 你的新远程仓库地址
git remote add origin [email protected]:weiLiangHare/xx.git 关联一个远程库
git push -u origin master第一次推送master分支的所有内容;
git push origin master此后推送最新修改;
git clone [email protected]:weiLiangHare/gitHello.git 克隆远程库的gitHello里的内容
git branch查看分支
git branch 创建分支
git checkout 切换分支
git push origin 上传本地分支到远程仓库
git branch -r -d origin/branch-name 删除远程分支仓库 git push origin :branch-name 删除远程分支仓库
git checkout -b 创建+切换分支
git merge 合并某分支到当前分支
git branch -d 删除分支
git merge --no-ff -m “merge with no-ff” 可以用普通模式合并,合并后的历史有分支,能看出来曾经做过合并git stash 保存当前分支的内容。
git stash pop 取出此分支的内容
git remote -v查看远程库信息
git checkout -b dev origin/dev 创建本地dev分支
git branch --set-upstream-to=origin/dev dev指定本地dev分支与远程origin/dev分支的链接
git log --graph --pretty=oneline --abbrev-commit 查看版本信息
rebase可以把本地未push的分叉提交历史整理成直线
git tag v0.1 给最新commit区打标签
git tag v0.1 commit_id
git tag -a v0.1 -m “descrietion”
git show 查看标签信息
git tag -d v0.1 删除标签
git push origin v0.1 推送标签到远程
git push origin --tags 推送所有标签
1.2PX4开发环境搭建
-
编译工具链的安装
-
vscode
编译工具链的安装
下载ubuntu.sh,requirements.txt
wget https://raw.githubusercontent.com/PX4/Firmware/master/Tools/setup/ubuntu.sh
#! /usr/bin/env bash
set -e
## Bash script to setup PX4 development environment on Ubuntu LTS (20.04, 18.04, 16.04).
## Can also be used in docker.
##
## Installs:
## - Common dependencies and tools for nuttx, jMAVSim, Gazebo
## - NuttX toolchain (omit with arg: --no-nuttx)
## - jMAVSim and Gazebo9 simulator (omit with arg: --no-sim-tools)
##
## Not Installs:
## - FastRTPS and FastCDR
INSTALL_NUTTX="true"
INSTALL_SIM="true"
INSTALL_ARCH=`uname -m`
# Parse arguments
for arg in "$@"
do
if [[ $arg == "--no-nuttx" ]]; then
INSTALL_NUTTX="false"
fi
if [[ $arg == "--no-sim-tools" ]]; then
INSTALL_SIM="false"
fi
done
# detect if running in docker
if [ -f /.dockerenv ]; then
echo "Running within docker, installing initial dependencies";
apt-get --quiet -y update && DEBIAN_FRONTEND=noninteractive apt-get --quiet -y install \
ca-certificates \
gnupg \
lsb-core \
sudo \
wget \
;
fi
# script directory
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# check requirements.txt exists (script not run in source tree)
REQUIREMENTS_FILE="requirements.txt"
if [[ ! -f "${DIR}/${REQUIREMENTS_FILE}" ]]; then
echo "FAILED: ${REQUIREMENTS_FILE} needed in same directory as ubuntu.sh (${DIR})."
return 1
fi
# check ubuntu version
# otherwise warn and point to docker?
UBUNTU_RELEASE="`lsb_release -rs`"
if [[ "${UBUNTU_RELEASE}" == "14.04" ]]; then
echo "Ubuntu 14.04 is no longer supported"
exit 1
elif [[ "${UBUNTU_RELEASE}" == "16.04" ]]; then
echo "Ubuntu 16.04 is no longer supported"
exit 1
elif [[ "${UBUNTU_RELEASE}" == "18.04" ]]; then
echo "Ubuntu 18.04"
elif [[ "${UBUNTU_RELEASE}" == "20.04" ]]; then
echo "Ubuntu 20.04"
fi
echo
echo "Installing PX4 general dependencies"
sudo apt-get update -y --quiet
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
astyle \
build-essential \
ccache \
cmake \
cppcheck \
file \
g++ \
gcc \
gdb \
git \
lcov \
libxml2-dev \
libxml2-utils \
make \
ninja-build \
python3 \
python3-dev \
python3-pip \
python3-setuptools \
python3-wheel \
rsync \
shellcheck \
unzip \
zip \
;
if [[ "${UBUNTU_RELEASE}" == "16.04" ]]; then
echo "Installing Ubuntu 16.04 PX4-compatible ccache version"
wget -O /tmp/ccache_3.4.1-1_amd64.deb http://launchpadlibrarian.net/356662933/ccache_3.4.1-1_amd64.deb
sudo dpkg -i /tmp/ccache_3.4.1-1_amd64.deb
fi
# Python3 dependencies
echo
echo "Installing PX4 Python3 dependencies"
if [ -n "$VIRTUAL_ENV" ]; then
# virtual envrionments don't allow --user option
python -m pip install -r ${DIR}/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
else
# older versions of Ubuntu require --user option
python3 -m pip install --user -r ${DIR}/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
fi
# NuttX toolchain (arm-none-eabi-gcc)
if [[ $INSTALL_NUTTX == "true" ]]; then
echo
echo "Installing NuttX dependencies"
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
automake \
binutils-dev \
bison \
build-essential \
flex \
g++-multilib \
gcc-multilib \
gdb-multiarch \
genromfs \
gettext \
gperf \
libelf-dev \
libexpat-dev \
libgmp-dev \
libisl-dev \
libmpc-dev \
libmpfr-dev \
libncurses5 \
libncurses5-dev \
libncursesw5-dev \
libtool \
pkg-config \
screen \
texinfo \
u-boot-tools \
util-linux \
vim-common \
;
if [[ "${UBUNTU_RELEASE}" == "20.04" ]]; then
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
kconfig-frontends \
;
fi
if [ -n "$USER" ]; then
# add user to dialout group (serial port access)
sudo usermod -a -G dialout $USER
fi
# arm-none-eabi-gcc
NUTTX_GCC_VERSION="9-2020-q2-update"
NUTTX_GCC_VERSION_SHORT="9-2020q2"
source $HOME/.profile # load changed path for the case the script is reran before relogin
if [ $(which arm-none-eabi-gcc) ]; then
GCC_VER_STR=$(arm-none-eabi-gcc --version)
GCC_FOUND_VER=$(echo $GCC_VER_STR | grep -c "${NUTTX_GCC_VERSION}")
fi
if [[ "$GCC_FOUND_VER" == "1" ]]; then
echo "arm-none-eabi-gcc-${NUTTX_GCC_VERSION} found, skipping installation"
else
echo "Installing arm-none-eabi-gcc-${NUTTX_GCC_VERSION}";
wget -O /tmp/gcc-arm-none-eabi-${NUTTX_GCC_VERSION}-linux.tar.bz2 https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/${NUTTX_GCC_VERSION_SHORT}/gcc-arm-none-eabi-${NUTTX_GCC_VERSION}-${INSTALL_ARCH}-linux.tar.bz2 && \
sudo tar -jxf /tmp/gcc-arm-none-eabi-${NUTTX_GCC_VERSION}-linux.tar.bz2 -C /opt/;
# add arm-none-eabi-gcc to user's PATH
exportline="export PATH=/opt/gcc-arm-none-eabi-${NUTTX_GCC_VERSION}/bin:\$PATH"
if grep -Fxq "$exportline" $HOME/.profile; then
echo "${NUTTX_GCC_VERSION} path already set.";
else
echo $exportline >> $HOME/.profile;
fi
fi
fi
# Simulation tools
if [[ $INSTALL_SIM == "true" ]]; then
echo
echo "Installing PX4 simulation dependencies"
# General simulation dependencies
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
bc \
;
if [[ "${UBUNTU_RELEASE}" == "18.04" ]]; then
java_version=11
gazebo_version=9
elif [[ "${UBUNTU_RELEASE}" == "20.04" ]]; then
java_version=13
gazebo_version=11
else
java_version=14
gazebo_version=11
fi
# Java (jmavsim or fastrtps)
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
ant \
openjdk-$java_version-jre \
openjdk-$java_version-jdk \
libvecmath-java \
;
# Set Java 11 as default
sudo update-alternatives --set java $(update-alternatives --list java | grep "java-$java_version")
# Gazebo
sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
# Update list, since new gazebo-stable.list has been added
sudo apt-get update -y --quiet
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
dmidecode \
gazebo$gazebo_version \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-ugly \
gstreamer1.0-libav \
libeigen3-dev \
libgazebo$gazebo_version-dev \
libgstreamer-plugins-base1.0-dev \
libimage-exiftool-perl \
libopencv-dev \
libxml2-utils \
pkg-config \
protobuf-compiler \
;
if sudo dmidecode -t system | grep -q "Manufacturer: VMware, Inc." ; then
# fix VMWare 3D graphics acceleration for gazebo
echo "export SVGA_VGPU10=0" >> ~/.profile
fi
fi
if [[ $INSTALL_NUTTX == "true" ]]; then
echo
echo "Relogin or reboot computer before attempting to build NuttX targets"
fi
wget https://raw.githubusercontent.com/PX4/Firmware/master/Tools/setup/requirements.txt
argcomplete
argparse>=1.2
cerberus
coverage
empy>=3.3
future
jinja2>=2.8
jsonschema
kconfiglib
lxml
matplotlib>=3.0.*
numpy>=1.13
nunavut>=1.1.0
packaging
pandas>=0.21
pkgconfig
psutil
pygments
wheel>=0.31.1
pymavlink
pyros-genmsg
pyserial
pyulog>=0.5.0
pyyaml
requests
setuptools>=39.2.0
six>=1.12.0
toml>=0.9
或者: 手动到 px4 github下载
然后运行:
source ubuntu.sh
wget -O /tmp/gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2 https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/7-2017q4/gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2
sudo tar -jxf gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2 -C /opt/
百度网盘:gcc-arm-none-eabi
提取码: atwu
gedit ~/.profile
export PATH=/opt/gcc-arm-none-eabi-7-2017-q4-major/bin:$PATH
参考于http://dev.px4.io/master/en/setup/dev_env_linux_ubuntu.html
下载编译firmware
在此目录下下载px4源码并切换v1.11.0-beta1的固件
git clone https://github.com/PX4/Firmware
或下载码云中的px4源码
git clone https://gitee.com/bingobinlw/Firmware
然后更新submodule切换固件并编译
cd Firmware
git submodule update --init --recursive
git checkout v1.11.0-beta1
make distclean
QGC安装
编译代码
编译
make px4_fmu-v5_default
编译加下载
make px4_fmu-v5_default upload
仿真
make px4_sitl_default gazebo
问题1:如果出现报错
解决办法sudo apt-get install libgazebo9-dev
问题2:
解决办法:修改标志位,把True改为1
code
- 安装
- 使用
安装
使用
vscode 仿真在线调试