出坑 最新版本Ubuntu 20.04+ROS Noetic+Gazebo 11+PX4仿真环境Mavros offboard模式自主飞行仿真实例的调试(无人机不能起飞的问题解决)

使用PX4学习Mavros,offboard模式控制例程是无法跨过的一个经典例子。

所谓offboard模式,是使多旋翼无人机飞行器遵循通过 MAVLink 提供的位置、速度或姿态设定点。

以下是官方解释。

飞行模式:PX4 Flight Modes Overview | PX4 User Guide

offboard模式:Offboard Mode | PX4 User Guide

offboard模式在官网上有代码和相应解释。

MAVROS Offboard control example | PX4 User Guide

—————————————————————————————————————————

关于PX4仿真环境的搭建, 后续会综合整理一篇,这里只针对我碰到的问题做个梳理,因为在我解决此问题之前,我找了很多地方,都没有找到适合的解决办法,不知道是否因为我安装环境的版本太新,还没有同伴遇到此类问题。

另外,关于offboard模式案例仿真,网上的案例大都是介绍的比较顺利的顺序执行过程,像我这样遇到问题的不多,关于问题的解决,案例涉及的不多。

总之,希望有人通过文章能够有些新的思路。

__________________________________________________________________________

问题描述:安装ROS+PX4+Gazebo+MAVROS,完成仿真环境的搭建后,参考官网offboard模式,在Gazebo 11中实现无人机的offboard模式自主飞行实例,无人机不能启动旋翼定点起飞。

而正常情况应该是无人机自主起飞至2米高度并且悬停。

我安装的元素为:Ubuntu 20.0+ROS Noetic+Gazebo 11+QGC Ground+MAVLink+MAVROS+PX4

说明:ROS Noetic Full版本自带安装Gazebo 11。

我执行的操作

1. 在工作空间目录下创建功能包offboard,按照官网的代码创建节点offb_node,并编译成功。

2. 启动launch文件。

cd ~/PX4-Autopilot

roslaunch px4 mavros_posix_sitl.launch

3. 新打开一个终端窗口,运行ROS功能包offboard下的节点offb_node

rosrun offboard offb_node

问题现象

1. roslaunch运行窗口一直间隔显示“Failsafe mode deactivated”和“Failsafe mode activated”

2. rosrun运行窗口一直显示“offboard enabled”

3. Gazebo窗口的无人机螺旋桨不启动,无人机不起飞

另外,当我打开QGC Ground地面端软件,QGC显示连接状态,对Gazebo中的无人机执行takeoff和land命令时,无人机在Gazebo中均能正常起飞和着陆。

问题处理(以下仅列出对该问题处理有效的方法):

1. 通过查看mavros话题的state消息,检查MAVROS连接是否正常。

rostopic echo /mavros/state

用rostopic echo /mavros/state发现连接状态是false,说明用roslaunch启动仿真时,MAVROS没能正确的连接到PX4,也就是MAVROS没有与PX4固件SITL建立通信。

 1)检查MAVROS是否安装成功。

路径/opt/ros/noetic/lib/mavros应该存在。如果不存在,请安装MAVROS。

说明:安装软件包前请养成更新的习惯,包括更新软件列表和软件。

sudo apt update  //更新软件列表

sudo apt upgarde  //更新软件

rosinstall_generator --upstream mavros | tee -a /tmp/mavros.rosinstall  //安装MAVROS

sudo apt-get install ros-noetic-mavros ros-noetic-mavros-extras  //安装MAVROS

2)检查隐藏文件.bashrc里添加的环境变量路径是否正确。

隐藏文件.bashrc在主目录下,目录表示为

在主目录下按ctrl+h组合键,就能看到.bashrc文件了,直接双击打开、拉到文件最后,检查是否添加以下内容。

source ~/PX4-Autopilot/Tools/setup_gazebo.bash ~/PX4-Autopilot ~/PX4-Autopilot/build/px4_sitl_default

export ROS_PACKAGE_PATH=~/PX4-Autopilot:$ROS_PACKAGE_PATH

export ROS_PACKAGE_PATH=~/PX4-Autopilot/Tools/sitl_gazebo:$ROS_PACKAGE_PATH

执行以上处理步骤,重新执行roslaunch命令,可以发现,mavros话题的state消息中,“connected”状态已变为“True”。

2. 检查安装PX4固件时是否执行的“git clone https://github.com/PX4/PX4-Autopilot.git --recursive

说明:在我的安装环境下,证明执行此条命令是有问题的(其他版本不敢保证)。
 我安装的元素为:Ubuntu 20.0+ROS Noetic+Gazebo 11+QGC Ground+MAVLink+MAVROS+PX4

Github上也有相应的case。

I'm able to connect, and I publish to mavros/setpoint_attitude/attitude topic successfully, but the copter keeps on arming/disarming itself for some reason. It never takes off. Just sits on the ground.
I am using this code (this example) and it works perfectly when I publish /mavros/setpoint_position/local. But when I change the topic to be attitude, it doesn't work.

Sometimes I get this warning: CMD: Unexpected command 176, result 0. Sometimes I get this warning: CMD: Unexpected command 400, result 0. When I look at the /mavros/state, it is connected and in offboard mode, but it keeps flipping between arm/disarm.

Any advice?

____________________________

Which version of PX4-Autopilot are you using?

I have tested a lot of possibilities here and with the last release (version 12) I have this problem, the drone stays in fail safe mode and it doesn't take off. A friend of mine tested the same commands on his PC and works, so we tried to step back in the version, now I'm using version PX4-Autopilot 11.3 (the last version that worked for me) and it is working fine now!

To flight using commander directly the PX4 it is needed to define the takeoff point to avoid error. To flight using script you just keep the position and the drone stays stable!

About the PX4-Avoindace I haven't success to run on my actual PC.

OS: Ubuntu 18
ROS: Melodic
Gazebo: 9
PX-Autopilot: 11.3.0

PX4 SITL/mavros error "unexpected command 176" using setpoint_* topics · Issue #512 · mavlink/mavros · GitHub

___________________________

解决办法:

I see two solutions

  1. Use comment of benjinne.
    Run simulation and run QGroundControl. In Vehicle setup->Parameters set COM_RCL_EXCEPT=4.

  2. Use an older version of autopilot.
    Personally, I am using the latest stable version of autopilot at the moment (available by tag v1.12.3). Can be downloaded using this command:
    git clone --recurse-submodules --branch v1.12.3 https://github.com/PX4/PX4-Autopilot.git 

FAILSAFE mode activating constantly after the vehicle enters the OFFBOARD mode · Issue #18367 · PX4/PX4-Autopilot · GitHub

我是参考了第二种办法, 也就是说,我们下载的PX4固件是使用的最新版本,但最新版本可能不够稳定,而使用稳定版本,就不会有这个问题了。

对于最新版本的PX4,同时还有一个open的issue,大家也正在讨论这个问题的解决办法,看状态是open,不确定是否解决,总之,我们按上面的结论,下载稳定版本即可。

https://github.com/PX4/PX4-Autopilot/pull/18160

———————————————————————

关于如何下载指定版本的PX4,详细内容可以参考以下文章。

PX4下载指定版本代码和刷固件的三种方式_ FC的博客-CSDN博客_px4 刷固件

1)查看当前下载的PX4固件版本

git describe

这里我下载了一个最新版本做为示例。

2)清除下载的PX4固件版本,直接将PX4-Autopilot文件夹删除即可。

3)在原位置,重新下载PX4固件稳定版本。

在PX4源码网站,单击Tags,查看到最新的PX4固件稳定版本是V1.12.3,同时前面的结论里也提到使用该版本能解决问题。

 在原位置执行以下命令,重新下载。

git clone -b v1.12.3 https://github.com/PX4/PX4-Autopilot.git --recursive

4)重复以前的编译PX4步骤,对新下载的固件进行编译。

cd PX4-Autopilot
make px4_sitl_default gazebo

5)重新执行roslaunch和rosrun命令,无人机飞行成功。

a. roslaunch命令窗口中不再间隔显示“Failsafe mode deactivated”和“Failsafe mode activated”,而是出现“Armed by external command”和“Takeoff detected”状态。

b. rosrun命令窗口中不再一直显示“offboard enabled”,而是先显示“Offboard enabled”继而出现“Vehicle armed”状态。

c. Gazebo中的无人机螺旋桨启动,缓慢上升到2m,并保持悬停。

 这里插入一个视频看下演示效果。

PX4 MAVROS offboard控制实例仿真结果

猜你喜欢

转载自blog.csdn.net/qq_38250687/article/details/123251913