Mavlink messages to qgc

Hi, a question about qgroundcontrol: I’m sending mavlink debug messages from px4 to qgc and i can see them in the MavLink Inspector, If i want for instance to print the debug msg payload on the Flight map, how can i do it? Maybe somebody can provide a simple example? According to the manual: all MAVLink messages are routed to Vehicle’s which are associated with the link by MAVLinkProtocol . So what object in Vehicle.h is handling the incommoding messages? Or maybe it is done elsewhere?

Hi,

Create a class (YourCustomClass) with an activeVehicle property :
Vehicle* activeVehicle;

And a slot to read messages :
.h

public slots:
  void readMavlinkMessage(const mavlink_message_t& message);  

.cpp

void YourCustomClass::readMavlinkMessage(const mavlink_message_t& message){
    if(message.msgid == MAVLINK_MSG_ID_DEBUG){
        uint8_t ind = mavlink_msg_debug_get_ind(&message);
        qCDebug() << "Debug message index: " << ind;
    }
}

Connect the message received signal to the read slot :
QObject::connect(activeVehicle, SIGNAL(mavlinkMessageReceived(const mavlink_message_t&)), this, SLOT(readMavlinkMessage(const mavlink_message_t&)));

Add an instance of your custom class in CustomPlugin.h/.cc, and then from qml (for instance in CustomFlyView.qml) :

    Connections{
        target: QGroundControl.multiVehicleManager
        onActiveVehicleChanged: {
            QGroundControl.corePlugin.YourCustomInstance.activeVehicle = QGroundControl.multiVehicleManager.activeVehicle
        }
    }

Tom

I have the same problem : thanks for these precious informations Tom ! I make it right !

I would like to speak with you a little about our project. There are others functionalities we need and you are surely the good person to ask for.

Mickaël.

Nethertheless, I lost something. In my case, I want to catch a specific mavlink message, got data and printed it in my modified FlyViewCustomLayer.qml as it said here : custom_build/FlyView.html
Nothing happens because I don’t know how to “add an instance of your custom class in CustomPlugin.h/.cc” because I’m not using the “custom-example” example, and I don’t have those classes…
Where can I put my instance to make it working with my version of QGC ?

Thanks a lot !

This way worked out for me to get debug messages on qgc view:

  1. Create debug variable in Vehicle.h class:

mavlink_debug_t debug_msg;

2. Crate Q_Property

private:
         mavlink_debug_t debug_msg;
public:
         Q_PROPERTY( int debug_ind  READ debug_ind    NOTIFY debug_ind_Changed)
         int debug_ind () { return debug_msg.ind; }

         Q_PROPERTY( float debug_value  READ debug_value  NOTIFY debug_value_Changed)
         float debug_value () { return debug_msg.value; }
signals:
         void debug_ind_Changed (int debug_ind);
         void debug_value_Changed (float debug_value );

3. Add message to mavlink message handler in Vehicle.c

switch (message.msgid) {
........
    /*My code*/
    case MAVLINK_MSG_ID_DEBUG:
        mavlink_msg_debug_decode(&message, &debug_msg);
        emit debug_ind_Changed(debug_msg.ind);
        emit debug_value_Changed(debug_msg.value);
        break;
        
  }

4.In qml file create label that shows the values

P.S. TomRvr thanks a lot for your reply!

1 Like