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 \
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
......
#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"
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<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 @@
#include <QGridLayout>
#include <QHBoxLayout>
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<float> log;
};
#endif // AIRFOILSERVOCALIBRATOR_H
#include "CurveCalibrator.h"
CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) :
QWidget(parent),
AbstractCalibrator(parent),
setpoints(QVector<double>(5)),
positions(QVector<double>())
......@@ -39,8 +39,3 @@ CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) :
this->setLayout(grid);
}
void CurveCalibrator::channelChanged(float raw)
{
pulseWidth->setText(QString::number(static_cast<double>(raw)));
}
......@@ -10,7 +10,9 @@
#include <QLabel>
#include <QPushButton>
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<double> setpoints;
QVector<double> positions;
QwtPlot *plot;
QwtPlotCurve *curve;
QLabel *pulseWidth;
};
#endif // CURVECALIBRATOR_H
#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<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 @@
#include <QGridLayout>
#include <QHBoxLayout>
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<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