QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
CalcAmpsPerVoltDialog.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl.FactControls
6import QGroundControl.Controls
7
8QGCPopupDialog {
9 id: popupDialog
10 title: qsTr("Calculate Amps per Volt")
11 buttons: Dialog.Close
12
13 property int batteryIndex: 1
14 property var _controller: controller
15 property var _batteryFactGroup: controller.vehicle.getFactGroup("battery" + (batteryIndex - 1))
16
17 BatteryParams {
18 id: batParams
19 controller: _controller
20 batteryIndex: popupDialog.batteryIndex
21 }
22
23 ColumnLayout {
24 spacing: ScreenTools.defaultFontPixelHeight
25
26 QGCLabel {
27 Layout.preferredWidth: gridLayout.width
28 wrapMode: Text.WordWrap
29 text: qsTr("Measure current draw using an external current meter and enter the value below. Click Calculate to set the new amps per volt value.")
30 }
31
32 GridLayout {
33 id: gridLayout
34 columns: 2
35
36 QGCLabel { text: qsTr("Measured current:") }
37 QGCTextField { id: measuredCurrent; numericValuesOnly: true }
38
39 QGCLabel { text: qsTr("Vehicle current:") }
40 QGCLabel { text: _batteryFactGroup.current.valueString }
41
42 QGCLabel { text: qsTr("Amps per volt:") }
43 FactLabel { fact: batParams.battAmpsPerVolt }
44 }
45
46 QGCButton {
47 text: qsTr("Calculate")
48
49 onClicked: {
50 var measuredCurrentValue = parseFloat(measuredCurrent.text)
51 if (measuredCurrentValue === 0 || isNaN(measuredCurrentValue)) {
52 return
53 }
54 var newAmpsPerVolt = (measuredCurrentValue * batParams.battAmpsPerVolt.value) / _batteryFactGroup.current.value
55 if (newAmpsPerVolt != 0) {
56 batParams.battAmpsPerVolt.value = newAmpsPerVolt
57 }
58 }
59 }
60 }
61}