From 0378568d2b736bbc1c1a6b3678dd79c72b763453 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 1 May 2019 11:34:43 -0700 Subject: [PATCH 1/2] Add support for tuning on/off live updating --- src/FactSystem/FactGroup.cc | 19 ++++++++++++++++++- src/FactSystem/FactGroup.h | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/FactSystem/FactGroup.cc b/src/FactSystem/FactGroup.cc index c67c02d..55aedaf 100644 --- a/src/FactSystem/FactGroup.cc +++ b/src/FactSystem/FactGroup.cc @@ -46,7 +46,8 @@ void FactGroup::_setupTimer() if (_updateRateMSecs > 0) { connect(&_updateTimer, &QTimer::timeout, this, &FactGroup::_updateAllValues); _updateTimer.setSingleShot(false); - _updateTimer.start(_updateRateMSecs); + _updateTimer.setInterval(_updateRateMSecs); + _updateTimer.start(); } } @@ -125,3 +126,19 @@ void FactGroup::_updateAllValues(void) fact->sendDeferredValueChangedSignal(); } } + +void FactGroup::setLiveUpdates(bool liveUpdates) +{ + if (_updateTimer.interval() == 0) { + return; + } + + if (liveUpdates) { + _updateTimer.stop(); + } else { + _updateTimer.start(); + } + for(Fact* fact: _nameToFactMap) { + fact->setSendValueChangedSignals(liveUpdates); + } +} diff --git a/src/FactSystem/FactGroup.h b/src/FactSystem/FactGroup.h index 78a97fc..9e8320f 100644 --- a/src/FactSystem/FactGroup.h +++ b/src/FactSystem/FactGroup.h @@ -38,6 +38,9 @@ public: /// @return FactGroup for specified name, NULL if not found Q_INVOKABLE FactGroup* getFactGroup(const QString& name); + /// Turning on live updates will allow value changes to flow through as they are received. + Q_INVOKABLE void setLiveUpdates(bool liveUpdates); + QStringList factNames(void) const { return _factNames; } QStringList factGroupNames(void) const { return _nameToFactGroupMap.keys(); } From 14b8979b90e660899f55e0801ad995c0fd6d4091 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 1 May 2019 11:35:11 -0700 Subject: [PATCH 2/2] Turn on live updating for vehicle facts used in PID charts --- src/QmlControls/PIDTuning.qml | 58 ++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/src/QmlControls/PIDTuning.qml b/src/QmlControls/PIDTuning.qml index 20f74c8..b691a06 100644 --- a/src/QmlControls/PIDTuning.qml +++ b/src/QmlControls/PIDTuning.qml @@ -142,9 +142,17 @@ RowLayout { } Component.onCompleted: { + // Stop deferring updates to vehicle values. We need them as fast as we can for charting. + _activeVehicle.setLiveUpdates(true) + _activeVehicle.setpoint.setLiveUpdates(true) saveTuningParamValues() } + Component.onDestruction: { + _activeVehicle.setLiveUpdates(false) + _activeVehicle.setpoint.setLiveUpdates(true) + } + on_CurrentTuneTypeChanged: { saveTuningParamValues() resetGraphs() @@ -159,7 +167,8 @@ RowLayout { min: 0 max: 0 labelFormat: "%d" - titleText: "sec" + titleText: "msec" + tickCount: 11 } ValueAxis { @@ -167,7 +176,8 @@ RowLayout { min: 0 max: 0 labelFormat: "%d" - titleText: "sec" + titleText: "msec" + tickCount: 11 } ValueAxis { @@ -192,41 +202,37 @@ RowLayout { running: false repeat: true + function startOrStop() { + if (dataTimer.running) { + dataTimer.stop() + } else { + dataTimer.start() + } + } + onTriggered: { - var seconds = _msecs / 1000 - _valueXAxis.max = seconds - _valueRateXAxis.max = seconds + _valueXAxis.max = _msecs + _valueRateXAxis.max = _msecs getValues() - valueSeries.append(seconds, _value) + valueSeries.append(_msecs, _value) adjustYAxisMin(_valueYAxis, _value) adjustYAxisMax(_valueYAxis, _value) - valueSetpointSeries.append(seconds, _valueSetpoint) + valueSetpointSeries.append(_msecs, _valueSetpoint) adjustYAxisMin(_valueYAxis, _valueSetpoint) adjustYAxisMax(_valueYAxis, _valueSetpoint) - valueRateSeries.append(seconds, _valueRate) + valueRateSeries.append(_msecs, _valueRate) adjustYAxisMin(_valueRateYAxis, _valueRate) adjustYAxisMax(_valueRateYAxis, _valueRate) - valueRateSetpointSeries.append(seconds, _valueRateSetpoint) + valueRateSetpointSeries.append(_msecs, _valueRateSetpoint) adjustYAxisMin(_valueRateYAxis, _valueRateSetpoint) adjustYAxisMax(_valueRateYAxis, _valueRateSetpoint) _msecs += interval - /* - Testing with just start/stop for now. No time limit. - if (valueSeries.count > _maxPointCount) { - valueSeries.remove(0) - valueSetpointSeries.remove(0) - valueRateSeries.remove(0) - valueRateSetpointSeries.remove(0) - valueXAxis.min = valueSeries.at(0).x - valueRateXAxis.min = valueSeries.at(0).x - } - */ } property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle @@ -279,7 +285,10 @@ RowLayout { text: "-" onClicked: { var value = modelData.value - modelData.value -= value * adjustPercentModel.get(adjustPercentCombo.currentIndex).value + var newValue = value - (value * adjustPercentModel.get(adjustPercentCombo.currentIndex).value) + if (newValue >= modelData.min) { + modelData.value = newValue + } } } } @@ -301,7 +310,10 @@ RowLayout { text: "+" onClicked: { var value = modelData.value - modelData.value += value * adjustPercentModel.get(adjustPercentCombo.currentIndex).value + var newValue = value + (value * adjustPercentModel.get(adjustPercentCombo.currentIndex).value) + if (newValue <= modelData.max) { + modelData.value = newValue + } } } } @@ -372,7 +384,7 @@ RowLayout { QGCButton { text: dataTimer.running ? qsTr("Stop") : qsTr("Start") - onClicked: dataTimer.running = !dataTimer.running + onClicked: dataTimer.startOrStop() } } }