Pymavlink: sending optical flow messages

I have computed optical flow from a downwards-facing camera.
Now I would like to publish this data with pymavlink.

I’ve tried it like this:

from pymavlink import mavutil
...
self.mavlink_connection = mavutil.mavlink_connection('0.0.0.0:14550', autoreconnect=True, baud=57600)
self.mavlink_connection.wait_heartbeat()
...
self.mavlink_connection.mav.optical_flow_send(timestamp, 77, dx, dy, dx_m, dy_m, 255, z)

However, this doesn’t work:

pxh> listener optical_flow
never published

Why?
How would I do it correctly?
Thanks.

(I’m working with posix gazebo simulation.)

Appendix:

  • publishing distance sensor data works just fine:

    self.mavlink_connection.mav.distance_sensor_send(timestamp, 2, 700, 6, mavutil.mavlink.MAV_DISTANCE_SENSOR_INFRARED, 0, mavutil.mavlink.MAV_SENSOR_ROTATION_PITCH_270, 1)

  • I’ve been able to verify that both messages arrive in the self.mavlink_connection.mav.send(...) method, get handed over to a mavudp file object and are sent successfully in mavutil.py line 917.

  • Also rostopic echo /mavlink/from only shows messages with msgid: 132 (DISTANCE_SENSOR), not msgid: 100 (OPTICAL_FLOW).

  • I’ve figured out that messages sent with optical_flow_rad_send (instead of optical_flow_send) are received. However, they are still ignored by the position estimator (EKF2). iris_opt_flow works though. Maybe it has something to do with the broken MAVROS <-> MAVLink timestamps?
    listener optical_flow states timestamp: 20260000 (18446744073707.664062 seconds ago)
    Everything else seems identical to the messages published by iris_opt_flow.

    • Fun fact: ROS time issued by MAVROS is slower than r̴e͏a̧l time (53 s in 60 s). Simulation time however is even slower. Th͠ree̴ ͜diffe͏ren͏t times … w̢̕h͘y?̴͢͠?

/̛
͢
͢ Get ́ab̴s͢olu͝te tim̴è.
̵ ͠*̧/̕
̵h͏r̕t_́ab҉sţime ̨_͡h̵rt̸_a͝b͢so̕lute͘_t͡i̸m̴e̷_͡interna͟l͡(́void͘)̢
̸{̵ ͟OMG̢ ̧w̕h̶y̢
͝s͜t͜r͘u͏çt̕ ́ti̛m̀e̶spec ̷t̴s;̷

͜#if̵ d͢ef̕i͞ne̷d(__̧PX4͜_QU͡R͘T)
͢//̀ Do͡n̸’t̵ ͜us̷è t̀h҉e̶ t͢im͢esta͢rt̢ on ̴the DS̷P͜ ̢o͡n͠ Sna̕pd͟ragon ̶b̕ȩcause w͠ȩ m̡an̵ual̴ly
/͏/ s͜et͜ ̵t̷hé ́p̷x4̕_tim҉es̴t̵a͠rt̵ usi̧ņg t̵hé h͢rt_͜set͠_a̡b͏s͡o̶lųte_tim̵e_̢of͟f̀set͜().͡
͘px͏4̵_͢c̡l̛oc̕k͜_getti̵m̸e(CL̛O̕C͘K҉_͏M̕ON͠OTO̕N̢ÌC, &̢ts͡);
͘ ̛r̡etu̴r͘n ͡ts_t͜o_̸abst̸i̧m͝e(̢&ts͟)͘ +҉ ̧dsp_of͏fse͢ţ;̧

͟͠#̸͟e̸ļ̶íf̨͞ ̶͘(d̴̢e͢f̷͢i͜n͘͜͝é̸̕d͘(͟_̸͜_̛̀P͘͞X̡4͜͝͏_PO̶S̛IX_̧̀͘E̛̕À̶̢G̛͠L͞͞E)̀ ̢̨͜|̧͞|̡͟ ̶͟dè̶͟f͠ín̢͘͢e̛͢d͞(̧__PX̛4̀͠_PO̵҉͠S̶͘I͘̕X͏_̡͘È͜XC̀E͘͞L̛S̴̶͢IOR͏͏͠)̨͘͡)̛̀
̧͏ ̸̡/̷͘͜/ ̀͘D̸o̴̷n̴’͡t̷̵̕ ̶̛͟d͜͞͡o̡҉ ͟ą͞n̸͠y̢͘ ͠͡o̕f̢͝f̸̡ś̶e͟͡͠t͞i̶͟n͘͟g ̴̨́o̷n̡͞ ́́t̶̛͠he҉͜ L̶̵͜in̸͢͢u̧͟x͢ ̧s̕͞i̧d̛̀e̷͟ on҉̕ ̕͏t̡̡́h͜͢͡e̡ ̴͠S̵̴n̵͞a̵̷̧pd͏r̷̀ag͢o̸̷ń̷.̨̀҉
͘ ̸͜px͏̸4̨͘_̴̷͠ć͘͘l̀o̴c̢k̷_̷̨̛g̢҉e̵t̸ti͠m̛͜͢éC̛̕H̨A̵͟OS͏̀͝(̵̶́C͟͜LO̶̢CḰ_͜͞M̛͜͏O̶N̛O͜͡Ţ̛͞O̷͠͞N͢͝I͝Ç,̕͜ &̡͟t͟͏s̢͝)̶̛;҉̛
͏̢͢ ͟r̢͘͜et̡ur̛n̵͘ ̷͏t͘s̨̨_t҉̛o̴͝͞_̡͘͢a̕͝b͘s͏͢t́im͝e̢̕(̧͞&̨̨t̀͘͝s͟͟)̢̧͜;͜҉
C͞H̨A͏̧͜O̧S̷
҉͠#͞e͠l͟͡͞s̨̨e̢͝͝V̕͠ƠI͏D
̵̷̪̥̟̱͇̲͚́í̱͖̼̦͈̻͝f̴̡̜̟͙͎̞̯͈̼̻̞̯͈̟̖̦̙̕͞͠ ̷̶̡̰̗͓̯̥̭̖̲̤̬̫͎̘̟̟̠͓͞(̸̴̖̥̘̭̫͜͡!̴̸̴̼̟̙̗̮̦͉̮͚͔̖̜͚͎͎̞̙͍͘͠p̨̻͇̺͉̖̫̭̺̭͇͎̗̕x̣̖̩͍̳̘̙̬̞͍̰͇͠ͅ4̴̵̶̢̠̠̲̩̰̱̰͔̟̱̪̻͎̯̫̼͔̯͟ͅ_̷̛̫̙̞̲̘̟͈ͅt̵̴҉̵̳̥̦̫̣̫͇̩̻͎͖̤̹͡ͅͅì͚̠̱̯̱͉̮͍̹̬͔̻̪̲̞̹͝͡m̹̱͚͇̝͓̙̦͙̥͈͍̯̮̳̲̮̻͉̕̕e̕҉̟̘̙̱̮̼s̨̛̹͕͈̜̲̥͎͝ţ̷̫̠͎͖̟̤͈͖̜̠̰̳͓̻͇̲͟͞á̧̛̯͚̝̝͔̺̳ŕ̢̹̱̭͍͈͕͔̳̦͘̕͞t̷̝̲̩̘͙̤́́̕͟)̥̯͕̗̳̭̯̳̺̩͚̣̱̪̤̲͓͡ͅ ̶̻͙̦͎̬̻͇̟͖̘͔̮͠͝{̰͈̲͚͖̹͍͉̬̝̠͓́͝
̙̯͕̰̪̕͡ ̢̱̱̰̖̬̯͔̗͍͚̖̠͈͜ͅͅ ̵̢̡̥̰̜̹̯̮͚͉̲̲̝̘͕̝̭̀͢p̵̢̧̯͙̗̘̦̥͉͉̟̺̕͠x̢̡̣̙͕͉̭͕̗͔̟͔̝̭̯̲̼͓͞4̴̫̫̳͠͝͠͡ͅ_̴̢̛̜͚͓̘͞c̸̕͢͝҉̼̞̖̻͉̻̘̦l̷̨̩̻͇̩͇̖̠̬͔̘̬͉͘͟ơ̷̶̴̭̖̠̺͔̥͔̙͉̼̞̦̘̣̻̕ć̻̣̹̫̣͚̦͙̺̭̞̪͔̖̣͎̬́͢ͅk̴̷̨̛͉̗̲̞̥͚̪̯̘̺̀ͅ_̖̤̭̟̥̣͖̩͙̙̰͕̰͉̦͕̕̕̕͡ͅg͢͞҉͍͉̪͇̦̱̮̼ḙ̶̤͍̰̼̟͓͘͢͡ͅt̷̼̜̭͈̼̥͍̺̻̯̗̜͙̺̹͚̕͜͜ţ̧̺̣̰̗̫̼̬͙̜i̸̴҉̛̗̯̳͕̩͚̱̺̗̫̣̘̪͕m̛̪̭̖̣͍̮̭̫̺̻̫̕͟e͞͏̡̞̞͕̞̙̩̩͍͙͔͖͕̙̭́ͅ(̜͈̲̟̻͇̀̕Ç̛̗̱͔͈̝͔̖̰̹͚͞͞͠L̟͈̤͕̦̘̪͜͢͢͞͡ͅO̼͇̦͙̦̳̻͔͘͢͞C̴̞͎̩̮̯̩̦̦͉͢͟K̴̗̫͚̪͎͈̺̟̠̘͎̰̹͚̬̠̺͞_̴͠͏̳͔̻͔̤̞͘M̡̠̯̞̘̹̟͎̫̟͚̱̺̗̝̪̫̕͡ͅͅO̧͏̶̴͔̩͇̫̙̦̫͎͚̯͘Ṋ̸̯̭̖̭͉͜Ơ̷̜̩̙̰̰̩͚̖͖̱͖̩̥̙ͅŢ̴̗̫̻̤͈͕̻̳̭̭͕̺̰̠͝ͅO̢̨̦̼̜̘̖̙̮͈̺̖̥̮̰͉͚̻N͙̼̳̜͘͜I̶̝̰̘̼͈̺̗͠C̵̢̘̥̮̰̪̩̺̕͢͠,͠͏̡̢̛̦̜̞̺̲̩̫̺͎̪͚̼̦̭̼͕̣ ̶̵̢͚̟̟̞̣̪̖̻̹̟ͅ&̷̦͍̮̘̟̲̝̪̗̫̀ͅt̛̖̻̘̮̹̜̮̩̣͔̬̝͍̀͠͝s̸̡͎̫͚̦̟͇̞̘͘͜͠)̸̷̢̰̝̰̟̞̯̟́ͅ;̷̹̮̱͉͓͚͔̰̟̺̲̲̰̼̫̕
̵̨̞͉̹͔̲̻͕̳̦͠ ̨͉̲̫͕͔̥̼͎̖̦̹̙̹̼̼ͅ ͡҉̧̧̲̖̟̮͖͖̹̥̣̤̹p̡̧͓̘̼̦͓͠x̧̛̝̲̦̲̖̫̰͉̖̩͔̫̞̺́͞͠ͅͅ4̷̹̝̣̥̰̱̻̭̫̺̩̦͍̜͇͇̟̣_̨͞͏̼̣̲̗̟͓̪̣̬̟̹̗̱͓t̵̵̤͕̝̝̯̺͍͖̲̬̬͓̻̤̬̀í̶̳̼̪̹͕͜ͅm͎̦̤̠̙͘͡͡e̶͍̻͓͍͕̙͓̥̫̞̜̙͢͝͠ͅs҉̢̪͔̖̻t̸̷̵̯̣̰͍͍͎̰̱͓̤̟͎̪͘ͅa҉̴̛́҉̲̱̟͎̮͓ŕ̦̹̩̼͙͡͡ţ̴̥̜͉͖̫̱̠̹͡͡ ̵҉͏͈͖̤͔͍̤̙̺͎̥̫̯͉̲̹̖̠͠=̨͔̘̭̥͔̻͖̘͔͕͙͈͘̕͟͞ ̴̨̩̺͓̻̯̘͈̞̻̮͈̣̻͍̕͝t̶̸̨̲͉͇̜̺̮̬̤̩̲̣̖̟̰̀ͅs̠͍͓͚͖̖̦̳̠̗͔̻̪̘̲̲̗̣͘͡_̵̡̹̭̝̣́͡t̶҉͙̳̤̺̱̳̬̲̤̳͓̙͙̣̯ò̢͎͚̬̠͍̖̜̹͍͍͓̫͖̰̟̯_̰̼̖̹͍̖̟̣̳̤͜͡ͅa͇̭̞͙̫͖͉͉̰̫̬͠b̛͞͏̵͓͚͚s҉̶̨̤͓̦̤t̶̛̝̜̳̯̝̟͈͓̻̖͈̭͔̠͉̳̥͈̝͞í̩͈͙̪̥̮͇̯̩͍̲͉̝ḿ̝̠̙͠ͅé͠͏̤̫̞͚͚(̶̶̠͚̗̼͟͞&̷̱̭͎̤̳̻̫̟̭͔̬̦̝̀͢ͅt͏̵̵̧̜̩͉̫̼͚͖̲̦͍̺͇͝ş̷̛͓̬̦̩̫̠̭̥̟̼̩̮͠͝)̧͏̡͇͓͍̫̱̤̣̞̞̠͠͞;̗͙̤̦̘͔̞̱̥̼̼͈̹͍̥̫́͘
͓̬̥͕̮̫̝̰̯̪͎́̕͞ ͓̮̩̞̣̹͔̀̕}͔̠͔̩͟͡͠ͅ
͕̖̙̺̟̤̲̗̹͉͔̻́̀ͅI̧҉͔̜͎͎̼̮̱͈̯̳͉̦͔̩̤́͘ͅM̢͏̠͇̦͎̯̣͖̝̟̼̘̱̘̗̮͚͉̖̕ ̷̪̹͙̼̕͟͡D̶҉҉̠̼̮̤̥̗͓̺̟͓̮̳͍̮̞̗̫ͅO̵͏҉̢̹͉̞̭̩̲͖͔̩͈̩̣͚̘̺̗̱̀N̴̦̺̟͓̳͇̪͖̰̬͔̰͙͞È̮̟͓͉͚̰͖͕̙̼̗͇͖̭̭͕̝̫̕͟͡
̯̰͓̹̰̩̩̬̀̕ ̶̡̳͓͈̻͉͙̦̝̬̲͉̯̣͚̫͠ṕ͓̲͙̤̦̤͈͕͈̺̬͉̱͈̮x҉̸̣̹̲̭͈̜͙̭͙̳̠͈̺̙̖̪͉̺͜ͅ4̧̝̳̫͚̹̫̜͡_̶̬̟̬̹͉̩͈͔̻̳̩͍̱͓̺͇c̨̛̜̲̪͉̪̀͠͠ͅļ̨̪͕͕̣̮̞͖̼͙̪̤͓͈̱̺͖̺̳͢o̴̯̜̬̣̭̦̦̺̕͢c̕҉̪̝͍̯̳̮̩͔̺̞̹͕̳̲k̶̸̼̲̰̱͖̫̣̦̬͍̗_̣̲͔̘̲͘͜g͞͏̢͕͚̟͔̬̰̮̘̜̦̼͇̹̟̜͈̫̪͢͟e̶̢̧̯͖͖̦̯̦̳͇̳͟͝t̸͎͖͍̟̫̰͇̜̟́t̵̷͢͏͖͍̳͓̙͈͉̺͓̙̺͚̩̭̭i̶̴̧̹͍̭̥͓̬͍̰͕̬̰͉̻̦͜ḿ̷̶̶͎̠̦̠̫͎̱̩̖͔̣̼͠e̶̸̸̟̲͍̝͈̬̣̝̞̪̞̹̗͉͖̤̗͈͢͟ͅ(̡̘̦̩͙͇͎̹̥̮͖̩̹̮̳̙̥͕͈̀̕̕C̸̢̛͖̥̱Ļ̧͈̫̻͕̤̩̪̠̥̠̯͇͙͕̘̳̭Ǫ̴͏̟̰̣̬̻̣̻̘͎C̀͞҉͏̗̜̱Ḳ̛̣̪̠̼̖̦͇̪̺͖̩͓̮̭͕͉͈͟͜_̷̠̲̯̩̺̯̖̣͚͚̕M̞͕̖̯̩̯͙͔͈̘͕͎͇͠͡͝͞Ò̶̞͍͈͉̤͙̠̣̩̥̺̟͘͟ͅN͔̹͚̹̕͜Ó̮͉̘̤͕͓̝͕̻͢Ţ̹̹͈̹̝͕̰̝̹̮̻̬̮̮̣̞O̶̡҉̥͚̻͉̰̩͈̰̫̩̹ͅN͝͏̴̙̣̙̠̗͙̺̰͉͇̩̙̰͎̮͈͡͝ͅĮ̨̧̫̹̮̲͢C̨҉̭͖̤̱͓̜̜͚̖̘͈̜͠͞,̴̤̤̼̺̮̩͉͉̪͖̞̭͠ ̨̧̦̹̝͉̙̣͘&́́͜͏̨͉͍̫t̶͓͖̬͍̰̰̼̻̣̬̱̞͔̫͘͟ͅs̶̨̫̦͚͚̺̰͇̬̭͈͝)͝͏̫̫̻̠;̶̘͓̘̯̯̗̯̪̺̤̩͔͇̕
̷̵͚̼̠̠̭ ̛͚̱͓͖̬̖̱͚̯̫͕̣͍̰̪̹̘̜̙͢r̢̨͍̣̱̱̥͝ȩ̨̩̬͕̞̹́͝͝ͅt̵͏̷̢͍͔͔̙̤͙̖͙̞͖̟̪̥͡ų̷̸̜͇͍̥̟̜͕̤̬̣̀͢ṟ̵̛̣͉͓̦̮̭̫͚̣̭̦̯̞ͅn҉͕̝̗̣͙͕̳̱̭̘́́͘ ̻̞̼̝͇͖̩̦̩̮̳͘͝t̛̳͍̺̖̯̮̞̳̺̺̯̬͎̰ͅs̵̛͙͕̠̣̰͖̘̣̰͍_̡̛̩̻̦̯̰̰̫̜̤͎̯̲̭̮͟t̷̵̢͉̬͖̲̥̤̹̥͕̩̳̥̀ͅó̴̴̸̗̣̳̘̜̪̯͜_̵̧̖͕̣̠̱̦̫̝̺̲̜͍̳̬̺̩͎͟͝a̸̧̧̼̻̺̘̲ͅb̵̪̪̫͇̀s̶͏҉̶̣̭̮̪t̶͟҉̦͈̦̯̟̣̀́ͅì͟͟҉̸̭̲͉̝̖̭̬̜̹̹m̴҉͉͉̱̪͈̦̭̺͕ḛ̵̺̩̻̭͙̭͘͢͡(͠͏̵̛̮̱̖̱̝̪̱&̴̘̲̳͉̱͚͎̬̖̮̀͟͜͝ţ̼͈͕̱s̵̵̻͎̞̱̼͍͢͟ͅͅ)̕͟͢҉̶͎͍͔̮̻͍̖ ̧̛͔̭̣̻̖͇̕͝-̷̱͇̜̲̫͓͍̜͟͝ ̷̵̫̻̬͙͈̝̤̺̖̜͈̱͇̞p̶̝̬̗̰̻̩̻̖͚̙͕͖̪͕̯̰͚͜͡x̸̛͇̹͈͍̕4̵̢̣͙̥̝̦͎̺̘͙̙͕̼͚̕ͅ_̶̵̧̻͉̰̟̹t̷̵̲͍̹̮͖̺̣̼̤̖̯͎̲̹͎̼̗i̛̪̬͎͕͎͕͚̲͍͘͜͟͡m̷̴̝̘̦͇̰͉̦̖̼̼͠e͞҉͙̥͍s͞҉̷̛̫͓̮̙̳͕͍͙̦̥̹̩͔̖̩ţ̜̹͎̩̪͕̤̰̗̗͜͞ą̸̛̺̥̠̹̙̭͙͙̝̖̘͇̀͘ŕ̴̢̖͔̣̩͇̜̦̩̭̜͉̫̳̫̗̤̕͠t̺̞͚̩͕͉͉̙͔̼̤̘͖͍͓͢͞;̨̧̠͍̭̺͓̠̩̰̭̺͓̹
̸̶͏҉̦͎̙̥̼͎͇̤͎̮̩̜̘͇̮̫#̵̸̵̴̹̼̲̳̣̻͎͚͇̯͕̖̙e͡҉̨̡̛̹͙͎̮ǹ̴̹̺̪̜̳̝̞͚̯͙͕͜d̶̶̛̛̬̣̹͎̲̘̲͍͕̗̻̩̼̠͡i̬̞̣̻͇͈̪͍̣͈̬̩̠̘͔̗͍͚̞͡f͕̺̠̕̕͡ ̷̠̣̙̳̖̮͖̜̲͇̫͙͚͚͈͟͜͜T̴̷̶̷̯̥̬́H̶̛̛̜͈̱̰̼̯̜͓͕̟̱̩̞͇̀į̴̶̖̯̥͕͔̖͓̱̲͎͓̰̣͍̣s̵̡̪̩̮̙̰̰͈̦͎̹͔̼̼̣̮͜͡ ̛͖͎̦̯̜̮̻̙̀́i̴͖̝̙͙͙̺͝Ş̶̯̰̭͙̫̖͈̟͚̣͢͢͝ͅ ̷̵҉͓̗͉̘̭̥͕̣͓̲̦̻͎̪̙̀T̶̤̖̫̝͍̺̳͇̞̖͎͇͕̩̥̀̀͘͘Ḩ͙͉̗͈̟̘̫E̢̨͖̖͙͍ ̛̪̥̻̲̘͇̥͞E̶̜͇̞̟̺̗N̛̖̘̬̰͉̼̟̫̠͠D̡̢̡̛̛̬͙͈͈̭̼̯͈̻͚̬̪̙ͅ
h̶̕el̵̸p̀͏͜