Skip to content

Commit

Permalink
Rework AutoPilotPlugin to support knowing if VehicleComponent available
Browse files Browse the repository at this point in the history
  • Loading branch information
DonLakeFlyer committed Feb 17, 2025
1 parent 9ab9d65 commit 7a4b4e1
Show file tree
Hide file tree
Showing 41 changed files with 135 additions and 99 deletions.
2 changes: 1 addition & 1 deletion src/AutoPilotPlugins/APM/APMAirframeComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "Vehicle.h"

APMAirframeComponent::APMAirframeComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent (vehicle, autopilot, parent)
: VehicleComponent (vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
, _requiresFrameSetup (false)
, _name (tr("Frame"))
{
Expand Down
2 changes: 1 addition & 1 deletion src/AutoPilotPlugins/APM/APMCameraComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "Vehicle.h"

APMCameraComponent::APMCameraComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
, _name(tr("Camera"))
{
}
Expand Down
6 changes: 3 additions & 3 deletions src/AutoPilotPlugins/APM/APMFlightModesComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

#include "APMFlightModesComponent.h"

APMFlightModesComponent::APMFlightModesComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
VehicleComponent(vehicle, autopilot, parent),
_name(tr("Flight Modes"))
APMFlightModesComponent::APMFlightModesComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::KnownFlightModesVehicleComponent, parent)
, _name(tr("Flight Modes"))
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/AutoPilotPlugins/APM/APMFollowComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include "APMAutoPilotPlugin.h"

APMFollowComponent::APMFollowComponent(Vehicle *vehicle, AutoPilotPlugin *autopilot, QObject *parent)
: VehicleComponent(vehicle, autopilot, parent),
_name(QStringLiteral("Follow Me"))
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
, _name(QStringLiteral("Follow Me"))
{
// qCDebug() << Q_FUNC_INFO << this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/AutoPilotPlugins/APM/APMHeliComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "APMAutoPilotPlugin.h"

APMHeliComponent::APMHeliComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
, _name(tr("Heli"))
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/AutoPilotPlugins/APM/APMLightsComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "APMLightsComponent.h"

APMLightsComponent::APMLightsComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
, _name(tr("Lights"))
{
}
Expand Down
4 changes: 2 additions & 2 deletions src/AutoPilotPlugins/APM/APMPowerComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include "APMPowerComponent.h"

APMPowerComponent::APMPowerComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, parent),
_name(tr("Power"))
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::KnownPowerVehicleComponent, parent)
, _name(tr("Power"))
{
}

Expand Down
6 changes: 3 additions & 3 deletions src/AutoPilotPlugins/APM/APMRadioComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#include "Fact.h"
#include "Vehicle.h"

APMRadioComponent::APMRadioComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
VehicleComponent(vehicle, autopilot, parent),
_name(tr("Radio"))
APMRadioComponent::APMRadioComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::KnownRadioVehicleComponent, parent)
, _name(tr("Radio"))
{
_mapParams << QStringLiteral("RCMAP_ROLL") << QStringLiteral("RCMAP_PITCH") << QStringLiteral("RCMAP_YAW") << QStringLiteral("RCMAP_THROTTLE");

Expand Down
2 changes: 1 addition & 1 deletion src/AutoPilotPlugins/APM/APMRemoteSupportComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "APMRemoteSupportComponent.h"

APMRemoteSupportComponent::APMRemoteSupportComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
, _name(tr("Remote Support"))
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/AutoPilotPlugins/APM/APMSafetyComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "QGCMAVLink.h"

APMSafetyComponent::APMSafetyComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::KnownSafetyVehicleComponent, parent)
, _name(tr("Safety"))
{
}
Expand Down
6 changes: 3 additions & 3 deletions src/AutoPilotPlugins/APM/APMSensorsComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

// These two list must be kept in sync

APMSensorsComponent::APMSensorsComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
VehicleComponent(vehicle, autopilot, parent),
_name(tr("Sensors"))
APMSensorsComponent::APMSensorsComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::KnownSensorsVehicleComponent, parent)
, _name(tr("Sensors"))
{

}
Expand Down
2 changes: 1 addition & 1 deletion src/AutoPilotPlugins/APM/APMSubFrameComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "APMSubFrameComponent.h"

APMSubFrameComponent::APMSubFrameComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
, _name(tr("Frame"))
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/AutoPilotPlugins/APM/APMTuningComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "Vehicle.h"

APMTuningComponent::APMTuningComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
, _name(tr("Tuning"))
{
}
Expand Down
18 changes: 16 additions & 2 deletions src/AutoPilotPlugins/AutoPilotPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,22 @@ void AutoPilotPlugin::parametersReadyPreChecks(void)
if (!_setupComplete) {
qgcApp()->showAppMessage(tr("One or more vehicle components require setup prior to flight."));

// Take the user to Vehicle Summary
qgcApp()->showSetupView();
// Take the user to Vehicle Config Summary
qgcApp()->showVehicleConfig();
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
}
}

VehicleComponent* AutoPilotPlugin::findKnownVehicleComponent(KnownVehicleComponent knownVehicleComponent)
{
if (knownVehicleComponent != UnknownVehicleComponent) {
for(const QVariant& componentVariant: vehicleComponents()) {
VehicleComponent* component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject *>(componentVariant));
if (component && component->KnownVehicleComponent() == knownVehicleComponent) {
return component;
}
}
}

return nullptr;
}
18 changes: 15 additions & 3 deletions src/AutoPilotPlugins/AutoPilotPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ class AutoPilotPlugin : public QObject
AutoPilotPlugin(Vehicle* vehicle, QObject* parent);
~AutoPilotPlugin();

// Vehicle Components which are available for firmware types
enum KnownVehicleComponent {
KnownRadioVehicleComponent,
KnownFlightModesVehicleComponent,
KnownSensorsVehicleComponent,
KnownSafetyVehicleComponent,
KnownPowerVehicleComponent,
UnknownVehicleComponent // Firmware specific vehicle components
};
Q_ENUM(KnownVehicleComponent)

Q_PROPERTY(QVariantList vehicleComponents READ vehicleComponents NOTIFY vehicleComponentsChanged) ///< List of VehicleComponent objects
Q_PROPERTY(bool setupComplete READ setupComplete NOTIFY setupCompleteChanged) ///< false: One or more vehicle components require setup

Expand All @@ -45,6 +56,10 @@ class AutoPilotPlugin : public QObject
/// Returns the name of the vehicle component which must complete setup prior to this one. Empty string for none.
Q_INVOKABLE virtual QString prerequisiteSetup(VehicleComponent* component) const = 0;

Q_INVOKABLE VehicleComponent* findKnownVehicleComponent(KnownVehicleComponent knownVehicleComponent);

Q_INVOKABLE bool knownVehicleComponentAvailable(KnownVehicleComponent knownVehicleComponent) { return findKnownVehicleComponent(knownVehicleComponent) != nullptr; }

// Property accessors
bool setupComplete(void) const;

Expand All @@ -53,9 +68,6 @@ class AutoPilotPlugin : public QObject
void vehicleComponentsChanged (void);

protected:
/// All access to AutoPilotPugin objects is through getInstanceForAutoPilotPlugin
AutoPilotPlugin(QObject* parent = nullptr) : QObject(parent) { }

Vehicle* _vehicle;
FirmwarePlugin* _firmwarePlugin;
bool _setupComplete;
Expand Down
2 changes: 2 additions & 0 deletions src/AutoPilotPlugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ qt_add_library(AutoPilotPlugins STATIC
AutoPilotPlugin.h
Generic/GenericAutoPilotPlugin.cc
Generic/GenericAutoPilotPlugin.h
VehicleComponent.cc
VehicleComponent.h
)

target_link_libraries(AutoPilotPlugins
Expand Down
2 changes: 1 addition & 1 deletion src/AutoPilotPlugins/Common/ESP8266Component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "AutoPilotPlugin.h"

ESP8266Component::ESP8266Component(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
, _name(tr("WiFi Bridge"))
{

Expand Down
6 changes: 3 additions & 3 deletions src/AutoPilotPlugins/Common/MotorComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include "MotorComponent.h"
#include "AutoPilotPlugin.h"

MotorComponent::MotorComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
VehicleComponent(vehicle, autopilot, parent),
_name(tr("Motors"))
MotorComponent::MotorComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
, _name(tr("Motors"))
{

}
Expand Down
2 changes: 1 addition & 1 deletion src/AutoPilotPlugins/Common/SyslinkComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "AutoPilotPlugin.h"

SyslinkComponent::SyslinkComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
, _name(tr("Syslink"))
{

Expand Down
7 changes: 4 additions & 3 deletions src/AutoPilotPlugins/PX4/ActuatorComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

static bool imageProviderAdded{false};

ActuatorComponent::ActuatorComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
VehicleComponent(vehicle, autopilot, parent),
_name(tr("Actuators")), _actuators(*vehicle->actuators())
ActuatorComponent::ActuatorComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
, _name(tr("Actuators"))
, _actuators(*vehicle->actuators())
{
if (!imageProviderAdded) {
// TODO: qmlAppEngine should not be accessed inside app
Expand Down
6 changes: 3 additions & 3 deletions src/AutoPilotPlugins/PX4/AirframeComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#include "ParameterManager.h"
#include "Vehicle.h"

AirframeComponent::AirframeComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
VehicleComponent(vehicle, autopilot, parent),
_name(tr("Airframe"))
AirframeComponent::AirframeComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
, _name(tr("Airframe"))
{

}
Expand Down
6 changes: 3 additions & 3 deletions src/AutoPilotPlugins/PX4/FlightModesComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ struct SwitchListItem {
const char* name;
};

FlightModesComponent::FlightModesComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
VehicleComponent(vehicle, autopilot, parent),
_name(tr("Flight Modes"))
FlightModesComponent::FlightModesComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::KnownFlightModesVehicleComponent, parent)
, _name(tr("Flight Modes"))
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/AutoPilotPlugins/PX4/PX4FlightBehavior.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "Vehicle.h"

PX4FlightBehavior::PX4FlightBehavior(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
, _name(tr("Flight Behavior"))
{
}
Expand Down
6 changes: 3 additions & 3 deletions src/AutoPilotPlugins/PX4/PX4RadioComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include "ParameterManager.h"
#include "Vehicle.h"

PX4RadioComponent::PX4RadioComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
VehicleComponent(vehicle, autopilot, parent),
_name(tr("Radio"))
PX4RadioComponent::PX4RadioComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::KnownRadioVehicleComponent, parent)
, _name(tr("Radio"))
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/AutoPilotPlugins/PX4/PX4TuningComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "Vehicle.h"

PX4TuningComponent::PX4TuningComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
, _name(tr("PID Tuning"))
{
}
Expand Down
6 changes: 3 additions & 3 deletions src/AutoPilotPlugins/PX4/PowerComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#include "ParameterManager.h"
#include "Vehicle.h"

PowerComponent::PowerComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
VehicleComponent(vehicle, autopilot, parent),
_name(tr("Power"))
PowerComponent::PowerComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::KnownPowerVehicleComponent, parent)
, _name(tr("Power"))
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/AutoPilotPlugins/PX4/SafetyComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "SafetyComponent.h"

SafetyComponent::SafetyComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
VehicleComponent(vehicle, autopilot, parent),
VehicleComponent(vehicle, autopilot, AutoPilotPlugin::KnownSafetyVehicleComponent, parent),
_name(tr("Safety"))
{
}
Expand Down
6 changes: 3 additions & 3 deletions src/AutoPilotPlugins/PX4/SensorsComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include "ParameterManager.h"
#include "Vehicle.h"

SensorsComponent::SensorsComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
VehicleComponent(vehicle, autopilot, parent),
_name(tr("Sensors"))
SensorsComponent::SensorsComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::KnownSensorsVehicleComponent, parent)
, _name(tr("Sensors"))
{
_deviceIds = QStringList({QStringLiteral("CAL_GYRO0_ID"), QStringLiteral("CAL_ACC0_ID") });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
#include <QtQml/QQmlContext>
#include <QtQuick/QQuickItem>

VehicleComponent::VehicleComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
QObject(parent),
_vehicle(vehicle),
_autopilot(autopilot)
VehicleComponent::VehicleComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, AutoPilotPlugin::KnownVehicleComponent KnownVehicleComponent, QObject* parent)
: QObject (parent)
, _vehicle (vehicle)
, _autopilot (autopilot)
, _KnownVehicleComponent (KnownVehicleComponent)
{
if (!vehicle || !autopilot) {
qWarning() << "Internal error";
Expand Down
Loading

0 comments on commit 7a4b4e1

Please sign in to comment.