QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
APMCalcAmpsPerVoltDialog.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: 0
14 property var _controller: controller
15 property var _batteryFactGroup: controller.vehicle.getFactGroup("battery" + batteryIndex)
16
17 APMBatteryParams {
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 QGCLabel {
33 Layout.preferredWidth: gridLayout.width
34 wrapMode: Text.WordWrap
35 visible: !_batteryFactGroup || _batteryFactGroup.current.value === 0
36 text: qsTr("Vehicle current telemetry is not available. Connect to a vehicle with a powered battery to enable automatic calculation.")
37 color: qgcPal.warningText
38 }
39
40 GridLayout {
41 id: gridLayout
42 columns: 2
43
44 QGCLabel { text: qsTr("Measured current:") }
45 QGCTextField { id: measuredCurrent; numericValuesOnly: true }
46
47 QGCLabel {
48 text: qsTr("Vehicle current:")
49 visible: _batteryFactGroup && _batteryFactGroup.current.value !== 0
50 }
51 QGCLabel {
52 text: _batteryFactGroup ? _batteryFactGroup.current.valueString : ""
53 visible: _batteryFactGroup && _batteryFactGroup.current.value !== 0
54 }
55
56 QGCLabel { text: qsTr("Amps per volt:") }
57 FactLabel { fact: batParams.battAmpPerVolt }
58 }
59
60 QGCButton {
61 text: qsTr("Calculate And Set")
62 enabled: _batteryFactGroup && _batteryFactGroup.current.value !== 0
63
64 onClicked: {
65 let measuredCurrentValue = parseFloat(measuredCurrent.text)
66 if (measuredCurrentValue === 0 || isNaN(measuredCurrentValue)) {
67 return
68 }
69 let newAmpsPerVolt = (measuredCurrentValue * batParams.battAmpPerVolt.value) / _batteryFactGroup.current.value
70 if (newAmpsPerVolt !== 0) {
71 batParams.battAmpPerVolt.value = newAmpsPerVolt
72 }
73 }
74 }
75 }
76}