PowerComponent.qml 24.2 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9 10 11 12 13 14


/// @file
///     @brief Battery, propeller and magnetometer settings
///     @author Gus Grubba <mavlink@grubba.com>

15
import QtQuick          2.2
dogmaphobic's avatar
dogmaphobic committed
16
import QtQuick.Controls 1.2
17 18
import QtQuick.Dialogs  1.2
import QtQuick.Layouts  1.2
dogmaphobic's avatar
dogmaphobic committed
19

20 21 22 23 24
import QGroundControl.FactSystem    1.0
import QGroundControl.FactControls  1.0
import QGroundControl.Controls      1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controllers   1.0
dogmaphobic's avatar
dogmaphobic committed
25

26 27 28
SetupPage {
    id:             powerPage
    pageComponent:  pageComponent
29

30
    Component {
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
        id: pageComponent

        Column {
            id:         innerColumn
            width:      availableWidth
            spacing:    ScreenTools.defaultFontPixelHeight * 0.5

            property int textEditWidth:    ScreenTools.defaultFontPixelWidth * 8

            property Fact battNumCells:         controller.getParameterFact(-1, "BAT_N_CELLS")
            property Fact battHighVolt:         controller.getParameterFact(-1, "BAT_V_CHARGED")
            property Fact battLowVolt:          controller.getParameterFact(-1, "BAT_V_EMPTY")
            property Fact battVoltLoadDrop:     controller.getParameterFact(-1, "BAT_V_LOAD_DROP")
            property Fact battVoltageDivider:   controller.getParameterFact(-1, "BAT_V_DIV")
            property Fact battAmpsPerVolt:      controller.getParameterFact(-1, "BAT_A_PER_V")
            property Fact uavcanEnable:         controller.getParameterFact(-1, "UAVCAN_ENABLE", false)

            readonly property string highlightPrefix:   "<font color=\"" + qgcPal.warningText + "\">"
            readonly property string highlightSuffix:   "</font>"


            function getBatteryImage()
            {
                switch(battNumCells.value) {
                case 1:  return "/qmlimages/PowerComponentBattery_01cell.svg";
                case 2:  return "/qmlimages/PowerComponentBattery_02cell.svg"
                case 3:  return "/qmlimages/PowerComponentBattery_03cell.svg"
                case 4:  return "/qmlimages/PowerComponentBattery_04cell.svg"
                case 5:  return "/qmlimages/PowerComponentBattery_05cell.svg"
                case 6:  return "/qmlimages/PowerComponentBattery_06cell.svg"
                default: return "/qmlimages/PowerComponentBattery_01cell.svg";
                }
            }

            function drawArrowhead(ctx, x, y, radians)
            {
                ctx.save();
                ctx.beginPath();
                ctx.translate(x,y);
                ctx.rotate(radians);
                ctx.moveTo(0,0);
                ctx.lineTo(5,10);
                ctx.lineTo(-5,10);
                ctx.closePath();
                ctx.restore();
                ctx.fill();
            }

            function drawLineWithArrow(ctx, x1, y1, x2, y2)
            {
                ctx.beginPath();
                ctx.moveTo(x1, y1);
                ctx.lineTo(x2, y2);
                ctx.stroke();
                var rd = Math.atan((y2 - y1) / (x2 - x1));
                rd += ((x2 > x1) ? 90 : -90) * Math.PI/180;
                drawArrowhead(ctx, x2, y2, rd);
            }

            PowerComponentController {
                id:         controller
                factPanel:  powerPage.viewPanel

                onOldFirmware:          showMessage(qsTr("ESC Calibration"), qsTr("QGroundControl cannot perform ESC Calibration with this version of firmware. You will need to upgrade to a newer firmware."), StandardButton.Ok)
                onNewerFirmware:        showMessage(qsTr("ESC Calibration"), qsTr("QGroundControl cannot perform ESC Calibration with this version of firmware. You will need to upgrade QGroundControl."), StandardButton.Ok)
                onBatteryConnected:     showMessage(qsTr("ESC Calibration"), qsTr("Performing calibration. This will take a few seconds.."), 0)
                onCalibrationFailed:    showMessage(qsTr("ESC Calibration failed"), errorMessage, StandardButton.Ok)
                onCalibrationSuccess:   showMessage(qsTr("ESC Calibration"), qsTr("Calibration complete. You can disconnect your battery now if you like."), StandardButton.Ok)
                onConnectBattery:       showMessage(qsTr("ESC Calibration"), highlightPrefix + qsTr("WARNING: Props must be removed from vehicle prior to performing ESC calibration.") + highlightSuffix + qsTr(" Connect the battery now and calibration will begin."), 0)
                onDisconnectBattery:    showMessage(qsTr("ESC Calibration failed"), qsTr("You must disconnect the battery prior to performing ESC Calibration. Disconnect your battery and try again."), StandardButton.Ok)
            }

            Component {
                id: calcVoltageDividerDlgComponent

                QGCViewDialog {
                    id: calcVoltageDividerDlg

                    QGCFlickable {
                        anchors.fill:   parent
                        contentHeight:  column.height
                        contentWidth:   column.width

                        Column {
                            id:         column
                            width:      calcVoltageDividerDlg.width
                            spacing:    ScreenTools.defaultFontPixelHeight
118

119 120 121 122 123
                            QGCLabel {
                                width:      parent.width
                                wrapMode:   Text.WordWrap
                                text:       "Measure battery voltage using an external voltmeter and enter the value below. Click Calculate to set the new voltage multiplier."
                            }
124

125 126 127 128
                            Grid {
                                columns: 2
                                spacing: ScreenTools.defaultFontPixelHeight / 2
                                verticalItemAlignment: Grid.AlignVCenter
129

130 131 132 133
                                QGCLabel {
                                    text: "Measured voltage:"
                                }
                                QGCTextField { id: measuredVoltage }
134

135 136
                                QGCLabel { text: "Vehicle voltage:" }
                                QGCLabel { text: controller.vehicle.battery.voltage.valueString }
137

138 139 140
                                QGCLabel { text: "Voltage divider:" }
                                FactLabel { fact: battVoltageDivider }
                            }
141

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
                            QGCButton {
                                text: "Calculate"

                                onClicked:  {
                                    var measuredVoltageValue = parseFloat(measuredVoltage.text)
                                    if (measuredVoltageValue == 0) {
                                        return
                                    }
                                    var newVoltageDivider = (measuredVoltageValue * battVoltageDivider.value) / controller.vehicle.battery.voltage.value
                                    if (newVoltageDivider != 0) {
                                        battVoltageDivider.value = newVoltageDivider
                                    }
                                }
                            }
                        } // Column
                    } // QGCFlickable
                } // QGCViewDialog
            } // Component - calcVoltageDividerDlgComponent
160

161 162
            Component {
                id: calcAmpsPerVoltDlgComponent
163

164 165
                QGCViewDialog {
                    id: calcAmpsPerVoltDlg
166

167 168 169 170
                    QGCFlickable {
                        anchors.fill:   parent
                        contentHeight:  column.height
                        contentWidth:   column.width
171

172 173 174 175 176 177 178 179 180
                        Column {
                            id:         column
                            width:      calcAmpsPerVoltDlg.width
                            spacing:    ScreenTools.defaultFontPixelHeight

                            QGCLabel {
                                width:      parent.width
                                wrapMode:   Text.WordWrap
                                text:       "Measure current draw using an external current meter and enter the value below. Click Calculate to set the new amps per volt value."
181 182
                            }

183 184 185 186
                            Grid {
                                columns: 2
                                spacing: ScreenTools.defaultFontPixelHeight / 2
                                verticalItemAlignment: Grid.AlignVCenter
187

188 189 190 191
                                QGCLabel {
                                    text: "Measured current:"
                                }
                                QGCTextField { id: measuredCurrent }
192

193 194
                                QGCLabel { text: "Vehicle current:" }
                                QGCLabel { text: controller.vehicle.battery.current.valueString }
195

196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
                                QGCLabel { text: "Amps per volt:" }
                                FactLabel { fact: battAmpsPerVolt }
                            }

                            QGCButton {
                                text: "Calculate"

                                onClicked:  {
                                    var measuredCurrentValue = parseFloat(measuredCurrent.text)
                                    if (measuredCurrentValue == 0) {
                                        return
                                    }
                                    var newAmpsPerVolt = (measuredCurrentValue * battAmpsPerVolt.value) / controller.vehicle.battery.current.value
                                    if (newAmpsPerVolt != 0) {
                                        battAmpsPerVolt.value = newAmpsPerVolt
                                    }
                                }
                            }
                        } // Column
                    } // QGCFlickable
                } // QGCViewDialog
            } // Component - calcAmpsPerVoltDlgComponent


            QGCLabel {
                text: qsTr("Battery")
                font.family: ScreenTools.demiboldFontFamily
            }

            Rectangle {
                width:  parent.width
                height: batteryGrid.height + ScreenTools.defaultFontPixelHeight
                color:  qgcPal.windowShade

                GridLayout {
                    id:                 batteryGrid
                    anchors.margins:    ScreenTools.defaultFontPixelHeight / 2
                    anchors.left:       parent.left
                    anchors.top:        parent.top
                    columns:            5
                    columnSpacing:      ScreenTools.defaultFontPixelWidth
237 238

                    QGCLabel {
239
                        text:               qsTr("Number of Cells (in Series)")
240 241
                    }

242 243 244 245 246
                    FactTextField {
                        id:         cellsField
                        width:      textEditWidth
                        fact:       battNumCells
                        showUnits:  true
247 248
                    }

249 250 251 252 253 254 255 256 257 258 259
                    QGCColoredImage {
                        id:                     batteryImage
                        Layout.rowSpan:         3
                        width:                  height * 0.75
                        height:                 100
                        sourceSize.height:      height
                        fillMode:               Image.PreserveAspectFit
                        smooth:                 true
                        color:                  qgcPal.text
                        cache:                  false
                        source:                 getBatteryImage();
260
                    }
261

262
                    Item { width: 1; height: 1; Layout.columnSpan: 2 }
263

264 265 266 267
                    QGCLabel {
                        id:                 battHighLabel
                        text:               qsTr("Full Voltage (per cell)")
                    }
268

269 270 271 272 273 274
                    FactTextField {
                        id:         battHighField
                        width:      textEditWidth
                        fact:       battHighVolt
                        showUnits:  true
                    }
275

276 277 278
                    QGCLabel {
                        text:   qsTr("Battery Max:")
                    }
279

280 281 282
                    QGCLabel {
                        text:   (battNumCells.value * battHighVolt.value).toFixed(1) + ' V'
                    }
283

284 285 286 287
                    QGCLabel {
                        id:                 battLowLabel
                        text:               qsTr("Empty Voltage (per cell)")
                    }
288

289 290 291 292 293 294
                    FactTextField {
                        id:         battLowField
                        width:      textEditWidth
                        fact:       battLowVolt
                        showUnits:  true
                    }
295

296 297 298
                    QGCLabel {
                        text:   qsTr("Battery Min:")
                    }
299

300 301 302
                    QGCLabel {
                        text:   (battNumCells.value * battLowVolt.value).toFixed(1) + ' V'
                    }
303

304 305 306
                    QGCLabel {
                        text:               qsTr("Voltage divider")
                    }
307

308 309 310 311
                    FactTextField {
                        id:                 voltMultField
                        fact:               battVoltageDivider
                    }
312

313 314 315 316 317
                    QGCButton {
                        id:                 voltMultCalculateButton
                        text:               "Calculate"
                        onClicked:          showDialog(calcVoltageDividerDlgComponent, qsTr("Calculate Voltage Divider"), powerPage.showDialogDefaultWidth, StandardButton.Close)
                    }
318

319
                    Item { width: 1; height: 1; Layout.columnSpan: 2 }
320

321 322 323 324 325 326 327 328 329
                    QGCLabel {
                        id:                 voltMultHelp
                        Layout.columnSpan:  batteryGrid.columns
                        Layout.fillWidth:   true
                        font.pointSize:     ScreenTools.smallFontPointSize
                        wrapMode:           Text.WordWrap
                        text:               "If the battery voltage reported by the vehicle is largely different than the voltage read externally using a voltmeter you can adjust the voltage multiplier value to correct this. " +
                                            "Click the Calculate button for help with calculating a new value."
                    }
Don Gagne's avatar
Don Gagne committed
330

331 332 333 334
                    QGCLabel {
                        id:                 ampPerVoltLabel
                        text:               qsTr("Amps per volt")
                    }
Don Gagne's avatar
Don Gagne committed
335

336 337 338 339
                    FactTextField {
                        id:                 ampPerVoltField
                        fact:               battAmpsPerVolt
                    }
Don Gagne's avatar
Don Gagne committed
340

341 342 343 344 345
                    QGCButton {
                        id:                 ampPerVoltCalculateButton
                        text:               "Calculate"
                        onClicked:          showDialog(calcAmpsPerVoltDlgComponent, qsTr("Calculate Amps per Volt"), powerPage.showDialogDefaultWidth, StandardButton.Close)
                    }
Don Gagne's avatar
Don Gagne committed
346

347
                    Item { width: 1; height: 1; Layout.columnSpan: 2 }
348

349 350 351 352 353 354 355 356 357 358 359
                    QGCLabel {
                        id:                 ampPerVoltHelp
                        Layout.columnSpan:  batteryGrid.columns
                        Layout.fillWidth:   true
                        font.pointSize:     ScreenTools.smallFontPointSize
                        wrapMode:           Text.WordWrap
                        text:               "If the current draw reported by the vehicle is largely different than the current read externally using a current meter you can adjust the amps per volt value to correct this. " +
                                            "Click the Calculate button for help with calculating a new value."
                    }
                } // Grid
            } // Rectangle - Battery settings
Don Gagne's avatar
Don Gagne committed
360

361 362 363 364
            QGCLabel {
                text:           qsTr("ESC PWM Minimum and Maximum Calibration")
                font.family:    ScreenTools.demiboldFontFamily
            }
Don Gagne's avatar
Don Gagne committed
365

366 367 368 369
            Rectangle {
                width:  parent.width
                height: escCalColumn.height + ScreenTools.defaultFontPixelHeight
                color:  qgcPal.windowShade
370

371 372 373 374 375 376 377
                Column {
                    id :                escCalColumn
                    anchors.margins:    ScreenTools.defaultFontPixelHeight / 2
                    anchors.left:       parent.left
                    anchors.right:      parent.right
                    anchors.top:        parent.top
                    spacing:            ScreenTools.defaultFontPixelWidth
378

379 380 381 382 383 384
                    QGCLabel {
                        width:      parent.width
                        color:      qgcPal.warningText
                        wrapMode:   Text.WordWrap
                        text:       qsTr("WARNING: Propellers must be removed from vehicle prior to performing ESC calibration.")
                    }
385

386 387 388
                    QGCLabel {
                        text: qsTr("You must use USB connection for this operation.")
                    }
389

390 391 392 393 394
                    QGCButton {
                        text:       qsTr("Calibrate")
                        width:      ScreenTools.defaultFontPixelWidth * 20
                        onClicked:  controller.calibrateEsc()
                    }
395
                }
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
            }

            QGCCheckBox {
                id:         showUAVCAN
                text:       qsTr("Show UAVCAN Settings")
                visible:    uavcanEnable !== -1
            }

            QGCLabel {
                text:           qsTr("UAVCAN Bus Configuration")
                font.family:    ScreenTools.demiboldFontFamily
                visible:        showUAVCAN.checked
            }

            Rectangle {
                width:      parent.width
                height:     uavCanConfigColumn.height + ScreenTools.defaultFontPixelHeight
                color:      qgcPal.windowShade
                visible:    showUAVCAN.checked
415

416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
                Column {
                    id:                 uavCanConfigColumn
                    anchors.margins:    ScreenTools.defaultFontPixelHeight / 2
                    anchors.left:       parent.left
                    anchors.top:        parent.top
                    spacing:            ScreenTools.defaultFontPixelWidth

                    FactCheckBox {
                        id:                 uavcanEnabledCheckBox
                        width:              ScreenTools.defaultFontPixelWidth * 20
                        fact:               uavcanEnable
                        checkedValue:       3
                        uncheckedValue:     0
                        text:               qsTr("Enable UAVCAN as the default MAIN output bus (requires autopilot restart)")
                    }
                }
            }
433

434 435 436 437 438
            QGCLabel {
                text:           qsTr("UAVCAN Motor Index and Direction Assignment")
                font.family:    ScreenTools.demiboldFontFamily
                visible:        showUAVCAN.checked
            }
439

440 441 442 443 444 445
            Rectangle {
                width:      parent.width
                height:     uavCanEscCalColumn.height + ScreenTools.defaultFontPixelHeight
                color:      qgcPal.windowShade
                visible:    showUAVCAN.checked
                enabled:    uavcanEnabledCheckBox.checked
Don Gagne's avatar
Don Gagne committed
446

447 448 449 450 451 452 453
                Column {
                    id:                 uavCanEscCalColumn
                    anchors.margins:    ScreenTools.defaultFontPixelHeight / 2
                    anchors.left:       parent.left
                    anchors.right:      parent.right
                    anchors.top:        parent.top
                    spacing:            ScreenTools.defaultFontPixelWidth
454

455 456 457 458 459
                    QGCLabel {
                        width:      parent.width
                        wrapMode:   Text.WordWrap
                        color:      qgcPal.warningText
                        text:       qsTr("WARNING: Propellers must be removed from vehicle prior to performing UAVCAN ESC configuration.")
dogmaphobic's avatar
dogmaphobic committed
460
                    }
461

462 463 464 465 466
                    QGCLabel {
                        width:      parent.width
                        wrapMode:   Text.WordWrap
                        text:       qsTr("ESC parameters will only be accessible in the editor after assignment.")
                    }
dogmaphobic's avatar
dogmaphobic committed
467

468 469 470 471 472
                    QGCLabel {
                        width:      parent.width
                        wrapMode:   Text.WordWrap
                        text:       qsTr("Start the process, then turn each motor into its turn direction, in the order of their motor indices.")
                    }
473

474 475 476 477
                    QGCButton {
                        text:       qsTr("Start Assignment")
                        width:      ScreenTools.defaultFontPixelWidth * 20
                        onClicked:  controller.busConfigureActuators()
478 479
                    }

480 481 482 483 484
                    QGCButton {
                        text:       qsTr("Stop Assignment")
                        width:      ScreenTools.defaultFontPixelWidth * 20
                        onClicked:  controller.stopBusConfigureActuators()
                    }
485
                }
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
            }

            QGCCheckBox {
                id:     showAdvanced
                text:   qsTr("Show Advanced Settings")
            }

            QGCLabel {
                text:           qsTr("Advanced Power Settings")
                font.family:    ScreenTools.demiboldFontFamily
                visible:        showAdvanced.checked
            }

            Rectangle {
                id:         batteryRectangle
                width:      parent.width
                height:     advBatteryColumn.height + ScreenTools.defaultFontPixelHeight
                color:      qgcPal.windowShade
                visible:    showAdvanced.checked
505

506 507 508 509 510 511 512
                Column {
                    id: advBatteryColumn
                    anchors.margins:    ScreenTools.defaultFontPixelHeight / 2
                    anchors.left:       parent.left
                    anchors.right:      parent.right
                    anchors.top:        parent.top
                    spacing:            ScreenTools.defaultFontPixelWidth
513

514 515
                    Row {
                        spacing: ScreenTools.defaultFontPixelWidth
516 517

                        QGCLabel {
518 519
                            text:               qsTr("Voltage Drop on Full Load (per cell)")
                            anchors.baseline:   battDropField.baseline
520 521
                        }

522 523 524 525 526
                        FactTextField {
                            id:         battDropField
                            width:      textEditWidth
                            fact:       battVoltLoadDrop
                            showUnits:  true
527
                        }
528
                    }
529

530 531 532 533 534 535 536
                    QGCLabel {
                        width:      parent.width
                        wrapMode:   Text.WordWrap
                        text:       qsTr("Batteries show less voltage at high throttle. Enter the difference in Volts between idle throttle and full ") +
                                    qsTr("throttle, divided by the number of battery cells. Leave at the default if unsure. ") +
                                    highlightPrefix + qsTr("If this value is set too high, the battery might be deep discharged and damaged.") + highlightSuffix
                    }
537

538 539
                    Row {
                        spacing: ScreenTools.defaultFontPixelWidth
540

541
                        QGCLabel {
542
                            text: qsTr("Compensated Minimum Voltage:")
543 544
                        }

545 546
                        QGCLabel {
                            text: ((battNumCells.value * battLowVolt.value) - (battNumCells.value * battVoltLoadDrop.value)).toFixed(1) + qsTr(" V")
547 548
                        }
                    }
549 550 551 552 553
                }
            } // Rectangle - Advanced power settings
        } // Column
    } // Component
} // SetupPage