diff --git a/src/AutoPilotPlugins/PX4/ActuatorComponent.qml b/src/AutoPilotPlugins/PX4/ActuatorComponent.qml index 68cc175..9de170b 100644 --- a/src/AutoPilotPlugins/PX4/ActuatorComponent.qml +++ b/src/AutoPilotPlugins/PX4/ActuatorComponent.qml @@ -286,7 +286,7 @@ SetupPage { model: actionGroup.actions QGCMenuItem { text: object.label - onTriggered: object.trigger() + onTriggered: object.trigger() } onObjectAdded: actionMenu.insertItem(index, object) onObjectRemoved: actionMenu.removeItem(object) @@ -354,6 +354,7 @@ SetupPage { QGCButton { text: qsTr("Identify & Assign Motors") visible: !actuators.motorAssignmentActive && selActuatorOutput.actuatorOutput.groupsVisible + enabled: actuators.motorAssignmentEnabled onClicked: { var success = actuators.initMotorAssignment() if (success) { diff --git a/src/Vehicle/Actuators/Actuators.cc b/src/Vehicle/Actuators/Actuators.cc index 06cd17e..292781f 100644 --- a/src/Vehicle/Actuators/Actuators.cc +++ b/src/Vehicle/Actuators/Actuators.cc @@ -103,6 +103,9 @@ void Actuators::updateGeometryImage() _imageRefreshFlag = !_imageRefreshFlag; emit imageRefreshFlagChanged(); + + _motorAssignmentEnabled = provider->numMotors() > 0; + emit motorAssignmentEnabledChanged(); } bool Actuators::isMultirotor() const @@ -674,13 +677,7 @@ bool Actuators::showUi() const bool Actuators::initMotorAssignment() { GeometryImage::VehicleGeometryImageProvider* provider = GeometryImage::VehicleGeometryImageProvider::instance(); - int numMotors = 0; - QList& actuators = provider->actuators(); - for (const auto& actuator : actuators) { - if (actuator.type == ActuatorGeometry::Type::Motor) { - ++numMotors; - } - } + int numMotors = provider->numMotors(); // get the minimum function for motors bool ret = false; diff --git a/src/Vehicle/Actuators/Actuators.h b/src/Vehicle/Actuators/Actuators.h index 2f552a6..350e50f 100644 --- a/src/Vehicle/Actuators/Actuators.h +++ b/src/Vehicle/Actuators/Actuators.h @@ -33,6 +33,7 @@ public: Q_PROPERTY(bool imageRefreshFlag READ imageRefreshFlag NOTIFY imageRefreshFlagChanged) Q_PROPERTY(bool hasUnsetRequiredFunctions READ hasUnsetRequiredFunctions NOTIFY hasUnsetRequiredFunctionsChanged) Q_PROPERTY(bool motorAssignmentActive READ motorAssignmentActive NOTIFY motorAssignmentActiveChanged) + Q_PROPERTY(bool motorAssignmentEnabled READ motorAssignmentEnabled NOTIFY motorAssignmentEnabledChanged) Q_PROPERTY(QString motorAssignmentMessage READ motorAssignmentMessage NOTIFY motorAssignmentMessageChanged) Q_PROPERTY(ActuatorTesting::ActuatorTest* actuatorTest READ actuatorTest CONSTANT) @@ -75,6 +76,7 @@ public: Q_INVOKABLE void spinCurrentMotor() { _motorAssignment.spinCurrentMotor(); } Q_INVOKABLE void abortMotorAssignment(); bool motorAssignmentActive() const { return _motorAssignment.active(); } + bool motorAssignmentEnabled() const { return _motorAssignmentEnabled; } const QString& motorAssignmentMessage() const { return _motorAssignment.message(); } public slots: @@ -86,6 +88,7 @@ signals: void imageRefreshFlagChanged(); void hasUnsetRequiredFunctionsChanged(); void motorAssignmentActiveChanged(); + void motorAssignmentEnabledChanged(); void motorAssignmentMessageChanged(); void actuatorActionsChanged(); @@ -112,6 +115,7 @@ private: ActuatorTesting::ActuatorTest _actuatorTest; Mixer::Mixers _mixer; MotorAssignment _motorAssignment; + bool _motorAssignmentEnabled{false}; bool _hasUnsetRequiredFunctions{false}; bool _imageRefreshFlag{false}; ///< indicator to QML to reload the image int _selectedActuatorOutput{0}; diff --git a/src/Vehicle/Actuators/GeometryImage.cc b/src/Vehicle/Actuators/GeometryImage.cc index bd7a819..e83c2b4 100644 --- a/src/Vehicle/Actuators/GeometryImage.cc +++ b/src/Vehicle/Actuators/GeometryImage.cc @@ -415,3 +415,14 @@ int VehicleGeometryImageProvider::getHighlightedMotorIndexAtPos(const QPointF &p } return -1; } + +int VehicleGeometryImageProvider::numMotors() const +{ + int numMotors = 0; + for (const auto& actuator : _actuators) { + if (actuator.type == ActuatorGeometry::Type::Motor) { + ++numMotors; + } + } + return numMotors; +} diff --git a/src/Vehicle/Actuators/GeometryImage.h b/src/Vehicle/Actuators/GeometryImage.h index 34a0b1b..5e0021c 100644 --- a/src/Vehicle/Actuators/GeometryImage.h +++ b/src/Vehicle/Actuators/GeometryImage.h @@ -50,6 +50,8 @@ public: QList& actuators() { return _actuators; } + int numMotors() const; + private: VehicleGeometryImageProvider(); ~VehicleGeometryImageProvider() = default;