Skip to content

Commit

Permalink
Autotune enabled in QGC.
Browse files Browse the repository at this point in the history
  • Loading branch information
batinkov committed Oct 19, 2021
1 parent b0c5423 commit a30b412
Show file tree
Hide file tree
Showing 14 changed files with 452 additions and 46 deletions.
1 change: 1 addition & 0 deletions custom-example/qgroundcontrol.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
<file alias="QGroundControl/Controls/PreFlightCheckGroup.qml">../src/QmlControls/PreFlightCheckGroup.qml</file>
<file alias="QGroundControl/Controls/PreFlightCheckModel.qml">../src/QmlControls/PreFlightCheckModel.qml</file>
<file alias="QGroundControl/Controls/QGCButton.qml">../src/QmlControls/QGCButton.qml</file>
<file alias="QGroundControl/Controls/AutotuneUI.qml">../src/QmlControls/AutotuneUI.qml</file>
<file alias="QGroundControl/Controls/QGCCheckBox.qml">../src/QmlControls/QGCCheckBox.qml</file>
<file alias="QGroundControl/Controls/QGCColoredImage.qml">../src/QmlControls/QGCColoredImage.qml</file>
<file alias="QGroundControl/Controls/QGCControlDebug.qml">../src/QmlControls/QGCControlDebug.qml</file>
Expand Down
2 changes: 2 additions & 0 deletions qgroundcontrol.pro
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ DebugBuild { PX4FirmwarePlugin { PX4FirmwarePluginFactory { APMFirmwarePlugin {
src/qgcunittest/MultiSignalSpy.h \
src/qgcunittest/MultiSignalSpyV2.h \
src/qgcunittest/UnitTest.h \
src/Vehicle/Autotune.h \
src/Vehicle/FTPManagerTest.h \
src/Vehicle/InitialConnectTest.h \
src/Vehicle/RequestMessageTest.h \
Expand Down Expand Up @@ -547,6 +548,7 @@ DebugBuild { PX4FirmwarePlugin { PX4FirmwarePluginFactory { APMFirmwarePlugin {
src/qgcunittest/MultiSignalSpyV2.cc \
src/qgcunittest/UnitTest.cc \
src/qgcunittest/UnitTestList.cc \
src/Vehicle/Autotune.cpp \
src/Vehicle/FTPManagerTest.cc \
src/Vehicle/InitialConnectTest.cc \
src/Vehicle/RequestMessageTest.cc \
Expand Down
1 change: 1 addition & 0 deletions qgroundcontrol.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<file alias="QGroundControl/Controls/PreFlightCheckGroup.qml">src/QmlControls/PreFlightCheckGroup.qml</file>
<file alias="QGroundControl/Controls/PreFlightCheckModel.qml">src/QmlControls/PreFlightCheckModel.qml</file>
<file alias="QGroundControl/Controls/QGCButton.qml">src/QmlControls/QGCButton.qml</file>
<file alias="QGroundControl/Controls/AutotuneUI.qml">src/QmlControls/AutotuneUI.qml</file>
<file alias="QGroundControl/Controls/QGCCheckBox.qml">src/QmlControls/QGCCheckBox.qml</file>
<file alias="QGroundControl/Controls/QGCColoredImage.qml">src/QmlControls/QGCColoredImage.qml</file>
<file alias="QGroundControl/Controls/QGCControlDebug.qml">src/QmlControls/QGCControlDebug.qml</file>
Expand Down
6 changes: 6 additions & 0 deletions src/FirmwarePlugin/FirmwarePlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "QGCFileDownload.h"
#include "QGCCameraManager.h"
#include "RadioComponentController.h"
#include "Autotune.h"

#include <QRegularExpression>
#include <QDebug>
Expand Down Expand Up @@ -1109,3 +1110,8 @@ void FirmwarePlugin::sendGCSMotionReport(Vehicle* vehicle, FollowMe::GCSMotionRe
vehicle->sendMessageOnLinkThreadSafe(sharedLink.get(), message);
}
}

Autotune* FirmwarePlugin::createAutotune(Vehicle *vehicle)
{
return new Autotune(vehicle);
}
4 changes: 4 additions & 0 deletions src/FirmwarePlugin/FirmwarePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
class Vehicle;
class QGCCameraControl;
class QGCCameraManager;
class Autotune;

/// This is the base class for Firmware specific plugins
///
Expand Down Expand Up @@ -333,6 +334,9 @@ class FirmwarePlugin : public QObject
// gets hobbs meter from autopilot. This should be reimplmeented for each firmware
virtual QString getHobbsMeter(Vehicle* vehicle) { Q_UNUSED(vehicle); return "Not Supported"; }

/// Creates Autotune object.
virtual Autotune* createAutotune(Vehicle *vehicle);

signals:
void toolIndicatorsChanged(void);
void modeIndicatorsChanged(void);
Expand Down
4 changes: 3 additions & 1 deletion src/QGCApplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
#include "ToolStripActionList.h"
#include "QGCMAVLink.h"
#include "VehicleLinkManager.h"
#include "Autotune.h"

#if defined(QGC_ENABLE_PAIRING)
#include "PairingManager.h"
Expand Down Expand Up @@ -523,14 +524,15 @@ void QGCApplication::_initCommon()
qmlRegisterUncreatableType<QGCVideoStreamInfo> (kQGCVehicle, 1, 0, "QGCVideoStreamInfo", kRefOnly);
qmlRegisterUncreatableType<LinkInterface> (kQGCVehicle, 1, 0, "LinkInterface", kRefOnly);
qmlRegisterUncreatableType<VehicleLinkManager> (kQGCVehicle, 1, 0, "VehicleLinkManager", kRefOnly);
qmlRegisterUncreatableType<Autotune> (kQGCVehicle, 1, 0, "Autotune", kRefOnly);

qmlRegisterUncreatableType<MissionController> (kQGCControllers, 1, 0, "MissionController", kRefOnly);
qmlRegisterUncreatableType<GeoFenceController> (kQGCControllers, 1, 0, "GeoFenceController", kRefOnly);
qmlRegisterUncreatableType<RallyPointController> (kQGCControllers, 1, 0, "RallyPointController", kRefOnly);

qmlRegisterUncreatableType<MissionItem> (kQGroundControl, 1, 0, "MissionItem", kRefOnly);
qmlRegisterUncreatableType<VisualMissionItem> (kQGroundControl, 1, 0, "VisualMissionItem", kRefOnly);
qmlRegisterUncreatableType<FlightPathSegment> (kQGroundControl, 1, 0, "FlightPathSegment", kRefOnly);
qmlRegisterUncreatableType<FlightPathSegment> (kQGroundControl, 1, 0, "FlightPathSegment", kRefOnly);
qmlRegisterUncreatableType<QmlObjectListModel> (kQGroundControl, 1, 0, "QmlObjectListModel", kRefOnly);
qmlRegisterUncreatableType<MissionCommandTree> (kQGroundControl, 1, 0, "MissionCommandTree", kRefOnly);
qmlRegisterUncreatableType<CameraCalc> (kQGroundControl, 1, 0, "CameraCalc", kRefOnly);
Expand Down
106 changes: 106 additions & 0 deletions src/QmlControls/AutotuneUI.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/****************************************************************************
*
* (c) 2009-2021 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Dialogs 1.2

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

Item {
id: _root

property var _autotune: globals.activeVehicle.autotune
property real _margins: ScreenTools.defaultFontPixelHeight

readonly property string dialogTitle: qsTr("Autotune")

QGCPalette {
id: palette
colorGroupEnabled: enabled
}

Component {
id: autotuneConfirmationDialogComponent
QGCViewMessage {
message: qsTr("WARNING!\
\n\nThe auto-tuning procedure should be executed with caution and requires the vehicle to fly stable enough before \
attempting the procedure!\n\nBefore starting the auto-tuning process, make sure that: \
\n1. You have read the auto-tuning guide and have followed the preliminary steps \
\n2. The current control gains are good enough to stabilize the drone in presence of medium disturbances \
\n3. You are ready to abort the auto-tuning sequence by moving the RC sticks, if anything unexpected happens. \
\n\nClick Ok to start the auto-tuning process.\n")

function accept() {
hideDialog()
_autotune.autotuneRequest()
}
}
}

Rectangle {
width: _root.width
height: statusColumn.height + (2 * _margins)
color: palette.windowShade
enabled: _autotune.autotuneEnabled

QGCButton {
id: autotuneButton
primary: true
text: dialogTitle
enabled: !_autotune.autotuneInProgress
anchors {
left: parent.left
leftMargin: _margins
verticalCenter: parent.verticalCenter
}

onClicked: {
mainWindow.showComponentDialog(autotuneConfirmationDialogComponent,
dialogTitle,
mainWindow.showDialogDefaultWidth,
StandardButton.Ok | StandardButton.Cancel)
}
}

Column {
id: statusColumn
spacing: _margins
anchors {
left: autotuneButton.right
right: parent.right
leftMargin: _margins
rightMargin: _margins
verticalCenter: parent.verticalCenter
}

QGCLabel {
text: _autotune.autotuneStatus

anchors {
left: parent.left
}
}

ProgressBar {
value: _autotune.autotuneProgress

anchors {
left: parent.left
right: parent.right
}
}
}
}
}
1 change: 1 addition & 0 deletions src/QmlControls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ add_custom_target(QmlControlsQml
PreFlightCheckList.qml
PreFlightCheckModel.qml
QGCButton.qml
AutotuneUI.qml
QGCCheckBox.qml
QGCColoredImage.qml
QGCComboBox.qml
Expand Down
124 changes: 79 additions & 45 deletions src/QmlControls/PIDTuning.qml
Original file line number Diff line number Diff line change
Expand Up @@ -177,77 +177,111 @@ RowLayout {
Layout.minimumWidth: contentWidth
Layout.maximumWidth: contentWidth
Layout.alignment: Qt.AlignTop

Column {
spacing: _margins
Layout.alignment: Qt.AlignTop

width: parent.width
id: rightColumn

Row {
spacing: _margins

Switch {
id: autotuningEnabled
checked: true
}

QGCLabel {
color: qgcPal.text
text: autotuningEnabled.checked ? qsTr("Autotune enabled") : qsTr("Autotune disabled")
}
}

Column {
width: parent.width
visible: autotuningEnabled.checked

RowLayout {
spacing: _margins
visible: axis.length > 1
AutotuneUI {
anchors {
top: parent.top
topMargin: _margins * 2
}

QGCLabel { text: qsTr("Select Tuning:") }
width: parent.width
}
}

Repeater {
model: axis
QGCRadioButton {
text: modelData.name
checked: index == _currentAxis
onClicked: _currentAxis = index
Column {
width: parent.width
visible: !autotuningEnabled.checked

Column {
RowLayout {
spacing: _margins
visible: axis.length > 1

QGCLabel { text: qsTr("Select Tuning:") }

Repeater {
model: axis
QGCRadioButton {
text: modelData.name
checked: index == _currentAxis
onClicked: _currentAxis = index
}
}
}
}
}

// Instantiate all sliders (instead of switching the model), so that
// values are not changed unexpectedly if they do not match with a tick
// value
Repeater {
model: axis
FactSliderPanel {
width: parent.width
visible: _currentAxis === index
sliderModel: axis[index].params
// Instantiate all sliders (instead of switching the model), so that
// values are not changed unexpectedly if they do not match with a tick
// value
Repeater {
model: axis
FactSliderPanel {
width: parent.width
visible: _currentAxis === index
sliderModel: axis[index].params
}
}
}

Column {
QGCLabel { text: qsTr("Clipboard Values:") }
Column {
QGCLabel { text: qsTr("Clipboard Values:") }

GridLayout {
rows: savedRepeater.model.length
flow: GridLayout.TopToBottom
rowSpacing: 0
columnSpacing: _margins
GridLayout {
rows: savedRepeater.model.length
flow: GridLayout.TopToBottom
rowSpacing: 0
columnSpacing: _margins

Repeater {
model: axis[_currentAxis].params
Repeater {
model: axis[_currentAxis].params

QGCLabel { text: param }
}
QGCLabel { text: param }
}

Repeater {
id: savedRepeater
Repeater {
id: savedRepeater

QGCLabel { text: modelData }
QGCLabel { text: modelData }
}
}
}
}

RowLayout {
spacing: _margins
RowLayout {
spacing: _margins

QGCButton {
text: qsTr("Save To Clipboard")
onClicked: saveTuningParamValues()
}
QGCButton {
text: qsTr("Save To Clipboard")
onClicked: saveTuningParamValues()
}

QGCButton {
text: qsTr("Restore From Clipboard")
onClicked: resetToSavedTuningParamValues()
QGCButton {
text: qsTr("Restore From Clipboard")
onClicked: resetToSavedTuningParamValues()
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/QmlControls/QGroundControl/Controls/qmldir
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ PreFlightCheckButton 1.0 PreFlightCheckButton.qml
PreFlightCheckGroup 1.0 PreFlightCheckGroup.qml
PreFlightCheckModel 1.0 PreFlightCheckModel.qml
QGCButton 1.0 QGCButton.qml
AutotuneUI 1.0 AutotuneUI.qml
QGCCheckBox 1.0 QGCCheckBox.qml
QGCColoredImage 1.0 QGCColoredImage.qml
QGCComboBox 1.0 QGCComboBox.qml
Expand Down
Loading

0 comments on commit a30b412

Please sign in to comment.