How to call sendCommand from qml

Hi,

So I am trying to modify QGC on my Herelink to have some on screen buttons to control a Flir Duo Pro R camera, because I don’t have enough hardware buttons.
I have managed to create the UI as widget, but am stuck on how to send a Mavlink command to the vehicle. Here is what I have so far:

import QtQuick 2.4
import QtPositioning 5.2
import QtQuick.Layouts 1.2
import QtQuick.Controls 1.4
import QtQuick.Dialogs 1.2
import QtGraphicalEffects 1.0

import QGroundControl 1.0
import QGroundControl.ScreenTools 1.0
import QGroundControl.Controls 1.0
import QGroundControl.Palette 1.0
import QGroundControl.Vehicle 1.0
import QGroundControl.Controllers 1.0
import QGroundControl.FactSystem 1.0
import QGroundControl.FactControls 1.0

/// Flir page for controlling a Duo Pro R
Column {
    width: pageWidth
    spacing: ScreenTools.defaultFontPixelHeight * 0.25
   
    property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle

    GridLayout {
        columns: 2
        columnSpacing: ScreenTools.defaultFontPixelWidth * 2
        rowSpacing: ScreenTools.defaultFontPixelHeight
        anchors.horizontalCenter: parent.horizontalCenter

        QGCLabel {
            text: qsTr("Camera Mode")
        }
        QGCComboBox {
            model: ["IR", "RGB", "PIP"]
            onActivated: {

                //move servo via MAVLINK
            }
        }

        QGCLabel {
            text: qsTr("Photo/Video")
        }
        QGCSwitch {
            id: videoMode
            onCheckedChanged: {
                if (checked) {

                    //move servo
                } else {

                    //move servo the other way
                }
            }
        }

        QGCLabel {
            text: qsTr("REC")
        }
        QGCButton {
            text: "Test"
            onClicked: QGroundControl.vehicle.sendCommand(_activeVehicle,   //Component to send to
                                                          183,              //MAV_CMD to send 183:MAV_CMD_DO_SET_SERVO
                                                          true,             //showError
                                                          11,               //servo instance
                                                          1500)             //servo value in us
        }
    }
}

How can I send a mavlink command to the current active vehicle from qml? I found the function “Q_INVOKABLE void sendCommand(…)” in Vehicle.h but don’t know how to call it. I get the error “TypeError: Cannot call method ‘sendCommand’ of undefined” in the QGC console. Can anyone help me out?

@AltitudeDavid,
You need to call sendCommand method on _activeVehicle variable.

onClicked:
    _activeVehicle.sendCommand(...)
1 Like

Thanks, works perfectly!