diff --git a/groundStation/gui/MicroCART/mainwindow.cpp b/groundStation/gui/MicroCART/mainwindow.cpp index 68b410c57da1b4b6e8aaf2d73a14dfde7f21d273..f68d25ea7502ba478c7f6440ddca8700f3bbf987 100644 --- a/groundStation/gui/MicroCART/mainwindow.cpp +++ b/groundStation/gui/MicroCART/mainwindow.cpp @@ -19,7 +19,11 @@ MainWindow::MainWindow(QWidget *parent) : ui(new Ui::MainWindow), backendPid(0), backendPipe(-1), - setpointList(new QStandardItemModel(this)) + setpointList(new QStandardItemModel(this)), + nextSpTimer(new QTimer(this)), + sp_x(0.0f), + sp_y(0.0f), + sp_z(0.0f) { ui->setupUi(this); @@ -70,6 +74,10 @@ MainWindow::MainWindow(QWidget *parent) : connect(trackerTimer, SIGNAL(timeout()), trackerWorker, SLOT(process())); connect(findChild<QPushButton *>("pbRefresh"), SIGNAL (clicked()), trackerWorker, SLOT (process())); + /* Timer used for next setpoint */ + nextSpTimer->setSingleShot(true); + connect(nextSpTimer, SIGNAL (timeout()), this, SLOT (on_pbNextSetpoint_clicked())); + /* Start the things */ trackerTimer->start(300); workerThread->start(); @@ -113,6 +121,15 @@ void MainWindow::updateTracker(float x, float y, float z, float p, float r, floa findChild<QLineEdit *>("pitchActual")->setText(QString::number(p)); findChild<QLineEdit *>("rollActual")->setText(QString::number(r)); findChild<QLineEdit *>("yawActual")->setText(QString::number(yaw)); + + float dist = sqrt(pow(x - sp_x, 2.0) + pow(y - sp_y, 2.0) + pow(z - sp_z, 2.0)); + + findChild<QLineEdit *>("dist")->setText(QString::number(dist)); + + if (!nextSpTimer->isActive() && findChild<QCheckBox *>("autonavEnabled")->isChecked() && + (dist < findChild<QLineEdit *>("autonavThreshold")->text().toFloat())) { + nextSpTimer->start(findChild<QLineEdit *>("autonavDelay")->text().toInt()); + } } void MainWindow::on_pbStart_clicked() @@ -232,17 +249,17 @@ void MainWindow::on_paramValue_returnPressed() void MainWindow::sendSetpoints() { + sp_x = findChild<QLineEdit *>("xSetpoint")->text().toFloat(); emit (setParamValue(findChild<QComboBox *>("xSetpointSelect")->currentText(), - blockDefs[BLOCK_CONSTANT]->param_names[0], - findChild<QLineEdit *>("xSetpoint")->text().toFloat())); + blockDefs[BLOCK_CONSTANT]->param_names[0], sp_x)); + sp_y = findChild<QLineEdit *>("ySetpoint")->text().toFloat(); emit (setParamValue(findChild<QComboBox *>("ySetpointSelect")->currentText(), - blockDefs[BLOCK_CONSTANT]->param_names[0], - findChild<QLineEdit *>("ySetpoint")->text().toFloat())); + blockDefs[BLOCK_CONSTANT]->param_names[0], sp_y)); + sp_z = findChild<QLineEdit *>("zSetpoint")->text().toFloat(); emit (setParamValue(findChild<QComboBox *>("zSetpointSelect")->currentText(), - blockDefs[BLOCK_CONSTANT]->param_names[0], - findChild<QLineEdit *>("zSetpoint")->text().toFloat())); + blockDefs[BLOCK_CONSTANT]->param_names[0], sp_z)); } void MainWindow::on_pbAppendSetpoint_clicked() diff --git a/groundStation/gui/MicroCART/mainwindow.h b/groundStation/gui/MicroCART/mainwindow.h index e704deecdc779444034bb308affd264f5a12046b..5c5c38fe38f222c5b1f8cbcd9ec949062db0a7ce 100644 --- a/groundStation/gui/MicroCART/mainwindow.h +++ b/groundStation/gui/MicroCART/mainwindow.h @@ -65,6 +65,10 @@ private: int backendPipe; int backendState; QStandardItemModel * setpointList; + QTimer * nextSpTimer; + float sp_x; + float sp_y; + float sp_z; }; #endif // MAINWINDOW_H diff --git a/groundStation/gui/MicroCART/mainwindow.ui b/groundStation/gui/MicroCART/mainwindow.ui index 4b75cdbafa31e49f8bef144eaad91e5bf6a9f31d..2476c75d595f5fb78a492e9a5799c070c79f5162 100644 --- a/groundStation/gui/MicroCART/mainwindow.ui +++ b/groundStation/gui/MicroCART/mainwindow.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>1369</width> - <height>995</height> + <width>1004</width> + <height>934</height> </rect> </property> <property name="windowTitle"> @@ -18,7 +18,7 @@ <item> <widget class="QTabWidget" name="tabWidget"> <property name="currentIndex"> - <number>2</number> + <number>0</number> </property> <widget class="QWidget" name="backend"> <attribute name="title"> @@ -151,8 +151,8 @@ <rect> <x>0</x> <y>0</y> - <width>1333</width> - <height>727</height> + <width>968</width> + <height>666</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout_8"> @@ -503,6 +503,46 @@ </item> </layout> </item> + <item> + <widget class="Line" name="line_6"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <layout class="QFormLayout" name="formLayout_5"> + <item row="0" column="1"> + <widget class="QLineEdit" name="dist"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="label_10"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>D</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_5"/> + </item> <item> <widget class="QPushButton" name="pbActualToSetpoint"> <property name="text"> @@ -700,22 +740,33 @@ </widget> </item> <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> + <layout class="QHBoxLayout" name="horizontalLayout"> <item> - <widget class="QCheckBox" name="autonavEnabled"> + <widget class="QPushButton" name="pbSaveWaypoints"> <property name="text"> - <string>Auto</string> + <string>Save</string> </property> </widget> </item> <item> - <widget class="Line" name="line_5"> - <property name="orientation"> - <enum>Qt::Vertical</enum> + <widget class="QPushButton" name="pbLoadWaypoints"> + <property name="text"> + <string>Load</string> </property> </widget> </item> - <item> + </layout> + </item> + <item> + <widget class="QCheckBox" name="autonavEnabled"> + <property name="text"> + <string>Enable Autonavigation</string> + </property> + </widget> + </item> + <item> + <layout class="QFormLayout" name="formLayout_6"> + <item row="0" column="0"> <widget class="QLabel" name="label_9"> <property name="sizePolicy"> <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> @@ -723,12 +774,19 @@ <verstretch>0</verstretch> </sizepolicy> </property> + <property name="text"> + <string>Threshold</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="delayLabel"> <property name="text"> <string>Delay</string> </property> </widget> </item> - <item> + <item row="1" column="1"> <widget class="QLineEdit" name="autonavDelay"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> @@ -741,6 +799,19 @@ </property> </widget> </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="autonavThreshold"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>0.05</string> + </property> + </widget> + </item> </layout> </item> <item> @@ -750,24 +821,6 @@ </property> </widget> </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QPushButton" name="pbSaveWaypoints"> - <property name="text"> - <string>Save</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pbLoadWaypoints"> - <property name="text"> - <string>Load</string> - </property> - </widget> - </item> - </layout> - </item> </layout> </item> <item> @@ -803,7 +856,7 @@ <rect> <x>0</x> <y>0</y> - <width>1369</width> + <width>1004</width> <height>30</height> </rect> </property>