Commit 95011df1 authored by Bryan Godbolt's avatar Bryan Godbolt

Filled in functions for airfoils and switch

parent a47b16fb
...@@ -164,7 +164,8 @@ HEADERS += src/MG.h \ ...@@ -164,7 +164,8 @@ HEADERS += src/MG.h \
src/ui/RadioCalibration/RadioCalibrationWindow.h \ src/ui/RadioCalibration/RadioCalibrationWindow.h \
src/ui/RadioCalibration/AirfoilServoCalibrator.h \ src/ui/RadioCalibration/AirfoilServoCalibrator.h \
src/ui/RadioCalibration/SwitchCalibrator.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 \ SOURCES += src/main.cc \
src/Core.cc \ src/Core.cc \
src/uas/UASManager.cc \ src/uas/UASManager.cc \
...@@ -234,7 +235,8 @@ SOURCES += src/main.cc \ ...@@ -234,7 +235,8 @@ SOURCES += src/main.cc \
src/ui/RadioCalibration/RadioCalibrationWindow.cc \ src/ui/RadioCalibration/RadioCalibrationWindow.cc \
src/ui/RadioCalibration/AirfoilServoCalibrator.cc \ src/ui/RadioCalibration/AirfoilServoCalibrator.cc \
src/ui/RadioCalibration/SwitchCalibrator.cc \ src/ui/RadioCalibration/SwitchCalibrator.cc \
src/ui/RadioCalibration/CurveCalibrator.cc src/ui/RadioCalibration/CurveCalibrator.cc \
src/ui/RadioCalibration/AbstractCalibrator.cc
RESOURCES = mavground.qrc RESOURCES = mavground.qrc
# Include RT-LAB Library # Include RT-LAB Library
......
#include "AbstractCalibrator.h"
AbstractCalibrator::AbstractCalibrator(QWidget *parent) :
QWidget(parent),
pulseWidth(new QLabel()),
log(new QVector<float>())
{
}
AbstractCalibrator::~AbstractCalibrator()
{
delete log;
}
float AbstractCalibrator::logAverage()
{
float total = 0;
for (int i=0; i<log->size(); ++i)
total += log->value(i);
return (total/log->size());
}
float AbstractCalibrator::logExtrema()
{
float extrema = logAverage();
if (logAverage() < 1500)
{
for (int i=0; i<log->size(); ++i)
{
if (log->value(i) < extrema)
extrema = log->value(i);
}
}
else
{
for (int i=0; i<log->size(); ++i)
{
if (log->value(i) > extrema)
extrema = log->value(i);
}
}
return extrema;
}
void AbstractCalibrator::channelChanged(float raw)
{
pulseWidth->setText(QString::number(static_cast<double>(raw)));
if (log->size() == 5)
log->pop_front();
log->push_back(raw);
}
#ifndef ABSTRACTCALIBRATOR_H
#define ABSTRACTCALIBRATOR_H
#include <QWidget>
#include <QString>
#include <QLabel>
class AbstractCalibrator : public QWidget
{
Q_OBJECT
public:
explicit AbstractCalibrator(QWidget *parent = 0);
~AbstractCalibrator();
public slots:
void channelChanged(float raw);
protected:
QLabel *pulseWidth;
QVector<float> *log;
float logExtrema();
float logAverage();
};
#endif // ABSTRACTCALIBRATOR_H
#include "AirfoilServoCalibrator.h" #include "AirfoilServoCalibrator.h"
AirfoilServoCalibrator::AirfoilServoCalibrator(AirfoilType type, QWidget *parent) : AirfoilServoCalibrator::AirfoilServoCalibrator(AirfoilType type, QWidget *parent) :
QWidget(parent) AbstractCalibrator(parent),
highPulseWidth(new QLabel()),
centerPulseWidth(new QLabel()),
lowPulseWidth(new QLabel())
{ {
QGridLayout *grid = new QGridLayout(this); QGridLayout *grid = new QGridLayout(this);
...@@ -26,16 +29,79 @@ AirfoilServoCalibrator::AirfoilServoCalibrator(AirfoilType type, QWidget *parent ...@@ -26,16 +29,79 @@ AirfoilServoCalibrator::AirfoilServoCalibrator(AirfoilType type, QWidget *parent
/* Add current Pulse Width Display */ /* Add current Pulse Width Display */
QLabel *pulseWidthTitle = new QLabel(tr("Pulse Width (us)")); QLabel *pulseWidthTitle = new QLabel(tr("Pulse Width (us)"));
pulseWidth = new QLabel();
QHBoxLayout *pulseLayout = new QHBoxLayout(); QHBoxLayout *pulseLayout = new QHBoxLayout();
pulseLayout->addWidget(pulseWidthTitle); pulseLayout->addWidget(pulseWidthTitle);
pulseLayout->addWidget(pulseWidth); pulseLayout->addWidget(pulseWidth);
grid->addLayout(pulseLayout, 1, 0, 1, 3); 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); 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<double>(logExtrema())));
emit highSetpointChanged(logExtrema());
}
void AirfoilServoCalibrator::setCenter()
{
centerPulseWidth->setText(QString::number(static_cast<double>(logAverage())));
emit centerSetpointChanged(logAverage());
} }
void AirfoilServoCalibrator::channelChanged(float raw) void AirfoilServoCalibrator::setLow()
{ {
pulseWidth->setText(QString::number(static_cast<double>(raw))); lowPulseWidth->setText(QString::number(static_cast<double>(logExtrema())));
emit lowSetpointChanged(logExtrema());
} }
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
#include <QGridLayout> #include <QGridLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
class AirfoilServoCalibrator : public QWidget #include "AbstractCalibrator.h"
class AirfoilServoCalibrator : public AbstractCalibrator
{ {
Q_OBJECT Q_OBJECT
public: public:
...@@ -21,26 +23,24 @@ public: ...@@ -21,26 +23,24 @@ public:
explicit AirfoilServoCalibrator(AirfoilType type = AILERON, QWidget *parent = 0); explicit AirfoilServoCalibrator(AirfoilType type = AILERON, QWidget *parent = 0);
signals: signals:
void highSetpointChanged(float); void highSetpointChanged(float);
void centerSetpointChanged(float); void centerSetpointChanged(float);
void lowSetpointChanged(float); void lowSetpointChanged(float);
public slots: protected slots:
void channelChanged(float raw); void setHigh();
protected: void setCenter();
QLabel *pulseWidth; void setLow();
QPushButton *highButton;
QPushButton *centerButton; protected:
QPushButton *lowButton; QLabel *highPulseWidth;
QLabel *centerPulseWidth;
QLabel *lowPulseWidth;
float high; float high;
float center; float center;
float low; float low;
QVector<float> log;
}; };
#endif // AIRFOILSERVOCALIBRATOR_H #endif // AIRFOILSERVOCALIBRATOR_H
#include "CurveCalibrator.h" #include "CurveCalibrator.h"
CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) : CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) :
QWidget(parent), AbstractCalibrator(parent),
setpoints(QVector<double>(5)), setpoints(QVector<double>(5)),
positions(QVector<double>()) positions(QVector<double>())
...@@ -39,8 +39,3 @@ CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) : ...@@ -39,8 +39,3 @@ CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) :
this->setLayout(grid); this->setLayout(grid);
} }
void CurveCalibrator::channelChanged(float raw)
{
pulseWidth->setText(QString::number(static_cast<double>(raw)));
}
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
#include <QLabel> #include <QLabel>
#include <QPushButton> #include <QPushButton>
class CurveCalibrator : public QWidget #include "AbstractCalibrator.h"
class CurveCalibrator : public AbstractCalibrator
{ {
Q_OBJECT Q_OBJECT
public: public:
...@@ -18,15 +20,12 @@ public: ...@@ -18,15 +20,12 @@ public:
signals: signals:
void setpointChanged(float[5]); void setpointChanged(float[5]);
public slots:
void channelChanged(float raw);
protected: protected:
QVector<double> setpoints; QVector<double> setpoints;
QVector<double> positions; QVector<double> positions;
QwtPlot *plot; QwtPlot *plot;
QwtPlotCurve *curve; QwtPlotCurve *curve;
QLabel *pulseWidth;
}; };
#endif // CURVECALIBRATOR_H #endif // CURVECALIBRATOR_H
#include "SwitchCalibrator.h" #include "SwitchCalibrator.h"
SwitchCalibrator::SwitchCalibrator(QString titleString, QWidget *parent) : SwitchCalibrator::SwitchCalibrator(QString titleString, QWidget *parent) :
QWidget(parent) AbstractCalibrator(parent),
defaultPulseWidth(new QLabel()),
toggledPulseWidth(new QLabel())
{ {
/* Add title label*/ /* Add title label*/
QLabel *title = new QLabel(titleString); QLabel *title = new QLabel(titleString);
...@@ -9,17 +11,39 @@ SwitchCalibrator::SwitchCalibrator(QString titleString, QWidget *parent) : ...@@ -9,17 +11,39 @@ SwitchCalibrator::SwitchCalibrator(QString titleString, QWidget *parent) :
grid->addWidget(title, 0, 0, 1, 3); grid->addWidget(title, 0, 0, 1, 3);
/* Add current Pulse Width Display */ /* Add current Pulse Width Display */
QLabel *pulseWidthTitle = new QLabel(tr("Pulse Width (us)")); QLabel *pulseWidthTitle = new QLabel(tr("Pulse Width (us)"));
pulseWidth = new QLabel();
QHBoxLayout *pulseLayout = new QHBoxLayout(); QHBoxLayout *pulseLayout = new QHBoxLayout();
pulseLayout->addWidget(pulseWidthTitle); pulseLayout->addWidget(pulseWidthTitle);
pulseLayout->addWidget(pulseWidth); pulseLayout->addWidget(pulseWidth);
grid->addLayout(pulseLayout, 1, 0, 1, 3); 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); 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<double>(logExtrema())));
emit defaultSetpointChanged(logExtrema());
} }
void SwitchCalibrator::channelChanged(float raw) void SwitchCalibrator::setToggled()
{ {
pulseWidth->setText(QString::number(static_cast<double>(raw))); toggledPulseWidth->setText(QString::number(static_cast<double>(logExtrema())));
emit toggledSetpointChanged(logExtrema());
} }
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
#include <QGridLayout> #include <QGridLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
class SwitchCalibrator : public QWidget #include "AbstractCalibrator.h"
class SwitchCalibrator : public AbstractCalibrator
{ {
Q_OBJECT Q_OBJECT
public: public:
...@@ -18,17 +20,13 @@ signals: ...@@ -18,17 +20,13 @@ signals:
void defaultSetpointChanged(float); void defaultSetpointChanged(float);
void toggledSetpointChanged(float); void toggledSetpointChanged(float);
public slots: protected slots:
void channelChanged(float raw); void setDefault();
protected: void setToggled();
QLabel *pulseWidth;
QPushButton *defaultButton;
QPushButton *toggledButton;
float defaultPos;
float toggled;
QVector<float> log; protected:
QLabel *defaultPulseWidth;
QLabel *toggledPulseWidth;
}; };
......
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