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