这个软件包提供了针对各种自动驾驶仪(如PX4,Ardupilot)使用 MAVLink 通信协议的通信驱动程序。
此外,它还提供了用于地面控制站(例如 QGroundControl)的 UDP MAVLink 桥接功能。
通常与PX4的offboard模式联合使用
Offboard控制背后的想法是能够使用在自动驾驶仪外运行的软件来控制 PX4 飞控, 这是通过 Mavlink 协议完成的。
其中硬件部分连接模式大部分如下:
在飞行器上部署一台小型将计算机,用 UART 转 USB 适配器连接飞控
ROS (机器人操作系统) 是一个通用的机器人库,可以用于为 PX4 自动驾驶仪创建强大的无人机应用程序。
MAVROS可以通过源码或者二进制安装。
通过下面指令进行二进制安装
sudo apt-get install ros-${ROS_DISTRO}-mavros ros-${ROS_DISTRO}-mavros-extras ros-${ROS_DISTRO}-mavros-msgs
其中ROS_DISTRO
需要根据ROS的本部换成 kinetic、noetic
然后需要安装 GeographicLib ,通过如下指令
先下载 文件 install_geographiclib_datasets.sh
wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh
执行这个文件
./install_geographiclib_datasets.sh
通过在gazebo中启动 px4 ,并启动mavros ,来测试
通过MAVROS可以从飞控端获取的信息
在gazebo中启动px4
roslaunch px4 posix_sitl.launch
启动mavros指令
roslaunch mavros px4.launch fcu_url:="udp://:14540@127.0.0.1:14557"
话题名称: mavros/altitude
频率 :10HZ
消息类型:mavros_msgs/Altitude
消息体定义:
std_msgs/Header header float32 monotonic float32 amsl float32 local float32 relative float32 terrain float32 bottom_clearance
解释
实例数据
gazebo中无人机在地面
header:
seq: 752
stamp:
secs: 78
nsecs: 528000000
frame_id: “map”
monotonic: 488.1638488769531
amsl: 488.08782958984375
local: 0.1731969118118286
relative: -0.0031573623418807983
terrain: nan
bottom_clearance: nan
通过QGC 让其起飞
QGC显示高度为9.3m
header:
seq: 11002
stamp:
secs: 1103
nsecs: 528000000
frame_id: “map”
monotonic: 497.4364929199219
amsl: 497.36468505859375
local: 9.450032234191895
relative: 9.288766860961914
terrain: nan
bottom_clearance: nan
话题名称:mavros/battery
频率: 0.5hz
消息类型:sensor_msgs/BatteryState
消息体定义
std_msgs/Header header float32 voltage float32 current float32 charge float32 capacity float32 design_capacity float32 percentage uint8 power_supply_status uint8 power_supply_health uint8 power_supply_technology bool present float32[] cell_voltage string location string serial_number
解释:
gazebo中无人机 话题实例
header:
seq: 704
stamp:
secs: 1400
nsecs: 528000000
frame_id: ‘’
voltage: 15.30000114440918
temperature: 0.0
current: 1.0
charge: nan
capacity: nan
design_capacity: nan
percentage: 0.6599999666213989
power_supply_status: 2
power_supply_health: 0
power_supply_technology: 3
present: True
cell_voltage: [15.30000114440918]
cell_temperature: []
location: “id0”
serial_number: ‘’
话题名称:/mavros/estimator_status
频率:1HZ
消息类型: mavros_msgs/EstimatorStatus
消息体定义:
std_msgs/Header header bool attitude_status_flag bool velocity_horiz_status_flag bool velocity_vert_status_flag bool pos_horiz_rel_status_flag bool pos_horiz_abs_status_flag bool pos_vert_abs_status_flag bool pos_vert_agl_status_flag bool const_pos_mode_status_flag bool pred_pos_horiz_rel_status_flag bool pred_pos_horiz_abs_status_flag bool gps_glitch_status_flag bool accel_error_status_flag
解释:
gazebo中无人机 话题实例
header:
seq: 2145
stamp:
secs: 2148
nsecs: 524000000
frame_id: ‘’
attitude_status_flag: True
velocity_horiz_status_flag: True
velocity_vert_status_flag: True
pos_horiz_rel_status_flag: True
pos_horiz_abs_status_flag: True
pos_vert_abs_status_flag: True
pos_vert_agl_status_flag: False
const_pos_mode_status_flag: False
pred_pos_horiz_rel_status_flag: True
pred_pos_horiz_abs_status_flag: True
gps_glitch_status_flag: False
accel_error_status_flag: False
话题名称:/mavros/extended_state
频率:5HZ
消息类型: mavros_msgs/ExtendedState
消息体定义:
uint8 VTOL_STATE_UNDEFINED=0 uint8 VTOL_STATE_TRANSITION_TO_FW=1 uint8 VTOL_STATE_TRANSITION_TO_MC=2 uint8 VTOL_STATE_MC=3 uint8 VTOL_STATE_FW=4 uint8 LANDED_STATE_UNDEFINED=0 uint8 LANDED_STATE_ON_GROUND=1 uint8 LANDED_STATE_IN_AIR=2 uint8 LANDED_STATE_TAKEOFF=3 uint8 LANDED_STATE_LANDING=4 std_msgs/Header header uint8 vtol_state uint8 landed_state
解释:
gazebo中实例(无人机飞在9.2m)
header:
seq: 15936
stamp:
secs: 3190
nsecs: 528000000
frame_id: ‘’
vtol_state: 0
landed_state: 2
话题名称:/mavros/global_position/compass_hdg
频率:50HZ
消息类型:std_msgs/Float64
gazebo中消息实例
通过直接旋转模型,可以发现数值发生变化,变化范围0~360
data: 100.63
data: 16.48
话题名称:/mavros/global_position/global
频率:50HZ
消息类型:sensor_msgs/NavSatFix
std_msgs/Header header uint32 seq time stamp string frame_id sensor_msgs/NavSatStatus status int8 status uint16 service float64 latitude float64 longitude float64 altitude float64[9] position_covariance uint8 position_covariance_type
解释:
int8 STATUS_NO_FIX = -1 # unable to fix position 不能定位 int8 STATUS_FIX = 0 # unaugmented fix 未增强的定位 int8 STATUS_SBAS_FIX = 1 # with satellite-based augmentation int8 STATUS_GBAS_FIX = 2 # with ground-based augmentation
uint16 SERVICE_GPS = 1 # GPS导航系统 uint16 SERVICE_GLONASS = 2 # GLONASS导航系统 uint16 SERVICE_COMPASS = 4 # includes BeiDou. uint16 SERVICE_GALILEO = 8 # 伽利略导航系统
uint8 COVARIANCE_TYPE_UNKNOWN=0 # 未知类型。表示协方差的具体类型未知,可能是由于某些原因无法确定 uint8 COVARIANCE_TYPE_APPROXIMATED=1 # 协方差未知。表示协方差矩阵中的元素值未知,即不提供具体的协方差信息 uint8 COVARIANCE_TYPE_DIAGONAL_KNOWN=2 # 对角协方差已知。表示协方差矩阵是对角矩阵,对角线上的元素已知,而非对角线上的元素未知。这种情况下,只有位置坐标之间的不确定性(方差)已知,协方差矩阵的其他元素未提供 uint8 COVARIANCE_TYPE_KNOWN=3 # 完全协方差已知。表示协方差矩阵的所有元素都已知,包括位置坐标之间的不确定性和它们之间的协方差。这种情况下,提供了协方差矩阵的所有元素
gazebo中消息实例
header:
seq: 65
stamp:
secs: 5935
nsecs: 852000000
frame_id: “base_link”
status:
status: 0
service: 1
latitude: 47.3977412
longitude: 8.5455928
altitude: 535.2749169098639
position_covariance: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
position_covariance_type: 2
话题名称:/mavros/global_position/local
频率:50HZ
消息类型:nav_msgs/Odometry
原消息体定义
std_msgs/Header header string child_frame_id geometry_msgs/PoseWithCovariance pose geometry_msgs/TwistWithCovariance twist
解释:
gazebo中消息实例
header:
seq: 333735
stamp:
secs: 6680
nsecs: 492000000
frame_id: “map”
child_frame_id: “base_link”
pose:
pose:
position:
x: -2.0383938369578134
y: -1.4676804439870572
z: -2.918
orientation:
x: -0.0031129252366190966
y: 0.005099263730816597
z: 0.5929551081780201
w: 0.8052133175543716
covariance: [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 99999.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 99999.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 99999.0]
twist:
twist:
linear:
x: 0.02
y: 0.02
z: -0.01
angular:
x: 0.0
y: 0.0
z: 0.0
covariance: [-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
话题名称:/mavros/global_position/raw/fix
频率:2.5HZ
消息类型:sensor_msgs/NavSatFix
消息定义上面有提到
gazebo中消息实例
header:
seq: 21054
stamp:
secs: 7923
nsecs: 184000000
frame_id: “base_link”
status:
status: 0
service: 1
latitude: 47.3977413
longitude: 8.5455928
altitude: 535.3319169567044
position_covariance: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
position_covariance_type: 2
话题名称:/mavros/global_position/raw/gps_vel
频率:2.5HZ
消息类型:geometry_msgs/TwistStamped
std_msgs/Header header geometry_msgs/Twist twist
twist 包含角速度与线速度
gazebo中消息实例
header:
seq: 21606
stamp:
secs: 8130
nsecs: 980000000
frame_id: “map”
twist:
linear:
x: -0.0
y: -0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.0
话题名称:/mavros/global_position/raw/satellites
频率:2.5HZ
消息类型:std_msgs/UInt32
gazebo中消息实例
data: 10
与QGC中卫星数量一致
话题名称:/mavros/global_position/rel_alt
频率:50HZ
消息类型:std_msgs/Float64
gazebo中消息实例
data: 6.33
与QGC中一致