Commit a298165f authored by Don Gagne's avatar Don Gagne

New FirmwarePlugin support

- FirmwarePlugin is the new place for code which is specific to
firmware flight stack
- FirmwarePlugin currently supports flight mode apis
- Modify code to use new FirmwarePlugin support
parent 13cc2cfb
......@@ -554,14 +554,19 @@ SOURCES += \
} # MobileBuild
#
# AutoPilot Plugin Support
# Firmware Plugin Support
#
INCLUDEPATH += \
src/FirmwarePlugin \
src/VehicleSetup \
src/AutoPilotPlugins/PX4 \
HEADERS+= \
src/FirmwarePlugin/FirmwarePluginManager.h \
src/FirmwarePlugin/FirmwarePlugin.h \
src/FirmwarePlugin/Generic/GenericFirmwarePlugin.h \
src/FirmwarePlugin/PX4/PX4FirmwarePlugin.h \
src/AutoPilotPlugins/AutoPilotPlugin.h \
src/AutoPilotPlugins/AutoPilotPluginManager.h \
src/AutoPilotPlugins/Generic/GenericAutoPilotPlugin.h \
......@@ -594,6 +599,9 @@ HEADERS += \
}
SOURCES += \
src/FirmwarePlugin/FirmwarePluginManager.cc \
src/FirmwarePlugin/Generic/GenericFirmwarePlugin.cc \
src/FirmwarePlugin/PX4/PX4FirmwarePlugin.cc \
src/AutoPilotPlugins/AutoPilotPlugin.cc \
src/AutoPilotPlugins/AutoPilotPluginManager.cc \
src/AutoPilotPlugins/Generic/GenericAutoPilotPlugin.cc \
......
......@@ -117,39 +117,6 @@ QSharedPointer<AutoPilotPlugin> AutoPilotPluginManager::getInstanceForAutoPilotP
return _pluginMap[autopilotType][uasId];
}
QList<AutoPilotPluginManager::FullMode_t> AutoPilotPluginManager::getModes(int autopilotType) const
{
switch (autopilotType) {
case MAV_AUTOPILOT_PX4:
return PX4AutoPilotPlugin::getModes();
case MAV_AUTOPILOT_GENERIC:
default:
return GenericAutoPilotPlugin::getModes();
}
}
QString AutoPilotPluginManager::getAudioModeText(uint8_t baseMode, uint32_t customMode, int autopilotType) const
{
switch (autopilotType) {
case MAV_AUTOPILOT_PX4:
return PX4AutoPilotPlugin::getAudioModeText(baseMode, customMode);
case MAV_AUTOPILOT_GENERIC:
default:
return GenericAutoPilotPlugin::getAudioModeText(baseMode, customMode);
}
}
QString AutoPilotPluginManager::getShortModeText(uint8_t baseMode, uint32_t customMode, int autopilotType) const
{
switch (autopilotType) {
case MAV_AUTOPILOT_PX4:
return PX4AutoPilotPlugin::getShortModeText(baseMode, customMode);
case MAV_AUTOPILOT_GENERIC:
default:
return GenericAutoPilotPlugin::getShortModeText(baseMode, customMode);
}
}
/// If autopilot is not an installed plugin, returns MAV_AUTOPILOT_GENERIC
MAV_AUTOPILOT AutoPilotPluginManager::_installedAutopilotType(MAV_AUTOPILOT autopilot)
{
......
......@@ -52,20 +52,6 @@ public:
/// @param uas Uas to get plugin for
QSharedPointer<AutoPilotPlugin> getInstanceForAutoPilotPlugin(UASInterface* uas);
typedef struct {
uint8_t baseMode;
uint32_t customMode;
} FullMode_t;
/// Returns the list of modes which are available for the specified autopilot type.
QList<FullMode_t> getModes(int autopilotType) const;
/// @brief Returns a human readable short description for the specified mode.
QString getShortModeText(uint8_t baseMode, uint32_t customMode, int autopilotType) const;
/// @brief Returns a human hearable short description for the specified mode.
QString getAudioModeText(uint8_t baseMode, uint32_t customMode, int autopilotType) const;
private slots:
void _uasCreated(UASInterface* uas);
void _uasDeleted(UASInterface* uas);
......
......@@ -38,61 +38,6 @@ GenericAutoPilotPlugin::GenericAutoPilotPlugin(UASInterface* uas, QObject* paren
connect(_parameterFacts, &GenericParameterFacts::parameterListProgress, this, &GenericAutoPilotPlugin::parameterListProgress);
}
QList<AutoPilotPluginManager::FullMode_t> GenericAutoPilotPlugin::getModes(void)
{
AutoPilotPluginManager::FullMode_t fullMode;
QList<AutoPilotPluginManager::FullMode_t> modeList;
fullMode.customMode = 0;
fullMode.baseMode = MAV_MODE_FLAG_MANUAL_INPUT_ENABLED;
modeList << fullMode;
fullMode.baseMode = MAV_MODE_FLAG_MANUAL_INPUT_ENABLED | MAV_MODE_FLAG_STABILIZE_ENABLED;
modeList << fullMode;
fullMode.baseMode = MAV_MODE_FLAG_MANUAL_INPUT_ENABLED | MAV_MODE_FLAG_STABILIZE_ENABLED | MAV_MODE_FLAG_GUIDED_ENABLED;
modeList << fullMode;
fullMode.baseMode = MAV_MODE_FLAG_AUTO_ENABLED | MAV_MODE_FLAG_STABILIZE_ENABLED | MAV_MODE_FLAG_GUIDED_ENABLED;
modeList << fullMode;
return modeList;
}
QString GenericAutoPilotPlugin::getAudioModeText(uint8_t baseMode, uint32_t customMode)
{
Q_UNUSED(baseMode);
Q_UNUSED(customMode);
QString mode = "";
return mode;
}
QString GenericAutoPilotPlugin::getShortModeText(uint8_t baseMode, uint32_t customMode)
{
Q_UNUSED(customMode);
QString mode;
// use base_mode - not autopilot-specific
if (baseMode == 0) {
mode = "|PREFLIGHT";
} else if (baseMode & MAV_MODE_FLAG_DECODE_POSITION_AUTO) {
mode = "|AUTO";
} else if (baseMode & MAV_MODE_FLAG_DECODE_POSITION_MANUAL) {
mode = "|MANUAL";
if (baseMode & MAV_MODE_FLAG_DECODE_POSITION_GUIDED) {
mode += "|GUIDED";
} else if (baseMode & MAV_MODE_FLAG_DECODE_POSITION_STABILIZE) {
mode += "|STABILIZED";
}
}
return mode;
}
void GenericAutoPilotPlugin::clearStaticData(void)
{
// No Static data yet
......
......@@ -43,9 +43,6 @@ public:
// Overrides from AutoPilotPlugin
virtual const QVariantList& vehicleComponents(void);
static QList<AutoPilotPluginManager::FullMode_t> getModes(void);
static QString getAudioModeText(uint8_t baseMode, uint32_t customMode);
static QString getShortModeText(uint8_t baseMode, uint32_t customMode);
static void clearStaticData(void);
private slots:
......
......@@ -96,172 +96,6 @@ PX4AutoPilotPlugin::~PX4AutoPilotPlugin()
delete _airframeFacts;
}
QList<AutoPilotPluginManager::FullMode_t> PX4AutoPilotPlugin::getModes(void)
{
union px4_custom_mode px4_cm;
AutoPilotPluginManager::FullMode_t fullMode;
QList<AutoPilotPluginManager::FullMode_t> modeList;
px4_cm.data = 0;
px4_cm.main_mode = PX4_CUSTOM_MAIN_MODE_MANUAL;
fullMode.baseMode = MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | MAV_MODE_FLAG_MANUAL_INPUT_ENABLED;
fullMode.customMode = px4_cm.data;
modeList << fullMode;
px4_cm.data = 0;
px4_cm.main_mode = PX4_CUSTOM_MAIN_MODE_ACRO;
fullMode.baseMode = MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | MAV_MODE_FLAG_MANUAL_INPUT_ENABLED;
fullMode.customMode = px4_cm.data;
modeList << fullMode;
px4_cm.data = 0;
px4_cm.main_mode = PX4_CUSTOM_MAIN_MODE_STABILIZED;
fullMode.baseMode = MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | MAV_MODE_FLAG_MANUAL_INPUT_ENABLED | MAV_MODE_FLAG_STABILIZE_ENABLED;
fullMode.customMode = px4_cm.data;
modeList << fullMode;
px4_cm.data = 0;
px4_cm.main_mode = PX4_CUSTOM_MAIN_MODE_ALTCTL;
fullMode.baseMode = MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | MAV_MODE_FLAG_MANUAL_INPUT_ENABLED | MAV_MODE_FLAG_STABILIZE_ENABLED;
fullMode.customMode = px4_cm.data;
modeList << fullMode;
px4_cm.data = 0;
px4_cm.main_mode = PX4_CUSTOM_MAIN_MODE_POSCTL;
fullMode.baseMode = MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | MAV_MODE_FLAG_MANUAL_INPUT_ENABLED | MAV_MODE_FLAG_STABILIZE_ENABLED | MAV_MODE_FLAG_GUIDED_ENABLED;
fullMode.customMode = px4_cm.data;
modeList << fullMode;
px4_cm.data = 0;
px4_cm.main_mode = PX4_CUSTOM_MAIN_MODE_AUTO;
fullMode.baseMode = MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | MAV_MODE_FLAG_AUTO_ENABLED | MAV_MODE_FLAG_STABILIZE_ENABLED | MAV_MODE_FLAG_GUIDED_ENABLED;
fullMode.customMode = px4_cm.data;
modeList << fullMode;
px4_cm.data = 0;
px4_cm.main_mode = PX4_CUSTOM_MAIN_MODE_OFFBOARD;
fullMode.baseMode = MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | MAV_MODE_FLAG_AUTO_ENABLED | MAV_MODE_FLAG_STABILIZE_ENABLED | MAV_MODE_FLAG_GUIDED_ENABLED;
fullMode.customMode = px4_cm.data;
modeList << fullMode;
return modeList;
}
QString PX4AutoPilotPlugin::getAudioModeText(uint8_t baseMode, uint32_t customMode)
{
QString mode;
Q_ASSERT(baseMode & MAV_MODE_FLAG_CUSTOM_MODE_ENABLED);
if (baseMode & MAV_MODE_FLAG_CUSTOM_MODE_ENABLED) {
union px4_custom_mode px4_mode;
px4_mode.data = customMode;
if (px4_mode.main_mode == PX4_CUSTOM_MAIN_MODE_MANUAL) {
mode = "manual";
} else if (px4_mode.main_mode == PX4_CUSTOM_MAIN_MODE_ACRO) {
mode = "caro";
} else if (px4_mode.main_mode == PX4_CUSTOM_MAIN_MODE_STABILIZED) {
mode = "stabilized";
} else if (px4_mode.main_mode == PX4_CUSTOM_MAIN_MODE_ALTCTL) {
mode = "altitude control";
} else if (px4_mode.main_mode == PX4_CUSTOM_MAIN_MODE_POSCTL) {
mode = "position control";
} else if (px4_mode.main_mode == PX4_CUSTOM_MAIN_MODE_AUTO) {
mode = "auto and ";
if (px4_mode.sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_READY) {
mode += "ready";
} else if (px4_mode.sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_TAKEOFF) {
mode += "taking off";
} else if (px4_mode.sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_LOITER) {
mode += "loitering";
} else if (px4_mode.sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_MISSION) {
mode += "following waypoints";
} else if (px4_mode.sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_RTL) {
mode += "returning to land";
} else if (px4_mode.sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_LAND) {
mode += "landing";
}
} else if (px4_mode.main_mode == PX4_CUSTOM_MAIN_MODE_OFFBOARD) {
mode = "offboard controlled";
}
if (baseMode != 0)
{
mode += " mode";
}
// ARMED STATE DECODING
if (baseMode & (uint8_t)MAV_MODE_FLAG_DECODE_POSITION_SAFETY)
{
mode.append(" and armed");
}
} else {
mode = "";
}
return mode;
}
QString PX4AutoPilotPlugin::getShortModeText(uint8_t baseMode, uint32_t customMode)
{
QString mode;
Q_ASSERT(baseMode & MAV_MODE_FLAG_CUSTOM_MODE_ENABLED);
if (baseMode & MAV_MODE_FLAG_CUSTOM_MODE_ENABLED) {
union px4_custom_mode px4_mode;
px4_mode.data = customMode;
if (px4_mode.main_mode == PX4_CUSTOM_MAIN_MODE_MANUAL) {
mode = "|MANUAL";
} else if (px4_mode.main_mode == PX4_CUSTOM_MAIN_MODE_ACRO) {
mode = "|ACRO";
} else if (px4_mode.main_mode == PX4_CUSTOM_MAIN_MODE_STABILIZED) {
mode = "|STAB";
} else if (px4_mode.main_mode == PX4_CUSTOM_MAIN_MODE_ALTCTL) {
mode = "|ALTCTL";
} else if (px4_mode.main_mode == PX4_CUSTOM_MAIN_MODE_POSCTL) {
mode = "|POSCTL";
} else if (px4_mode.main_mode == PX4_CUSTOM_MAIN_MODE_AUTO) {
mode = "|AUTO";
if (px4_mode.sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_READY) {
mode += "|READY";
} else if (px4_mode.sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_TAKEOFF) {
mode += "|TAKEOFF";
} else if (px4_mode.sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_LOITER) {
mode += "|LOITER";
} else if (px4_mode.sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_MISSION) {
mode += "|MISSION";
} else if (px4_mode.sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_RTL) {
mode += "|RTL";
} else if (px4_mode.sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_LAND) {
mode += "|LAND";
}
} else if (px4_mode.main_mode == PX4_CUSTOM_MAIN_MODE_OFFBOARD) {
mode = "|OFFBOARD";
}
} else {
// use base_mode - not autopilot-specific
if (baseMode == 0) {
mode = "|PREFLIGHT";
} else if (baseMode & MAV_MODE_FLAG_DECODE_POSITION_AUTO) {
mode = "|AUTO";
} else if (baseMode & MAV_MODE_FLAG_DECODE_POSITION_MANUAL) {
mode = "|MANUAL";
if (baseMode & MAV_MODE_FLAG_DECODE_POSITION_GUIDED) {
mode += "|GUIDED";
} else if (baseMode & MAV_MODE_FLAG_DECODE_POSITION_STABILIZE) {
mode += "|STABILIZED";
}
}
}
return mode;
}
void PX4AutoPilotPlugin::clearStaticData(void)
{
PX4ParameterLoader::clearStaticData();
......
......@@ -53,9 +53,6 @@ public:
// Overrides from AutoPilotPlugin
virtual const QVariantList& vehicleComponents(void);
static QList<AutoPilotPluginManager::FullMode_t> getModes(void);
static QString getAudioModeText(uint8_t baseMode, uint32_t customMode);
static QString getShortModeText(uint8_t baseMode, uint32_t customMode);
static void clearStaticData(void);
// These methods should only be used by objects within the plugin
......
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/// @file
/// @author Don Gagne <don@thegagnes.com>
#ifndef FirmwarePlugin_H
#define FirmwarePlugin_H
#include "QGCSingleton.h"
#include "QGCMAVlink.h"
#include "VehicleComponent.h"
#include "AutoPilotPlugin.h"
#include <QList>
#include <QString>
/// This is the base class for Firmware specific plugins
///
/// The FirmwarePlugin class is the abstract base class which represents the methods and objects
/// which are specific to a certain Firmware flight stack. This is the only place where
/// flight stack specific code should reside in QGroundControl. The remainder of the
/// QGroundControl source is generic to a common mavlink implementation. The implementation
/// in the base class supports mavlink generic firmware. Override the base clase virtuals
/// to create you firmware specific plugin.
class FirmwarePlugin : public QGCSingleton
{
Q_OBJECT
public:
/// Set of optional capabilites which firmware may support
typedef enum {
SetFlightModeCapability,
} FirmwareCapabilities;
/// @return true: Firmware supports all specified capabilites
virtual bool isCapable(FirmwareCapabilities capabilities) = 0;
/// Returns VehicleComponents for specified Vehicle
/// @param vehicle Vehicle to associate with components
/// @return List of VehicleComponents for the specified vehicle. Caller owns returned objects and must
/// free when no longer needed.
virtual QList<VehicleComponent*> componentsForVehicle(AutoPilotPlugin* vehicle) = 0;
/// Returns the list of available flight modes
virtual QStringList flightModes(void) = 0;
/// Returns the name for this flight mode. Flight mode names must be human readable as well as audio speakable.
/// @param base_mode Base mode from mavlink HEARTBEAT message
/// @param custom_mode Custom mode from mavlink HEARTBEAT message
virtual QString flightMode(uint8_t base_mode, uint32_t custom_mode) = 0;
/// Sets base_mode and custom_mode to specified flight mode.
/// @param[out] base_mode Base mode for SET_MODE mavlink message
/// @param[out] custom_mode Custom mode for SET_MODE mavlink message
virtual bool setFlightMode(const QString& flightMode, uint8_t* base_mode, uint32_t* custom_mode) = 0;
protected:
FirmwarePlugin(QObject* parent = NULL) : QGCSingleton(parent) { }
};
#endif
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/// @file
/// @author Don Gagne <don@thegagnes.com>
#include "FirmwarePluginManager.h"
#include "Generic/GenericFirmwarePlugin.h"
#include "PX4/PX4FirmwarePlugin.h"
IMPLEMENT_QGC_SINGLETON(FirmwarePluginManager, FirmwarePluginManager)
FirmwarePluginManager::FirmwarePluginManager(QObject* parent) :
QGCSingleton(parent)
{
}
FirmwarePluginManager::~FirmwarePluginManager()
{
}
FirmwarePlugin* FirmwarePluginManager::firmwarePluginForAutopilot(MAV_AUTOPILOT autopilotType)
{
if (autopilotType == MAV_AUTOPILOT_PX4) {
return PX4FirmwarePlugin::instance();
} else {
return GenericFirmwarePlugin::instance();
}
}
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/// @file
/// @author Don Gagne <don@thegagnes.com>
#ifndef FirmwarePluginManager_H
#define FirmwarePluginManager_H
#include <QObject>
#include "QGCSingleton.h"
#include "FirmwarePlugin.h"
#include "QGCMAVLink.h"
/// FirmwarePluginManager is a singleton which is used to return the correct FirmwarePlugin for a MAV_AUTOPILOT type.
class FirmwarePluginManager : public QGCSingleton
{
Q_OBJECT
DECLARE_QGC_SINGLETON(FirmwarePluginManager, FirmwarePluginManager)
public:
/// Returns appropriate plugin for autopilot type.
/// @param autopilotType Type of autopilot to return plugin for.
/// @return Singleton FirmwarePlugin instance for the specified MAV_AUTOPILOT.
FirmwarePlugin* firmwarePluginForAutopilot(MAV_AUTOPILOT autopilotType);
private:
/// All access to singleton is through FirmwarePluginManager::instance
FirmwarePluginManager(QObject* parent = NULL);
~FirmwarePluginManager();
};
#endif
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/// @file
/// @author Don Gagne <don@thegagnes.com>
#include "GenericFirmwarePlugin.h"
#include <QDebug>
IMPLEMENT_QGC_SINGLETON(GenericFirmwarePlugin, FirmwarePlugin)
GenericFirmwarePlugin::GenericFirmwarePlugin(QObject* parent) :
FirmwarePlugin(parent)
{
}
GenericFirmwarePlugin::GenericFirmwarePlugin()
{
}
QList<VehicleComponent*> GenericFirmwarePlugin::componentsForVehicle(AutoPilotPlugin* vehicle)
{
Q_UNUSED(vehicle);
return QList<VehicleComponent*>();
}
QString GenericFirmwarePlugin::flightMode(uint8_t base_mode, uint32_t custom_mode)
{
QString flightMode;
struct Bit2Name {
uint8_t baseModeBit;
const char* name;
};
static const struct Bit2Name rgBit2Name[] = {
{ MAV_MODE_FLAG_MANUAL_INPUT_ENABLED, "Manual" },
{ MAV_MODE_FLAG_STABILIZE_ENABLED, "Stabilize" },
{ MAV_MODE_FLAG_GUIDED_ENABLED, "Guided" },
{ MAV_MODE_FLAG_AUTO_ENABLED, "Auto" },
{ MAV_MODE_FLAG_TEST_ENABLED, "Test" },
};
Q_UNUSED(custom_mode);
if (base_mode == 0) {
flightMode = "PreFlight";
} else if (base_mode & MAV_MODE_FLAG_CUSTOM_MODE_ENABLED) {
flightMode = QString("Custom:0x%1").arg(custom_mode, 0, 16);
} else {
for (size_t i=0; i<sizeof(rgBit2Name)/sizeof(rgBit2Name[0]); i++) {
if (base_mode & rgBit2Name[i].baseModeBit) {
if (i != 0) {
flightMode += " ";
}
flightMode += rgBit2Name[i].name;
}
}
}
return flightMode;
}
bool GenericFirmwarePlugin::setFlightMode(const QString& flightMode, uint8_t* base_mode, uint32_t* custom_mode)
{
Q_UNUSED(flightMode);
Q_UNUSED(base_mode);
Q_UNUSED(custom_mode);
qWarning() << "GenericFirmwarePlugin::setFlightMode called on base class, not supported";
return false;
}
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/// @file
/// @author Don Gagne <don@thegagnes.com>
#ifndef GenericFirmwarePlugin_H
#define GenericFirmwarePlugin_H
#include "FirmwarePlugin.h"
class GenericFirmwarePlugin : public FirmwarePlugin
{
Q_OBJECT
DECLARE_QGC_SINGLETON(GenericFirmwarePlugin, FirmwarePlugin)
public:
// Overrides from FirmwarePlugin
virtual bool isCapable(FirmwareCapabilities capabilities) { Q_UNUSED(capabilities); return false; }
virtual QList<VehicleComponent*> componentsForVehicle(AutoPilotPlugin* vehicle);
virtual QStringList flightModes(void) { return QStringList(); }
virtual QString flightMode(uint8_t base_mode, uint32_t custom_mode);
virtual bool setFlightMode(const QString& flightMode, uint8_t* base_mode, uint32_t* custom_mode);
private:
/// All access to singleton is through AutoPilotPluginManager::instance
GenericFirmwarePlugin(QObject* parent = NULL);
GenericFirmwarePlugin();
};
#endif
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/// @file
/// @author Don Gagne <don@thegagnes.com>
#include "PX4FirmwarePlugin.h"
#include <QDebug>
IMPLEMENT_QGC_SINGLETON(PX4FirmwarePlugin, FirmwarePlugin)
enum PX4_CUSTOM_MAIN_MODE {
PX4_CUSTOM_MAIN_MODE_MANUAL = 1,
PX4_CUSTOM_MAIN_MODE_ALTCTL,
PX4_CUSTOM_MAIN_MODE_POSCTL,
PX4_CUSTOM_MAIN_MODE_AUTO,
PX4_CUSTOM_MAIN_MODE_ACRO,
PX4_CUSTOM_MAIN_MODE_OFFBOARD,
PX4_CUSTOM_MAIN_MODE_STABILIZED,
};
enum PX4_CUSTOM_SUB_MODE_AUTO {
PX4_CUSTOM_SUB_MODE_AUTO_READY = 1,
PX4_CUSTOM_SUB_MODE_AUTO_TAKEOFF,
PX4_CUSTOM_SUB_MODE_AUTO_LOITER,
PX4_CUSTOM_SUB_MODE_AUTO_MISSION,
PX4_CUSTOM_SUB_MODE_AUTO_RTL,
PX4_CUSTOM_SUB_MODE_AUTO_LAND,
PX4_CUSTOM_SUB_MODE_AUTO_RTGS
};
union px4_custom_mode {
struct {
uint16_t reserved;
uint8_t main_mode;
uint8_t sub_mode;
};
uint32_t data;
float data_float;
};
struct Modes2Name {
uint8_t main_mode;
uint8_t sub_mode;
const char* name; ///< Name for flight mode
bool canBeSet; ///< true: Vehicle can be set to this flight mode
};
/// Tranlates from PX4 custom modes to flight mode names
// FIXME: Doens't handle fixed-wing/multi-rotor name differences
static const struct Modes2Name rgModes2Name[] = {
{ PX4_CUSTOM_MAIN_MODE_MANUAL, 0, "Manual", true },
{ PX4_CUSTOM_MAIN_MODE_ACRO, 0, "Acro", true },
{ PX4_CUSTOM_MAIN_MODE_STABILIZED, 0, "Stabilized", true },
{ PX4_CUSTOM_MAIN_MODE_ALTCTL, 0, "Altitude control", true },
{ PX4_CUSTOM_MAIN_MODE_POSCTL, 0, "Position control", true },
{ PX4_CUSTOM_MAIN_MODE_OFFBOARD, 0, "Offboard control", true },
{ PX4_CUSTOM_MAIN_MODE_AUTO, PX4_CUSTOM_SUB_MODE_AUTO_READY, "Auto ready", false },
{ PX4_CUSTOM_MAIN_MODE_AUTO, PX4_CUSTOM_SUB_MODE_AUTO_TAKEOFF, "Taking off", false },
{ PX4_CUSTOM_MAIN_MODE_AUTO, PX4_CUSTOM_SUB_MODE_AUTO_LOITER, "Loiter", true },
{ PX4_CUSTOM_MAIN_MODE_AUTO, PX4_CUSTOM_SUB_MODE_AUTO_MISSION, "Mission", true },
{ PX4_CUSTOM_MAIN_MODE_AUTO, PX4_CUSTOM_SUB_MODE_AUTO_RTL, "Return to Land", true },
{ PX4_CUSTOM_MAIN_MODE_AUTO, PX4_CUSTOM_SUB_MODE_AUTO_LAND, "Landing", false },
};
PX4FirmwarePlugin::PX4FirmwarePlugin(QObject* parent) :
FirmwarePlugin(parent)
{
}
PX4FirmwarePlugin::PX4FirmwarePlugin()
{
}
QList<VehicleComponent*> PX4FirmwarePlugin::componentsForVehicle(AutoPilotPlugin* vehicle)
{
Q_UNUSED(vehicle);
return QList<VehicleComponent*>();
}
QStringList PX4FirmwarePlugin::flightModes(void)
{
QStringList flightModes;
// FIXME: fixed-wing/multi-rotor differences?
for (size_t i=0; i<sizeof(rgModes2Name)/sizeof(rgModes2Name[0]); i++) {
const struct Modes2Name* pModes2Name = &rgModes2Name[i];
if (pModes2Name->canBeSet) {
flightModes += pModes2Name->name;
}
}
return flightModes;
}
QString PX4FirmwarePlugin::flightMode(uint8_t base_mode, uint32_t custom_mode)
{
QString flightMode = "Unknown";
if (base_mode & MAV_MODE_FLAG_CUSTOM_MODE_ENABLED) {
union px4_custom_mode px4_mode;
px4_mode.data = custom_mode;
// FIXME: fixed-wing/multi-rotor differences?
bool found = false;
for (size_t i=0; i<sizeof(rgModes2Name)/sizeof(rgModes2Name[0]); i++) {
const struct Modes2Name* pModes2Name = &rgModes2Name[i];
if (pModes2Name->main_mode == px4_mode.main_mode && pModes2Name->sub_mode == px4_mode.sub_mode) {
flightMode = pModes2Name->name;
found = true;
break;
}
}
if (!found) {
qWarning() << "Unknown flight mode" << custom_mode;
}
} else {
qWarning() << "PX4 Flight Stack flight mode without custom mode enabled?";
}
return flightMode;
}
bool PX4FirmwarePlugin::setFlightMode(const QString& flightMode, uint8_t* base_mode, uint32_t* custom_mode)
{
*base_mode = 0;
*custom_mode = 0;
bool found = false;
for (size_t i=0; i<sizeof(rgModes2Name)/sizeof(rgModes2Name[0]); i++) {
const struct Modes2Name* pModes2Name = &rgModes2Name[i];
if (flightMode.compare(pModes2Name->name, Qt::CaseInsensitive) == 0) {
union px4_custom_mode px4_mode;
px4_mode.data = 0;
px4_mode.main_mode = pModes2Name->main_mode;
px4_mode.sub_mode = pModes2Name->sub_mode;
*base_mode = MAV_MODE_FLAG_CUSTOM_MODE_ENABLED;
*custom_mode = px4_mode.data;
found = true;
break;
}
}
if (!found) {
qWarning() << "Unknown flight Mode" << flightMode;
}
return found;
}
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/// @file
/// @author Don Gagne <don@thegagnes.com>
#ifndef PX4FirmwarePlugin_H
#define PX4FirmwarePlugin_H
#include "FirmwarePlugin.h"
class PX4FirmwarePlugin : public FirmwarePlugin
{
Q_OBJECT
DECLARE_QGC_SINGLETON(PX4FirmwarePlugin, FirmwarePlugin)
public:
// Overrides from FirmwarePlugin
virtual bool isCapable(FirmwareCapabilities capabilities) { Q_UNUSED(capabilities); return false; }
virtual QList<VehicleComponent*> componentsForVehicle(AutoPilotPlugin* vehicle);
virtual QStringList flightModes(void);
virtual QString flightMode(uint8_t base_mode, uint32_t custom_mode);
virtual bool setFlightMode(const QString& flightMode, uint8_t* base_mode, uint32_t* custom_mode);
private:
/// All access to singleton is through AutoPilotPluginManager::instance
PX4FirmwarePlugin(QObject* parent = NULL);
PX4FirmwarePlugin();
};
#endif
......@@ -83,8 +83,10 @@ G_END_DECLS
#endif
#include "AutoPilotPlugin.h"
#include "VehicleComponent.h"
#include "MavManager.h"
#include "FirmwarePluginManager.h"
#include "Generic/GenericFirmwarePlugin.h"
#include "PX4/PX4FirmwarePlugin.h"
#ifdef QGC_RTLAB_ENABLED
#include "OpalLink.h"
......@@ -565,10 +567,25 @@ void QGCApplication::_createSingletons(void)
{
// The order here is important since the singletons reference each other
// No dependencies
FirmwarePlugin* firmwarePlugin = GenericFirmwarePlugin::_createSingleton();
Q_UNUSED(firmwarePlugin);
Q_ASSERT(firmwarePlugin);
// No dependencies
firmwarePlugin = PX4FirmwarePlugin::_createSingleton();
// No dependencies
FirmwarePluginManager* firmwarePluginManager = FirmwarePluginManager::_createSingleton();
Q_UNUSED(firmwarePluginManager);
Q_ASSERT(firmwarePluginManager);
// No dependencies
GAudioOutput* audio = GAudioOutput::_createSingleton();
Q_UNUSED(audio);
Q_ASSERT(audio);
// No dependencies
LinkManager* linkManager = LinkManager::_createSingleton();
Q_UNUSED(linkManager);
Q_ASSERT(linkManager);
......
......@@ -27,6 +27,8 @@
#ifndef QGCSINGLETON_H
#define QGCSINGLETON_H
#include "QGCApplication.h"
#include <QObject>
#include <QMutex>
......
......@@ -33,7 +33,7 @@
#include "SerialLink.h"
#endif
#include <Eigen/Geometry>
#include "AutoPilotPluginManager.h"
#include "FirmwarePluginManager.h"
#include "QGCMessageBox.h"
#include "QGCLoggingCategory.h"
......@@ -48,7 +48,7 @@ QGC_LOGGING_CATEGORY(UASLog, "UASLog")
* creating the UAS.
*/
UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(),
UAS::UAS(MAVLinkProtocol* protocol, int id, MAV_AUTOPILOT autopilotType) : UASInterface(),
lipoFull(4.2f),
lipoEmpty(3.5f),
uasId(id),
......@@ -60,7 +60,7 @@ UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(),
name(""),
type(MAV_TYPE_GENERIC),
airframe(QGC_AIRFRAME_GENERIC),
autopilot(-1),
autopilot(autopilotType),
systemIsArmed(false),
base_mode(0),
custom_mode(0),
......@@ -532,7 +532,7 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message)
bool statechanged = false;
bool modechanged = false;
QString audiomodeText = getAudioModeTextFor(state.base_mode, state.custom_mode);
QString audiomodeText = FirmwarePluginManager::instance()->firmwarePluginForAutopilot((MAV_AUTOPILOT)autopilot)->flightMode(state.base_mode, state.custom_mode);
if ((state.system_status != this->status) && state.system_status != MAV_STATE_UNINIT)
{
......@@ -558,11 +558,10 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message)
modechanged = true;
this->base_mode = state.base_mode;
this->custom_mode = state.custom_mode;
shortModeText = getShortModeTextFor(this->base_mode, this->custom_mode);
shortModeText = FirmwarePluginManager::instance()->firmwarePluginForAutopilot((MAV_AUTOPILOT)autopilot)->flightMode(base_mode, custom_mode);
emit modeChanged(this->getUASID(), shortModeText, "");
modeAudio = " is now in " + audiomodeText;
modeAudio = " is now in " + audiomodeText + "flight mode";
}
// We got the mode
......@@ -3293,101 +3292,6 @@ const QString& UAS::getShortState() const
return shortStateText;
}
/**
* The mode can be autonomous, guided, manual or armed. It will also return if
* hardware in the loop is being used.
* @return the audio mode text for the id given.
*/
QString UAS::getAudioModeTextFor(uint8_t base_mode, uint32_t custom_mode) const
{
QString mode = AutoPilotPluginManager::instance()->getAudioModeText(base_mode, custom_mode, autopilot);
if (mode.length() == 0)
{
// Fall back to generic decoding
QString mode;
uint8_t modeid = base_mode;
// BASE MODE DECODING
if (modeid & (uint8_t)MAV_MODE_FLAG_DECODE_POSITION_AUTO)
{
mode += "autonomous";
}
else if (modeid & (uint8_t)MAV_MODE_FLAG_DECODE_POSITION_GUIDED)
{
mode += "guided";
}
else if (modeid & (uint8_t)MAV_MODE_FLAG_DECODE_POSITION_STABILIZE)
{
mode += "stabilized";
}
else if (modeid & (uint8_t)MAV_MODE_FLAG_DECODE_POSITION_MANUAL)
{
mode += "manual";
}
else
{
// Nothing else applies, we're in preflight
mode += "preflight";
}
if (modeid != 0)
{
mode += " mode";
}
// ARMED STATE DECODING
if (modeid & (uint8_t)MAV_MODE_FLAG_DECODE_POSITION_SAFETY)
{
mode.append(" and armed");
}
// HARDWARE IN THE LOOP DECODING
if (modeid & (uint8_t)MAV_MODE_FLAG_DECODE_POSITION_HIL)
{
mode.append(" using hardware in the loop simulation");
}
}
return mode;
}
/**
* The mode returned depends on the specific autopilot used.
* @return the short text of the mode for the id given.
*/
QString UAS::getShortModeTextFor(uint8_t base_mode, uint32_t custom_mode) const
{
QString mode = AutoPilotPluginManager::instance()->getShortModeText(base_mode, custom_mode, autopilot);
if (mode.length() == 0)
{
mode = "|UNKNOWN";
qDebug() << __FILE__ << __LINE__ << " Unknown mode: base_mode=" << base_mode << " custom_mode=" << custom_mode << " autopilot=" << autopilot;
}
// ARMED STATE DECODING
if (base_mode & MAV_MODE_FLAG_DECODE_POSITION_SAFETY)
{
mode.prepend("A");
}
else
{
mode.prepend("D");
}
// HARDWARE IN THE LOOP DECODING
if (base_mode & MAV_MODE_FLAG_DECODE_POSITION_HIL)
{
mode.prepend("HIL:");
}
//qDebug() << "base_mode=" << base_mode << " custom_mode=" << custom_mode << " autopilot=" << autopilot << ": " << mode;
return mode;
}
const QString& UAS::getShortMode() const
{
return shortModeText;
......
......@@ -59,7 +59,7 @@ class UAS : public UASInterface
{
Q_OBJECT
public:
UAS(MAVLinkProtocol* protocol, int id = 0);
UAS(MAVLinkProtocol* protocol, int id, MAV_AUTOPILOT autopilotType);
~UAS();
float lipoFull; ///< 100% charged voltage
......@@ -73,10 +73,6 @@ public:
const QString& getShortState() const;
/** @brief Get short mode */
const QString& getShortMode() const;
/** @brief Translate from mode id to text */
QString getShortModeTextFor(uint8_t base_mode, uint32_t custom_mode) const;
/** @brief Translate from mode id to audio text */
QString getAudioModeTextFor(uint8_t base_mode, uint32_t custom_mode) const;
/** @brief Get the unique system id */
int getUASID() const;
/** @brief Get the airframe */
......
......@@ -100,8 +100,6 @@ public:
virtual const QString& getShortState() const = 0;
/** @brief Get short mode */
virtual const QString& getShortMode() const = 0;
/** @brief Translate mode id into text */
virtual QString getShortModeTextFor(uint8_t base_mode, uint32_t custom_mode) const = 0;
//virtual QColor getColor() = 0;
virtual int getUASID() const = 0; ///< Get the ID of the connected UAS
/** @brief The time interval the robot is switched on **/
......
......@@ -112,7 +112,6 @@ signals:
void homePositionChanged(double lat, double lon, double alt);
protected:
// FIXME: Do we need this here?
UASManagerInterface(QObject* parent = NULL) :
QGCSingleton(parent) { }
};
......
......@@ -38,6 +38,7 @@ This file is part of the QGROUNDCONTROL project
#include "FlightDisplay.h"
#include "QGCApplication.h"
#include "MavManager.h"
#include "AutoPilotPluginManager.h"
MainToolBar::MainToolBar(QWidget* parent)
: QGCQmlWidgetHolder(parent)
......
......@@ -40,10 +40,10 @@ This file is part of the PIXHAWK project
#include <UAS.h>
#include "QGC.h"
#include "AutoPilotPluginManager.h"
#include "FirmwarePluginManager.h"
UASControlWidget::UASControlWidget(QWidget *parent) : QWidget(parent),
uasID(-1),
modeIdx(0),
armed(false)
{
ui.setupUi(this);
......@@ -51,7 +51,6 @@ UASControlWidget::UASControlWidget(QWidget *parent) : QWidget(parent),
this->setUAS(UASManager::instance()->getActiveUAS());
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setUAS(UASInterface*)));
connect(ui.modeComboBox, SIGNAL(activated(int)), this, SLOT(setMode(int)));
connect(ui.setModeButton, SIGNAL(clicked()), this, SLOT(transmitMode()));
ui.liftoffButton->hide();
......@@ -70,17 +69,16 @@ void UASControlWidget::updateModesList()
UASInterface*uas = UASManager::instance()->getUASForId(this->uasID);
Q_ASSERT(uas);
_modeList = AutoPilotPluginManager::instance()->getModes(uas->getAutopilotType());
_modeList = FirmwarePluginManager::instance()->firmwarePluginForAutopilot((MAV_AUTOPILOT)uas->getAutopilotType())->flightModes();
// Set combobox items
ui.modeComboBox->clear();
foreach (AutoPilotPluginManager::FullMode_t fullMode, _modeList) {
ui.modeComboBox->addItem(uas->getShortModeTextFor(fullMode.baseMode, fullMode.customMode).remove(0, 2));
foreach (QString flightMode, _modeList) {
ui.modeComboBox->addItem(flightMode);
}
// Select first mode in list
modeIdx = 0;
ui.modeComboBox->setCurrentIndex(modeIdx);
ui.modeComboBox->setCurrentIndex(0);
ui.modeComboBox->update();
}
......@@ -93,8 +91,6 @@ void UASControlWidget::setUAS(UASInterface* uas)
disconnect(ui.liftoffButton, SIGNAL(clicked()), oldUAS, SLOT(launch()));
disconnect(ui.landButton, SIGNAL(clicked()), oldUAS, SLOT(home()));
disconnect(ui.shutdownButton, SIGNAL(clicked()), oldUAS, SLOT(shutdown()));
//connect(ui.setHomeButton, SIGNAL(clicked()), uas, SLOT(setLocalOriginAtCurrentGPSPosition()));
disconnect(oldUAS, SIGNAL(modeChanged(int,QString,QString)), this, SLOT(updateMode(int, QString, QString)));
disconnect(oldUAS, SIGNAL(statusChanged(int)), this, SLOT(updateState(int)));
}
}
......@@ -105,8 +101,6 @@ void UASControlWidget::setUAS(UASInterface* uas)
connect(ui.liftoffButton, SIGNAL(clicked()), uas, SLOT(launch()));
connect(ui.landButton, SIGNAL(clicked()), uas, SLOT(home()));
connect(ui.shutdownButton, SIGNAL(clicked()), uas, SLOT(shutdown()));
//connect(ui.setHomeButton, SIGNAL(clicked()), uas, SLOT(setLocalOriginAtCurrentGPSPosition()));
connect(uas, SIGNAL(modeChanged(int, QString, QString)), this, SLOT(updateMode(int, QString, QString)));
connect(uas, SIGNAL(statusChanged(int)), this, SLOT(updateState(int)));
ui.controlStatusLabel->setText(tr("Connected to ") + uas->getUASName());
......@@ -158,13 +152,6 @@ void UASControlWidget::setBackgroundColor(QColor color)
}
void UASControlWidget::updateMode(int uas, QString mode, QString description)
{
Q_UNUSED(uas);
Q_UNUSED(mode);
Q_UNUSED(description);
}
void UASControlWidget::updateState(int state)
{
switch (state) {
......@@ -178,45 +165,27 @@ void UASControlWidget::updateState(int state)
this->updateArmText();
}
/**
* Called by the button
*/
void UASControlWidget::setMode(int mode)
{
// Adapt context button mode
modeIdx = mode;
ui.modeComboBox->blockSignals(true);
ui.modeComboBox->setCurrentIndex(mode);
ui.modeComboBox->blockSignals(false);
emit changedMode(mode);
}
void UASControlWidget::transmitMode()
{
UASInterface* uas_iface = UASManager::instance()->getUASForId(this->uasID);
if (uas_iface) {
if (modeIdx >= 0 && modeIdx < _modeList.count()) {
AutoPilotPluginManager::FullMode_t fullMode = _modeList[modeIdx];
// include armed state
UAS* uas = dynamic_cast<UAS*>(UASManager::instance()->getUASForId(this->uasID));
if (uas) {
uint8_t base_mode;
uint32_t custom_mode;
QString flightMode = ui.modeComboBox->itemText(ui.modeComboBox->currentIndex());
if (FirmwarePluginManager::instance()->firmwarePluginForAutopilot((MAV_AUTOPILOT)uas->getAutopilotType())->setFlightMode(flightMode, &base_mode, &custom_mode)) {
if (armed) {
fullMode.baseMode |= MAV_MODE_FLAG_SAFETY_ARMED;
} else {
fullMode.baseMode &= ~MAV_MODE_FLAG_SAFETY_ARMED;
base_mode |= MAV_MODE_FLAG_SAFETY_ARMED;
}
UAS* uas = dynamic_cast<UAS*>(uas_iface);
if (uas->isHilEnabled() || uas->isHilActive()) {
fullMode.baseMode |= MAV_MODE_FLAG_HIL_ENABLED;
} else {
fullMode.baseMode &= ~MAV_MODE_FLAG_HIL_ENABLED;
base_mode |= MAV_MODE_FLAG_HIL_ENABLED;
}
uas->setMode(fullMode.baseMode, fullMode.customMode);
uas->setMode(base_mode, custom_mode);
QString modeText = ui.modeComboBox->currentText();
ui.lastActionLabel->setText(QString("Sent new mode %1 to %2").arg(modeText).arg(uas->getUASName()));
ui.lastActionLabel->setText(QString("Sent new mode %1 to %2").arg(flightMode).arg(uas->getUASName()));
}
}
}
......
......@@ -58,29 +58,20 @@ public slots:
void setUAS(UASInterface* uasID);
/** @brief Trigger next context action */
void cycleContextButton();
/** @brief Set the operation mode of the MAV */
void setMode(int mode);
/** @brief Transmit the operation mode */
void transmitMode();
/** @brief Update the mode */
void updateMode(int uasID, QString mode, QString description);
/** @brief Update state */
void updateState(int state);
/** @brief Update internal state machine */
void updateArmText();
signals:
void changedMode(int);
protected slots:
/** @brief Set the background color for the widget */
void setBackgroundColor(QColor color);
protected:
int uasID; ///< Reference to the current uas
QList<AutoPilotPluginManager::FullMode_t> _modeList; ///< Mode list for the current UAS
int modeIdx; ///< Current uas mode index
QStringList _modeList; ///< Mode list for the current UAS
bool armed; ///< Engine state
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment