本文主要是介绍Jetson Orin NX 开发指南(9): MAVROS 的安装、配置与运行,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、前言
由于 Jetson 系列开发板常作为自主无人机的机载电脑,而无人机硬件平台如 PX4 和 ArduPilot 等通过 MAVLink 进行发布无人机状态和位姿等信息,要实现机载电脑与 MAVLink 的通信,必须借助 Mavros 功能包,因此,本文主要介绍 Mavros 功能包的安装、配置与使用,主要参考
GitHub - mavlink/mavros at master
https://github.com/mavlink/mavros/blob/master/mavros/README.md#installation
Ubuntu 安装并配置 mavros (USB 连接)_ubuntu安装mavros-CSDN博客
官方给出了直接安装和源码安装两种方法,由于一般 mavros 安装并配置完成后不会轻易改动,且十分常用,因此比较推荐直接安装方法,本文也只介绍直接安装方法。
二、Mavros 的安装
由于 Jetson Orin NX 的 JetPack 5.1.2 对应的是 Ubuntu 20.04,因此我们选择安装 noetic 版本的 mavros 功能包,终端输入
sudo apt-get install ros-noetic-mavros ros-noetic-mavros-extras -y
此时可以查看 /usr/share/ 下多了一个 GeographicLib 文件夹,其内容是空的,需要我们自己添加进去
进入 ~/Documents/ 目录,下载脚本文件
wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh
然后给下载好的脚本文件添加可执行权限,
sudo chmod +x ./install_geographiclib_datasets.sh
运行该脚本下载所需文件
sudo ./install_geographiclib_datasets.sh
如果执行报错,就直接去GeographicLib 官网下载(可能要挂梯子。。。)对应的三个包,下载得到三个文件夹:
1.GeographicLib geoids egm96-5 官网下载链接:
Download egm96-5.tar.bz2 (GeographicLib)
2.GeographicLib gravity egm 96官网下载链接
Download egm96.zip (GeographicLib)
3.GeographicLib magnetic emm2015 官网下载链接:
Download emm2015.zip (GeographicLib)
在 /usr/share/GeographicLib/ 路径下,将上面下载的三个压缩包解压后放在这个文件夹内,如下所示
至此,mavros 就安装成功了!
三、Mavrso 的运行
由于 Jetson Orin NX 与飞控(飞行控制器)一般有两种通信连接方式,一种是通过 USB 连接,另一种是通过串口连接,本节将分别介绍两种连接方式使得 Jetson Orin NX 通过 Mavros 实现与飞控的通信。
由于时下最新的 Pixhawk 系列飞控为 Pixhawk 6X,因此本文主要介绍 Jetson Orin NX 与 Pixhawk 6X 的通信,其他电脑与飞控的通信方式也是相同的!
3.1 Jetson Orin NX 与 Pixhawk 6X 实现 USB 通信
运行 Mavros 之前需要现修改 launch 启动文件
打开 /opt/ros/noetic/share/mavros/launch/ 路径下的 px4.launch 文件
可以看到 fcu_url 默认为 /dev/ttyACM0:57600,其中 ttyACM0 表示 USB 连接,57600 表示波特率,这里我们不对这个文件进行修改,而是在当前目录下新建一个
终端输入
cd /opt/ros/noetic/share/mavros/launch/
sudo touch px4_ACM0.launch
打开 px4_ACM0.launch 文件,
sudo gedit px4_ACM0.launch
将其内容改为
<launch><!-- vim: set ft=xml noet : --><!-- example launch script for PX4 based FCU's --><arg name="fcu_url" default="/dev/ttyACM0:921600" /><arg name="gcs_url" default="" /><arg name="tgt_system" default="1" /><arg name="tgt_component" default="1" /><arg name="log_output" default="screen" /><arg name="fcu_protocol" default="v2.0" /><arg name="respawn_mavros" default="false" /><include file="$(find mavros)/launch/node.launch"><arg name="pluginlists_yaml" value="$(find mavros)/launch/px4_pluginlists.yaml" /><arg name="config_yaml" value="$(find mavros)/launch/px4_config.yaml" /><arg name="fcu_url" value="$(arg fcu_url)" /><arg name="gcs_url" value="$(arg gcs_url)" /><arg name="tgt_system" value="$(arg tgt_system)" /><arg name="tgt_component" value="$(arg tgt_component)" /><arg name="log_output" value="$(arg log_output)" /><arg name="fcu_protocol" value="$(arg fcu_protocol)" /><arg name="respawn_mavros" default="$(arg respawn_mavros)" /></include>
</launch>
至此,Mavros 的启动文件就配置完成了!
然后终端输入
roslaunch mavros px4_ACM0.launch
启动 mavros,发现报错
[FATAL] [1697177878.518260611]: FCU: DeviceError:serial:open: Permission denied
原因是 /dev/ttyACM0 没有可执行权限,需要先添加可执行权限,终端输入
sudo chmod 777 /dev/ttyACM0
然后再次启动 mavros,终端输入
roslaunch mavros px4_ACM0.launch
结果显示
这表示 mavros 成功连接上了飞控!
此时可以查看 mavros 话题,终端输入
rostopic list
打印输出
/diagnostics
/mavlink/from
/mavlink/gcs_ip
/mavlink/to
/mavros/actuator_control
/mavros/adsb/send
/mavros/adsb/vehicle
/mavros/altitude
/mavros/battery
/mavros/cam_imu_sync/cam_imu_stamp
/mavros/camera/image_captured
/mavros/cellular_status/status
/mavros/companion_process/status
/mavros/debug_value/debug
/mavros/debug_value/debug_float_array
/mavros/debug_value/debug_vector
/mavros/debug_value/named_value_float
/mavros/debug_value/named_value_int
/mavros/debug_value/send
/mavros/esc_info
/mavros/esc_status
/mavros/esc_telemetry
/mavros/estimator_status
/mavros/extended_state
/mavros/fake_gps/mocap/tf
/mavros/geofence/waypoints
/mavros/global_position/compass_hdg
/mavros/global_position/global
/mavros/global_position/gp_lp_offset
/mavros/global_position/gp_origin
/mavros/global_position/local
/mavros/global_position/raw/fix
/mavros/global_position/raw/gps_vel
/mavros/global_position/raw/satellites
/mavros/global_position/rel_alt
/mavros/global_position/set_gp_origin
/mavros/gps_input/gps_input
/mavros/gps_rtk/rtk_baseline
/mavros/gps_rtk/send_rtcm
/mavros/gpsstatus/gps1/raw
/mavros/gpsstatus/gps1/rtk
/mavros/gpsstatus/gps2/raw
/mavros/gpsstatus/gps2/rtk
/mavros/hil/actuator_controls
/mavros/hil/controls
/mavros/hil/gps
/mavros/hil/imu_ned
/mavros/hil/optical_flow
/mavros/hil/rc_inputs
/mavros/hil/state
/mavros/home_position/home
/mavros/home_position/set
/mavros/imu/data
/mavros/imu/data_raw
/mavros/imu/diff_pressure
/mavros/imu/mag
/mavros/imu/static_pressure
/mavros/imu/temperature_baro
/mavros/imu/temperature_imu
/mavros/landing_target/lt_marker
/mavros/landing_target/pose
/mavros/landing_target/pose_in
/mavros/local_position/accel
/mavros/local_position/odom
/mavros/local_position/pose
/mavros/local_position/pose_cov
/mavros/local_position/velocity_body
/mavros/local_position/velocity_body_cov
/mavros/local_position/velocity_local
/mavros/log_transfer/raw/log_data
/mavros/log_transfer/raw/log_entry
/mavros/mag_calibration/report
/mavros/mag_calibration/status
/mavros/manual_control/control
/mavros/manual_control/send
/mavros/mission/reached
/mavros/mission/waypoints
/mavros/mocap/pose
/mavros/mount_control/command
/mavros/mount_control/orientation
/mavros/mount_control/status
/mavros/nav_controller_output
/mavros/obstacle/send
/mavros/odometry/in
/mavros/odometry/out
/mavros/onboard_computer/status
/mavros/param/param_value
/mavros/play_tune
/mavros/px4flow/ground_distance
/mavros/px4flow/raw/optical_flow_rad
/mavros/px4flow/raw/send
/mavros/px4flow/temperature
/mavros/radio_status
/mavros/rallypoint/waypoints
/mavros/rc/in
/mavros/rc/out
/mavros/rc/override
/mavros/setpoint_accel/accel
/mavros/setpoint_attitude/cmd_vel
/mavros/setpoint_attitude/thrust
/mavros/setpoint_position/global
/mavros/setpoint_position/global_to_local
/mavros/setpoint_position/local
/mavros/setpoint_raw/attitude
/mavros/setpoint_raw/global
/mavros/setpoint_raw/local
/mavros/setpoint_raw/target_attitude
/mavros/setpoint_raw/target_global
/mavros/setpoint_raw/target_local
/mavros/setpoint_trajectory/desired
/mavros/setpoint_trajectory/local
/mavros/setpoint_velocity/cmd_vel
/mavros/setpoint_velocity/cmd_vel_unstamped
/mavros/state
/mavros/statustext/recv
/mavros/statustext/send
/mavros/target_actuator_control
/mavros/terrain/report
/mavros/time_reference
/mavros/timesync_status
/mavros/trajectory/desired
/mavros/trajectory/generated
/mavros/trajectory/path
/mavros/tunnel/in
/mavros/tunnel/out
/mavros/vfr_hud
/mavros/vision_pose/pose
/mavros/vision_pose/pose_cov
/mavros/vision_speed/speed_twist_cov
/mavros/wind_estimation
/move_base_simple/goal
/rosout
/rosout_agg
/tf
/tf_static
可以查看 IMU 频率,终端输入
rostopic hz /mavros/imu/data
结果显示
此时 IMU 话题频率为 200 左右,至此 Mavros 就安装完成了!
3.2 Jetson Orin NX 与 Pixhawk 6X 实现串口通信
首先查询 Pixhawk 6X 中 TELEM 2 的接口情况,参考
Pixhawk Mini-Base Ports - Holybro Docs
我们发现 TELEM 2 端口的 2 号口是信号输出(TX),3 号口是信号输入 (RX),6号口是地线(GND),因此我们只需要这三个接口连到机载电脑(Jetson Orin NX)即可。
我们需要查询机载电脑的飞控串口(pinout),用于连接飞控,注意到在 Jetson Orin NX 上有 40 个针脚(pinout),Jetson 系列的 PINOUT 主要参考
NVIDIA Jetson Xavier NX GPIO Header Pinout - JetsonHacks
但是其目前没有更新 Jetson Orin NX 的 PINOUT 情况,但是实际上其接口情况是与 Jetson Xavier NX 一致的,这里给出 Jetson Xavier NX 的 部分 PINOUT 的接口情况
我们这里需要的是 6 号串口(GND)、 8 号串口(TX)、10 号串口(RX),它们与飞控的连接方式为 GND —— GND,TX —— RX, RX —— TX,也就是
Jetson Orin NX 端 6 号串口 ——> Pixhawk 6X 端 TELEM 2 的 6 号端口
Jetson Orin NX 端 8 号串口 ——> Pixhawk 6X 端 TELEM 2 的 3 号端口
Jetson Orin NX 端 10 号串口——> Pixhawk 6X 端 TELEM 2 的 2 号端口
接线对应如下图所示(蓝——蓝,白——白,黑——黑)
至此接线就完成了,最后在 Jetson Orin NX 端配置 mavros 启动文件即可实现 Jetson Orin NX 与 Pixhawk 6X 通过串口通信。
在此之前我们先通过下图查看 Jetson Orin NX 的 PINOUT 的 8 号和 10 号接口对应文件为 /dev/ttyTHS0 文件
因此我们在 /opt/ros/noetic/share/mavros/launch/ 路径下创建一个 px4_THS0.launch 文件,其内容修改为(注意到其 fcu_url 的默认值为 /dev/ttyTHS0:921600,分别对应串口文件和波特率)
<launch><!-- vim: set ft=xml noet : --><!-- example launch script for PX4 based FCU's --><arg name="fcu_url" default="/dev/ttyTHS0:921600" /><arg name="gcs_url" default="" /><arg name="tgt_system" default="1" /><arg name="tgt_component" default="1" /><arg name="log_output" default="screen" /><arg name="fcu_protocol" default="v2.0" /><arg name="respawn_mavros" default="false" /><include file="$(find mavros)/launch/node.launch"><arg name="pluginlists_yaml" value="$(find mavros)/launch/px4_pluginlists.yaml" /><arg name="config_yaml" value="$(find mavros)/launch/px4_config.yaml" /><arg name="fcu_url" value="$(arg fcu_url)" /><arg name="gcs_url" value="$(arg gcs_url)" /><arg name="tgt_system" value="$(arg tgt_system)" /><arg name="tgt_component" value="$(arg tgt_component)" /><arg name="log_output" value="$(arg log_output)" /><arg name="fcu_protocol" value="$(arg fcu_protocol)" /><arg name="respawn_mavros" default="$(arg respawn_mavros)" /></include>
</launch>
修改完成后保存,然后将 Jetson Orin NX 与 Pixhawk 6X 通过串口连接,如下图所示
可以看到此时 Pixhawk 6X 是通过电池供电的(也可以通过 USB 方式供电),并且 Pixhawk 6X 与 Jetson Orin NX 只有 Pixhawk 6X 的 TELEM 2 端口 到 Jetson Orin NX 的 PINOUT 6 号、8 号、10 号接口的接线(并没有 USB 线连接),因此如果在 Jetson Orin NX 上如果能够接收到来自 Pixhawk 6X 的飞控信息,那么通信数据必然是通过串口传输的!
连接后我们先给 /dev/ttyTHS0 授予可执行权限
sudo chmod 777 /dev/ttyTHS0
接下来我们启动 mavros,终端输入
roslaunch mavros px4_THS0.launch
结果显示
这表示 mavros 成功连接上了飞控!
此时可以查看 mavros 话题,终端输入
rostopic list
可以受到如下话题
/diagnostics
/mavlink/from
/mavlink/gcs_ip
/mavlink/to
/mavros/actuator_control
/mavros/adsb/send
/mavros/adsb/vehicle
/mavros/altitude
/mavros/battery
/mavros/cam_imu_sync/cam_imu_stamp
/mavros/camera/image_captured
/mavros/cellular_status/status
/mavros/companion_process/status
/mavros/debug_value/debug
/mavros/debug_value/debug_float_array
/mavros/debug_value/debug_vector
/mavros/debug_value/named_value_float
/mavros/debug_value/named_value_int
/mavros/debug_value/send
/mavros/esc_info
/mavros/esc_status
/mavros/esc_telemetry
/mavros/estimator_status
/mavros/extended_state
/mavros/fake_gps/mocap/tf
/mavros/geofence/waypoints
/mavros/global_position/compass_hdg
/mavros/global_position/global
/mavros/global_position/gp_lp_offset
/mavros/global_position/gp_origin
/mavros/global_position/local
/mavros/global_position/raw/fix
/mavros/global_position/raw/gps_vel
/mavros/global_position/raw/satellites
/mavros/global_position/rel_alt
/mavros/global_position/set_gp_origin
/mavros/gps_input/gps_input
/mavros/gps_rtk/rtk_baseline
/mavros/gps_rtk/send_rtcm
/mavros/gpsstatus/gps1/raw
/mavros/gpsstatus/gps1/rtk
/mavros/gpsstatus/gps2/raw
/mavros/gpsstatus/gps2/rtk
/mavros/hil/actuator_controls
/mavros/hil/controls
/mavros/hil/gps
/mavros/hil/imu_ned
/mavros/hil/optical_flow
/mavros/hil/rc_inputs
/mavros/hil/state
/mavros/home_position/home
/mavros/home_position/set
/mavros/imu/data
/mavros/imu/data_raw
/mavros/imu/diff_pressure
/mavros/imu/mag
/mavros/imu/static_pressure
/mavros/imu/temperature_baro
/mavros/imu/temperature_imu
/mavros/landing_target/lt_marker
/mavros/landing_target/pose
/mavros/landing_target/pose_in
/mavros/local_position/accel
/mavros/local_position/odom
/mavros/local_position/pose
/mavros/local_position/pose_cov
/mavros/local_position/velocity_body
/mavros/local_position/velocity_body_cov
/mavros/local_position/velocity_local
/mavros/log_transfer/raw/log_data
/mavros/log_transfer/raw/log_entry
/mavros/mag_calibration/report
/mavros/mag_calibration/status
/mavros/manual_control/control
/mavros/manual_control/send
/mavros/mission/reached
/mavros/mission/waypoints
/mavros/mocap/pose
/mavros/mount_control/command
/mavros/mount_control/orientation
/mavros/mount_control/status
/mavros/nav_controller_output
/mavros/obstacle/send
/mavros/odometry/in
/mavros/odometry/out
/mavros/onboard_computer/status
/mavros/param/param_value
/mavros/play_tune
/mavros/px4flow/ground_distance
/mavros/px4flow/raw/optical_flow_rad
/mavros/px4flow/raw/send
/mavros/px4flow/temperature
/mavros/radio_status
/mavros/rallypoint/waypoints
/mavros/rc/in
/mavros/rc/out
/mavros/rc/override
/mavros/setpoint_accel/accel
/mavros/setpoint_attitude/cmd_vel
/mavros/setpoint_attitude/thrust
/mavros/setpoint_position/global
/mavros/setpoint_position/global_to_local
/mavros/setpoint_position/local
/mavros/setpoint_raw/attitude
/mavros/setpoint_raw/global
/mavros/setpoint_raw/local
/mavros/setpoint_raw/target_attitude
/mavros/setpoint_raw/target_global
/mavros/setpoint_raw/target_local
/mavros/setpoint_trajectory/desired
/mavros/setpoint_trajectory/local
/mavros/setpoint_velocity/cmd_vel
/mavros/setpoint_velocity/cmd_vel_unstamped
/mavros/state
/mavros/statustext/recv
/mavros/statustext/send
/mavros/target_actuator_control
/mavros/terrain/report
/mavros/time_reference
/mavros/timesync_status
/mavros/trajectory/desired
/mavros/trajectory/generated
/mavros/trajectory/path
/mavros/tunnel/in
/mavros/tunnel/out
/mavros/vfr_hud
/mavros/vision_pose/pose
/mavros/vision_pose/pose_cov
/mavros/vision_speed/speed_twist_cov
/mavros/wind_estimation
/move_base_simple/goal
/rosout
/rosout_agg
/tf
/tf_static
可以查看 IMU 频率,终端输入
rostopic hz /mavros/imu/data
结果显示
我们IMU 话题频率为 150 左右,这比 USB 连接时数据的接收频率要慢(USB 连接是 IMU 话题频率为 200 HZ 左右),这是正常现象,至此,我们就实现了 Jetson Orin NX 与 Pixhawk 6X 的串口通信!
这篇关于Jetson Orin NX 开发指南(9): MAVROS 的安装、配置与运行的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!