1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

Merge branch 'thread/OP-1590_PID_Bank_Management' into rel-14.10

This commit is contained in:
m_thread 2014-11-04 21:19:30 +01:00
commit 07a14c48ab
6 changed files with 263 additions and 27 deletions

View File

@ -3,7 +3,6 @@
<file>images/help2.png</file>
<file>images/ahrs-calib.svg</file>
<file>images/multirotor-shapes.svg</file>
<!-- these are different from the files in /setupwiz/resources -->
<file>images/fixedwing-shapes.svg</file>
<file>images/ccpm_setup.svg</file>
<file>images/PipXtreme.png</file>
@ -47,5 +46,6 @@
<file>images/calibration/empty.png</file>
<file>images/calibration/plane-swd.png</file>
<file>images/calibration/board-swd.png</file>
<file>images/gear.png</file>
</qresource>
</RCC>

View File

@ -37,6 +37,9 @@
#include <QList>
#include <QTabBar>
#include <QMessageBox>
#include <QToolButton>
#include <QMenu>
#include <QAction>
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/generalsettings.h>
@ -56,29 +59,7 @@ ConfigStabilizationWidget::ConfigStabilizationWidget(QWidget *parent) : ConfigTa
setupExpoPlot();
StabilizationSettings *stabSettings = qobject_cast<StabilizationSettings *>(getObject("StabilizationSettings"));
Q_ASSERT(stabSettings);
m_pidBankCount = stabSettings->getField("FlightModeMap")->getOptions().count();
// Set up fake tab widget stuff for pid banks support
m_pidTabBars.append(ui->basicPIDBankTabBar);
m_pidTabBars.append(ui->advancedPIDBankTabBar);
foreach(QTabBar * tabBar, m_pidTabBars) {
for (int i = 0; i < m_pidBankCount; i++) {
tabBar->addTab(tr("Settings Bank %1").arg(i + 1));
tabBar->setTabData(i, QString("StabilizationSettingsBank%1").arg(i + 1));
}
tabBar->setExpanding(false);
connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(pidBankChanged(int)));
}
for (int i = 0; i < m_pidBankCount; i++) {
if (i > 0) {
m_stabilizationObjectsString.append(",");
}
m_stabilizationObjectsString.append(m_pidTabBars.at(0)->tabData(i).toString());
}
setupPIDBanksGUI();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
Core::Internal::GeneralSettings *settings = pm->getObject<Core::Internal::GeneralSettings>();
@ -160,6 +141,92 @@ ConfigStabilizationWidget::ConfigStabilizationWidget(QWidget *parent) : ConfigTa
updateEnableControls();
}
void ConfigStabilizationWidget::setupPIDBanksGUI()
{
StabilizationSettings *stabSettings = qobject_cast<StabilizationSettings *>(getObject("StabilizationSettings"));
Q_ASSERT(stabSettings);
m_pidBankCount = stabSettings->getField("FlightModeMap")->getOptions().count();
// Set up fake tab widget stuff for pid banks support
m_pidTabBars.append(ui->basicPIDBankTabBar);
m_pidTabBars.append(ui->advancedPIDBankTabBar);
m_defaultPIDMenuAction = new QAction(QIcon(":configgadget/images/gear.png"), QString(), this);
QAction *restoreAllAction = new QAction(tr("Restore all to saved"), this);
connect(restoreAllAction, SIGNAL(triggered()), this, SLOT(restoreAllPIDBanks()));
QAction *resetAllAction = new QAction(tr("Reset all to default"), this);
connect(resetAllAction, SIGNAL(triggered()), this, SLOT(resetAllPIDBanks()));
QAction *restoreCurrentAction = new QAction(tr("Restore to saved"), this);
connect(restoreCurrentAction, SIGNAL(triggered()), this, SLOT(restoreCurrentAction()));
QAction *resetCurrentAction = new QAction(tr("Reset to default"), this);
connect(resetCurrentAction, SIGNAL(triggered()), this, SLOT(resetCurrentPIDBank()));
QAction *copyCurrentAction = new QAction(tr("Copy to others"), this);
connect(copyCurrentAction, SIGNAL(triggered()), this, SLOT(copyCurrentPIDBank()));
connect(&m_PIDCopyFromSignalMapper, SIGNAL(mapped(int)), this, SLOT(copyFromBankToCurrent(int)));
connect(&m_PIDCopyToSignalMapper, SIGNAL(mapped(int)), this, SLOT(copyToBankFromCurrent(int)));
connect(&m_PIDSwapSignalMapper, SIGNAL(mapped(int)), this, SLOT(swapBankAndCurrent(int)));
foreach(QTabBar * tabBar, m_pidTabBars) {
for (int i = 0; i < m_pidBankCount; i++) {
tabBar->addTab(tr("Settings Bank %1").arg(i + 1));
tabBar->setTabData(i, QString("StabilizationSettingsBank%1").arg(i + 1));
QToolButton *tabButton = new QToolButton();
connect(this, SIGNAL(enableControlsChanged(bool)), tabButton, SLOT(setEnabled(bool)));
tabButton->setDefaultAction(m_defaultPIDMenuAction);
tabButton->setAutoRaise(true);
tabButton->setPopupMode(QToolButton::InstantPopup);
tabButton->setToolTip(tr("The actions in this menu acts on all fields in the settings banks,\n"
"not only the ones visible on this tab or in this GUI."));
QMenu *tabMenu = new QMenu();
QMenu *restoreMenu = new QMenu(tr("Restore"));
QMenu *resetMenu = new QMenu(tr("Reset"));
QMenu *copyMenu = new QMenu(tr("Copy"));
QMenu *swapMenu = new QMenu(tr("Swap"));
QAction *menuAction;
for (int j = 0; j < m_pidBankCount; j++) {
if (j == i) {
restoreMenu->addAction(restoreCurrentAction);
resetMenu->addAction(resetCurrentAction);
copyMenu->addAction(copyCurrentAction);
} else {
menuAction = new QAction(tr("Copy from %1").arg(j + 1), this);
connect(menuAction, SIGNAL(triggered()), &m_PIDCopyFromSignalMapper, SLOT(map()));
m_PIDCopyFromSignalMapper.setMapping(menuAction, j);
copyMenu->addAction(menuAction);
menuAction = new QAction(tr("Copy to %1").arg(j + 1), this);
connect(menuAction, SIGNAL(triggered()), &m_PIDCopyToSignalMapper, SLOT(map()));
m_PIDCopyToSignalMapper.setMapping(menuAction, j);
copyMenu->addAction(menuAction);
menuAction = new QAction(tr("Swap with %1").arg(j + 1), this);
connect(menuAction, SIGNAL(triggered()), &m_PIDSwapSignalMapper, SLOT(map()));
m_PIDSwapSignalMapper.setMapping(menuAction, j);
swapMenu->addAction(menuAction);
}
}
restoreMenu->addAction(restoreAllAction);
resetMenu->addAction(resetAllAction);
tabMenu->addMenu(copyMenu);
tabMenu->addMenu(swapMenu);
tabMenu->addMenu(resetMenu);
tabMenu->addMenu(restoreMenu);
tabButton->setMenu(tabMenu);
tabBar->setTabButton(i, QTabBar::RightSide, tabButton);
}
tabBar->setExpanding(false);
connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(pidBankChanged(int)));
}
for (int i = 0; i < m_pidBankCount; i++) {
if (i > 0) {
m_stabilizationObjectsString.append(",");
}
m_stabilizationObjectsString.append(m_pidTabBars.at(0)->tabData(i).toString());
}
}
ConfigStabilizationWidget::~ConfigStabilizationWidget()
{
// Do nothing
@ -168,7 +235,6 @@ ConfigStabilizationWidget::~ConfigStabilizationWidget()
void ConfigStabilizationWidget::refreshWidgetsValues(UAVObject *o)
{
ConfigTaskWidget::refreshWidgetsValues(o);
updateThrottleCurveFromObject();
ui->basicResponsivenessCheckBox->setChecked(ui->rateRollKp_3->value() == ui->ratePitchKp_4->value() &&
@ -340,6 +406,138 @@ void ConfigStabilizationWidget::replotExpoYaw(int value)
replotExpo(value, m_expoPlotCurveYaw);
}
void ConfigStabilizationWidget::restoreAllPIDBanks()
{
qDebug() << "restoreAllPIDBanks";
for (int i = 0; i < m_pidBankCount; i++) {
restoreStabBank(i);
}
}
void ConfigStabilizationWidget::resetAllPIDBanks()
{
qDebug() << "resetAllPIDBanks";
for (int i = 0; i < m_pidBankCount; i++) {
resetStabBank(i);
}
}
void ConfigStabilizationWidget::restoreCurrentAction()
{
qDebug() << "restoreCurrentAction";
restoreStabBank(m_currentPIDBank);
}
void ConfigStabilizationWidget::resetStabBank(int bank)
{
UAVDataObject *stabBankObject =
dynamic_cast<UAVDataObject *>(getObject(QString("StabilizationSettingsBank%1").arg(bank + 1)));
if (stabBankObject) {
UAVDataObject * defaultStabBankObject = stabBankObject->dirtyClone();
quint8 data[stabBankObject->getNumBytes()];
defaultStabBankObject->pack(data);
stabBankObject->unpack(data);
}
}
void ConfigStabilizationWidget::restoreStabBank(int bank)
{
UAVObject *stabBankObject =
getObject(QString("StabilizationSettingsBank%1").arg(bank + 1));
if (stabBankObject) {
ObjectPersistence *objectPersistenceObject = ObjectPersistence::GetInstance(getObjectManager());
QTimer updateTimer(this);
QEventLoop eventLoop(this);
connect(&updateTimer, SIGNAL(timeout()), &eventLoop, SLOT(quit()));
connect(objectPersistenceObject, SIGNAL(objectUpdated(UAVObject *)), &eventLoop, SLOT(quit()));
ObjectPersistence::DataFields data;
data.Operation = ObjectPersistence::OPERATION_LOAD;
data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT;
data.ObjectID = stabBankObject->getObjID();
data.InstanceID = stabBankObject->getInstID();
objectPersistenceObject->setData(data);
objectPersistenceObject->updated();
updateTimer.start(500);
eventLoop.exec();
if (updateTimer.isActive()) {
stabBankObject->requestUpdate();
}
updateTimer.stop();
}
}
void ConfigStabilizationWidget::resetCurrentPIDBank()
{
qDebug() << "resetCurrentPIDBank";
resetStabBank(m_currentPIDBank);
}
void ConfigStabilizationWidget::copyCurrentPIDBank()
{
qDebug() << "copyCurrentPIDBank";
UAVObject *fromStabBankObject =
getObject(QString("StabilizationSettingsBank%1").arg(m_currentPIDBank + 1));
if (fromStabBankObject) {
quint8 fromStabBankObjectData[fromStabBankObject->getNumBytes()];
fromStabBankObject->pack(fromStabBankObjectData);
for (int i = 0; i < m_pidBankCount; i++) {
if (i != m_currentPIDBank) {
UAVObject *toStabBankObject =
getObject(QString("StabilizationSettingsBank%1").arg(i + 1));
if (toStabBankObject) {
toStabBankObject->unpack(fromStabBankObjectData);
}
}
}
}
}
void ConfigStabilizationWidget::copyFromBankToCurrent(int bank)
{
qDebug() << "copyFromBankToCurrent" << bank;
UAVObject *fromStabBankObject =
getObject(QString("StabilizationSettingsBank%1").arg(bank + 1));
UAVObject *toStabBankObject =
getObject(QString("StabilizationSettingsBank%1").arg(m_currentPIDBank + 1));
if (fromStabBankObject && toStabBankObject) {
quint8 data[fromStabBankObject->getNumBytes()];
fromStabBankObject->pack(data);
toStabBankObject->unpack(data);
}
}
void ConfigStabilizationWidget::copyToBankFromCurrent(int bank)
{
qDebug() << "copyToBankFromCurrent" << bank;
UAVObject *fromStabBankObject =
getObject(QString("StabilizationSettingsBank%1").arg(m_currentPIDBank + 1));
UAVObject *toStabBankObject =
getObject(QString("StabilizationSettingsBank%1").arg(bank + 1));
if (fromStabBankObject && toStabBankObject) {
quint8 data[fromStabBankObject->getNumBytes()];
fromStabBankObject->pack(data);
toStabBankObject->unpack(data);
}
}
void ConfigStabilizationWidget::swapBankAndCurrent(int bank)
{
qDebug() << "swapBankAndCurrent" << bank;
UAVObject *fromStabBankObject =
getObject(QString("StabilizationSettingsBank%1").arg(m_currentPIDBank + 1));
UAVObject *toStabBankObject =
getObject(QString("StabilizationSettingsBank%1").arg(bank + 1));
if (fromStabBankObject && toStabBankObject) {
quint8 fromStabBankObjectData[fromStabBankObject->getNumBytes()];
quint8 toStabBankObjectData[toStabBankObject->getNumBytes()];
fromStabBankObject->pack(fromStabBankObjectData);
toStabBankObject->pack(toStabBankObjectData);
toStabBankObject->unpack(fromStabBankObjectData);
fromStabBankObject->unpack(toStabBankObjectData);
}
}
void ConfigStabilizationWidget::realtimeUpdatesSlot(bool value)
{
ui->realTimeUpdates_6->setChecked(value);

View File

@ -35,6 +35,7 @@
#include "stabilizationsettings.h"
#include <QWidget>
#include <QTimer>
#include <QSignalMapper>
#include "qwt/src/qwt_plot_curve.h"
#include "qwt/src/qwt_plot_grid.h"
@ -51,6 +52,7 @@ private:
QTimer *realtimeUpdates;
QList<QTabBar *> m_pidTabBars;
QString m_stabilizationObjectsString;
QAction *m_defaultPIDMenuAction;
// Milliseconds between automatic 'Instant Updates'
static const int AUTOMATIC_UPDATE_RATE = 500;
@ -66,10 +68,17 @@ private:
QwtPlotCurve m_expoPlotCurvePitch;
QwtPlotCurve m_expoPlotCurveYaw;
QwtPlotGrid m_plotGrid;
QSignalMapper m_PIDCopyFromSignalMapper;
QSignalMapper m_PIDCopyToSignalMapper;
QSignalMapper m_PIDSwapSignalMapper;
void updateThrottleCurveFromObject();
void updateObjectFromThrottleCurve();
void setupExpoPlot();
void setupPIDBanksGUI();
void resetStabBank(int bank);
void restoreStabBank(int bank);
protected:
QString mapObjectName(const QString objectName);
@ -89,5 +98,15 @@ private slots:
void replotExpoRoll(int value);
void replotExpoPitch(int value);
void replotExpoYaw(int value);
void restoreAllPIDBanks();
void resetAllPIDBanks();
void restoreCurrentAction();
void resetCurrentPIDBank();
void copyCurrentPIDBank();
void copyFromBankToCurrent(int bank);
void copyToBankFromCurrent(int bank);
void swapBankAndCurrent(int bank);
};
#endif // ConfigStabilizationWidget_H

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -31,6 +31,7 @@
#include <QWidget>
#include <QLineEdit>
#include <QToolButton>
ConfigTaskWidget::ConfigTaskWidget(QWidget *parent) : QWidget(parent), m_currentBoardId(-1), m_isConnected(false), m_isWidgetUpdatesAllowed(true),
m_saveButton(NULL), m_isDirty(false), m_outOfLimitsStyle("background-color: rgb(255, 0, 0);"), m_realtimeUpdateTimer(NULL)
@ -294,8 +295,12 @@ void ConfigTaskWidget::refreshWidgetsValues(UAVObject *obj)
emit refreshWidgetsValuesRequested();
QList<WidgetBinding *> bindings = obj == NULL ? m_widgetBindingsPerObject.values() : m_widgetBindingsPerObject.values(obj);
foreach(WidgetBinding * binding, bindings) {
if (binding->isEnabled() && binding->field() != NULL && binding->widget() != NULL) {
setWidgetFromField(binding->widget(), binding->field(), binding);
if (binding->field() != NULL && binding->widget() != NULL) {
if (binding->isEnabled()) {
setWidgetFromField(binding->widget(), binding->field(), binding);
} else {
binding->updateValueFromObjectField();
}
}
}
setDirty(dirtyBack);
@ -361,6 +366,7 @@ void ConfigTaskWidget::enableControls(bool enable)
}
}
}
emit enableControlsChanged(enable);
}
bool ConfigTaskWidget::shouldObjectBeSaved(UAVObject *object)
@ -809,6 +815,8 @@ void ConfigTaskWidget::connectWidgetUpdatesToSlot(QWidget *widget, const char *f
connect(cb, SIGNAL(stateChanged(int)), this, function, Qt::UniqueConnection);
} else if (QPushButton * cb = qobject_cast<QPushButton *>(widget)) {
connect(cb, SIGNAL(clicked()), this, function, Qt::UniqueConnection);
} else if (QToolButton * cb = qobject_cast<QToolButton *>(widget)) {
connect(cb, SIGNAL(clicked()), this, function, Qt::UniqueConnection);
} else {
qDebug() << __FUNCTION__ << "widget binding not implemented" << widget->metaObject()->className();
}
@ -837,6 +845,8 @@ void ConfigTaskWidget::disconnectWidgetUpdatesToSlot(QWidget *widget, const char
disconnect(cb, SIGNAL(stateChanged(int)), this, function);
} else if (QPushButton * cb = qobject_cast<QPushButton *>(widget)) {
disconnect(cb, SIGNAL(clicked()), this, function);
} else if (QToolButton * cb = qobject_cast<QToolButton *>(widget)) {
disconnect(cb, SIGNAL(clicked()), this, function);
} else {
qDebug() << __FUNCTION__ << "widget binding not implemented" << widget->metaObject()->className();
}
@ -1201,6 +1211,13 @@ void WidgetBinding::updateObjectFieldFromValue()
}
}
void WidgetBinding::updateValueFromObjectField()
{
if (m_field->getValue(m_index).isValid()) {
m_value = m_field->getValue(m_index);
}
}
ShadowWidgetBinding::ShadowWidgetBinding(QWidget *widget, double scale, bool isLimited)
{
m_widget = widget;

View File

@ -86,6 +86,7 @@ public:
void setValue(const QVariant &value);
void updateObjectFieldFromValue();
void updateValueFromObjectField();
private:
UAVObject *m_object;
@ -173,6 +174,7 @@ signals:
// fired when the autopilot disconnects
void autoPilotDisconnected();
void defaultRequested(int group);
void enableControlsChanged(bool enable);
private slots:
void objectUpdated(UAVObject *object);