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 title: qsTr("Calculate Amps per Volt")
10 buttons: Dialog.Close
11
12 property int batteryIndex: 1
13 property var _controller: controller
14 property var _batteryFactGroup: controller.vehicle.getFactGroup("battery" + (batteryIndex - 1))
15
16 BatteryParams {
17 id: batParams
18 controller: _controller
19 batteryIndex: parent.batteryIndex
20 }
21
22 ColumnLayout {
23 spacing: ScreenTools.defaultFontPixelHeight
24
25 QGCLabel {
26 Layout.preferredWidth: gridLayout.width
27 wrapMode: Text.WordWrap
28 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.")
29 }
30
31 GridLayout {
32 id: gridLayout
33 columns: 2
34
35 QGCLabel { text: qsTr("Measured current:") }
36 QGCTextField { id: measuredCurrent; numericValuesOnly: true }
37
38 QGCLabel { text: qsTr("Vehicle current:") }
39 QGCLabel { text: _batteryFactGroup.current.valueString }
40
41 QGCLabel { text: qsTr("Amps per volt:") }
42 FactLabel { fact: batParams.battAmpsPerVolt }
43 }
44
45 QGCButton {
46 text: qsTr("Calculate")
47
48 onClicked: {
49 var measuredCurrentValue = parseFloat(measuredCurrent.text)
50 if (measuredCurrentValue === 0 || isNaN(measuredCurrentValue)) {
51 return
52 }
53 var newAmpsPerVolt = (measuredCurrentValue * batParams.battAmpsPerVolt.value) / _batteryFactGroup.current.value
54 if (newAmpsPerVolt != 0) {
55 batParams.battAmpsPerVolt.value = newAmpsPerVolt
56 }
57 }
58 }
59 }
60}