diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 7c90c12545e5ba98c9edccbbae79ba78e7b708fd..c96f121172abd5fb19dca4b669e4fd699c0d989d 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -76,8 +76,7 @@ FORMS += src/ui/MainWindow.ui \ src/ui/QGCPxImuFirmwareUpdate.ui \ src/ui/QGCDataPlot2D.ui \ src/ui/QGCRemoteControlView.ui \ - src/ui/WaypointGlobalView.ui \ - src/ui/QGCRadioCalibration.ui + src/ui/WaypointGlobalView.ui INCLUDEPATH += src \ src/ui \ src/ui/linechart \ @@ -162,7 +161,10 @@ HEADERS += src/MG.h \ src/ui/QGCRemoteControlView.h \ src/WaypointGlobal.h \ src/ui/WaypointGlobalView.h \ - src/ui/RadioCalibration/RadioCalibrationWindow.h + src/ui/RadioCalibration/RadioCalibrationWindow.h \ + src/ui/RadioCalibration/AirfoilServoCalibrator.h \ + src/ui/RadioCalibration/SwitchCalibrator.h \ + src/ui/RadioCalibration/CurveCalibrator.h SOURCES += src/main.cc \ src/Core.cc \ src/uas/UASManager.cc \ @@ -229,7 +231,10 @@ SOURCES += src/main.cc \ src/ui/QGCRemoteControlView.cc \ src/WaypointGlobal.cpp \ src/ui/WaypointGlobalView.cpp \ - src/ui/RadioCalibration/RadioCalibrationWindow.cc + src/ui/RadioCalibration/RadioCalibrationWindow.cc \ + src/ui/RadioCalibration/AirfoilServoCalibrator.cc \ + src/ui/RadioCalibration/SwitchCalibrator.cc \ + src/ui/RadioCalibration/CurveCalibrator.cc RESOURCES = mavground.qrc # Include RT-LAB Library diff --git a/src/ui/QGCRemoteControlView.cc b/src/ui/QGCRemoteControlView.cc index bd056ef4a9c7b385a63fa78f53e64b564fa45557..95f2f4d877e16d7038c2eb8eddce5c8dd204cfda 100644 --- a/src/ui/QGCRemoteControlView.cc +++ b/src/ui/QGCRemoteControlView.cc @@ -76,7 +76,7 @@ QGCRemoteControlView::QGCRemoteControlView(QWidget *parent) : calibrateButtonLayout->addWidget(calibrate, 0, Qt::AlignHCenter); layout->addItem(calibrateButtonLayout, 3, 0, 1, 2); - calibrationWindow = new QWidget(this, Qt::Window); + calibrationWindow = new RadioCalibrationWindow(this); connect(calibrate, SIGNAL(clicked()), calibrationWindow, SLOT(show())); connect(UASManager::instance(), SIGNAL(activeUASSet(int)), this, SLOT(setUASId(int))); @@ -108,6 +108,7 @@ void QGCRemoteControlView::setUASId(int id) // New UAS exists, connect nameLabel->setText(QString("RC Input of %1").arg(newUAS->getUASName())); connect(newUAS, SIGNAL(remoteControlChannelChanged(int,float,float)), this, SLOT(setChannel(int,float,float))); + connect(newUAS, SIGNAL(remoteControlChannelChanged(int,float,float)), calibrationWindow, SLOT(setChannel(int,float,float))); connect(newUAS, SIGNAL(remoteControlRSSIChanged(float)), this, SLOT(setRemoteRSSI(float))); } } diff --git a/src/ui/QGCRemoteControlView.h b/src/ui/QGCRemoteControlView.h index 242d24ba813074eae8b6c72c54f9863910d9951e..c4044cdfd1b48257b2a2f16025ebb32f62ed44ef 100644 --- a/src/ui/QGCRemoteControlView.h +++ b/src/ui/QGCRemoteControlView.h @@ -34,6 +34,8 @@ This file is part of the QGROUNDCONTROL project #include #include +#include "RadioCalibration/RadioCalibrationWindow.h" + namespace Ui { class QGCRemoteControlView; } @@ -70,7 +72,7 @@ protected: QProgressBar* rssiBar; QLabel* nameLabel; QPushButton *calibrate; - QWidget *calibrationWindow; + RadioCalibrationWindow *calibrationWindow; private: Ui::QGCRemoteControlView *ui; diff --git a/src/ui/RadioCalibration/AirfoilServoCalibrator.cc b/src/ui/RadioCalibration/AirfoilServoCalibrator.cc new file mode 100644 index 0000000000000000000000000000000000000000..3f19d64c37223943c366e5f5b0e7521e3f35d752 --- /dev/null +++ b/src/ui/RadioCalibration/AirfoilServoCalibrator.cc @@ -0,0 +1,41 @@ +#include "AirfoilServoCalibrator.h" + +AirfoilServoCalibrator::AirfoilServoCalibrator(AirfoilType type, QWidget *parent) : + QWidget(parent) +{ + QGridLayout *grid = new QGridLayout(this); + + /* Add title */ + QHBoxLayout *titleLayout = new QHBoxLayout(); + QLabel *title; + if (type == AILERON) + { + title = new QLabel(tr("Aileron")); + } + else if (type == ELEVATOR) + { + title = new QLabel(tr("Elevator")); + } + else if (type == RUDDER) + { + title = new QLabel(tr("Rudder")); + } + + titleLayout->addWidget(title); + grid->addLayout(titleLayout, 0, 0, 1, 3, Qt::AlignHCenter); + + /* 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); + + this->setLayout(grid); +} + +void AirfoilServoCalibrator::channelChanged(float raw) +{ + pulseWidth->setText(QString::number(static_cast(raw))); +} diff --git a/src/ui/RadioCalibration/AirfoilServoCalibrator.h b/src/ui/RadioCalibration/AirfoilServoCalibrator.h new file mode 100644 index 0000000000000000000000000000000000000000..6c45dcc33eb0b0372f8c1ad1c812ea83ae39fe1d --- /dev/null +++ b/src/ui/RadioCalibration/AirfoilServoCalibrator.h @@ -0,0 +1,46 @@ +#ifndef AIRFOILSERVOCALIBRATOR_H +#define AIRFOILSERVOCALIBRATOR_H + +#include +#include +#include +#include +#include +#include + +class AirfoilServoCalibrator : public QWidget +{ +Q_OBJECT +public: + enum AirfoilType + { + AILERON, + ELEVATOR, + RUDDER + }; + + 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; + + 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 new file mode 100644 index 0000000000000000000000000000000000000000..41c337c2606658e121abac600f30a88a5a7ffd76 --- /dev/null +++ b/src/ui/RadioCalibration/CurveCalibrator.cc @@ -0,0 +1,46 @@ +#include "CurveCalibrator.h" + +CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) : + QWidget(parent), + setpoints(QVector(5)), + positions(QVector()) + +{ + QGridLayout *grid = new QGridLayout(this); + QLabel *title = new QLabel(titleString); + grid->addWidget(title, 0, 0, 1, 5, Qt::AlignHCenter); + + 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, 5, Qt::AlignHCenter); + + for (int i=0; i<=100; i=i+100/4) + positions.append(static_cast(i)); + + + setpoints.fill(1500); + + plot = new QwtPlot(); + + grid->addWidget(plot, 2, 0, 1, 5, Qt::AlignHCenter); + + + plot->setAxisScale(QwtPlot::yLeft, 1000, 2000, 200); + + curve = new QwtPlotCurve(); + curve->setData(positions, setpoints); + curve->attach(plot); + + plot->replot(); + + + 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 new file mode 100644 index 0000000000000000000000000000000000000000..7115d3e3f115dbc3ddde51542c92edbf3ebad547 --- /dev/null +++ b/src/ui/RadioCalibration/CurveCalibrator.h @@ -0,0 +1,32 @@ +#ifndef CURVECALIBRATOR_H +#define CURVECALIBRATOR_H + +#include +#include +#include +#include +#include +#include +#include +#include + +class CurveCalibrator : public QWidget +{ +Q_OBJECT +public: + explicit CurveCalibrator(QString title = QString(), QWidget *parent = 0); + +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/RadioCalibrationWindow.cc b/src/ui/RadioCalibration/RadioCalibrationWindow.cc index 2490683b1599dd2b9503d242e14c426ef9f667b8..12b251241063d67ae6345d21771aa7f8543ea8cc 100644 --- a/src/ui/RadioCalibration/RadioCalibrationWindow.cc +++ b/src/ui/RadioCalibration/RadioCalibrationWindow.cc @@ -3,4 +3,56 @@ RadioCalibrationWindow::RadioCalibrationWindow(QWidget *parent) : QWidget(parent, Qt::Window) { + QGridLayout *grid = new QGridLayout(); + + aileron = new AirfoilServoCalibrator(AirfoilServoCalibrator::AILERON); + grid->addWidget(aileron, 0, 0, 1, 1, Qt::AlignTop); + + elevator = new AirfoilServoCalibrator(AirfoilServoCalibrator::ELEVATOR); + grid->addWidget(elevator, 0, 1, 1, 1, Qt::AlignTop); + + rudder = new AirfoilServoCalibrator(AirfoilServoCalibrator::RUDDER); + grid->addWidget(rudder, 0, 2, 1, 1, Qt::AlignTop); + + gyro = new SwitchCalibrator(tr("Gyro Mode/Gain")); + grid->addWidget(gyro, 0, 3, 1, 1, Qt::AlignTop); + + + pitch = new CurveCalibrator(tr("Collective Pitch")); + grid->addWidget(pitch, 1, 0, 1, 2); + + throttle = new CurveCalibrator(tr("Throttle")); + grid->addWidget(throttle, 1, 2, 1, 2); + + this->setLayout(grid); +} + +void RadioCalibrationWindow::setChannel(int ch, float raw, float normalized) +{ + /** this expects a particular channel to function mapping + \todo allow run-time channel mapping + */ + switch (ch) + { + case 0: + aileron->channelChanged(raw); + break; + case 1: + elevator->channelChanged(raw); + break; + case 2: + throttle->channelChanged(raw); + break; + case 3: + rudder->channelChanged(raw); + break; + case 4: + gyro->channelChanged(raw); + break; + case 5: + pitch->channelChanged(raw); + break; + + + } } diff --git a/src/ui/RadioCalibration/RadioCalibrationWindow.h b/src/ui/RadioCalibration/RadioCalibrationWindow.h index 1241432916ed86ae746198b8eebc4aca727c47ce..be3c1b09c833c854e4865e0a6e4df224693bbb95 100644 --- a/src/ui/RadioCalibration/RadioCalibrationWindow.h +++ b/src/ui/RadioCalibration/RadioCalibrationWindow.h @@ -6,6 +6,11 @@ #include #include #include +#include + +#include "AirfoilServoCalibrator.h" +#include "SwitchCalibrator.h" +#include "CurveCalibrator.h" class RadioCalibrationWindow : public QWidget { @@ -16,34 +21,15 @@ public: signals: public slots: + void setChannel(int ch, float raw, float normalized); protected: - class AirfoilServoCalibrator : public QWidget - { - Q_OBJECT - public: - explicit AirfoilServoCalibrator(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; - - float high; - float center; - float low; - - QVector log; - }; + AirfoilServoCalibrator *aileron; + AirfoilServoCalibrator *elevator; + AirfoilServoCalibrator *rudder; + SwitchCalibrator *gyro; + CurveCalibrator *pitch; + CurveCalibrator *throttle; }; diff --git a/src/ui/RadioCalibration/SwitchCalibrator.cc b/src/ui/RadioCalibration/SwitchCalibrator.cc new file mode 100644 index 0000000000000000000000000000000000000000..857d0488cc77ffc19a0628a52f1ebfd8f509f520 --- /dev/null +++ b/src/ui/RadioCalibration/SwitchCalibrator.cc @@ -0,0 +1,25 @@ +#include "SwitchCalibrator.h" + +SwitchCalibrator::SwitchCalibrator(QString titleString, QWidget *parent) : + QWidget(parent) +{ + /* Add title label*/ + QLabel *title = new QLabel(titleString); + QGridLayout *grid = new QGridLayout(); + grid->addWidget(title, 0, 0, 1, 3); + + /* 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); + + this->setLayout(grid); +} + +void SwitchCalibrator::channelChanged(float raw) +{ + pulseWidth->setText(QString::number(static_cast(raw))); +} diff --git a/src/ui/RadioCalibration/SwitchCalibrator.h b/src/ui/RadioCalibration/SwitchCalibrator.h new file mode 100644 index 0000000000000000000000000000000000000000..f77cce83bdc3750a6d87d0328b452a9d806155cf --- /dev/null +++ b/src/ui/RadioCalibration/SwitchCalibrator.h @@ -0,0 +1,35 @@ +#ifndef SWITCHCALIBRATOR_H +#define SWITCHCALIBRATOR_H + +#include +#include +#include +#include +#include +#include + +class SwitchCalibrator : public QWidget +{ +Q_OBJECT +public: + explicit SwitchCalibrator(QString title=QString(), QWidget *parent = 0); + +signals: + void defaultSetpointChanged(float); + void toggledSetpointChanged(float); + +public slots: + void channelChanged(float raw); +protected: + QLabel *pulseWidth; + QPushButton *defaultButton; + QPushButton *toggledButton; + + float defaultPos; + float toggled; + + QVector log; + +}; + +#endif // SWITCHCALIBRATOR_H