logo

通过mavlink实现光流这个例程是不是写错了?

2018-03-16 19:36
3
haha

这个例程 例程讲解18-MAVLink->mavlink_opticalflow 通过mavlink实现光流 (http://book.openmv.cc/example/18-MAVLink/mavlink-opticalflow.html)

中的`send_optical_flow_packet`函数:

在第一个stuct.pack中

    temp = struct.pack("<qfffhhbb",
                       0,
                       0,
                       0,
                       0,
                       int(x * 10 * 4), # up sample by 4
                       int(y * 10 * 4), # up sample by 4
                       MAV_OPTICAL_FLOW_id,
                       int(c * 255))

其格式应该对应 Mavlink光流信息格式 (http://mavlink.org/messages/common#OPTICAL_FLOW)。

按照上述各式,最后两个参数应该是quality和ground_distance。

然而,例程中的最后一个参数`int(c*255)`应该对应倒数第二个参数吧?

2018-03-16 21:38
I
网红小智智 星瞳科技

你再看一下程序,你说的这个temp不是最后发送的temp,这个temp后来变了。

2018-03-16 21:47
3
haha

后面的两个temp没错,是mavlink的格式。

一层一层解析出来的,第一个temp是光流信息,第二个temp是增加其他格式信息,最后一个temp是添加校验码。

主要问题就是这第一个temp。

2018-03-16 22:43
I
网红小智智 星瞳科技

<http://mavlink.org/messages/common#OPTICAL_FLOW>这里的字节数我数了一下,一共是8+1+2+2+4+4+1+4+4+4,也不是26个,我也很奇怪

2018-03-17 07:55
3
haha

你说的这个是没问题的。

MAVLink分为MAVLink1 和 MAVLink2,该项目使用的是1版本。

在更为详细的MAVLink Common Messages Format Doc (https://mavlink.io/en/messages/common.html)中写到:

ecbc46c2-f642-49cc-89c6-6b70ced9ebcf.png
5e2ce579-afd6-4c38-9f71-0a49777967b0.png

由此可见,最后两个参数是不存在的。

因此,前8个参数的字节数为:8+1+2+2+4+4+1+4=26.

但是,问题就是它不能相互对应啊。

2018-03-17 11:06
3
haha

@kidswong999

我貌似懂了?

看他在github上的代码,跟他所规定的消息格式不一致...

message format (http://mavlink.org/messages/common#OPTICAL_FLOW)

source code in github (https://github.com/mavlink/c_library_v1/blob/master/common/mavlink_msg_optical_flow.h)