Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework motor component into common base class #12352

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qgroundcontrol.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
<file alias="MAVLinkInspectorPage.qml">src/AnalyzeView/MAVLinkInspectorPage.qml</file>
<file alias="PX4LogTransferSettings.qml">src/UI/preferences/PX4LogTransferSettings.qml</file>
<file alias="MissionSettingsEditor.qml">src/PlanView/MissionSettingsEditor.qml</file>
<file alias="MotorComponent.qml">src/AutoPilotPlugins/Common/MotorComponent.qml</file>
<file alias="ActuatorComponent.qml">src/AutoPilotPlugins/PX4/ActuatorComponent.qml</file>
<file alias="ActuatorFact.qml">src/AutoPilotPlugins/PX4/ActuatorFact.qml</file>
<file alias="ActuatorSlider.qml">src/AutoPilotPlugins/PX4/ActuatorSlider.qml</file>
Expand Down Expand Up @@ -108,6 +107,7 @@
<file alias="QGroundControl/Controls/LabelledButton.qml">src/QmlControls/LabelledButton.qml</file>
<file alias="QGroundControl/Controls/LabelledComboBox.qml">src/QmlControls/LabelledComboBox.qml</file>
<file alias="QGroundControl/Controls/LabelledLabel.qml">src/QmlControls/LabelledLabel.qml</file>
<file alias="QGroundControl/Controls/MotorComponent.qml">src/AutoPilotPlugins/Common/MotorComponent.qml</file>
<file alias="QGroundControl/Controls/RemoteIDIndicatorPage.qml">src/UI/toolbar/RemoteIDIndicatorPage.qml</file>
<file alias="QGroundControl/Controls/SettingsGroupLayout.qml">src/QmlControls/SettingsGroupLayout.qml</file>
<file alias="QGroundControl/Controls/InstrumentValueLabel.qml">src/QmlControls/InstrumentValueLabel.qml</file>
Expand Down
7 changes: 0 additions & 7 deletions src/AutoPilotPlugins/APM/APMMotorComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,3 @@ QUrl APMMotorComponent::setupSource(void) const
return QUrl::fromUserInput(QStringLiteral("qrc:/qml/APMMotorComponent.qml"));
}
}

QString APMMotorComponent::motorIndexToLetter(int index)
{
char letter = 'A';

return QString(char(letter + index));
}
2 changes: 0 additions & 2 deletions src/AutoPilotPlugins/APM/APMMotorComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class APMMotorComponent : public MotorComponent
QUrl setupSource (void) const override;
bool allowSetupWhileArmed (void) const override { return true; }

Q_INVOKABLE QString motorIndexToLetter(int index);

private:
const QString _name;
};
120 changes: 3 additions & 117 deletions src/AutoPilotPlugins/APM/APMMotorComponent.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,122 +7,8 @@
*
****************************************************************************/

import QtQuick
import QtQuick.Controls
import QtQuick.Dialogs

import QGroundControl
import QGroundControl.Controls
import QGroundControl.FactSystem
import QGroundControl.ScreenTools

SetupPage {
id: motorPage
pageComponent: pageComponent

readonly property int _barHeight: 10
readonly property int _barWidth: 5
readonly property int _sliderWidth: 15
readonly property int _motorTimeoutSecs: 3

FactPanelController {
id: controller
}

Component {
id: pageComponent

Column {
spacing: ScreenTools.defaultFontPixelHeight

QGCLabel {
text: qsTr("Warning: Unable to determine motor count")
color: qgcPal.warningText
visible: controller.vehicle.motorCount == -1
}

Row {
id: motorSlider
enabled: safetySwitch.checked
spacing: ScreenTools.defaultFontPixelWidth * 4

ValueSlider {
id: sliderThrottle
width: motorButtons.width
label: qsTr("Throttle")
from: 0
to: 100
majorTickStepSize: 5
decimalPlaces: 0
unitsString: qsTr("%")
}
} // Row

QGCLabel {
anchors.left: parent.left
anchors.right: parent.right
wrapMode: Text.WordWrap
text: qsTr("Make sure you remove all props.")
}

Row {
id: motorButtons
enabled: safetySwitch.checked
spacing: ScreenTools.defaultFontPixelWidth * 4

Repeater {
id: buttonRepeater
model: controller.vehicle.motorCount === -1 ? 8 : controller.vehicle.motorCount

QGCButton {
id: button
anchors.verticalCenter: parent.verticalCenter
text: vehicleComponent.motorIndexToLetter(index)
onClicked: {
controller.vehicle.motorTest(index + 1, sliderThrottle.value, sliderThrottle.value === 0 ? 0 : _motorTimeoutSecs, true)
}
}
} // Repeater

QGCButton {
id: allButton
text: qsTr("All")
onClicked: {
for (var motorIndex=0; motorIndex<buttonRepeater.count; motorIndex++) {
controller.vehicle.motorTest(motorIndex + 1, sliderThrottle.value, sliderThrottle.value === 0 ? 0 : _motorTimeoutSecs, true)
}
}
}

QGCButton {
id: allStopButton
text: qsTr("Stop")
onClicked: {
for (var motorIndex=0; motorIndex<buttonRepeater.count; motorIndex++) {
controller.vehicle.motorTest(motorIndex + 1, 0, 0, true)
}
}
}
} // Row

Row {
spacing: ScreenTools.defaultFontPixelWidth

Switch {
id: safetySwitch
onClicked: {
if (!checked) {
sliderThrottle.setValue(0);
}
}
}

QGCLabel {
anchors.verticalCenter: parent.verticalCenter
color: qgcPal.warningText
text: safetySwitch.checked ? qsTr("Careful : Motors are enabled") : qsTr("Propellers are removed - Enable slider and motors")
}
} // Row
} // Column
} // Component
} // SetupPage
MotorComponent {
userLetterMotorIndices: true
}
2 changes: 1 addition & 1 deletion src/AutoPilotPlugins/Common/MotorComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ QStringList MotorComponent::setupCompleteChangedTriggerList(void) const

QUrl MotorComponent::setupSource(void) const
{
return QUrl::fromUserInput(QStringLiteral("qrc:/qml/MotorComponent.qml"));
return QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/Controls/MotorComponent.qml"));
}

QUrl MotorComponent::summaryQmlSource(void) const
Expand Down
15 changes: 13 additions & 2 deletions src/AutoPilotPlugins/Common/MotorComponent.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,24 @@ SetupPage {
id: motorPage
pageComponent: pageComponent

property bool userLetterMotorIndices: false

readonly property int _barHeight: 10
readonly property int _barWidth: 5
readonly property int _sliderWidth: 15
readonly property int _motorTimeoutSecs: 3

function motorIndexToString(motorIndex) {
let asciiA = 65;
if (userLetterMotorIndices) {
return String.fromCharCode(asciiA + motorIndex);
} else {
return motorIndex + 1;
}
}

FactPanelController {
id: controller
id: controller
}

Component {
Expand Down Expand Up @@ -77,7 +88,7 @@ SetupPage {
QGCButton {
id: button
anchors.verticalCenter: parent.verticalCenter
text: index + 1
text: motorIndexToString(index)
onClicked: {
controller.vehicle.motorTest(index + 1, sliderThrottle.value, sliderThrottle.value === 0 ? 0 : _motorTimeoutSecs, true)
}
Expand Down
1 change: 1 addition & 0 deletions src/QmlControls/QGroundControl/Controls/qmldir
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ MissionItemEditor 1.0 MissionItemEditor.qml
MissionItemIndexLabel 1.0 MissionItemIndexLabel.qml
MissionItemMapVisual 1.0 MissionItemMapVisual.qml
MissionItemStatus 1.0 MissionItemStatus.qml
MotorComponent 1.0 MotorComponent.qml
MvPanelPage 1.0 MvPanelPage.qml
OfflineMapButton 1.0 OfflineMapButton.qml
OfflineMapEditor 1.0 OfflineMapEditor.qml
Expand Down
Loading