这个例程 例程讲解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)`应该对应倒数第二个参数吧?
你再看一下程序,你说的这个temp不是最后发送的temp,这个temp后来变了。
后面的两个temp没错,是mavlink的格式。
一层一层解析出来的,第一个temp是光流信息,第二个temp是增加其他格式信息,最后一个temp是添加校验码。
主要问题就是这第一个temp。
<http://mavlink.org/messages/common#OPTICAL_FLOW>这里的字节数我数了一下,一共是8+1+2+2+4+4+1+4+4+4,也不是26个,我也很奇怪
你说的这个是没问题的。
MAVLink分为MAVLink1 和 MAVLink2,该项目使用的是1版本。
在更为详细的MAVLink Common Messages Format Doc (https://mavlink.io/en/messages/common.html)中写到:


由此可见,最后两个参数是不存在的。
因此,前8个参数的字节数为:8+1+2+2+4+4+1+4=26.
但是,问题就是它不能相互对应啊。
@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)