ubuntu20.04+ROS Noetic 安装PX4+Mavros

文章目录

系统环境

ubuntu 20.04

ROS Noetic

如果系统安装了Anaconda等虚拟环境管理器,要退出虚拟环境的激活,再进行下列安装,以下的安装过程我们默认退出了Anaconda的虚拟环境

shell 复制代码
conda deactivate

安装依赖

shell 复制代码
sudo apt install ninja-build exiftool ninja-build protobuf-compiler libeigen3-dev genromfs xmlstarlet libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev python3-pip gawk
shell 复制代码
pip3 install pandas jinja2 pyserial cerberus pyulog==0.7.0 numpy toml pyquaternion empy pyyaml 
pip3 install packaging numpy empy toml pyyaml jinja2 pyargparse kconfiglib jsonschema future

#若报错输入这两行命令

shell 复制代码
pip install --upgrade setuptools
python -m pip install --upgrade pip

PX4 安装

以下命令,会默认安装最新的PX4固件版本

shell 复制代码
git clone https://github.com/PX4/PX4-Autopilot.git --recursive
bash ./PX4-Autopilot/Tools/setup/ubuntu.sh

中间出错的话,执行下列命令

shell 复制代码
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow

如果安装过程中有错误的话,可以再用下列命令进行安装

shell 复制代码
bash ./PX4-Autopilot/Tools/setup/ubuntu.sh --fix-missing

老版本安装

bash 复制代码
git clone https://github.com/PX4/PX4-Autopilot.git
git status   # 查看当前分支,位于origin/main
git branch -r | grep "release"    # 查看所有远程分支,带release的

进行分支切换

bash 复制代码
cd PX4-Autopilot
git checkout origin/release/1.12  # 切换到发行分支v1.12
git submodule update --init --recursive	# 更新子模块
git status   # 查看当前分支,位于release/1.12

测试

安装完成,测试一下。这一步,第一次编译,需要一会功夫。

shell 复制代码
make px4_sitl_default gazebo

终端输入 commander takeoff ,可以看到无人机起飞

终端输入 commander land , 可以看到无人机降落

\;

环境变量添加

添加环境变量(添加到~/.bashrc文件中)

shell 复制代码
source ~/PX4-Autopilot/Tools/simulation/gazebo-classic/setup_gazebo.bash ~/PX4-Autopilot ~/PX4-Autopilot/build/px4_sitl_default
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4-Autopilot
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic

要根据自己 PX4-Autopilot 文件夹所在的目录来

shell 复制代码
source ~/.bashrc

版本查看

bash 复制代码
cd ~/PX4-Autopilot/ # 根据自己文件夹所在目录来
git describe --tags

此命令将显示当前Git标签,通常是PX4的版本号。

安装MAVROS(二进制安装非源码安装)

二进制安装只能通过ROS调用mavros,无法查看mavros源码。主要我试了几次,无法通过源码安装上。

shell 复制代码
sudo apt-get install ros-noetic-mavros ros-noetic-mavros-extras
sudo -E ./opt/ros/noetic/lib/mavros/install_geographiclib_datasets.sh

这里-E原因不好解释,请大家自行google。

如果你没有那个东西的话,可以尝试去github上把这里安装的3个文件下下来,再上传到/usr/share/GeographicLib/

测试

shell 复制代码
roslaunch mavros px4.launch fcu_url:="udp://:14540@127.0.0.1:14557"

来测试mavros是否安装成功,如果没有报错,那说明安装成功。

OGC 地面站安装

shell 复制代码
sudo usermod -a -G dialout $USER
sudo apt-get remove modemmanager -y
sudo apt install gstreamer1.0-plugins-bad gstreamer1.0-libav gstreamer1.0-gl -y
sudo apt install libqt5gui5 -y
sudo apt install libfuse2 -y

重启电脑,下载QGroundControl.AppImage

下载完成后,安装并运行

shell 复制代码
chmod +x ./QGroundControl.AppImage
./QGroundControl.AppImage  (or double click)

测试mavros与sitl通信

接下来我们测试MAVROS与SITL通信是否正常,先打开QGC地面站,然后输入

shell 复制代码
roslaunch px4 mavros_posix_sitl.launch
rostopic echo /mavros/state

如果出现了connected: True,则表明通信成功。

输入以下命令

shell 复制代码
commander takeoff # 起飞
commander land    # 降落

无人机将会起飞和降落,并且mavros显示信息会发生变化。

参考

PX4官网PX4安装指南
PX4官网MAVROS安装指南

相关推荐
古月居GYH20 天前
边缘计算与ROS结合:如何实现分布式机器人智能决策?
机器人·ros·边缘计算
古月居GYH24 天前
ROS应用之SwarmSim在ROS 中的协同路径规划
ros·路径规划
月照银海似蛟龙1 个月前
无人机 PX4 飞控 | PX4源码添加自定义参数方法并用QGC显示与调整
无人机·px4·qgc
陈傻鱼1 个月前
ROS2测试仿真
机器人·ros·slam
Mr.Winter`1 个月前
轨迹优化 | 基于ESDF的非线性最小二乘法路径平滑(附ROS C++仿真)
人工智能·科技·机器人·自动驾驶·ros·最小二乘法·ros2
kuan_li_lyg1 个月前
ROS2 与机器人视觉入门教程(ROS2 OpenCV)
开发语言·人工智能·opencv·计算机视觉·matlab·机器人·ros
两棵雪松1 个月前
为什么使用ROS的remap标签不起作用?
ros
加点油。。。。1 个月前
ubuntu22.4 ROS2 安装gazebo(环境变量配置)
linux·python·ubuntu·ros
Mr.Winter`1 个月前
轨迹优化 | 基于贝塞尔曲线的无约束路径平滑与粗轨迹生成(附ROS C++/Python仿真)
人工智能·机器人·自动驾驶·ros·几何学·ros2·轨迹优化
worthsen1 个月前
ROS1 与 ROS2 使用区别 【命令】
机器人·ros