1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

CameraStab UI: use ConfigTaskWidget API with objrelation dynamic property

This supports most of widgets which are directly related to UAVObjects.
This commit is contained in:
Oleg Semyonov 2012-08-13 10:13:35 +03:00
parent 08034df50e
commit a0977b405b
3 changed files with 226 additions and 134 deletions

View File

@ -27,8 +27,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>696</width>
<height>635</height>
<width>702</width>
<height>660</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
@ -107,6 +107,16 @@ have to define channel output range using Output configuration tab.</string>
<property name="value">
<number>20</number>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:OutputRange</string>
<string>element:Yaw</string>
<string>haslimits:no</string>
<string>scale:1</string>
<string>buttongroup:1</string>
</stringlist>
</property>
</widget>
</item>
<item row="2" column="2">
@ -126,6 +136,16 @@ have to define channel output range using Output configuration tab.</string>
<property name="value">
<number>20</number>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:OutputRange</string>
<string>element:Pitch</string>
<string>haslimits:no</string>
<string>scale:1</string>
<string>buttongroup:1</string>
</stringlist>
</property>
</widget>
</item>
<item row="2" column="1">
@ -145,6 +165,16 @@ have to define channel output range using Output configuration tab.</string>
<property name="value">
<number>20</number>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:OutputRange</string>
<string>element:Roll</string>
<string>haslimits:no</string>
<string>scale:1</string>
<string>buttongroup:1</string>
</stringlist>
</property>
</widget>
</item>
<item row="1" column="3">
@ -339,6 +369,14 @@ margin:1px;</string>
Don't forget to map this channel using Input configuration tab.</string>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:Input</string>
<string>element:Yaw</string>
<string>buttongroup:1</string>
</stringlist>
</property>
<item>
<property name="text">
<string>None</string>
@ -356,6 +394,14 @@ Don't forget to map this channel using Input configuration tab.</string>
Don't forget to map this channel using Input configuration tab.</string>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:Input</string>
<string>element:Pitch</string>
<string>buttongroup:1</string>
</stringlist>
</property>
<item>
<property name="text">
<string>None</string>
@ -373,6 +419,14 @@ Don't forget to map this channel using Input configuration tab.</string>
Don't forget to map this channel using Input configuration tab.</string>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:Input</string>
<string>element:Roll</string>
<string>buttongroup:1</string>
</stringlist>
</property>
<item>
<property name="text">
<string>None</string>
@ -398,6 +452,14 @@ Don't forget to map this channel using Input configuration tab.</string>
Attitude: camera tracks level for the axis. Input controls the deflection.
AxisLock: camera remembers tracking attitude. Input controls the rate of deflection.</string>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:StabilizationMode</string>
<string>element:Yaw</string>
<string>buttongroup:1</string>
</stringlist>
</property>
<item>
<property name="text">
<string>Attitude</string>
@ -419,6 +481,16 @@ AxisLock: camera remembers tracking attitude. Input controls the rate of deflect
<property name="value">
<number>20</number>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:InputRange</string>
<string>element:Yaw</string>
<string>haslimits:no</string>
<string>scale:1</string>
<string>buttongroup:1</string>
</stringlist>
</property>
</widget>
</item>
<item row="4" column="3">
@ -435,6 +507,16 @@ AxisLock: camera remembers tracking attitude. Input controls the rate of deflect
<property name="value">
<number>50</number>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:InputRate</string>
<string>element:Yaw</string>
<string>haslimits:no</string>
<string>scale:1</string>
<string>buttongroup:1</string>
</stringlist>
</property>
</widget>
</item>
<item row="5" column="3">
@ -453,6 +535,16 @@ This option smoothes the stick input. Zero value disables LPF.</string>
<property name="value">
<number>150</number>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:ResponseTime</string>
<string>element:Yaw</string>
<string>haslimits:no</string>
<string>scale:1</string>
<string>buttongroup:1</string>
</stringlist>
</property>
</widget>
</item>
<item row="2" column="2">
@ -466,6 +558,14 @@ This option smoothes the stick input. Zero value disables LPF.</string>
Attitude: camera tracks level for the axis. Input controls the deflection.
AxisLock: camera remembers tracking attitude. Input controls the rate of deflection.</string>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:StabilizationMode</string>
<string>element:Pitch</string>
<string>buttongroup:1</string>
</stringlist>
</property>
<item>
<property name="text">
<string>Attitude</string>
@ -487,6 +587,16 @@ AxisLock: camera remembers tracking attitude. Input controls the rate of deflect
<property name="value">
<number>20</number>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:InputRange</string>
<string>element:Pitch</string>
<string>haslimits:no</string>
<string>scale:1</string>
<string>buttongroup:1</string>
</stringlist>
</property>
</widget>
</item>
<item row="4" column="2">
@ -503,6 +613,16 @@ AxisLock: camera remembers tracking attitude. Input controls the rate of deflect
<property name="value">
<number>50</number>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:InputRate</string>
<string>element:Pitch</string>
<string>haslimits:no</string>
<string>scale:1</string>
<string>buttongroup:1</string>
</stringlist>
</property>
</widget>
</item>
<item row="5" column="2">
@ -521,6 +641,16 @@ This option smoothes the stick input. Zero value disables LPF.</string>
<property name="value">
<number>150</number>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:ResponseTime</string>
<string>element:Pitch</string>
<string>haslimits:no</string>
<string>scale:1</string>
<string>buttongroup:1</string>
</stringlist>
</property>
</widget>
</item>
<item row="2" column="1">
@ -534,6 +664,14 @@ This option smoothes the stick input. Zero value disables LPF.</string>
Attitude: camera tracks level for the axis. Input controls the deflection.
AxisLock: camera remembers tracking attitude. Input controls the rate of deflection.</string>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:StabilizationMode</string>
<string>element:Roll</string>
<string>buttongroup:1</string>
</stringlist>
</property>
<item>
<property name="text">
<string>Attitude</string>
@ -555,6 +693,16 @@ AxisLock: camera remembers tracking attitude. Input controls the rate of deflect
<property name="value">
<number>20</number>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:InputRange</string>
<string>element:Roll</string>
<string>haslimits:no</string>
<string>scale:1</string>
<string>buttongroup:1</string>
</stringlist>
</property>
</widget>
</item>
<item row="4" column="1">
@ -571,6 +719,16 @@ AxisLock: camera remembers tracking attitude. Input controls the rate of deflect
<property name="value">
<number>50</number>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:InputRate</string>
<string>element:Roll</string>
<string>haslimits:no</string>
<string>scale:1</string>
<string>buttongroup:1</string>
</stringlist>
</property>
</widget>
</item>
<item row="5" column="1">
@ -589,6 +747,16 @@ This option smoothes the stick input. Zero value disables LPF.</string>
<property name="value">
<number>150</number>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:ResponseTime</string>
<string>element:Roll</string>
<string>haslimits:no</string>
<string>scale:1</string>
<string>buttongroup:1</string>
</stringlist>
</property>
</widget>
</item>
<item row="6" column="0">
@ -657,6 +825,15 @@ value.</string>
<property name="value">
<double>1.000000000000000</double>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>objname:CameraStabSettings</string>
<string>fieldname:MaxAxisLockRate</string>
<string>haslimits:no</string>
<string>scale:1</string>
<string>buttongroup:1</string>
</stringlist>
</property>
</widget>
</item>
</layout>
@ -754,6 +931,32 @@ value.</string>
<property name="flat">
<bool>true</bool>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>button:help</string>
<string>url:http://wiki.openpilot.org/display/Doc/Camera+Stabilization+Configuration</string>
</stringlist>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="toolTip">
<string>Reloads current data from board into GCS.
Useful if you have accidentally changed some settings.
Loaded settings are not applied automatically. You have to click the
Apply or Save button afterwards.</string>
</property>
<property name="text">
<string>Reload Board Data</string>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>button:reload</string>
<string>buttongroup:1</string>
</stringlist>
</property>
</widget>
</item>
<item>
@ -767,6 +970,12 @@ Apply or Save button afterwards.</string>
<property name="text">
<string>Reset To Defaults</string>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>button:default</string>
<string>buttongroup:1</string>
</stringlist>
</property>
</widget>
</item>
<item>
@ -777,6 +986,11 @@ Apply or Save button afterwards.</string>
<property name="text">
<string>Apply</string>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>button:apply</string>
</stringlist>
</property>
</widget>
</item>
<item>
@ -790,6 +1004,11 @@ Apply or Save button afterwards.</string>
<property name="checked">
<bool>false</bool>
</property>
<property name="objrelation" stdset="0">
<stringlist>
<string>button:save</string>
</stringlist>
</property>
</widget>
</item>
</layout>

View File

@ -36,60 +36,26 @@
ConfigCameraStabilizationWidget::ConfigCameraStabilizationWidget(QWidget *parent) : ConfigTaskWidget(parent)
{
// TODO: this widget should use the addUAVObjectToWidgetRelation()
m_camerastabilization = new Ui_CameraStabilizationWidget();
m_camerastabilization->setupUi(this);
// These comboboxes require special processing
QComboBox *outputs[3] = {
m_camerastabilization->rollChannel,
m_camerastabilization->pitchChannel,
m_camerastabilization->yawChannel,
};
QComboBox *inputs[3] = {
m_camerastabilization->rollInputChannel,
m_camerastabilization->pitchInputChannel,
m_camerastabilization->yawInputChannel,
};
QComboBox *stabilizationMode[3] = {
m_camerastabilization->rollStabilizationMode,
m_camerastabilization->pitchStabilizationMode,
m_camerastabilization->yawStabilizationMode,
};
CameraStabSettings *cameraStab = CameraStabSettings::GetInstance(getObjectManager());
CameraStabSettings::DataFields cameraStabData = cameraStab->getData();
for (int i = 0; i < 3; i++) {
outputs[i]->clear();
outputs[i]->addItem("None");
for (quint32 j = 0; j < ActuatorCommand::CHANNEL_NUMELEM; j++)
outputs[i]->addItem(QString("Channel %1").arg(j+1));
UAVObjectField *field;
field = cameraStab->getField("Input");
Q_ASSERT(field);
inputs[i]->clear();
inputs[i]->addItems(field->getOptions());
inputs[i]->setCurrentIndex(cameraStabData.Input[i]);
field = cameraStab->getField("StabilizationMode");
Q_ASSERT(field);
stabilizationMode[i]->clear();
stabilizationMode[i]->addItems(field->getOptions());
stabilizationMode[i]->setCurrentIndex(cameraStabData.StabilizationMode[i]);
}
connectUpdates();
// Connect buttons
connect(m_camerastabilization->camerastabilizationResetToDefaults, SIGNAL(clicked()), this, SLOT(resetToDefaults()));
connect(m_camerastabilization->camerastabilizationSaveRAM, SIGNAL(clicked()), this, SLOT(applySettings()));
connect(m_camerastabilization->camerastabilizationSaveSD, SIGNAL(clicked()), this, SLOT(saveSettings()));
connect(m_camerastabilization->camerastabilizationHelp, SIGNAL(clicked()), this, SLOT(openHelp()));
autoLoadWidgets();
populateWidgets();
refreshWidgetsValues();
disableMouseWheelEvents();
}
@ -102,7 +68,6 @@ void ConfigCameraStabilizationWidget::connectUpdates()
{
// Now connect the widget to the StabilizationSettings object
connect(MixerSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues()));
connect(CameraStabSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues()));
// TODO: This will need to support both CC and OP later
connect(HwSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues()));
}
@ -111,7 +76,6 @@ void ConfigCameraStabilizationWidget::disconnectUpdates()
{
// Now connect the widget to the StabilizationSettings object
disconnect(MixerSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues()));
disconnect(CameraStabSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues()));
// TODO: This will need to support both CC and OP later
disconnect(HwSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues()));
}
@ -182,36 +146,6 @@ void ConfigCameraStabilizationWidget::applySettings()
}
}
// Update the settings
CameraStabSettings *cameraStab = CameraStabSettings::GetInstance(getObjectManager());
CameraStabSettings::DataFields cameraStabData = cameraStab->getData();
cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_ROLL] = m_camerastabilization->rollOutputRange->value();
cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_PITCH] = m_camerastabilization->pitchOutputRange->value();
cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_YAW] = m_camerastabilization->yawOutputRange->value();
cameraStabData.Input[CameraStabSettings::INPUT_ROLL] = m_camerastabilization->rollInputChannel->currentIndex();
cameraStabData.Input[CameraStabSettings::INPUT_PITCH] = m_camerastabilization->pitchInputChannel->currentIndex();
cameraStabData.Input[CameraStabSettings::INPUT_YAW] = m_camerastabilization->yawInputChannel->currentIndex();
cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_ROLL] = m_camerastabilization->rollStabilizationMode->currentIndex();
cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_PITCH] = m_camerastabilization->pitchStabilizationMode->currentIndex();
cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_YAW] = m_camerastabilization->yawStabilizationMode->currentIndex();
cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_ROLL] = m_camerastabilization->rollInputRange->value();
cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_PITCH] = m_camerastabilization->pitchInputRange->value();
cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_YAW] = m_camerastabilization->yawInputRange->value();
cameraStabData.InputRate[CameraStabSettings::INPUTRATE_ROLL] = m_camerastabilization->rollInputRate->value();
cameraStabData.InputRate[CameraStabSettings::INPUTRATE_PITCH] = m_camerastabilization->pitchInputRate->value();
cameraStabData.InputRate[CameraStabSettings::INPUTRATE_YAW] = m_camerastabilization->yawInputRate->value();
cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_ROLL] = m_camerastabilization->rollResponseTime->value();
cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_PITCH] = m_camerastabilization->pitchResponseTime->value();
cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_YAW] = m_camerastabilization->yawResponseTime->value();
cameraStabData.MaxAxisLockRate = m_camerastabilization->MaxAxisLockRate->value();
// Because multiple objects are updated, and all of them trigger the callback
// they must be done together (if update one then load settings from second
// the first update would wipe the UI controls). However to be extra cautious
@ -219,7 +153,6 @@ void ConfigCameraStabilizationWidget::applySettings()
disconnectUpdates();
hwSettings->setData(hwSettingsData);
mixerSettings->setData(mixerSettingsData);
cameraStab->setData(cameraStabData);
connectUpdates();
}
@ -237,40 +170,6 @@ void ConfigCameraStabilizationWidget::saveSettings()
saveObjectToSD(obj);
}
/**
* Refresh UI with new settings of CameraStabSettings object
* (either from active configuration or just loaded defaults
* to be applied or saved)
*/
void ConfigCameraStabilizationWidget::refreshUIValues(CameraStabSettings::DataFields &cameraStabData)
{
m_camerastabilization->rollOutputRange->setValue(cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_ROLL]);
m_camerastabilization->pitchOutputRange->setValue(cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_PITCH]);
m_camerastabilization->yawOutputRange->setValue(cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_YAW]);
m_camerastabilization->rollInputChannel->setCurrentIndex(cameraStabData.Input[CameraStabSettings::INPUT_ROLL]);
m_camerastabilization->pitchInputChannel->setCurrentIndex(cameraStabData.Input[CameraStabSettings::INPUT_PITCH]);
m_camerastabilization->yawInputChannel->setCurrentIndex(cameraStabData.Input[CameraStabSettings::INPUT_YAW]);
m_camerastabilization->rollStabilizationMode->setCurrentIndex(cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_ROLL]);
m_camerastabilization->pitchStabilizationMode->setCurrentIndex(cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_PITCH]);
m_camerastabilization->yawStabilizationMode->setCurrentIndex(cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_YAW]);
m_camerastabilization->rollInputRange->setValue(cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_ROLL]);
m_camerastabilization->pitchInputRange->setValue(cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_PITCH]);
m_camerastabilization->yawInputRange->setValue(cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_YAW]);
m_camerastabilization->rollInputRate->setValue(cameraStabData.InputRate[CameraStabSettings::INPUTRATE_ROLL]);
m_camerastabilization->pitchInputRate->setValue(cameraStabData.InputRate[CameraStabSettings::INPUTRATE_PITCH]);
m_camerastabilization->yawInputRate->setValue(cameraStabData.InputRate[CameraStabSettings::INPUTRATE_YAW]);
m_camerastabilization->rollResponseTime->setValue(cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_ROLL]);
m_camerastabilization->pitchResponseTime->setValue(cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_PITCH]);
m_camerastabilization->yawResponseTime->setValue(cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_YAW]);
m_camerastabilization->MaxAxisLockRate->setValue(cameraStabData.MaxAxisLockRate);
}
void ConfigCameraStabilizationWidget::refreshValues()
{
HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager());
@ -279,10 +178,6 @@ void ConfigCameraStabilizationWidget::refreshValues()
hwSettingsData.OptionalModules[HwSettings::OPTIONALMODULES_CAMERASTAB] ==
HwSettings::OPTIONALMODULES_ENABLED);
CameraStabSettings *cameraStabSettings = CameraStabSettings::GetInstance(getObjectManager());
CameraStabSettings::DataFields cameraStabData = cameraStabSettings->getData();
refreshUIValues(cameraStabData);
MixerSettings *mixerSettings = MixerSettings::GetInstance(getObjectManager());
MixerSettings::DataFields mixerSettingsData = mixerSettings->getData();
const int NUM_MIXERS = 10;
@ -319,25 +214,6 @@ void ConfigCameraStabilizationWidget::refreshValues()
}
}
void ConfigCameraStabilizationWidget::resetToDefaults()
{
CameraStabSettings cameraStabDefaults;
CameraStabSettings::DataFields defaults = cameraStabDefaults.getData();
refreshUIValues(defaults);
}
void ConfigCameraStabilizationWidget::openHelp()
{
QDesktopServices::openUrl( QUrl("http://wiki.openpilot.org/display/Doc/Camera+Stabilization+Configuration", QUrl::StrictMode) );
}
void ConfigCameraStabilizationWidget::enableControls(bool enable)
{
m_camerastabilization->camerastabilizationResetToDefaults->setEnabled(enable);
m_camerastabilization->camerastabilizationSaveSD->setEnabled(enable);
m_camerastabilization->camerastabilizationSaveRAM->setEnabled(enable);
}
/**
@}
@}

View File

@ -41,14 +41,11 @@ class ConfigCameraStabilizationWidget: public ConfigTaskWidget
public:
ConfigCameraStabilizationWidget(QWidget *parent = 0);
~ConfigCameraStabilizationWidget();
private:
Ui_CameraStabilizationWidget *m_camerastabilization;
virtual void enableControls(bool enable);
void refreshUIValues(CameraStabSettings::DataFields &cameraStabData);
private slots:
void openHelp();
void resetToDefaults();
void applySettings();
void saveSettings();
void refreshValues();