█ 【无人机学习之QGroundControl】android端App初解2-APMPowerComponent(含QML的介绍)
█ 系列文章目录
提示:这里是收集了无人机的相关文章
- 【无人机学习】无人机基础知识
- 【无人机学习】Mission Planner(pc端)和QGroundControl(android端)
- 【无人机学习之DroidPlanner】FlightActivity的启动过程
- 【无人机学习之DroidPlanner】msg_heartbeat心跳处理(含MAVLink协议)
- 【无人机学习之DroidPlanner】msg_sys_status系统状态
- 【无人机学习之QGroundControl】android端App初解1
- 【无人机学习之QGroundControl】android端App初解2-APMPowerComponent(含QML的介绍)
- 【无人机学习之QGroundControl】android端App初解3-ParameterEditorController
█ 文章目录
█ 读前说明
- 本文通过学习别人写demo,学习一些课件,参考一些博客,学习相关知识,如有涉及侵权请告知
- 本文可能只简单罗列了一些相关的代码实现过程,复制了一些大神的高论,如内容有误请自行辨别
- 涉及到的逻辑以及说明可能只做了简单的介绍,主要当做笔记,了解过程而已,如有不同看法,欢迎下方评论
- 本文源码:https://github.com/mavlink/qgroundcontrol
- 本文UI:https://github.com/mavlink/qgroundcontrol/blob/master/src/ui
- QGC中UI设计的主要模式是用QML编写的UI页面,多次与用C ++编写的定制“控制器”进行通信。类似MVC的设计模式。
提示:QGroundControl是使用QT & c++ 编写的
█ QML的介绍
- 可视元素具有几何坐标,会在屏幕上占据一块显示区域。
基本元素 | 说明 |
---|---|
Item | 基本的项元素,所有可视化项都继承Item |
Rectangle | 基本的可视化矩形元素 |
Gradient | 定义一个两种颜色的渐变过程 |
GradientStop | 定义个颜色,被Gradient使用 |
Image | 在场景中使用位图 |
BorderImage | (特殊的项) 定义一张图片并当做边界 |
AnimatedImage | 为播放动画存储一系列的帧 |
Text | 在场景中使用文本 |
TextInput | 显示可编辑为文本 |
IntValidatorint | 验证器 |
DoubleValidator | double 验证器 |
RegExpValidator | 验证字符串正则表达式 |
TextEdit | 显示多行可编辑文本 |
视图 | 说明 |
---|---|
ListView | 提供一个链表显示模型试图 |
GridView | 提供一个网格显示模型试图 |
PathView | 提供一个内容沿着路径来显示的模型 |
Path | 定义一个PathView使用的轨迹 |
PathLine | 定义一个线性的轨迹 |
PathQuad | 定义一个二次贝塞尔曲线的轨迹 |
PathCubic | 定义一个三次贝塞尔曲线的轨迹 |
PathAttribute | 允许绑定一个属性上,具体看例子 |
PathPercent | 修改item分配的轨迹 不是很明了其中的意思 |
WebView | 允许添加网页内容到一个canvas上 |
定位器 | 说明 |
---|---|
Column | 整理它的子列(纵) |
Row | 整理它的子行(横) |
Grid | 设置它的子到一个网格上 |
Flow | 目的是不让他的子项重叠在一起 |
锚点(anchor) | 说明:元素布局 |
---|---|
top | anchors.top、parent.top |
bottom | |
left | 左边 |
right | 右边 |
horizontalCenter | 水平居中 |
verticalCenter | 垂直居中 |
baseline | 基准线 |
- 不可视元素,通常提供一种作用于可视元素的功能。
基本的交互项 | 说明 |
---|---|
MouseArea | 鼠标句柄交互,如点击事件 |
FocusScope | 键盘焦点句柄 |
Flickable | 提供一种浏览整张图片的一部分的效果 |
Flipable | 提供一个平面,可以进行翻转看前面或后面 |
数据项 | 说明 |
---|---|
Binding | 在创建的时候绑定一些数据到一些属性 |
ListModel | 定义链表数据 |
ListElement | 定义ListModel的一个数据项 |
VisualItemModel | 包含可视化项(visual items)到一个view中,相当是一个容器 |
VisualDataModel | 包含一个model和一个delegate,model包含需要的数据,delegate设计显示的项的信息 |
Package | 把VisualDataModel共享给多个view |
XmlListModel | 特殊的一个模式使用XPath表达式,使用xml来设置元素 |
XmlRole | XmlListModel的一个特殊的角色 |
实用项 | 说明 |
---|---|
Connections | 明确连接信号和信号句柄 |
Component | 封装QML items 想一个组件一样 |
Timer | 提供时间触发器 |
QtObject | 基本的元素只包含objectName属性 |
Qt | qml全局Qt object提供使用的枚举和函数 |
WorkerScript | 允许在QML使用线程 |
Loader | 控制载入item或组件 |
Repeater | 使用一个模型创建多个组件 |
SystemPalette | 为Qt palettes提供一个通道 |
FontLoader | 载入字体根据名字或URL |
LayoutItem | 允许声明UI元素插入到qtGraphicsView 布局中 |
█ APMPowerComponent
1.电源界面
2.相关文件
3.APMPowerComponent.qml
此文件在qgroundcontrol-master\src\AutoPilotPlugins\APM\APMPowerComponent.qml(注意是APM不是PX4,看自己的硬件)
GridLayout {
columns: 3
rowSpacing: _margins
columnSpacing: _margins
QGCLabel { text: qsTr("Battery monitor:") }
FactComboBox {
id: monitorCombo
fact: battMonitor
indexModel: false
}
QGCLabel {
Layout.row: 1
Layout.column: 0
text: qsTr("Battery capacity:")
}
FactTextField {
id: capacityField
width: _fieldWidth
fact: battCapacity
}
QGCLabel {
Layout.row: 2
Layout.column: 0
text: qsTr("Minimum arming voltage:")
}
FactTextField {
id: armVoltField
width: _fieldWidth
fact: armVoltMin
}
QGCLabel {
Layout.row: 3
Layout.column: 0
text: qsTr("Power sensor:")
}
QGCComboBox {
id: sensorCombo
Layout.minimumWidth: _fieldWidth
model: sensorModel// 下一步需要查看的信息
textRole: "text"
onActivated: {
if (index < sensorModel.count - 1) {
battVoltPin.value = sensorModel.get(index).voltPin
battCurrPin.value = sensorModel.get(index).currPin
battVoltMult.value = sensorModel.get(index).voltMult
battAmpPerVolt.value = sensorModel.get(index).ampPerVolt
battAmpOffset.value = sensorModel.get(index).ampOffset
} else {
}
}
}
QGCLabel {
Layout.row: 4
Layout.column: 0
text: qsTr("Current pin:")
visible: _showAdvanced
}
FactComboBox {
Layout.minimumWidth: _fieldWidth
fact: battCurrPin
indexModel: false
visible: _showAdvanced
}
QGCLabel {
Layout.row: 5
Layout.column: 0
text: qsTr("Voltage pin:")
visible: _showAdvanced
}
FactComboBox {
Layout.minimumWidth: _fieldWidth
fact: battVoltPin
indexModel: false
visible: _showAdvanced
}
QGCLabel {
Layout.row: 6
Layout.column: 0
text: qsTr("Voltage multiplier:")
visible: _showAdvanced
}
FactTextField {
width: _fieldWidth
fact: battVoltMult
visible: _showAdvanced
}
QGCButton {
text: qsTr("Calculate")
visible: _showAdvanced
onClicked: {// 下一步需要查看的信息
_calcVoltageDlgVehicleVoltage = vehicleVoltage
_calcVoltageDlgBattVoltMultParam = battVoltMult
mainWindow.showComponentDialog(calcVoltageMultiplierDlgComponent, qsTr("Calculate Voltage Multiplier"), mainWindow.showDialogDefaultWidth, StandardButton.Close)
}
}
QGCLabel {
Layout.columnSpan: 3
Layout.fillWidth: true
font.pointSize: ScreenTools.smallFontPointSize
wrapMode: Text.WordWrap
text: qsTr("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.")
visible: _showAdvanced
}
QGCLabel {
text: qsTr("Amps per volt:")
visible: _showAdvanced
}
FactTextField {
width: _fieldWidth
fact: battAmpPerVolt
visible: _showAdvanced
}
QGCButton {
text: qsTr("Calculate")
visible: _showAdvanced
onClicked: {
_calcAmpsPerVoltDlgVehicleCurrent = vehicleCurrent
_calcAmpsPerVoltDlgBattAmpPerVoltParam = battAmpPerVolt
mainWindow.showComponentDialog(calcAmpsPerVoltDlgComponent, qsTr("Calculate Amps per Volt"), mainWindow.showDialogDefaultWidth, StandardButton.Close)
}
}
QGCLabel {
Layout.columnSpan: 3
Layout.fillWidth: true
font.pointSize: ScreenTools.smallFontPointSize
wrapMode: Text.WordWrap
text: qsTr("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.")
visible: _showAdvanced
}
QGCLabel {
text: qsTr("Amps Offset:")
visible: _showAdvanced
}
FactTextField {
width: _fieldWidth
fact: battAmpOffset
visible: _showAdvanced
}
QGCLabel {
Layout.columnSpan: 3
Layout.fillWidth: true
font.pointSize: ScreenTools.smallFontPointSize
wrapMode: Text.WordWrap
text: qsTr("If the vehicle reports a high current read when there is little or no current going through it, adjust the Amps Offset. It should be equal to the voltage reported by the sensor when the current is zero.")
visible: _showAdvanced
}
} // GridLayout
4.下拉框spinner
ListModel {
id: sensorModel// 下拉框spinner
ListElement {
text: qsTr("Power Module 90A")
voltPin: 2
currPin: 3
voltMult: 10.1
ampPerVolt: 17.0
ampOffset: 0
}
ListElement {
text: qsTr("Power Module HV")
voltPin: 2
currPin: 3
voltMult: 12.02
ampPerVolt: 39.877
ampOffset: 0
}
ListElement {
text: qsTr("3DR Iris")
voltPin: 2
currPin: 3
voltMult: 12.02
ampPerVolt: 17.0
ampOffset: 0
}
ListElement {
text: qsTr("Blue Robotics Power Sense Module R2")
voltPin: 2
currPin: 3
voltMult: 11.000
ampPerVolt: 37.8788
ampOffset: 0.330
}
ListElement {
text: qsTr("Other")
}
}
QGCComboBox {
id: sensorCombo
Layout.minimumWidth: _fieldWidth
model: sensorModel // 下拉框spinner
textRole: "text"
onActivated: {
if (index < sensorModel.count - 1) {
battVoltPin.value = sensorModel.get(index).voltPin
battCurrPin.value = sensorModel.get(index).currPin
battVoltMult.value = sensorModel.get(index).voltMult
battAmpPerVolt.value = sensorModel.get(index).ampPerVolt
battAmpOffset.value = sensorModel.get(index).ampOffset
} else {
}
}
}
5.参数编辑器
QGCLabel {
Layout.row: 6
Layout.column: 0
text: qsTr("Voltage multiplier:")
visible: _showAdvanced
}
FactTextField {
width: _fieldWidth
fact: battVoltMult
visible: _showAdvanced
}
QGCButton {
text: qsTr("Calculate")
visible: _showAdvanced
onClicked: {
_calcVoltageDlgVehicleVoltage = vehicleVoltage
_calcVoltageDlgBattVoltMultParam = battVoltMult
// calcVoltageMultiplierDlgComponent是对话框的id
mainWindow.showComponentDialog(calcVoltageMultiplierDlgComponent, qsTr("Calculate Voltage Multiplier"), mainWindow.showDialogDefaultWidth, StandardButton.Close)
}
}
// Must be set prior to use of calcVoltageMultiplierDlgComponent
property Fact _calcVoltageDlgVehicleVoltage
property Fact _calcVoltageDlgBattVoltMultParam
Component {
id: calcVoltageMultiplierDlgComponent// 对话框的id
QGCViewDialog {
id: calcVoltageMultiplierDlg
QGCFlickable {
anchors.fill: parent
contentHeight: column.height
contentWidth: column.width
Column {
id: column
width: calcVoltageMultiplierDlg.width
spacing: ScreenTools.defaultFontPixelHeight
QGCLabel {
width: parent.width
wrapMode: Text.WordWrap
text: qsTr("Measure battery voltage using an external voltmeter and enter the value below. Click Calculate to set the new adjusted voltage multiplier.")
}
Grid {
columns: 2
spacing: ScreenTools.defaultFontPixelHeight / 2
verticalItemAlignment: Grid.AlignVCenter
QGCLabel {
text: qsTr("Measured voltage:")
}
QGCTextField { id: measuredVoltage }
QGCLabel { text: qsTr("Vehicle voltage:") }
FactLabel { fact: _calcVoltageDlgVehicleVoltage }
QGCLabel { text: qsTr("Voltage multiplier:") }
FactLabel { fact: _calcVoltageDlgBattVoltMultParam }
}
QGCButton {
text: qsTr("Calculate And Set")
onClicked: {
var measuredVoltageValue = parseFloat(measuredVoltage.text)
if (measuredVoltageValue == 0 || isNaN(measuredVoltageValue)) {
return
}
var newVoltageMultiplier = (measuredVoltageValue * _calcVoltageDlgBattVoltMultParam.value) / _calcVoltageDlgVehicleVoltage.value
if (newVoltageMultiplier > 0) {
_calcVoltageDlgBattVoltMultParam.value = newVoltageMultiplier
}
}
}
} // Column
} // QGCFlickable
} // QGCViewDialog
} // Component - calcVoltageMultiplierDlgComponent
6.APMPowerComponent.cc
此文件在qgroundcontrol-master\src\AutoPilotPlugins\APM\APMPowerComponent.cc(注意是APM不是PX4,看自己的硬件)
图片和qml设置
APMPowerComponent::APMPowerComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, parent),
_name(tr("Power"))
{
}
QString APMPowerComponent::name(void) const
{
return _name;
}
QString APMPowerComponent::description(void) const
{
return tr("The Power Component is used to setup battery parameters.");
}
QString APMPowerComponent::iconResource(void) const
{
return QStringLiteral("/qmlimages/PowerComponentIcon.png");
}
QUrl APMPowerComponent::setupSource(void) const
{
return QUrl::fromUserInput(QStringLiteral("qrc:/qml/APMPowerComponent.qml"));
}
QUrl APMPowerComponent::summaryQmlSource(void) const
{
return QUrl::fromUserInput(QStringLiteral("qrc:/qml/APMPowerComponentSummary.qml"));// 下一步需要查看的信息
}
7.APMPowerComponentSummary.qml
此文件在qgroundcontrol-master\src\AutoPilotPlugins\APM\APMPowerComponentSummary.qml(注意是APM不是PX4,看自己的硬件)
目前还不太清楚做什么
Item {
anchors.fill: parent
FactPanelController { id: controller; }
property Fact _batt1Monitor: controller.getParameterFact(-1, "BATT_MONITOR")
property Fact _batt2Monitor: controller.getParameterFact(-1, "BATT2_MONITOR", false /* reportMissing */)
property bool _batt2MonitorAvailable: controller.parameterExists(-1, "BATT2_MONITOR")
property bool _batt1MonitorEnabled: _batt1Monitor.rawValue !== 0
property bool _batt2MonitorEnabled: _batt2MonitorAvailable && _batt2Monitor.rawValue !== 0
property Fact _battCapacity: controller.getParameterFact(-1, "BATT_CAPACITY", false /* reportMissing */)
property Fact _batt2Capacity: controller.getParameterFact(-1, "BATT2_CAPACITY", false /* reportMissing */)
property bool _battCapacityAvailable: controller.parameterExists(-1, "BATT_CAPACITY")
Column {
anchors.fill: parent
VehicleSummaryRow {
labelText: qsTr("Batt1 monitor")
valueText: _batt1Monitor.enumStringValue
}
VehicleSummaryRow {
labelText: qsTr("Batt1 capacity")
valueText: _batt1MonitorEnabled ? _battCapacity.valueString + " " + _battCapacity.units : ""
visible: _batt1MonitorEnabled
}
VehicleSummaryRow {
labelText: qsTr("Batt2 monitor")
valueText: _batt2MonitorAvailable ? _batt2Monitor.enumStringValue : ""
visible: _batt2MonitorAvailable
}
VehicleSummaryRow {
labelText: qsTr("Batt2 capacity")
valueText: _batt2MonitorEnabled ? _batt2Capacity.valueString + " " + _batt2Capacity.units : ""
visible: _batt2MonitorEnabled
}
}
}
█ 相关资料
提示:这里是参考的相关文章
- 2018-03-08 QGC 连接功能 底层执行逻辑_/* */-CSDN博客
- 2019-01-15 QT Qml 的qmlRegisterUncreatableType()函数_小马哔哔-CSDN博客
- 2018-03-04 QGroundControl 开发人员指南_/* */-CSDN博客_qgroundcontrol
- 2019-05-11 Qt学习笔记:多语言文件.qm的生成和使用_chase_hung的博客-CSDN博客:生成ts文件,修改ts文件,生成qm文件,加载qm语言包
█ 免责声明
博主分享的所有文章内容,部分参考网上教程,引用大神高论,部分亲身实践,记下笔录,内容可能存在诸多不实之处,还望海涵,本内容仅供学习研究使用,切勿用于商业用途,若您是部分内容的作者,不喜欢此内容被分享出来,可联系博主说明相关情况通知删除,感谢您的理解与支持! |
---|
提示:转载请注明出处:
https://blog.csdn.net/ljb568838953/article/details/112903990