diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index c96f121172abd5fb19dca4b669e4fd699c0d989d..c3d37796635821e43115dbf827180d67bd0acdd8 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -164,7 +164,8 @@ HEADERS += src/MG.h \ src/ui/RadioCalibration/RadioCalibrationWindow.h \ src/ui/RadioCalibration/AirfoilServoCalibrator.h \ src/ui/RadioCalibration/SwitchCalibrator.h \ - src/ui/RadioCalibration/CurveCalibrator.h + src/ui/RadioCalibration/CurveCalibrator.h \ + src/ui/RadioCalibration/AbstractCalibrator.h SOURCES += src/main.cc \ src/Core.cc \ src/uas/UASManager.cc \ @@ -234,7 +235,8 @@ SOURCES += src/main.cc \ src/ui/RadioCalibration/RadioCalibrationWindow.cc \ src/ui/RadioCalibration/AirfoilServoCalibrator.cc \ src/ui/RadioCalibration/SwitchCalibrator.cc \ - src/ui/RadioCalibration/CurveCalibrator.cc + src/ui/RadioCalibration/CurveCalibrator.cc \ + src/ui/RadioCalibration/AbstractCalibrator.cc RESOURCES = mavground.qrc # Include RT-LAB Library diff --git a/src/ui/RadioCalibration/AbstractCalibrator.cc b/src/ui/RadioCalibration/AbstractCalibrator.cc new file mode 100644 index 0000000000000000000000000000000000000000..2efda5eb4c1e4789f22d4e7bb0a2984ecaa77e9a --- /dev/null +++ b/src/ui/RadioCalibration/AbstractCalibrator.cc @@ -0,0 +1,52 @@ +#include "AbstractCalibrator.h" + +AbstractCalibrator::AbstractCalibrator(QWidget *parent) : + QWidget(parent), + pulseWidth(new QLabel()), + log(new QVector()) +{ +} + +AbstractCalibrator::~AbstractCalibrator() +{ + delete log; +} + +float AbstractCalibrator::logAverage() +{ + float total = 0; + for (int i=0; isize(); ++i) + total += log->value(i); + return (total/log->size()); +} + +float AbstractCalibrator::logExtrema() +{ + float extrema = logAverage(); + if (logAverage() < 1500) + { + for (int i=0; isize(); ++i) + { + if (log->value(i) < extrema) + extrema = log->value(i); + } + } + else + { + for (int i=0; isize(); ++i) + { + if (log->value(i) > extrema) + extrema = log->value(i); + } + } + + return extrema; +} + +void AbstractCalibrator::channelChanged(float raw) +{ + pulseWidth->setText(QString::number(static_cast(raw))); + if (log->size() == 5) + log->pop_front(); + log->push_back(raw); +} diff --git a/src/ui/RadioCalibration/AbstractCalibrator.h b/src/ui/RadioCalibration/AbstractCalibrator.h new file mode 100644 index 0000000000000000000000000000000000000000..3b650a8826c3f186e3d2d241b7cf3c24aa6aec2b --- /dev/null +++ b/src/ui/RadioCalibration/AbstractCalibrator.h @@ -0,0 +1,26 @@ +#ifndef ABSTRACTCALIBRATOR_H +#define ABSTRACTCALIBRATOR_H + +#include +#include +#include + +class AbstractCalibrator : public QWidget +{ +Q_OBJECT +public: + explicit AbstractCalibrator(QWidget *parent = 0); + ~AbstractCalibrator(); + +public slots: + void channelChanged(float raw); + +protected: + QLabel *pulseWidth; + + QVector *log; + float logExtrema(); + float logAverage(); +}; + +#endif // ABSTRACTCALIBRATOR_H diff --git a/src/ui/RadioCalibration/AirfoilServoCalibrator.cc b/src/ui/RadioCalibration/AirfoilServoCalibrator.cc index 3f19d64c37223943c366e5f5b0e7521e3f35d752..472aa4101c999b4aa27ac30d3f75b50124ecb083 100644 --- a/src/ui/RadioCalibration/AirfoilServoCalibrator.cc +++ b/src/ui/RadioCalibration/AirfoilServoCalibrator.cc @@ -1,7 +1,10 @@ #include "AirfoilServoCalibrator.h" AirfoilServoCalibrator::AirfoilServoCalibrator(AirfoilType type, QWidget *parent) : - QWidget(parent) + AbstractCalibrator(parent), + highPulseWidth(new QLabel()), + centerPulseWidth(new QLabel()), + lowPulseWidth(new QLabel()) { QGridLayout *grid = new QGridLayout(this); @@ -26,16 +29,79 @@ AirfoilServoCalibrator::AirfoilServoCalibrator(AirfoilType type, QWidget *parent /* Add current Pulse Width Display */ QLabel *pulseWidthTitle = new QLabel(tr("Pulse Width (us)")); - pulseWidth = new QLabel(); QHBoxLayout *pulseLayout = new QHBoxLayout(); pulseLayout->addWidget(pulseWidthTitle); pulseLayout->addWidget(pulseWidth); grid->addLayout(pulseLayout, 1, 0, 1, 3); + QLabel *highPulseString; + QLabel *centerPulseString; + QLabel *lowPulseString; + if (type == AILERON) + { + highPulseString = new QLabel(tr("Bank Left")); + centerPulseString = new QLabel(tr("Center")); + lowPulseString = new QLabel(tr("Bank Right")); + } + else if (type == ELEVATOR) + { + highPulseString = new QLabel(tr("Nose Down")); + centerPulseString = new QLabel(tr("Center")); + lowPulseString = new QLabel(tr("Nose Up")); + } + else if (type == RUDDER) + { + highPulseString = new QLabel(tr("Nose Left")); + centerPulseString = new QLabel(tr("Center")); + lowPulseString = new QLabel(tr("Nose Right")); + } + else + { + highPulseString = new QLabel(tr("High")); + centerPulseString = new QLabel(tr("Center")); + lowPulseString = new QLabel(tr("Low")); + } + + + QPushButton *highButton = new QPushButton(tr("Set")); + QPushButton *centerButton = new QPushButton(tr("Set")); + QPushButton *lowButton = new QPushButton(tr("Set")); + + grid->addWidget(highPulseString, 2, 0); + grid->addWidget(highPulseWidth, 2, 1); + grid->addWidget(highButton, 2, 2); + + grid->addWidget(centerPulseString, 3, 0); + grid->addWidget(centerPulseWidth, 3, 1); + grid->addWidget(centerButton, 3, 2); + + grid->addWidget(lowPulseString, 4, 0); + grid->addWidget(lowPulseWidth, 4, 1); + grid->addWidget(lowButton, 4, 2); + this->setLayout(grid); + + connect(highButton, SIGNAL(clicked()), this, SLOT(setHigh())); + connect(centerButton, SIGNAL(clicked()), this, SLOT(setCenter())); + connect(lowButton, SIGNAL(clicked()), this, SLOT(setLow())); +} + + + +void AirfoilServoCalibrator::setHigh() +{ + highPulseWidth->setText(QString::number(static_cast(logExtrema()))); + emit highSetpointChanged(logExtrema()); +} + +void AirfoilServoCalibrator::setCenter() +{ + centerPulseWidth->setText(QString::number(static_cast(logAverage()))); + emit centerSetpointChanged(logAverage()); } -void AirfoilServoCalibrator::channelChanged(float raw) +void AirfoilServoCalibrator::setLow() { - pulseWidth->setText(QString::number(static_cast(raw))); + lowPulseWidth->setText(QString::number(static_cast(logExtrema()))); + emit lowSetpointChanged(logExtrema()); } diff --git a/src/ui/RadioCalibration/AirfoilServoCalibrator.h b/src/ui/RadioCalibration/AirfoilServoCalibrator.h index 6c45dcc33eb0b0372f8c1ad1c812ea83ae39fe1d..234a13dc993f1773f664c5e95990abfcfe8147c7 100644 --- a/src/ui/RadioCalibration/AirfoilServoCalibrator.h +++ b/src/ui/RadioCalibration/AirfoilServoCalibrator.h @@ -8,7 +8,9 @@ #include #include -class AirfoilServoCalibrator : public QWidget +#include "AbstractCalibrator.h" + +class AirfoilServoCalibrator : public AbstractCalibrator { Q_OBJECT public: @@ -21,26 +23,24 @@ public: explicit AirfoilServoCalibrator(AirfoilType type = AILERON, QWidget *parent = 0); - - signals: void highSetpointChanged(float); void centerSetpointChanged(float); void lowSetpointChanged(float); -public slots: - void channelChanged(float raw); -protected: - QLabel *pulseWidth; - QPushButton *highButton; - QPushButton *centerButton; - QPushButton *lowButton; +protected slots: + void setHigh(); + void setCenter(); + void setLow(); + +protected: + QLabel *highPulseWidth; + QLabel *centerPulseWidth; + QLabel *lowPulseWidth; float high; float center; float low; - - QVector log; }; #endif // AIRFOILSERVOCALIBRATOR_H diff --git a/src/ui/RadioCalibration/CurveCalibrator.cc b/src/ui/RadioCalibration/CurveCalibrator.cc index 41c337c2606658e121abac600f30a88a5a7ffd76..5ec46e037a02d70417c4722d946e82621fb45e56 100644 --- a/src/ui/RadioCalibration/CurveCalibrator.cc +++ b/src/ui/RadioCalibration/CurveCalibrator.cc @@ -1,7 +1,7 @@ #include "CurveCalibrator.h" CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) : - QWidget(parent), + AbstractCalibrator(parent), setpoints(QVector(5)), positions(QVector()) @@ -39,8 +39,3 @@ CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) : this->setLayout(grid); } - -void CurveCalibrator::channelChanged(float raw) -{ - pulseWidth->setText(QString::number(static_cast(raw))); -} diff --git a/src/ui/RadioCalibration/CurveCalibrator.h b/src/ui/RadioCalibration/CurveCalibrator.h index 7115d3e3f115dbc3ddde51542c92edbf3ebad547..84befdf45c8940f274a8812712ecc9d591bdb362 100644 --- a/src/ui/RadioCalibration/CurveCalibrator.h +++ b/src/ui/RadioCalibration/CurveCalibrator.h @@ -10,7 +10,9 @@ #include #include -class CurveCalibrator : public QWidget +#include "AbstractCalibrator.h" + +class CurveCalibrator : public AbstractCalibrator { Q_OBJECT public: @@ -18,15 +20,12 @@ public: signals: void setpointChanged(float[5]); -public slots: - void channelChanged(float raw); protected: QVector setpoints; QVector positions; QwtPlot *plot; QwtPlotCurve *curve; - QLabel *pulseWidth; }; #endif // CURVECALIBRATOR_H diff --git a/src/ui/RadioCalibration/SwitchCalibrator.cc b/src/ui/RadioCalibration/SwitchCalibrator.cc index 857d0488cc77ffc19a0628a52f1ebfd8f509f520..2062d985219920cd0d9a8a35ada5aa420e3b8833 100644 --- a/src/ui/RadioCalibration/SwitchCalibrator.cc +++ b/src/ui/RadioCalibration/SwitchCalibrator.cc @@ -1,7 +1,9 @@ #include "SwitchCalibrator.h" SwitchCalibrator::SwitchCalibrator(QString titleString, QWidget *parent) : - QWidget(parent) + AbstractCalibrator(parent), + defaultPulseWidth(new QLabel()), + toggledPulseWidth(new QLabel()) { /* Add title label*/ QLabel *title = new QLabel(titleString); @@ -9,17 +11,39 @@ SwitchCalibrator::SwitchCalibrator(QString titleString, QWidget *parent) : grid->addWidget(title, 0, 0, 1, 3); /* Add current Pulse Width Display */ - QLabel *pulseWidthTitle = new QLabel(tr("Pulse Width (us)")); - pulseWidth = new QLabel(); + QLabel *pulseWidthTitle = new QLabel(tr("Pulse Width (us)")); QHBoxLayout *pulseLayout = new QHBoxLayout(); pulseLayout->addWidget(pulseWidthTitle); pulseLayout->addWidget(pulseWidth); grid->addLayout(pulseLayout, 1, 0, 1, 3); + QLabel *defaultPulseString = new QLabel(tr("Default Position")); + QPushButton *defaultButton = new QPushButton(tr("Set")); + grid->addWidget(defaultPulseString, 2, 0); + grid->addWidget(defaultPulseWidth, 2, 1); + grid->addWidget(defaultButton, 2, 2); + + QLabel *toggledPulseString = new QLabel(tr("Toggled Position")); + QPushButton *toggledButton = new QPushButton(tr("Set")); + grid->addWidget(toggledPulseString, 3, 0); + grid->addWidget(toggledPulseWidth, 3, 1); + grid->addWidget(toggledButton, 3, 2); + this->setLayout(grid); + + connect(defaultButton, SIGNAL(clicked()), this, SLOT(setDefault())); + connect(toggledButton, SIGNAL(clicked()), this, SLOT(setToggled())); +} + + +void SwitchCalibrator::setDefault() +{ + defaultPulseWidth->setText(QString::number(static_cast(logExtrema()))); + emit defaultSetpointChanged(logExtrema()); } -void SwitchCalibrator::channelChanged(float raw) +void SwitchCalibrator::setToggled() { - pulseWidth->setText(QString::number(static_cast(raw))); + toggledPulseWidth->setText(QString::number(static_cast(logExtrema()))); + emit toggledSetpointChanged(logExtrema()); } diff --git a/src/ui/RadioCalibration/SwitchCalibrator.h b/src/ui/RadioCalibration/SwitchCalibrator.h index f77cce83bdc3750a6d87d0328b452a9d806155cf..430c1d121a588a7996ffb5cec646885a381d1e3c 100644 --- a/src/ui/RadioCalibration/SwitchCalibrator.h +++ b/src/ui/RadioCalibration/SwitchCalibrator.h @@ -8,7 +8,9 @@ #include #include -class SwitchCalibrator : public QWidget +#include "AbstractCalibrator.h" + +class SwitchCalibrator : public AbstractCalibrator { Q_OBJECT public: @@ -18,17 +20,13 @@ signals: void defaultSetpointChanged(float); void toggledSetpointChanged(float); -public slots: - void channelChanged(float raw); -protected: - QLabel *pulseWidth; - QPushButton *defaultButton; - QPushButton *toggledButton; - - float defaultPos; - float toggled; +protected slots: + void setDefault(); + void setToggled(); - QVector log; +protected: + QLabel *defaultPulseWidth; + QLabel *toggledPulseWidth; };