2011-02-22 23:03:32 +01:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file configstabilizationwidget.h
|
|
|
|
* @author E. Lafargue & The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
|
|
|
* @{
|
|
|
|
* @addtogroup ConfigPlugin Config Plugin
|
|
|
|
* @{
|
|
|
|
* @brief The Configuration Gadget used to update settings in the firmware
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
#include "configstabilizationwidget.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QtGui/QWidget>
|
|
|
|
#include <QtGui/QTextEdit>
|
|
|
|
#include <QtGui/QVBoxLayout>
|
|
|
|
#include <QtGui/QPushButton>
|
2011-05-31 09:16:01 +02:00
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QUrl>
|
2011-02-22 23:03:32 +01:00
|
|
|
|
|
|
|
ConfigStabilizationWidget::ConfigStabilizationWidget(QWidget *parent) : ConfigTaskWidget(parent)
|
|
|
|
{
|
2011-02-24 00:06:35 +01:00
|
|
|
stabSettings = StabilizationSettings::GetInstance(getObjectManager());
|
|
|
|
|
2011-02-22 23:03:32 +01:00
|
|
|
m_stabilization = new Ui_StabilizationWidget();
|
|
|
|
m_stabilization->setupUi(this);
|
|
|
|
|
|
|
|
|
2011-08-02 18:06:17 +02:00
|
|
|
setupButtons(m_stabilization->saveStabilizationToRAM,m_stabilization->saveStabilizationToSD);
|
2011-02-22 23:03:32 +01:00
|
|
|
|
2011-08-02 18:06:17 +02:00
|
|
|
addUAVObject("StabilizationSettings");
|
2011-06-07 16:56:16 +02:00
|
|
|
|
2011-08-02 18:06:17 +02:00
|
|
|
refreshWidgetsValues();
|
2011-02-22 23:03:32 +01:00
|
|
|
|
2011-02-25 22:17:07 +01:00
|
|
|
// Create a timer to regularly send the object update in case
|
2011-02-24 00:06:35 +01:00
|
|
|
// we want realtime updates.
|
2011-08-02 18:06:17 +02:00
|
|
|
connect(&updateTimer, SIGNAL(timeout()), this, SLOT(updateObjectsFromWidgets()));
|
2011-02-25 22:17:07 +01:00
|
|
|
connect(m_stabilization->realTimeUpdates, SIGNAL(toggled(bool)), this, SLOT(realtimeUpdateToggle(bool)));
|
2011-02-24 00:06:35 +01:00
|
|
|
|
2011-02-25 22:17:07 +01:00
|
|
|
// Connect the updates of the stab values
|
|
|
|
connect(m_stabilization->rateRollKp, SIGNAL(valueChanged(double)), this, SLOT(updateRateRollKP(double)));
|
|
|
|
connect(m_stabilization->rateRollKi, SIGNAL(valueChanged(double)), this, SLOT(updateRateRollKI(double)));
|
|
|
|
connect(m_stabilization->rateRollILimit, SIGNAL(valueChanged(double)), this, SLOT(updateRateRollILimit(double)));
|
|
|
|
|
|
|
|
connect(m_stabilization->ratePitchKp, SIGNAL(valueChanged(double)), this, SLOT(updateRatePitchKP(double)));
|
|
|
|
connect(m_stabilization->ratePitchKi, SIGNAL(valueChanged(double)), this, SLOT(updateRatePitchKI(double)));
|
|
|
|
connect(m_stabilization->ratePitchILimit, SIGNAL(valueChanged(double)), this, SLOT(updateRatePitchILimit(double)));
|
|
|
|
|
|
|
|
connect(m_stabilization->rollKp, SIGNAL(valueChanged(double)), this, SLOT(updateRollKP(double)));
|
|
|
|
connect(m_stabilization->rollKi, SIGNAL(valueChanged(double)), this, SLOT(updateRollKI(double)));
|
|
|
|
connect(m_stabilization->rollILimit, SIGNAL(valueChanged(double)), this, SLOT(updateRollILimit(double)));
|
|
|
|
|
|
|
|
connect(m_stabilization->pitchKp, SIGNAL(valueChanged(double)), this, SLOT(updatePitchKP(double)));
|
|
|
|
connect(m_stabilization->pitchKi, SIGNAL(valueChanged(double)), this, SLOT(updatePitchKI(double)));
|
|
|
|
connect(m_stabilization->pitchILimit, SIGNAL(valueChanged(double)), this, SLOT(updatePitchILimit(double)));
|
2011-02-24 00:06:35 +01:00
|
|
|
|
2011-05-31 09:16:01 +02:00
|
|
|
// Connect the help button
|
|
|
|
connect(m_stabilization->stabilizationHelp, SIGNAL(clicked()), this, SLOT(openHelp()));
|
2011-08-02 18:06:17 +02:00
|
|
|
addWidget(m_stabilization->rateRollKp);
|
|
|
|
addWidget(m_stabilization->rateRollKi);
|
|
|
|
addWidget(m_stabilization->rateRollILimit);
|
|
|
|
addWidget(m_stabilization->ratePitchKp);
|
|
|
|
addWidget(m_stabilization->ratePitchKi);
|
|
|
|
addWidget(m_stabilization->ratePitchILimit);
|
|
|
|
addWidget(m_stabilization->rateYawKp);
|
|
|
|
addWidget(m_stabilization->rateYawKi);
|
|
|
|
addWidget(m_stabilization->rateYawILimit);
|
|
|
|
addWidget(m_stabilization->rollKp);
|
|
|
|
addWidget(m_stabilization->rollKi);
|
|
|
|
addWidget(m_stabilization->rollILimit);
|
|
|
|
addWidget(m_stabilization->yawILimit);
|
|
|
|
addWidget(m_stabilization->yawKi);
|
|
|
|
addWidget(m_stabilization->yawKp);
|
|
|
|
addWidget(m_stabilization->pitchKp);
|
|
|
|
addWidget(m_stabilization->pitchKi);
|
|
|
|
addWidget(m_stabilization->pitchILimit);
|
|
|
|
addWidget(m_stabilization->rollMax);
|
|
|
|
addWidget(m_stabilization->pitchMax);
|
|
|
|
addWidget(m_stabilization->yawMax);
|
|
|
|
addWidget(m_stabilization->manualRoll);
|
|
|
|
addWidget(m_stabilization->manualPitch);
|
|
|
|
addWidget(m_stabilization->manualYaw);
|
|
|
|
addWidget(m_stabilization->maximumRoll);
|
|
|
|
addWidget(m_stabilization->maximumPitch);
|
|
|
|
addWidget(m_stabilization->maximumYaw);
|
2011-08-15 15:12:54 +02:00
|
|
|
addWidget(m_stabilization->lowThrottleZeroIntegral);
|
|
|
|
|
2011-02-22 23:03:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ConfigStabilizationWidget::~ConfigStabilizationWidget()
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
2011-02-25 22:17:07 +01:00
|
|
|
void ConfigStabilizationWidget::updateRateRollKP(double val)
|
|
|
|
{
|
|
|
|
if (m_stabilization->linkRateRP->isChecked()) {
|
|
|
|
m_stabilization->ratePitchKp->setValue(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigStabilizationWidget::updateRateRollKI(double val)
|
|
|
|
{
|
|
|
|
if (m_stabilization->linkRateRP->isChecked()) {
|
|
|
|
m_stabilization->ratePitchKi->setValue(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigStabilizationWidget::updateRateRollILimit(double val)
|
|
|
|
{
|
|
|
|
if (m_stabilization->linkRateRP->isChecked()) {
|
|
|
|
m_stabilization->ratePitchILimit->setValue(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigStabilizationWidget::updateRatePitchKP(double val)
|
|
|
|
{
|
|
|
|
if (m_stabilization->linkRateRP->isChecked()) {
|
|
|
|
m_stabilization->rateRollKp->setValue(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigStabilizationWidget::updateRatePitchKI(double val)
|
|
|
|
{
|
|
|
|
if (m_stabilization->linkRateRP->isChecked()) {
|
|
|
|
m_stabilization->rateRollKi->setValue(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigStabilizationWidget::updateRatePitchILimit(double val)
|
|
|
|
{
|
|
|
|
if (m_stabilization->linkRateRP->isChecked()) {
|
|
|
|
m_stabilization->rateRollILimit->setValue(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigStabilizationWidget::updateRollKP(double val)
|
|
|
|
{
|
|
|
|
if (m_stabilization->linkAttitudeRP->isChecked()) {
|
|
|
|
m_stabilization->pitchKp->setValue(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigStabilizationWidget::updateRollKI(double val)
|
|
|
|
{
|
|
|
|
if (m_stabilization->linkAttitudeRP->isChecked()) {
|
|
|
|
m_stabilization->pitchKi->setValue(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigStabilizationWidget::updateRollILimit(double val)
|
|
|
|
{
|
|
|
|
if (m_stabilization->linkAttitudeRP->isChecked()) {
|
|
|
|
m_stabilization->pitchILimit->setValue(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigStabilizationWidget::updatePitchKP(double val)
|
|
|
|
{
|
|
|
|
if (m_stabilization->linkAttitudeRP->isChecked()) {
|
|
|
|
m_stabilization->rollKp->setValue(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigStabilizationWidget::updatePitchKI(double val)
|
|
|
|
{
|
|
|
|
if (m_stabilization->linkAttitudeRP->isChecked()) {
|
|
|
|
m_stabilization->rollKi->setValue(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigStabilizationWidget::updatePitchILimit(double val)
|
|
|
|
{
|
|
|
|
if (m_stabilization->linkAttitudeRP->isChecked()) {
|
|
|
|
m_stabilization->rollILimit->setValue(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-22 23:03:32 +01:00
|
|
|
/*******************************
|
|
|
|
* Stabilization Settings
|
|
|
|
*****************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
Request stabilization settings from the board
|
|
|
|
*/
|
2011-08-02 18:06:17 +02:00
|
|
|
void ConfigStabilizationWidget::refreshWidgetsValues()
|
2011-02-22 23:03:32 +01:00
|
|
|
{
|
2011-08-02 18:06:17 +02:00
|
|
|
bool dirty=isDirty();
|
2011-06-07 16:56:16 +02:00
|
|
|
// Not needed anymore as this slot is only called whenever we get
|
2011-06-05 18:40:52 +02:00
|
|
|
// a signal that the object was just updated
|
|
|
|
// stabSettings->requestUpdate();
|
2011-02-24 00:06:35 +01:00
|
|
|
StabilizationSettings::DataFields stabData = stabSettings->getData();
|
|
|
|
// Now fill in all the fields, this is fairly tedious:
|
2011-06-23 02:06:39 +02:00
|
|
|
m_stabilization->rateRollKp->setValue(stabData.RollRatePID[StabilizationSettings::ROLLRATEPID_KP]);
|
|
|
|
m_stabilization->rateRollKi->setValue(stabData.RollRatePID[StabilizationSettings::ROLLRATEPID_KI]);
|
|
|
|
m_stabilization->rateRollILimit->setValue(stabData.RollRatePID[StabilizationSettings::ROLLRATEPID_ILIMIT]);
|
2011-02-24 00:06:35 +01:00
|
|
|
|
2011-06-23 02:06:39 +02:00
|
|
|
m_stabilization->ratePitchKp->setValue(stabData.PitchRatePID[StabilizationSettings::PITCHRATEPID_KP]);
|
|
|
|
m_stabilization->ratePitchKi->setValue(stabData.PitchRatePID[StabilizationSettings::PITCHRATEPID_KI]);
|
|
|
|
m_stabilization->ratePitchILimit->setValue(stabData.PitchRatePID[StabilizationSettings::PITCHRATEPID_ILIMIT]);
|
2011-02-24 00:06:35 +01:00
|
|
|
|
2011-06-23 02:06:39 +02:00
|
|
|
m_stabilization->rateYawKp->setValue(stabData.YawRatePID[StabilizationSettings::YAWRATEPID_KP]);
|
|
|
|
m_stabilization->rateYawKi->setValue(stabData.YawRatePID[StabilizationSettings::YAWRATEPID_KI]);
|
|
|
|
m_stabilization->rateYawILimit->setValue(stabData.YawRatePID[StabilizationSettings::YAWRATEPID_ILIMIT]);
|
2011-02-24 00:06:35 +01:00
|
|
|
|
|
|
|
m_stabilization->rollKp->setValue(stabData.RollPI[StabilizationSettings::ROLLPI_KP]);
|
|
|
|
m_stabilization->rollKi->setValue(stabData.RollPI[StabilizationSettings::ROLLPI_KI]);
|
|
|
|
m_stabilization->rollILimit->setValue(stabData.RollPI[StabilizationSettings::ROLLPI_ILIMIT]);
|
|
|
|
|
|
|
|
m_stabilization->pitchKp->setValue(stabData.PitchPI[StabilizationSettings::PITCHPI_KP]);
|
|
|
|
m_stabilization->pitchKi->setValue(stabData.PitchPI[StabilizationSettings::PITCHPI_KI]);
|
|
|
|
m_stabilization->pitchILimit->setValue(stabData.PitchPI[StabilizationSettings::PITCHPI_ILIMIT]);
|
|
|
|
|
|
|
|
m_stabilization->yawKp->setValue(stabData.YawPI[StabilizationSettings::YAWPI_KP]);
|
|
|
|
m_stabilization->yawKi->setValue(stabData.YawPI[StabilizationSettings::YAWPI_KI]);
|
|
|
|
m_stabilization->yawILimit->setValue(stabData.YawPI[StabilizationSettings::YAWPI_ILIMIT]);
|
|
|
|
|
2011-02-26 00:05:23 +01:00
|
|
|
m_stabilization->rollMax->setValue(stabData.RollMax);
|
|
|
|
m_stabilization->pitchMax->setValue(stabData.PitchMax);
|
|
|
|
m_stabilization->yawMax->setValue(stabData.YawMax);
|
|
|
|
|
2011-06-09 13:12:03 +02:00
|
|
|
m_stabilization->manualRoll->setValue(stabData.ManualRate[StabilizationSettings::MANUALRATE_ROLL]);
|
|
|
|
m_stabilization->manualPitch->setValue(stabData.ManualRate[StabilizationSettings::MANUALRATE_PITCH]);
|
|
|
|
m_stabilization->manualYaw->setValue(stabData.ManualRate[StabilizationSettings::MANUALRATE_YAW]);
|
|
|
|
|
|
|
|
m_stabilization->maximumRoll->setValue(stabData.MaximumRate[StabilizationSettings::MAXIMUMRATE_ROLL]);
|
|
|
|
m_stabilization->maximumPitch->setValue(stabData.MaximumRate[StabilizationSettings::MAXIMUMRATE_PITCH]);
|
|
|
|
m_stabilization->maximumYaw->setValue(stabData.MaximumRate[StabilizationSettings::MAXIMUMRATE_YAW]);
|
2011-08-15 15:12:54 +02:00
|
|
|
m_stabilization->lowThrottleZeroIntegral->setChecked(stabData.LowThrottleZeroIntegral==StabilizationSettings::LOWTHROTTLEZEROINTEGRAL_TRUE ? true : false);
|
|
|
|
|
2011-08-02 18:06:17 +02:00
|
|
|
setDirty(dirty);
|
2011-02-22 23:03:32 +01:00
|
|
|
}
|
|
|
|
|
2011-02-24 00:06:35 +01:00
|
|
|
|
2011-02-22 23:03:32 +01:00
|
|
|
/**
|
|
|
|
Send telemetry settings to the board
|
|
|
|
*/
|
2011-02-24 00:06:35 +01:00
|
|
|
|
2011-08-02 18:06:17 +02:00
|
|
|
void ConfigStabilizationWidget::updateObjectsFromWidgets()
|
2011-02-22 23:03:32 +01:00
|
|
|
{
|
2011-02-24 00:06:35 +01:00
|
|
|
StabilizationSettings::DataFields stabData = stabSettings->getData();
|
|
|
|
|
2011-06-23 02:06:39 +02:00
|
|
|
stabData.RollRatePID[StabilizationSettings::ROLLRATEPID_KP] = m_stabilization->rateRollKp->value();
|
|
|
|
stabData.RollRatePID[StabilizationSettings::ROLLRATEPID_KI] = m_stabilization->rateRollKi->value();
|
|
|
|
stabData.RollRatePID[StabilizationSettings::ROLLRATEPID_ILIMIT] = m_stabilization->rateRollILimit->value();
|
2011-02-24 00:06:35 +01:00
|
|
|
|
2011-06-23 02:06:39 +02:00
|
|
|
stabData.PitchRatePID[StabilizationSettings::PITCHRATEPID_KP] = m_stabilization->ratePitchKp->value();
|
|
|
|
stabData.PitchRatePID[StabilizationSettings::PITCHRATEPID_KI] = m_stabilization->ratePitchKi->value();
|
|
|
|
stabData.PitchRatePID[StabilizationSettings::PITCHRATEPID_ILIMIT] = m_stabilization->ratePitchILimit->value();
|
2011-02-24 00:06:35 +01:00
|
|
|
|
2011-06-23 02:06:39 +02:00
|
|
|
stabData.YawRatePID[StabilizationSettings::YAWRATEPID_KP] = m_stabilization->rateYawKp->value();
|
|
|
|
stabData.YawRatePID[StabilizationSettings::YAWRATEPID_KI] = m_stabilization->rateYawKi->value();
|
|
|
|
stabData.YawRatePID[StabilizationSettings::YAWRATEPID_ILIMIT] = m_stabilization->rateYawILimit->value();
|
2011-02-24 00:06:35 +01:00
|
|
|
|
|
|
|
stabData.RollPI[StabilizationSettings::ROLLPI_KP] = m_stabilization->rollKp->value();
|
|
|
|
stabData.RollPI[StabilizationSettings::ROLLPI_KI] = m_stabilization->rollKi->value();
|
|
|
|
stabData.RollPI[StabilizationSettings::ROLLPI_ILIMIT] = m_stabilization->rollILimit->value();
|
|
|
|
|
|
|
|
stabData.PitchPI[StabilizationSettings::PITCHPI_KP] = m_stabilization->pitchKp->value();
|
|
|
|
stabData.PitchPI[StabilizationSettings::PITCHPI_KI] = m_stabilization->pitchKi->value();
|
|
|
|
stabData.PitchPI[StabilizationSettings::PITCHPI_ILIMIT] = m_stabilization->pitchILimit->value();
|
|
|
|
|
|
|
|
stabData.YawPI[StabilizationSettings::YAWPI_KP] = m_stabilization->yawKp->value();
|
|
|
|
stabData.YawPI[StabilizationSettings::YAWPI_KI] = m_stabilization->yawKi->value();
|
|
|
|
stabData.YawPI[StabilizationSettings::YAWPI_ILIMIT] = m_stabilization->yawILimit->value();
|
|
|
|
|
2011-02-26 00:05:23 +01:00
|
|
|
stabData.RollMax = m_stabilization->rollMax->value();
|
|
|
|
stabData.PitchMax = m_stabilization->pitchMax->value();
|
|
|
|
stabData.YawMax = m_stabilization->yawMax->value();
|
|
|
|
|
2011-06-09 13:12:03 +02:00
|
|
|
stabData.ManualRate[StabilizationSettings::MANUALRATE_ROLL] = m_stabilization->manualRoll->value();
|
|
|
|
stabData.ManualRate[StabilizationSettings::MANUALRATE_PITCH] = m_stabilization->manualPitch->value();
|
|
|
|
stabData.ManualRate[StabilizationSettings::MANUALRATE_YAW] = m_stabilization->manualYaw->value();
|
|
|
|
|
|
|
|
stabData.MaximumRate[StabilizationSettings::MAXIMUMRATE_ROLL] = m_stabilization->maximumRoll->value();
|
|
|
|
stabData.MaximumRate[StabilizationSettings::MAXIMUMRATE_PITCH] = m_stabilization->maximumPitch->value();
|
|
|
|
stabData.MaximumRate[StabilizationSettings::MAXIMUMRATE_YAW] = m_stabilization->maximumYaw->value();
|
|
|
|
|
2011-08-15 15:12:54 +02:00
|
|
|
stabData.LowThrottleZeroIntegral = (m_stabilization->lowThrottleZeroIntegral->isChecked() ? StabilizationSettings::LOWTHROTTLEZEROINTEGRAL_TRUE :StabilizationSettings::LOWTHROTTLEZEROINTEGRAL_FALSE);
|
|
|
|
|
|
|
|
|
2011-02-24 00:06:35 +01:00
|
|
|
stabSettings->setData(stabData); // this is atomic
|
2011-02-22 23:03:32 +01:00
|
|
|
}
|
2011-02-24 00:06:35 +01:00
|
|
|
|
2011-02-25 22:17:07 +01:00
|
|
|
void ConfigStabilizationWidget::realtimeUpdateToggle(bool state)
|
2011-02-24 09:58:21 +01:00
|
|
|
{
|
2011-06-05 18:40:52 +02:00
|
|
|
if (state) {
|
2011-02-25 22:17:07 +01:00
|
|
|
updateTimer.start(300);
|
2011-06-05 18:40:52 +02:00
|
|
|
} else {
|
2011-02-25 22:17:07 +01:00
|
|
|
updateTimer.stop();
|
2011-06-05 18:40:52 +02:00
|
|
|
}
|
2011-02-24 09:58:21 +01:00
|
|
|
}
|
2011-05-17 06:54:23 +02:00
|
|
|
|
2011-05-31 09:16:01 +02:00
|
|
|
void ConfigStabilizationWidget::openHelp()
|
|
|
|
{
|
|
|
|
|
|
|
|
QDesktopServices::openUrl( QUrl("http://wiki.openpilot.org/display/Doc/Stabilization+panel", QUrl::StrictMode) );
|
|
|
|
}
|
|
|
|
|