当前位置:   article > 正文

Jetson Orin NX 开发指南(9): MAVROS 的安装、配置与运行_orin nx 串口

orin nx 串口

一、前言

由于 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 表示波特率,这里我们不对这个文件进行修改,而是在当前目录下新建一个

终端输入

  1. cd /opt/ros/noetic/share/mavros/launch/
  2. sudo touch px4_ACM0.launch

打开 px4_ACM0.launch 文件,

sudo gedit px4_ACM0.launch

将其内容改为

  1. <launch>
  2. <!-- vim: set ft=xml noet : -->
  3. <!-- example launch script for PX4 based FCU's -->
  4. <arg name="fcu_url" default="/dev/ttyACM0:921600" />
  5. <arg name="gcs_url" default="" />
  6. <arg name="tgt_system" default="1" />
  7. <arg name="tgt_component" default="1" />
  8. <arg name="log_output" default="screen" />
  9. <arg name="fcu_protocol" default="v2.0" />
  10. <arg name="respawn_mavros" default="false" />
  11. <include file="$(find mavros)/launch/node.launch">
  12. <arg name="pluginlists_yaml" value="$(find mavros)/launch/px4_pluginlists.yaml" />
  13. <arg name="config_yaml" value="$(find mavros)/launch/px4_config.yaml" />
  14. <arg name="fcu_url" value="$(arg fcu_url)" />
  15. <arg name="gcs_url" value="$(arg gcs_url)" />
  16. <arg name="tgt_system" value="$(arg tgt_system)" />
  17. <arg name="tgt_component" value="$(arg tgt_component)" />
  18. <arg name="log_output" value="$(arg log_output)" />
  19. <arg name="fcu_protocol" value="$(arg fcu_protocol)" />
  20. <arg name="respawn_mavros" default="$(arg respawn_mavros)" />
  21. </include>
  22. </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

打印输出

  1. /diagnostics
  2. /mavlink/from
  3. /mavlink/gcs_ip
  4. /mavlink/to
  5. /mavros/actuator_control
  6. /mavros/adsb/send
  7. /mavros/adsb/vehicle
  8. /mavros/altitude
  9. /mavros/battery
  10. /mavros/cam_imu_sync/cam_imu_stamp
  11. /mavros/camera/image_captured
  12. /mavros/cellular_status/status
  13. /mavros/companion_process/status
  14. /mavros/debug_value/debug
  15. /mavros/debug_value/debug_float_array
  16. /mavros/debug_value/debug_vector
  17. /mavros/debug_value/named_value_float
  18. /mavros/debug_value/named_value_int
  19. /mavros/debug_value/send
  20. /mavros/esc_info
  21. /mavros/esc_status
  22. /mavros/esc_telemetry
  23. /mavros/estimator_status
  24. /mavros/extended_state
  25. /mavros/fake_gps/mocap/tf
  26. /mavros/geofence/waypoints
  27. /mavros/global_position/compass_hdg
  28. /mavros/global_position/global
  29. /mavros/global_position/gp_lp_offset
  30. /mavros/global_position/gp_origin
  31. /mavros/global_position/local
  32. /mavros/global_position/raw/fix
  33. /mavros/global_position/raw/gps_vel
  34. /mavros/global_position/raw/satellites
  35. /mavros/global_position/rel_alt
  36. /mavros/global_position/set_gp_origin
  37. /mavros/gps_input/gps_input
  38. /mavros/gps_rtk/rtk_baseline
  39. /mavros/gps_rtk/send_rtcm
  40. /mavros/gpsstatus/gps1/raw
  41. /mavros/gpsstatus/gps1/rtk
  42. /mavros/gpsstatus/gps2/raw
  43. /mavros/gpsstatus/gps2/rtk
  44. /mavros/hil/actuator_controls
  45. /mavros/hil/controls
  46. /mavros/hil/gps
  47. /mavros/hil/imu_ned
  48. /mavros/hil/optical_flow
  49. /mavros/hil/rc_inputs
  50. /mavros/hil/state
  51. /mavros/home_position/home
  52. /mavros/home_position/set
  53. /mavros/imu/data
  54. /mavros/imu/data_raw
  55. /mavros/imu/diff_pressure
  56. /mavros/imu/mag
  57. /mavros/imu/static_pressure
  58. /mavros/imu/temperature_baro
  59. /mavros/imu/temperature_imu
  60. /mavros/landing_target/lt_marker
  61. /mavros/landing_target/pose
  62. /mavros/landing_target/pose_in
  63. /mavros/local_position/accel
  64. /mavros/local_position/odom
  65. /mavros/local_position/pose
  66. /mavros/local_position/pose_cov
  67. /mavros/local_position/velocity_body
  68. /mavros/local_position/velocity_body_cov
  69. /mavros/local_position/velocity_local
  70. /mavros/log_transfer/raw/log_data
  71. /mavros/log_transfer/raw/log_entry
  72. /mavros/mag_calibration/report
  73. /mavros/mag_calibration/status
  74. /mavros/manual_control/control
  75. /mavros/manual_control/send
  76. /mavros/mission/reached
  77. /mavros/mission/waypoints
  78. /mavros/mocap/pose
  79. /mavros/mount_control/command
  80. /mavros/mount_control/orientation
  81. /mavros/mount_control/status
  82. /mavros/nav_controller_output
  83. /mavros/obstacle/send
  84. /mavros/odometry/in
  85. /mavros/odometry/out
  86. /mavros/onboard_computer/status
  87. /mavros/param/param_value
  88. /mavros/play_tune
  89. /mavros/px4flow/ground_distance
  90. /mavros/px4flow/raw/optical_flow_rad
  91. /mavros/px4flow/raw/send
  92. /mavros/px4flow/temperature
  93. /mavros/radio_status
  94. /mavros/rallypoint/waypoints
  95. /mavros/rc/in
  96. /mavros/rc/out
  97. /mavros/rc/override
  98. /mavros/setpoint_accel/accel
  99. /mavros/setpoint_attitude/cmd_vel
  100. /mavros/setpoint_attitude/thrust
  101. /mavros/setpoint_position/global
  102. /mavros/setpoint_position/global_to_local
  103. /mavros/setpoint_position/local
  104. /mavros/setpoint_raw/attitude
  105. /mavros/setpoint_raw/global
  106. /mavros/setpoint_raw/local
  107. /mavros/setpoint_raw/target_attitude
  108. /mavros/setpoint_raw/target_global
  109. /mavros/setpoint_raw/target_local
  110. /mavros/setpoint_trajectory/desired
  111. /mavros/setpoint_trajectory/local
  112. /mavros/setpoint_velocity/cmd_vel
  113. /mavros/setpoint_velocity/cmd_vel_unstamped
  114. /mavros/state
  115. /mavros/statustext/recv
  116. /mavros/statustext/send
  117. /mavros/target_actuator_control
  118. /mavros/terrain/report
  119. /mavros/time_reference
  120. /mavros/timesync_status
  121. /mavros/trajectory/desired
  122. /mavros/trajectory/generated
  123. /mavros/trajectory/path
  124. /mavros/tunnel/in
  125. /mavros/tunnel/out
  126. /mavros/vfr_hud
  127. /mavros/vision_pose/pose
  128. /mavros/vision_pose/pose_cov
  129. /mavros/vision_speed/speed_twist_cov
  130. /mavros/wind_estimation
  131. /move_base_simple/goal
  132. /rosout
  133. /rosout_agg
  134. /tf
  135. /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,分别对应串口文件和波特率)

  1. <launch>
  2. <!-- vim: set ft=xml noet : -->
  3. <!-- example launch script for PX4 based FCU's -->
  4. <arg name="fcu_url" default="/dev/ttyTHS0:921600" />
  5. <arg name="gcs_url" default="" />
  6. <arg name="tgt_system" default="1" />
  7. <arg name="tgt_component" default="1" />
  8. <arg name="log_output" default="screen" />
  9. <arg name="fcu_protocol" default="v2.0" />
  10. <arg name="respawn_mavros" default="false" />
  11. <include file="$(find mavros)/launch/node.launch">
  12. <arg name="pluginlists_yaml" value="$(find mavros)/launch/px4_pluginlists.yaml" />
  13. <arg name="config_yaml" value="$(find mavros)/launch/px4_config.yaml" />
  14. <arg name="fcu_url" value="$(arg fcu_url)" />
  15. <arg name="gcs_url" value="$(arg gcs_url)" />
  16. <arg name="tgt_system" value="$(arg tgt_system)" />
  17. <arg name="tgt_component" value="$(arg tgt_component)" />
  18. <arg name="log_output" value="$(arg log_output)" />
  19. <arg name="fcu_protocol" value="$(arg fcu_protocol)" />
  20. <arg name="respawn_mavros" default="$(arg respawn_mavros)" />
  21. </include>
  22. </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

可以受到如下话题

  1. /diagnostics
  2. /mavlink/from
  3. /mavlink/gcs_ip
  4. /mavlink/to
  5. /mavros/actuator_control
  6. /mavros/adsb/send
  7. /mavros/adsb/vehicle
  8. /mavros/altitude
  9. /mavros/battery
  10. /mavros/cam_imu_sync/cam_imu_stamp
  11. /mavros/camera/image_captured
  12. /mavros/cellular_status/status
  13. /mavros/companion_process/status
  14. /mavros/debug_value/debug
  15. /mavros/debug_value/debug_float_array
  16. /mavros/debug_value/debug_vector
  17. /mavros/debug_value/named_value_float
  18. /mavros/debug_value/named_value_int
  19. /mavros/debug_value/send
  20. /mavros/esc_info
  21. /mavros/esc_status
  22. /mavros/esc_telemetry
  23. /mavros/estimator_status
  24. /mavros/extended_state
  25. /mavros/fake_gps/mocap/tf
  26. /mavros/geofence/waypoints
  27. /mavros/global_position/compass_hdg
  28. /mavros/global_position/global
  29. /mavros/global_position/gp_lp_offset
  30. /mavros/global_position/gp_origin
  31. /mavros/global_position/local
  32. /mavros/global_position/raw/fix
  33. /mavros/global_position/raw/gps_vel
  34. /mavros/global_position/raw/satellites
  35. /mavros/global_position/rel_alt
  36. /mavros/global_position/set_gp_origin
  37. /mavros/gps_input/gps_input
  38. /mavros/gps_rtk/rtk_baseline
  39. /mavros/gps_rtk/send_rtcm
  40. /mavros/gpsstatus/gps1/raw
  41. /mavros/gpsstatus/gps1/rtk
  42. /mavros/gpsstatus/gps2/raw
  43. /mavros/gpsstatus/gps2/rtk
  44. /mavros/hil/actuator_controls
  45. /mavros/hil/controls
  46. /mavros/hil/gps
  47. /mavros/hil/imu_ned
  48. /mavros/hil/optical_flow
  49. /mavros/hil/rc_inputs
  50. /mavros/hil/state
  51. /mavros/home_position/home
  52. /mavros/home_position/set
  53. /mavros/imu/data
  54. /mavros/imu/data_raw
  55. /mavros/imu/diff_pressure
  56. /mavros/imu/mag
  57. /mavros/imu/static_pressure
  58. /mavros/imu/temperature_baro
  59. /mavros/imu/temperature_imu
  60. /mavros/landing_target/lt_marker
  61. /mavros/landing_target/pose
  62. /mavros/landing_target/pose_in
  63. /mavros/local_position/accel
  64. /mavros/local_position/odom
  65. /mavros/local_position/pose
  66. /mavros/local_position/pose_cov
  67. /mavros/local_position/velocity_body
  68. /mavros/local_position/velocity_body_cov
  69. /mavros/local_position/velocity_local
  70. /mavros/log_transfer/raw/log_data
  71. /mavros/log_transfer/raw/log_entry
  72. /mavros/mag_calibration/report
  73. /mavros/mag_calibration/status
  74. /mavros/manual_control/control
  75. /mavros/manual_control/send
  76. /mavros/mission/reached
  77. /mavros/mission/waypoints
  78. /mavros/mocap/pose
  79. /mavros/mount_control/command
  80. /mavros/mount_control/orientation
  81. /mavros/mount_control/status
  82. /mavros/nav_controller_output
  83. /mavros/obstacle/send
  84. /mavros/odometry/in
  85. /mavros/odometry/out
  86. /mavros/onboard_computer/status
  87. /mavros/param/param_value
  88. /mavros/play_tune
  89. /mavros/px4flow/ground_distance
  90. /mavros/px4flow/raw/optical_flow_rad
  91. /mavros/px4flow/raw/send
  92. /mavros/px4flow/temperature
  93. /mavros/radio_status
  94. /mavros/rallypoint/waypoints
  95. /mavros/rc/in
  96. /mavros/rc/out
  97. /mavros/rc/override
  98. /mavros/setpoint_accel/accel
  99. /mavros/setpoint_attitude/cmd_vel
  100. /mavros/setpoint_attitude/thrust
  101. /mavros/setpoint_position/global
  102. /mavros/setpoint_position/global_to_local
  103. /mavros/setpoint_position/local
  104. /mavros/setpoint_raw/attitude
  105. /mavros/setpoint_raw/global
  106. /mavros/setpoint_raw/local
  107. /mavros/setpoint_raw/target_attitude
  108. /mavros/setpoint_raw/target_global
  109. /mavros/setpoint_raw/target_local
  110. /mavros/setpoint_trajectory/desired
  111. /mavros/setpoint_trajectory/local
  112. /mavros/setpoint_velocity/cmd_vel
  113. /mavros/setpoint_velocity/cmd_vel_unstamped
  114. /mavros/state
  115. /mavros/statustext/recv
  116. /mavros/statustext/send
  117. /mavros/target_actuator_control
  118. /mavros/terrain/report
  119. /mavros/time_reference
  120. /mavros/timesync_status
  121. /mavros/trajectory/desired
  122. /mavros/trajectory/generated
  123. /mavros/trajectory/path
  124. /mavros/tunnel/in
  125. /mavros/tunnel/out
  126. /mavros/vfr_hud
  127. /mavros/vision_pose/pose
  128. /mavros/vision_pose/pose_cov
  129. /mavros/vision_speed/speed_twist_cov
  130. /mavros/wind_estimation
  131. /move_base_simple/goal
  132. /rosout
  133. /rosout_agg
  134. /tf
  135. /tf_static

可以查看 IMU 频率,终端输入

rostopic hz /mavros/imu/data

结果显示

我们IMU 话题频率为 150 左右,这比 USB 连接时数据的接收频率要慢(USB 连接是 IMU 话题频率为 200 HZ 左右),这是正常现象,至此,我们就实现了 Jetson Orin NX 与 Pixhawk 6X 的串口通信!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/979594
推荐阅读
相关标签
  

闽ICP备14008679号