Skip to content

sender/receiver based on MavlinkDirect working too slow #2685

@pedramsafi

Description

@pedramsafi

I have created a sender/receiver pair to exchange custom mavlink messages over SiK Radio.

ideally, I would like to minimize the amount of data being sent over the link and keep it as minimal as possible to conserve bandwidth.

Below is an example of each of the sender and receiver modules:

Sender

int main(argc, char* argv[])
{

    uint8_t drone_system_id = 2;
    uint8_t drone_component_id = 1;
    bool always_send_heartbeat = true;

    Mavsdk::Configuration config = Mavsdk::Configuration(drone_system_id, drone_component_id, always_send_heartbeat);
    Mavsdk mavsdk_drone{config};
    std::shared_ptr<mavsdk::System> peer_system_;

    //connect to the local serial radio and obtain the peer_system_
    auto mavlink_direct = MavlinkDirect{peer_system_};

    //define and load custom_xml

    //create an instance of the message
    MavlinkDirect::MavlinkMessage msg_name{};

    while(1){
        msg_name.fields_json = R"({...});
        auto result = mavlink_direct.send_message(msg_name);
    }

    std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // 1Hz
    return 0;

}

Receiver

int main(argc, char* argv[])
{
    uint8_t gcs_system_id = 250;
    uint8_t gcs_component_id = 1;
    bool always_send_heartbeat = true;

    Mavsdk::Configuration config = Mavsdk::Configuration(gcs_system_id, gcs_component_id, always_send_heartbeat);
    Mavsdk mavsdk_drone{config};
    std::shared_ptr<mavsdk::System> peer_system_;

    //connect to the local serial radio and obtain the peer_system_
    auto mavlink_direct = MavlinkDirect{peer_system_};

    //define and load custom_xml

    //create an instance of the message
    MavlinkDirect::MavlinkMessage msg_name{};

    auto result = mavlink_direct.subscribe_message("msg_name", [](const mavsdk::MavlinkDirect::MavlinkMessage &message){
        std::cout << message.message_name << " was received!" <<  std::endl;
    });

    while(1){
         std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // 1Hz
    }
return 0;

}

The problem is the receiver is not receiving all the messages. It is dropping some. Here is a sample of the output log. the lat/lon alt values are dummy values and show "the number of seconds since start".

Listening for GPS messages. Press Ctrl+C to exit...
[12:42:07|Info ] heartbeats timed out (system_impl.cpp:370)
{"message_id":42000,"message_name":"END_TELEMETRY","altitude":13,"latitude":13,"longitude":13}
{"message_id":42000,"message_name":"END_TELEMETRY","altitude":18,"latitude":18,"longitude":18}
{"message_id":42000,"message_name":"END_TELEMETRY","altitude":19,"latitude":19,"longitude":19}
{"message_id":42000,"message_name":"END_TELEMETRY","altitude":24,"latitude":24,"longitude":24}
{"message_id":42000,"message_name":"END_TELEMETRY","altitude":25,"latitude":25,"longitude":25}
[12:42:23|Debug] Discovered 1 component(s) (system_impl.cpp:607)
[12:42:27|Info ] heartbeats timed out (system_impl.cpp:370)
{"message_id":42000,"message_name":"END_TELEMETRY","altitude":39,"latitude":39,"longitude":39}
[12:42:40|Debug] Discovered 1 component(s) (system_impl.cpp:607)
{"message_id":42000,"message_name":"END_TELEMETRY","altitude":47,"latitude":47,"longitude":47}
[12:42:43|Info ] heartbeats timed out (system_impl.cpp:370)
[12:42:44|Debug] Discovered 1 component(s) (system_impl.cpp:607)
[12:42:47|Info ] heartbeats timed out (system_impl.cpp:370)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions