MavlinkPassthrough.subscribe_message_async(...) , how to use it?

Hello there,

I have a custom message that I wish to send from a script on the ground station computer to an onboard computer (a Raspberry Pi) on the UAV. I’ve followed the steps to create the custom message and seem to have no issue with sending it using MavlinkPassthrough.send_message(…) as the result of this is a ‘Success’ as defined in the results enum.

My issue is on how to implement the subscribe_message_async(…) to receive the message. I assume this is the publish-subscribe pattern of sending mavlink messages. My problem probably stems from me never encountering the ‘std::function< >’ before. I’ll copy-paste the relevant parts of my code in the following section. Note that I have no errors and the code runs. This was tested in the px4_sitl gazebo_plane simulation.


void receive_waypoint_type(MavlinkPassthrough &mavlink_passthrough)

std::function<void(const mavlink_message_t &)> m_callback;

m_callback = [](const mavlink_message_t &msg_raw)
    const mavlink_message_t* msg = &msg_raw;
    int waypoint_index = mavlink_msg_waypoint_info_get_waypoint_index(msg);
    std::cout << NORMAL_CONSOLE_TEXT << "the waypoint index is: " << waypoint_index << std::endl;

    int category_num = mavlink_msg_waypoint_info_get_category(msg);
    std::cout << NORMAL_CONSOLE_TEXT << "the category number is:  " << category_num << std::endl;

    int length_of_items_num = mavlink_msg_waypoint_info_get_total_length_of_index(msg);
    std::cout << NORMAL_CONSOLE_TEXT << "the of items sent is: " << length_of_items_num << std::endl;

mavlink_passthrough.subscribe_message_async(302, m_callback);



auto mavlink_passthrough = MavlinkPassthrough{system};

In this same main I send out the custom message using MavlinkPassthrough.send_message(…). My issue is that the code terminates, which surprises me as I assumed subscribe_message_async would just continue.
An extra question, this is the best way to send and receive a messages using MAVSDK? I would prefer to do point-to-point communication but I can’t see how to do this with MAVSDK?


Did you solve your problem? I also have the same case…

Software development companies usually design for example, develop, and maintain mobile applications, web applications or other software modules for consumers or businesses. In addition to designing and developing modules, these companies also help maintain and support the modules once they are complete. This includes everything from the initial development to the final manifestation of your software innovation, from the development of the modules themselves to their continued maintenance, usability testing, bug-fixes, and integration with the rest of your system, to marketing and community strategies. Some development companies to work exclusively with an agency to provide their mobile applications and /or web applications for mobile websites, while others work through independent development shops.

I got a bit further but remained unsuccessful. I could pass-through pre-existing messages such as the battery level. By pre-exsisting I mean they are by default published on mavlink and are visible from Qground control. I could not however pass-through my custom message.