rt-thread移植并使用mavlink教程
一、移植
1、下载mavlink源码
打开mavlink官网
找到如下:
点击图中框下载。
2、将源文件添加到工程中
二、使用
1、发送包数据
void send_winch_command(winchCommage command)
{mavlink_message_t msg;mavlink_msg_command_long_pack(/*SENDER_SYS_ID=*/1,/*SENDER_COMP_ID=*/1,/*MESSAGE=*/&msg,/*TARGET_SYS_ID=*/0,/*TARGET_COMP_ID=*/0,/*CMD_ID=*/7001,/*CONFIRMATION#=*/0,/*P1_A2Z_COMMAND_TYPE=*/command,/*P2=*/0,/*P3=*/0,/*P4=*/0,/*P5=*/0,/*P6=*/0,/*P7=*/0);uint8_t buf[MAVLINK_MAX_PACKET_LEN];uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);// Here we presume the C file write operation but you can send the data in buf however you like.//write(target_filestream, buf, len);winch_send_data(buf, len);// For inspecting encoded messages:log_v("send data:");for (int i = 0; i < len; ++i) {elog_raw("%02X ", buf[i]);}elog_raw("\r\n");log_v("send over!");}
2、接收处理数据
void mavlink_process()
{rt_completion_wait(&winchg_received_completion,RT_WAITING_FOREVER);uint8_t buf[100];//从设备读取数据uint8_t count =winch_read_data(buf,sizeof(buf)); //read(target_filestream, buf, sizeof(buf));for (uint8_t i = 0; i < count; i++){// This function takes a byte at a time, returning true only when the last byte of a completed message is received:if (mavlink_parse_char(1, buf[i], &mavlink_msg_in, &mavlink_status_in)) {// You may also wish to check system ID, component ID, or other fields.if (mavlink_msg_in.msgid == 9005) {mavlink_winch_status_t winch_status;mavlink_msg_winch_status_decode(&mavlink_msg_in, &winch_status);// The "ride-along" A2Z state encoded in the last 8 bytes WINCH_STATUS field:winchState state = winch_status.status >> 24;// Print the info for debugginglog_d("Got a winch_status message:\n State %d\nTension %f m\nLength %f\n", state, winch_status.tension, winch_status.line_length);// Update your app/ui state (for you to impelement)/*SendStateToApp(state);SendMotorCurrentToApp(winch_status.tension);SendLineLengthToApp(winch_status.line_length);etc*/} else if (mavlink_msg_in.msgid == 132) {// The lidar value is encoded in the distance_sensor measurement // so that a ground control station and autopilot can also make use of itmavlink_distance_sensor_t distance_sensor;mavlink_msg_distance_sensor_decode(&mavlink_msg_in, &distance_sensor);log_i("Got a distnace_sensor message:\n Distance %i\n", distance_sensor.current_distance);//SendLidarToApp(distance_sensor.current_distance);} else {log_w("Invalid message type %i\n", mavlink_msg_in.msgid);}}}}
三、完整工程源码
完整工程下载点击我
rt-thread移植并使用mavlink教程相关推荐
- 正点原子delay函数移植到rt thread操作系统(HAL库)
正点原子教程中涉及到的操作系统只涉及了UCOS的教程,其中例程的system文件夹中的delay.c函数只是适配了UCOS. 下面将delay.c函数移植到rt thread中,使用的bsp是rt t ...
- RT Thread Free Modbus移植问题整理
RT Thread Free Modbus移植问题整理 问题描述: 在读写寄存器中,写数据正常,只能读1个寄存器的值,多个值会异常. 在移植过程中发现串口(或RS485)数据接收长度异常. 一.环境描 ...
- RT Thread根据开发板制作BSP方法
之前一直不懂怎么使用RT Thread的软件包,感谢网上的大神,看了你们的博客后大概了解一些,在此做下记录.用RT Thread软件包需要RT Thread的系统,但是RT Thread和RT Thr ...
- 基于rt thread smart构建EtherCAT主站
我把源码开源到到了gitee,https://gitee.com/rathon/rt-thread-smart-soem 有兴趣的去可以下载下来跑一下 软件工程推荐用vscode 打开.rt thre ...
- rt thread studio使用QBOOT和片外flash实现OTA升级
我们这里要使用单片机外部flash作为OTA的下载分区,外部flash硬件连接关系 PB3-->SPI3_CLK PB4-->SPI3_MISO PB5-->SPI3_MOSI PE ...
- Yeelink平台使用——远程控制 RT Thread + LwIP+ STM32
1.前言 [2014年4月重写该博文] 经过若干时间的努力终于搞定了STM32+LwIP和yeelink平台的数据互通,在学习的过程中大部分时间花在以太网协议栈学习上,但是在RT Th ...
- RT Thread利用STM32CUBEMX和RT Thread studio来创建模板工程
(1)RT Thread利用STM32CUBEMX来创建模板工程 1.参考文档: 基于 CubeMX 移植 RT-Thread Nano:RT-Thread 文档中心 注意:串口2必须使能异步模式(启 ...
- xpt 2046的触摸屏 rt thread设备驱动框架
1 基于rtt 开发触摸屏驱动 准备使用rtt 框架 , 驱动xpt 2046的触摸屏, 翻阅大量资料发现, 大部分文章强调的是时序图, 而且很多代码要么直接操作寄存器, 要么是io 口模拟, 只能用 ...
- 基于GD32F103C8T6添加RT Thread nano设备框架并添加串口设备(以控制台console( uart0 )为例)
最近没事琢磨了一下使用设备框架的问题.因为将串口注册到设备框架可以应用十分丰富的软件包. 于是就整理了一下手上的工程,重新将工程梳理了一遍. 像这样是十分清爽了,其中RTOS是操作系统源代码 并且学习 ...
最新文章
- python epoll多路复用技术_python:多路复用+零拷贝
- 旷视孙剑团队提出Anchor DETR:基于Transformer的目标检测新网络
- 深度学习分布式策略优化、显存优化、通信优化、编译优化综述
- 送你一份用Electron开发桌面应用的避坑指南【送3本书,含犀牛书】
- [css] 怎么IE6下在使用margin:0 auto;无法使其居中?
- C#中yield用法
- 使用Rss框架PHP开发流程
- Golang sort 包使用
- 深度优先搜索-和为某数的所有组合
- viiv个人计算机,欢娱尽情 欢跃平台PC导购
- c语言p1-melepeo,C语言做个学生选课系统 -电脑资料
- 16种常用的数据分析方法-聚类分析
- text 热敏打印机_便携热敏打印机API参考手册.pdf
- [转]用python来开发webgame服务端(5)
- Java中用System.getProperty(...)获取系统属性
- 39个让你受益的HTML5教程
- jvav是什么梗?jvav是什么?jvav史上最牛语言
- URAL 2037 Richness of binary words (回文子串,找规律)
- vue 替换路由地址参数(动态修改路由参数)
- 扫描文件存电子版方法