串口编程项目— PX4FLOW 传感器数据接收处理(英文paper直接贴过来)

二、pixhawk光流传感器PX4FLOW 这东西不好用啊 在官网介绍里我们主要看到这个是关于光流扩展的一般还会有一个声呐传感器,就是那个MaxBotix I2CXL-MaxSonar-EZ这里有介绍 这个超声波传感器得说一下,它可以单独通过IIC去链接pixhawk,然后有两个焊盘需要我们自己短接,一个是这个超声波模块背面有一个回字形的得焊上,还有一个就是光流模块上有一个给超声波供电的3V3-GND-5V的选择供电的焊盘得焊上一个。 不这么搞接上光流传感器是看不到高度数据的。 接下来是调试光流模块 第一步首先肯定是检查刚刚说的两个焊盘有没有焊接,我 阅读详情

写在前面:
七月份初,结束交流生项目,向导师申请了个项目,关于PX4FLOW传感器的,serial programming 的java编程,下午刚刚提交完paper,写个总结,把项目的一些知识分享。以下为本人项目总结后的英文版paper,直接贴过来,由于接下来忙于准备面试,没时间翻译,等回国再翻译。
具体的源代码和完整paper在个人github。https://github.com/gannyee/PX4FLOW
转载请注明出处,谢谢!

Abstract

It’s a hard task for a mobile robot navigation to estimation robust velocity and position at high update speed. A device named PX4Flow Sensor can effective to resolve the problem. PX4Flow Sensor is an open-source, open-hardware device for cross-platform. The task is to set up a software to gap and analysis the data send from PX4Flow Sensor device via USB port, then display processed data on interface. Core data includes ground-distance, quality, angular velocity, with the help of PX4Flow Sensor, we can guarantee the update speed, and optical flow is estimated on a 250 Hz update rate. The software is relative to port programming, importing rxtx(package name) library into project to open port and read data.

1. INTRODUCTION

1.1 PX4Flow Sensor

The PX4Flow Sensor is an open-source, open-hardware device for cross-platform. The PX4Flow Sensor outputs optical flow estimates at up to 250 Hz using the MAVLINK protocol over serial. This package parses the MAVLINK messages from the PX4Flow optical flow board.

1.2 Packet Structure

After get data which in binary type send from device, parsing gotten data packet, pick up needed data. The packet structure of data got from sensor as the figure1 shown. Identifying target data by identify several important parameters, such as STX ID, LEN, SEQ and so on. As for the details of each byte, shown in the Form 1. STX, SEQ and SYS guarantees the needed packet, LEN and MSG used to as a check to guarantee the payload is the target. Figure 2. Show the detail of the payload, the payload’s ID is 100, which is OPTICAL_FLOW, including time_usec, sensor_id, flow_x, flow_y, flow_comp_m_x, flow_comp_m_y, quality, ground_distance.

这里写图片描述
这里写图片描述
这里写图片描述

1.3 RXTX Library

“RXTX is a Java library, using a native implementation (via JNI), providing serial and parallel communication for the Java Development Toolkit (JDK). All deliverables are under the GNU LGPL license. It is based on the specification for Sun’s Java Communications API, though while many of the class descriptions are the same the package used it not, since gnu.io is used instead. A certain amount of compatibility is intended with API, though this project should be considered as a fork and therefore compatible in spirit, but not in implementation.”[1]Importing RXTX library into project, using relative classes or interfaces to code Java code to open destination port then read data send from PX4Flow Sensor. Before successfully use RXTX library, configuring the environmental of workspace is vital.

2.1 Installing PX4Flow USB Driver

Download PX4Flow USB Driver for Window system;
After driver installation, the PX4Flow shows up as COM port. Use Window “Device Manager” to display the PX4 Flow port to check whether driver has successfully installed.[2]
RXTX Library Environment Configuration
Identify Java Development Kit’s folder. For my case:
C:\Program Files\Java\jdk1.7.0_11
Copy rxtxParallel.dll to C:\Program Files\Java\jdk1.7.0_11\jre\bin\
Copy rxtxSerial.dll to C:\Program Files\Java\jdk1.7.0_11\jre\bin\
Copy rxtxcomm.jar to C:\Program Files\Java\jdk1.7.0_11\jre\lib’ext\ [3]

2.2 Port Open

Having configured the RXTX library environment the first step to get target packet is to find the target port, then open port read data flow from device, storing stream into the InputStream (Java I/O API).

Relative Java Code:

// Get all available ports

public String[] getAllAvailablePorts() {

    Enumeration<?> allPorts = CommPortIdentifier.getPortIdentifiers();

    Vector<String> a = new Vector<String>();

    int i = 0;

    while (allPorts.hasMoreElements()) {

        a.add(((CommPortIdentifier) allPorts.nextElement()).getName()

                .toString());

    }

    return (Arrays.toString(a.toArray()).substring(1,

            Arrays.toString(a.toArray()).length() - 1).split(", "));

}



try {

        // Get specify port ID number

        portId = CommPortIdentifier.getPortIdentifier(com);

        // Open specify port

        serialPort = (SerialPort) portId.open(com, 1000);

        // Configure parameters

        serialPort.setSerialPortParams(getBaudRate(), getDataBites(),getStopBites(), getParityCheck());

        // get data stream

        inputStream = serialPort.getInputStream();

        // Add listener

        serialPort.addEventListener(this);

        // Listeners for available even

        serialPort.notifyOnDataAvailable(true);

        System.out.println("Port: " + portId.getName() + ": opened successfully!");

        isOpen = true;

     }

2.3 Data Parser

Packets are stored in InputStream in binary type, read available data into buffer with length 2048, then transfer binary data into byte type, Programming code to parser packets to find the target payloads. The idea to get the target payload is that: when read data from InputStream stored in buffer array, the data in byte type. First step to distinguish STX is equal to 0XFE or not, if yes, then get next byte LEG, representing the length of payload, using to check our finally gotten data. Mostly important evidence to guarantee data correctly is by checking the third byte SEQ, increasing after reading each buffer array, if increasing, meaning that the data gotten is right, then go on next step to check the MSG the ID of payload, whether it equals to 100, if positive, write and store target payload into other parameters.

Relative Java Code:

//Parser Buffer Array

public void process(byte[] buffer){

    targetMessager.clear();

    for(int i = 0;i < buffer.length;i ++ ){

        //Find STX_BYTE = 0xFE

        if(buffer[i] == STX_BYTE){

            this.state = STATE_STX;

        }

        //Find Payload length

        else if(this.state == STATE_STX){

            this.massagerLength = buffer[i];

            this.state = STATE_LEN;

        //Important information to distinguish packet correctly

        }else if(this.state == STATE_LEN){

            this.state = STATE_SEQ;

        }else if(this.state == STATE_SEQ){

            this.state = STATE_SYS;

        }else if(this.state == STATE_SYS){

            this.state = STATE_COMP;

        //Write and store target massager

        }else if(this.state == STATE_COMP){

            this.massagerID = buffer[i];

            this.messager = new Vector<Byte>();

            this.state = STATE_MSG;

        }else if(this.state == STATE_MSG &&this.massagerID == this.targetID ){

            this.messager.add(buffer[i]);

        if( messager.size() == this.massagerLength ){

            this.state = STATE_CKA;

        }

        }else if(this.state == STATE_CKA){

            this.state = STATE_CKB;

        }else if(this.state == STATE_CKB){

            if(this.massagerID == this.targetID){

                targetMessager.addElement(this.messager);

                setTargetMassager(targetMessager);

                this.state = STATE_DFLT;

            }

        }          

    }

}

2.4 Data Type Transfer

When get target massager, we still can’t use the gotten data to be display or analyzed, the target massager is byte type, while the data we needed are in different types, as shown in the Figure 2. given the tails of each data, therefore another task is to resolve the transfer. A class named: ByteArrayTransfer mean to solve the problem. The basic idea to transfer is bite moving.

2.5 Display Interface

Interface contains two parts, one to display the result of processing massager, another part for chose the port relative parameters, as figure 3. shown. The south position part is to display result, while north position part is to configure parameters for port.

这里写图片描述

Getting target massager from Process() routine, then process the massager for displaying, from the massager, get the ground distance which range is 0.3~5 meter, as well as quality which range is integer and between 0 to 255, on the other hand, with the flow_comp_m_x, flow_comp_m_y, can easily to estimate X and Y direction flow velocity, also get the result of moving point to draw some line to show the device movements. Com_x represented X direction flow velocity, while Com_y for Y direction flow velocity. Then you will get the following formulations:
Com_x = (Float.valueOf(x.tostring)) * axis-length
Com_y = (Float.valueOf(y.tostring)) * axis-length

Relative Java Code:

//Set X Y direction flow velocity

public void setX_Y(Object x,Object y, Object distance) {

    float comp_x = (float) 0.0;

    float comp_y = (float) 0.0;

    if(Float.valueOf(distance.toString()) > 0){

        comp_x =  (Float.valueOf(x.toString()) * 35 ) ;  //'35' mean the length of axis

        comp_y =  (Float.valueOf(y.toString()) * 35) ;

        this.v_x = (int) comp_x;

        this.v_y = (int) comp_y;

    }else{

           this.failcount += 1;

           System.out.println("Fail: " + this.failcount);

    }

    repaint();

}
//Set device movements situation

 public void setXY(Object time,Object compX,Object compY){ 

    double timeSec =  (Long.valueOf(time.toString()) / 1e6);

    if(this.count != 0){

        if(this.timeSecPrev != 0){

            this.elapsedSec = (timeSec - this.timeSecPrev);    

            if(this.elapsedSec < 0.1){

                this.X_accum += (Float.valueOf(compX.toString()) * this.elapsedSec) ;

                this.Y_accum += (Float.valueOf(compY.toString()) * this.elapsedSec) ;

            }

            this.timeSecPrev = timeSec;

        }

    }

    this.count += 1;

    this.timeSecPrev = timeSec;

    Point pre = new Point();

    Point point = new Point();

    if(pre.x != (int) (XAxis_X -75 + PARALLAR_MOVE + (this.X_accum / 10  * 100)) || pre.y != (int) (Origin_Y + 5 +  (this.Y_accum / 10  * 100)))

        point = new Point((int) (XAxis_X -75 + PARALLAR_MOVE + (this.X_accum / 10  * 100)), (int) (Origin_Y + 5 +  (this.Y_accum / 10  * 100)));

    points.add(point); repaint();

}

3. RESULT DISPLAY

Connecting device by USB then start the application, putting the device on the desk without any movements, interface only display the value of ground distance, the length from desk to ceiling, for my situation, it’s about 1.67 meters, as Figure 4. shown.

这里写图片描述

The case is that moving the device, changing the ground distance, X, Y axes flow velocity, then you can see the recently ground distance, quality, regular velocity, and device movement position. As figure 5, 6 shown.
这里写图片描述
这里写图片描述

CONCLUSION

In a word, the project’s determination is to gap and analysis data, then display the result on the interface, the key is how to find the port, open port, then read data, transfer data, calculate massager. The difficult is getting needed massager, after got, how to successfully and accurately transfer data is another challenge.
It’s my first time to do something relative to the topic PX4Flow, it’s a challenge for me to accomplish the project, from the project, I really learn lots of experience and knowledge I never learnt before. For example, some knowledge about PX4Flow sensor configuration, java interface coding, data parsing and so on. The process is interesting and unforgettable, on the other hand, I got to know how to make good use of the google search for question make out, it is efficient in English searching, which I can get more useful information to resolve the problem. Finally I have to give my sincere thanks to professor Steiper, without his help, I think I can not finish the project in time, he is a kind and very patient guider or supervisor, no matter what problem or how easy problem I met, he always try his best to explain for patiently. Thanks!

REFERENCES

[1] Opensourceecology, what is RXTX. http://opensourceecology.org/wiki/RXTX
[2] PX4FLOW Windows Driver Installation https://pixhawk.org/users/px4flow_windows_driver
[3]Installation for window http://rxtx.qbang.org/wiki/index.php/Installation_for_Windows

PX4中通过串口读取STM32F4串口发送过来消息并发布UORB主题 PX4中通过串口读取STM32F4串口发送过来消息并发布UORB主题 本次小项目是通过PX4读取STM32F4发过来的数据,之前博客介绍了我做的STM32端项目,再稍微啰嗦一下:解析AIRMAR和测深仪数据,该数据采用NEMA0183协议传输的。PX4接收到数据会通过mavlink消息发布出去,通过433MHz来进行无线传输,然后在岸边读取内河中的气象信息。 本项目会通过几篇博客去介绍,本次主要介... 阅读详情

相关推荐

PX4固件通过UART连接串口读取超声波,和树莓派3通信

添加串口读取程序首先在Firmware/msg文件夹下添加rw_uart.msgchar[5] datastr int16 data #TOPICS rw_uart记住在这一文件夹下的CMakeLists.txt下注册这个msg,添加rw_uart.msg即可。 上面的文件make之后会自动产生rw_uart.h头文件,里面会有结构体rw_uart_s,存取了我们刚才定义的data和datas

FC的博客 3792

Pixhawk原生固件PX4之串口读取信息

串口读个数据都这么费劲…… orz

FantasyJXF的博客 1万+

2016.2.27 Px4 flow分析

Px4 flow<span style="font-family: 宋体;mso-ascii-font-family:Cambria;mso-ascii-theme-font:minor-latin;mso-fareast-font-family: 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Cambria; mso-

Zhaohui1995_Yang的专栏 4190

飞控(Pixhawk 4 Mini)与机载电脑(Jetson Xavier NX )实现串口通信

飞控(Pixhawk 4 Mini)与机载电脑(Jetson Xavier NX )实现串口通信

Pulsar 1万+

PX4FLOW 智能光流传感器使用说明(英文).doc

PX4FLOW 智能光流传感器使用说明(英文)

PX4Flow的I2C读取数据

px4flow光流传感器的iic读取数据注意事项,稍微懂些iic的就可以把光流数据读出来。

PX4读取串口消息,并通过MAVLINK发送给地面站

PX4版本:1.12.0QGC版本: 4.2.0。

WENLAISIJEI的博客 3788

ADS2023仿真变容二极管特性

仿真S-Param仿真控件,设置为Single Point,将频率设置为1MHz,同时勾选Z-parameters,取消S-parameters,从元件库中选择元器件搭建原理图,并根据器件spice提供的相关参数,对原理图中器件参数进行修改,修改完成的电路图如下图所示。添加var控件和MeasEqn控件,相关设置如图所示,Ct为变容管的电容值,Q0为其品质因数。因此,对变容二极管的模型仿真结果是可以信赖的。将其解压,在spice文件夹中,可以找到我们想要的器件参数,和仿真简要电路图。

weixin_45811090的博客 1万+

Pixhawk原生固件PX4之串口添加读取传感器实现

假装用串口添加了传感器…… orz

FantasyJXF的博客 8267

麒麟V10系统命令实战指南:从入门到精通

本文为麒麟V10操作系统用户提供了一份从入门到精通的命令行实战指南。内容涵盖文件管理、进程监控、网络诊断、文本处理及系统管理等核心场景,旨在帮助用户转变思维,掌握高效解决实际问题的系统命令技巧,从而提升在麒麟V10环境下的运维与工作效率。

sat99的博客 594

llama.cpp量化模型在MTT显卡上的性能对比:S80/S3000/S4000实测数据

本文基于摩尔线程MTT S80、S3000和S4000三款显卡,对llama.cpp量化模型进行了深度性能实测。报告详细对比了不同量化精度(如Q4_K_M、Q6_K)在Llama 3.2 1B和Qwen 2.5 7B模型上的推理速度、显存占用、功耗及温度表现,为开发者根据硬件选择最优模型配置与参数调优提供了关键数据参考和实战指南。

week9的博客 350

PX4Flow使用操作

       这两天测试了一下PX4FLOW模块,官网(https://docs.px4.io/en/sensor/px4flow.html)上对这个模块的描述太过简单,只能看出些大致思路。而国内关于这个模块使用的文章也是描述不是太细致。这里把这两天测试过程和经验向大家分享一下。        首先,我使用的是PX4FLOW1.3就是官网的图片的那块。使用的高度传感器也是板子上自带的那个(网上很...

Keven__Ding的博客 1万+

光斑大小控制【ZEMAX操作数】

在使用Zemax优化光学系统时,对成像的聚焦光斑大小进行限制,即弥散斑的大小; 一、RSCE(质心RMS光斑半径):二、RSCH(光线RMS光斑半径):

yh的博客 7859

PIXHAWK上安装PX4Flow光流传感器及调试过程

小编最近刚调试完光流传感器,效果非常理想,无GPS情况下很稳定。小编把调试过程的过程和遇到的问题分享给大家,希望大家少走弯路。 在安装和调试光流传感器之前,先保证旋翼机已经安装和调试完毕,在自稳模式下稳定飞行。 PX4Flo简介 PX4Flow光流传感器是一种高分辨率的图像传感器,内置3轴陀螺仪,通过分析摄像头下方相邻两帧图像的像素的移动,得到无人机X和Y方向的地速,光流模块用于定点悬停,采用速度...

wlrh253250的博客 2万+

树莓派5搭建ROS1开发环境:从系统安装到环境变量配置

本文详细指导如何在树莓派5上搭建ROS1开发环境。针对树莓派OS非标准安装路径导致的常见CMake报错问题,提供了从系统烧录、一键安装ROS到关键环境变量配置的完整解决方案,确保工作空间能成功编译,助力机器人项目开发。

weixin_29159127的博客 384

五段式S型算法笔记

又因为有 v-v0= 0.5jt通式: 所以有 vm-v0= 0.5jtm 所以有4vm-4v0= 2jtm。算法1: v=2vm-v0-0.5*jt+2jt*tm-2jtm*tm。加加速度j 自己设置 已知,vmax自己设置已知;所以有4vm-4v0= 2jtm带入算法1。

qq_36658033的博客 680

PIX4flow使用记录

想通过I2C直接读取pix4flow的数据,结果不好使,找原因。 找到官网https://pixhawk.org/modules/px4flow#i2c和http://www.pixhawk.com/zh/dev/px4flow,安装了QGC地面站和PX4flow的驱动,详细的如何装驱动https://pixhawk.org/users/px4flow_windows_driver 然后在地面站里

qq_33243369的博客 2426

AI大模型入门到实战系列(二十一)命名实体识别(NER)

命名实体识别(NER)是自然语言处理中的关键任务,旨在从文本中识别并分类预定义类别的实体(如人名、地点、组织等)。其核心步骤包括文本预处理、实体边界检测和类型分类。主流技术方法经历了从基于规则、统计机器学习到深度学习的演进,当前主要采用预训练语言模型(如BERT)和序列标注技术(如BiLSTM-CRF)。关键技术挑战包括实体边界模糊、嵌套实体和领域适应等问题。NER广泛应用于信息抽取、搜索引擎优化和知识图谱构建等领域,常用精确率、召回率和F1值作为评估指标。实际应用中通常采用BIO标注体系,并通过标签对齐处

echo的博客 1622

PX4FLOW光流模块DIY(含部分代码讲解)

PX4光流模块学习

xian_z的博客 1万+

【Frida Android】实战篇4:SSL Pinning 证书绑定绕过 Hook 教程(一)

在前两章中,我们学习了中间人抓包与 Hook 抓包的基础方法,这些方法在理想环境下能够有效获取网络请求数据。但在实际的企业级应用中,出于安全防护需求,很多 APP 会启用证书绑定(SSL Pinning)机制。这种机制会让客户端对服务器证书的校验更为严格,导致常规的抓包方法(即使将 BurpSuite/Charles 证书安装到系统信任区)也无法生效。因此,从本章开始,我们将系统学习 SSL Pinning 机制的绕过技术。SSL Pinning(证书绑定)是客户端校验服务器身份的进阶安全机制。

水滴石穿 1609

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

px4如何读取串口信息

前言:网上有一大堆,比如minicom,mavproxy等等,其实qgc就自带nutshell工具 在下面输入help就可以看到所有命令!!!

zouxu634866的博客 1161

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

pixhawk串口读取传感器数据

1、 Pixhawk板上串口说明:        测试使用Pixhawk板上TELEM2接口的USART2,对应的Nuttx UART设备文件尾/dev/ttyS2:     2 读取数据测试 步骤: 在Firmware/src/modules中添加一个新的文件夹,命名为rw_uart在rw_uart文件夹中创建CMakeLists.txt文件,并输

Gen_Ye的博客 6375

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

pixhawk-px4之通过串口添加传感器应用

前言: 看到有博客通过串口添加自定义传感器,按照步骤做了一遍 博客:http://blog.youkuaiyun.com/msq19895070/article/details/52012190 一 串口选择 Pixhawk板上TELEM2接口的USART2,对应的Nuttx UART设备文件尾/dev/ttyS2 二 添加应用 step 1:在Firmware/src/mod

点滴记录 6268

px4FLOW使用方法参考

资料参考 https://docs.px4.io/en/sensor/px4flow.html 外国友人,已经调试好的挺好的参考 http://ardupilot.org/copter/docs/common-px4flow-overview.html?highlight=px4flow

Keven__Ding的博客 1864

px4flow源码分析

Flow.c 计算光流用的是SAD块匹配算法   第一部分是生成直方图,第二部分是根据直方图来进行位移向量的计算。   外部的j、i的for循环是采样点的循环,内部的jj、ii的循环是对于一个小邻域的采样。采样点是从image1找的,之后根据采样点的坐标在image2的winmin到winmax的一个小矩形中找一个最相似的点。   PARAM_BOTTOM_FLOW_FEATURE_

sev_en77的博客 3587

pixhawk自学笔记之从串口获取光流数据

pixhawk代码已经给出了光流从iic接口获取数据的驱动,在driver文件下可以找到。因为我手边没有多余的传感器,也懒得重新配置mavlink协议,我们来看一下光流代码: 我在main.c文件中把源代码给修改了,现在我们通过串口3,利用mavlink_msg_optical_flow_send函数传送数据。我们追踪到这个函数: 在这个文件下。好,那我们看一下在飞控源代码里面怎么接受

Zodiac_V的专栏 7766
上一篇: Java 基于数组自定义实现容量可变向量Vector
下一篇: LeetCode解题报告--Palindrome Number
YatKam
博客等级 码龄12年 58粉丝 49原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值