offboard-control-using-mavros

本文介绍如何使用ROS与MAVROS包实现对开源飞行控制器的高级命令控制,包括安装配置过程及常见问题解决办法。

原文:https://404warehouse.net/2015/12/20/autopilot-offboard-control-using-mavros-package-on-ros/

Overview

Recently opensource autopilots have become reliable by various failsafe functions integrated by the opensource community. Developing different softwares for each application can be time consuming and hard to verify the reliablility of the software. An alternative to modifying the autopilot software, is to use an onboard computer to command the autopilot using high level commands. This way, the developer can use a reliable autopilot software which is still reliable and capable of staying in the air and use a software developed for the developer’s own purpose.
This article is to introduce how easy and practical it is to connect a PC, using ROS to control the autopilot running onbaord an onboard PC. A nice tutorial is up on the PX4 website but is a little unfriendly and I wanted to share some of the troubleshooting experiences while I was implementing the system.

로열모_5분스피치_임재영

what is ROS?

ROS is a framework for incorporating various modules of robotics by configuring modules as a TCP network. The ROS community is currently growing in a very fast pace both in the community and industry. The ROS wiki has great tutorials in understanding the framework. Please get used to using ROS following tutorials 1.~9. in the tutorials page.

Introduction to MAVROS

MAVROS is a ROS package which enables ROS to interact with autopilot software using the MAVLink protocol. MAVlink consists of 17 bytes and includes the message ID, target ID and data. The message ID shows what the data is. Message IDs can be seen in the messageID command set.
b15e6d130c9d606305c31ffedb3c1118.media.400x98

This enables MAVLink to be able to get information from multiple UAVs if messages are transferred in the same channel. Messages can either be transmitted through wireless signals.

mavros_raw


Installing MAVROS

MAVROS can be installed using the source in the mavros repository. The default dialect of MAVROS is apm. As we are installing px4 on the pixhawk flight controller, MAVROS should be built from source, by configuring mavros by the command below.

catkin config --cmake-args -DMAVLINK_DIALECT=common

Configuring PX4 for ROS

For the companion computer to communicate with the flight controller, a USB2TTL converter is needed to convert the voltage of the communication levels. A brief overview of configuring the companion computer with the pixhawk is shown in this link.

IMG_20151221_122909

It is recommended that the offboard control is done through the TELEM2 port. Telem2 port can be activated usign the SYS_COMPANION parameter. This can be done by modifying the parameter on qgroundcontrol.

SYS_COMPANION 921600

Configuring MAVROS for PX4

To launch MAVROS, the easiest way is to use the launch file

roslaunch mavros px4.launch

Launching MAVROS, it may not work on the first time. Do not panic!

Some parameters should be modified to be able to talk with the flight controller. The device name and baudrate should be configured to be able to talk to the autopilot.

1
2
3
4
5
6
7
8
9
10
11
12
< node name = "mavros" pkg = "mavros" type = "mavros_node" output = "screen" >
     < param name = "fcu_url" value = "$(arg fcu_url)" />
     < param name = "gcs_url" value = "$(arg gcs_url)" />
     < param name = "target_system_id" value = "$(arg tgt_system)" />
     < param name = "target_component_id" value = "$(arg tgt_component)" />
     <!-- enable heartbeat send and reduce timeout -->
     < param name = "conn_heartbeat" value = "5.0" />
     < param name = "conn_timeout" value = "5.0" />
     <!-- automatically start mavlink on USB -->
     < param name = "startup_px4_usb_quirk" value = "true" />
 
</ node >

Setting Setpoints

Setpoints should be sent to the flight controller with a 0.5s time out. This is a safety factor so that the control should converge to a specific objective. Otherwise the flight controller will not Go into offboard mode. Setpoints that can be used are as below.

  • Position Setpoints
  • Velocity Setpoints
  • Attitude Setpoints
  • Acceleration Setpoints
  • Actuator Control

An example node written in cpp is shown below. The node publishes setpoint_poistion_local message.

Integrating Companion Computer to quadrotor

The quadrotor is based on a F330 frame and the current integration follows as below. 330 frame feeled a little small for an onboard computer. For future integration, 450 frame should be more appropriate.

IMG_20151221_202606

Position Control Example

For position control, external position estimation using the Vicon motion capture system was used for more precise position measurement. The block diagram visualized using rtq_graph is shown as below.rosgraph2

### 无人机 Offboard 模式与 UXRCE-DDS 的集成 #### 定义与背景介绍 Offboard模式允许地面站或其他外部设备通过发送设定点(setpoints)完全接管飞行控制器的姿态、速度或位置控制[^2]。这种模式对于执行复杂的自动化任务至关重要,因为它提供了更高的灵活性和精确度。 UXRCE-DDS (Micro XRCE DDS) 是一种轻量级的消息传递协议,专为资源受限环境设计,适用于嵌入式系统间的通信。它实现了DDS标准的一个子集,特别适合于微控制器和其他低功耗平台上的应用开发[^4]。 #### 实现步骤概述 为了使无人机能够在Offboard模式下利用UXRCE-DDS进行操作,通常需要完成以下几个方面的工作: - **配置硬件连接**:确保所有必要的传感器和执行机构都已正确安装并能正常工作。 - **设置软件框架**:基于MAVROS节点建立ROS(机器人操作系统)环境,并加载适当的参数文件以支持特定类型的无人机模型[^3]。 - **编写客户端程序**:采用C++或者其他兼容的语言创建应用程序逻辑,该程序负责初始化UXRCE-DDS参与者(participant),定义主题(topic),发布者(publisher)/订阅者(subscriber),以及处理来自飞控的数据流。 - **安全措施实施**:鉴于在真实环境中使用Offboard模式存在潜在风险,在实际部署前务必验证所有的应急机制,比如预设好返回手动操控的方式以防不测发生[^1]。 ```cpp // 示例代码片段展示如何启动一个简单的Publisher用于向PX4发送目标高度指令 #include <uxrcedds_client/client.h> ... int main(int argc, char *argv[]) { uxr_init(); // 创建Participant实例 uint8_t participant_id; create_participant(&participant_id); // 注册Topic类型并创建相应的Publisher实体 register_topic_type(TOPIC_NAME, PARTICIPANT_ID); publisher = create_publisher(PARTICIPANT_ID); while (!is_shutdown()) { float target_altitude = 2.0f; // 设定目标高度为两米 publish_message(target_altitude); // 发送数据给PX4自动驾驶仪 sleep_for(std::chrono::milliseconds(10)); } destroy_all_entities(); // 清理资源 } ``` 此段伪代码仅作为概念证明用途,具体实现细节会依据所使用的库版本和个人需求有所不同。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值