diff --git a/groundStation/gui/MicroCART/MicroCART.pro b/groundStation/gui/MicroCART/MicroCART.pro index f8aa76c36c28c220e464900187f77d1a8b9225bf..094787c0fc0a27ed7504a4aaeed3448e5a849aaf 100644 --- a/groundStation/gui/MicroCART/MicroCART.pro +++ b/groundStation/gui/MicroCART/MicroCART.pro @@ -16,13 +16,11 @@ INCLUDEPATH += ../../src/frontend/ SOURCES += main.cpp\ mainwindow.cpp \ - wrappers.c \ trackerworker.cpp \ controlworker.cpp \ quaditem.cpp HEADERS += mainwindow.h \ - wrappers.h \ trackerworker.h \ controlworker.h \ quaditem.h diff --git a/groundStation/gui/MicroCART/MicroCART.pro.user b/groundStation/gui/MicroCART/MicroCART.pro.user index b87c55319792272b73342ccf2bffbc7f0a466fba..8f29bfe9f697ee1b2584da69d9159b8d6bfa6801 100644 --- a/groundStation/gui/MicroCART/MicroCART.pro.user +++ b/groundStation/gui/MicroCART/MicroCART.pro.user @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE QtCreatorProject> -<!-- Written by QtCreator 4.0.1, 2017-04-21T10:58:17. --> +<!-- Written by QtCreator 4.0.1, 2017-04-23T16:38:08. --> <qtcreator> <data> <variable>EnvironmentId</variable> diff --git a/groundStation/gui/MicroCART/controlworker.cpp b/groundStation/gui/MicroCART/controlworker.cpp index 6cd8b01c08877ad2b17ef8c27307006f361cb265..b4e743639027ec03e4dc762e7b57ac3b40db3e3e 100644 --- a/groundStation/gui/MicroCART/controlworker.cpp +++ b/groundStation/gui/MicroCART/controlworker.cpp @@ -40,7 +40,7 @@ void ControlWorker::getNodes() QStringList const_block_nodes; for (size_t i = 0; i < num_nodes; i++) { nodes.append(QString(nd[i].name)); - if (nd[i].type == BLOCK_CONSTANT) { + if ((nd[i].type == BLOCK_CONSTANT) || (nd[i].type == BLOCK_ADD)) { const_block_nodes.append(nd[i].name); } } diff --git a/groundStation/gui/MicroCART/mainwindow.cpp b/groundStation/gui/MicroCART/mainwindow.cpp index b3ee612dd1d3eedeaa233ccd380f1159662599f4..1f6eeeae08336c4b1f80274b63b210e1ec58c972 100644 --- a/groundStation/gui/MicroCART/mainwindow.cpp +++ b/groundStation/gui/MicroCART/mainwindow.cpp @@ -8,17 +8,15 @@ #include <QProcessEnvironment> #include <QPixmap> -#include "wrappers.h" #include "trackerworker.h" #include "controlworker.h" #include "graph_blocks.h" #include "quaditem.h" +#include <iostream> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), - backendPid(0), - backendPipe(-1), setpointList(new QStandardItemModel(this)), nextSpTimer(new QTimer(this)), sp_x(0.0f), @@ -80,8 +78,10 @@ MainWindow::MainWindow(QWidget *parent) : /* Connect refresh button and refresh timer to tracker worker */ QTimer * trackerTimer = new QTimer(this); - connect(trackerTimer, SIGNAL(timeout()), trackerWorker, SLOT(process())); - connect(ui->pbRefresh, SIGNAL (clicked()), trackerWorker, SLOT (process())); + connect(trackerTimer, SIGNAL(timeout()), this, SLOT(updatePosAtt())); + connect(ui->pbRefresh, SIGNAL (clicked()), this, SLOT (updatePosAtt())); + + connect(this, SIGNAL(getPosAttFromBackend()), trackerWorker, SLOT(process())); /* Timer used for next setpoint */ nextSpTimer->setSingleShot(true); @@ -105,9 +105,17 @@ MainWindow::~MainWindow() delete ui; } -void MainWindow::updateConsole() +void MainWindow::updatePosAtt() { - if (backendPipe != -1) { + if (ui->posattSrcVrpn->isChecked()) { + emit(getPosAttFromBackend()); + } else if (ui->posattSrcQuad->isChecked()) { + emit(getParamValue(ui->xPositionSelect->currentText(), blockDefs[BLOCK_CONSTANT]->param_names[0])); + emit(getParamValue(ui->yPositionSelect->currentText(), blockDefs[BLOCK_CONSTANT]->param_names[0])); + emit(getParamValue(ui->zPositionSelect->currentText(), blockDefs[BLOCK_CONSTANT]->param_names[0])); + emit(getParamValue(ui->pAttitudeSelect->currentText(), blockDefs[BLOCK_CONSTANT]->param_names[0])); + emit(getParamValue(ui->rAttitudeSelect->currentText(), blockDefs[BLOCK_CONSTANT]->param_names[0])); + emit(getParamValue(ui->yAttitudeSelect->currentText(), blockDefs[BLOCK_CONSTANT]->param_names[0])); } } @@ -133,10 +141,8 @@ void MainWindow::updateTracker(float x, float y, float z, float p, float r, floa void MainWindow::on_pbStart_clicked() { QProcessEnvironment::systemEnvironment().insert("UCART_SOCKET", ui->socketPath->text()); - this->backendPid = startBackend(ui->backendPath_2->text().toStdString().c_str(), &backendPipe); ui->pbStart->setEnabled(false); ui->pbStop->setEnabled(true); - backendState = 1; } void MainWindow::on_pbConnect_clicked() @@ -146,21 +152,14 @@ void MainWindow::on_pbConnect_clicked() ui->pbConnect->setEnabled(false); ui->pbStop->setEnabled(true); emit(connectWorkers()); - backendState = 1; } void MainWindow::on_pbStop_clicked() { emit(disconnectWorkers()); - if (backendPid) { - stopBackend(backendPid, backendPipe); - backendPipe = -1; - backendPid = 0; - } ui->pbStart->setEnabled(true); ui->pbConnect->setEnabled(true); ui->pbStop->setEnabled(false); - backendState = 0; } void MainWindow::on_chooseBackend_clicked() @@ -185,30 +184,69 @@ void MainWindow::newNodes(QStringList blocks) void MainWindow::newConstantBlocks(QStringList blocks) { - QComboBox * xSelect = ui->xSetpointSelect; - xSelect->clear(); - xSelect->addItems(blocks); + ui->xSetpointSelect->clear(); + ui->xSetpointSelect->addItems(blocks); + + ui->ySetpointSelect->clear(); + ui->ySetpointSelect->addItems(blocks); + + ui->zSetpointSelect->clear(); + ui->zSetpointSelect->addItems(blocks); + + ui->xPositionSelect->clear(); + ui->xPositionSelect->addItems(blocks); + + ui->yPositionSelect->clear(); + ui->yPositionSelect->addItems(blocks); - QComboBox * ySelect = ui->ySetpointSelect; - ySelect->clear(); - ySelect->addItems(blocks); + ui->zPositionSelect->clear(); + ui->zPositionSelect->addItems(blocks); - QComboBox * zSelect = ui->zSetpointSelect; - zSelect->clear(); - zSelect->addItems(blocks); + ui->pAttitudeSelect->clear(); + ui->pAttitudeSelect->addItems(blocks); + + ui->rAttitudeSelect->clear(); + ui->rAttitudeSelect->addItems(blocks); + + ui->yAttitudeSelect->clear(); + ui->yAttitudeSelect->addItems(blocks); for (ssize_t i = 0; i < blocks.size(); i++) { if (blocks[i].contains("setpoint", Qt::CaseInsensitive) || blocks[i].contains("sp", Qt::CaseInsensitive)) { if (blocks[i].contains("x ", Qt::CaseInsensitive)) { - xSelect->setCurrentIndex(i); + ui->xSetpointSelect->setCurrentIndex(i); } if (blocks[i].contains("y ", Qt::CaseInsensitive)) { - ySelect->setCurrentIndex(i); + ui->ySetpointSelect->setCurrentIndex(i); } if (blocks[i].contains("z ", Qt::CaseInsensitive) || blocks[i].contains("alt", Qt::CaseInsensitive)) { - zSelect->setCurrentIndex(i); + ui->zSetpointSelect->setCurrentIndex(i); } } + + if (blocks[i] == QString("Pitch")) { + ui->pAttitudeSelect->setCurrentIndex(i); + } + + if (blocks[i] == QString("Roll")) { + ui->rAttitudeSelect->setCurrentIndex(i); + } + + if (blocks[i] == QString("Yaw")) { + ui->yAttitudeSelect->setCurrentIndex(i); + } + + if (blocks[i] == QString("Lidar")) { + ui->zPositionSelect->setCurrentIndex(i); + } + + if (blocks[i] == QString("OF X Trim Add")) { + ui->xPositionSelect->setCurrentIndex(i); + } + + if (blocks[i] == QString("OF Y Trim Add")) { + ui->yPositionSelect->setCurrentIndex(i); + } } } @@ -231,6 +269,23 @@ void MainWindow::newParamValue(QString node, QString param, float val) } else if (node == ui->zSetpointSelect->currentText()) { ui->zSetpoint->setText(QString::number(val)); } + + std::cout << node.toStdString() << " " << param.toStdString() << " " << val << std::endl; + + /* Update the nav page if quad is set as the source for pos/att */ + if (node == ui->xPositionSelect->currentText()) { + ui->xActual->setText(QString::number(val)); + } else if (node == ui->yPositionSelect->currentText()) { + ui->yActual->setText(QString::number(val)); + } else if (node == ui->zPositionSelect->currentText()) { + ui->zActual->setText(QString::number(val)); + } else if (node == ui->pAttitudeSelect->currentText()) { + ui->pitchActual->setText(QString::number(val)); + } else if (node == ui->rAttitudeSelect->currentText()) { + ui->rollActual->setText(QString::number(val)); + } else if (node == ui->yAttitudeSelect->currentText()) { + ui->yawActual->setText(QString::number(val)); + } } void MainWindow::on_paramSelect_currentIndexChanged(const QString &arg1) diff --git a/groundStation/gui/MicroCART/mainwindow.h b/groundStation/gui/MicroCART/mainwindow.h index 62b0443047c1fab4a612573f8d90f4ee1e150cda..3c6bc21d48c88743fba7949301dfec636de830e2 100644 --- a/groundStation/gui/MicroCART/mainwindow.h +++ b/groundStation/gui/MicroCART/mainwindow.h @@ -24,6 +24,7 @@ signals: void disconnectWorkers(); void getParamValue(QString node, QString param); void setParamValue(QString node, QString param, float value); + void getPosAttFromBackend(); private slots: void on_pbStart_clicked(); @@ -36,7 +37,7 @@ private slots: void updateTracker(float x, float y, float z, float p, float r, float yaw); - void updateConsole(); + void updatePosAtt(); void newNodes(QStringList blocks); void newParams(QStringList params); @@ -73,11 +74,14 @@ private slots: void on_socketPath_returnPressed(); + void on_xSetpoint_returnPressed(); + + void on_ySetpoint_returnPressed(); + + void on_zSetpoint_returnPressed(); + private: Ui::MainWindow *ui; - pid_t backendPid; - int backendPipe; - int backendState; QStandardItemModel * setpointList; QTimer * nextSpTimer; float sp_x; diff --git a/groundStation/gui/MicroCART/mainwindow.ui b/groundStation/gui/MicroCART/mainwindow.ui index a6795802eddc4c1dc1e89b03f408fb82bb30762b..dea7a13c68d0ea4e1c4daac01cb6a4a74763b89e 100644 --- a/groundStation/gui/MicroCART/mainwindow.ui +++ b/groundStation/gui/MicroCART/mainwindow.ui @@ -37,7 +37,7 @@ <item row="0" column="1"> <widget class="QLineEdit" name="socketPath"> <property name="enabled"> - <bool>true</bool> + <bool>false</bool> </property> <property name="text"> <string/> @@ -154,8 +154,8 @@ <rect> <x>0</x> <y>0</y> - <width>98</width> - <height>76</height> + <width>968</width> + <height>577</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout_8"> @@ -258,6 +258,13 @@ </item> </layout> </item> + <item> + <widget class="Line" name="line_5"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> <item> <layout class="QHBoxLayout" name="horizontalLayout_4"> <item> @@ -317,6 +324,110 @@ </item> </layout> </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_10"> + <item> + <widget class="QLabel" name="label_11"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>X Position</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="xPositionSelect"/> + </item> + <item> + <widget class="QLabel" name="label_13"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Y Position </string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="yPositionSelect"/> + </item> + <item> + <widget class="QLabel" name="label_14"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Z Position</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="zPositionSelect"/> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_11"> + <item> + <widget class="QLabel" name="label_15"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>P Attitude</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="pAttitudeSelect"/> + </item> + <item> + <widget class="QLabel" name="label_16"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>R Attitude</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="rAttitudeSelect"/> + </item> + <item> + <widget class="QLabel" name="label_17"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Y Attitude</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="yAttitudeSelect"/> + </item> + </layout> + </item> </layout> </widget> <widget class="QWidget" name="navigation"> @@ -362,6 +473,52 @@ </property> </widget> </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_9"> + <item> + <widget class="QLabel" name="label_12"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Position/Attitude Source: </string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="posattSrcVrpn"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Backend Tracker (&VRPN)</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="posattSrcQuad"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>From &Quad</string> + </property> + </widget> + </item> + </layout> + </item> <item> <layout class="QHBoxLayout" name="horizontalLayout_3"> <item> @@ -882,7 +1039,7 @@ <x>0</x> <y>0</y> <width>1004</width> - <height>27</height> + <height>30</height> </rect> </property> </widget> diff --git a/groundStation/gui/MicroCART/wrappers.c b/groundStation/gui/MicroCART/wrappers.c deleted file mode 100644 index 45fdf0b28619f4d7d3cd6803239e6b0e2f999f62..0000000000000000000000000000000000000000 --- a/groundStation/gui/MicroCART/wrappers.c +++ /dev/null @@ -1,68 +0,0 @@ -#include "wrappers.h" -#include <sys/types.h> -#include <sys/wait.h> -#include <sys/socket.h> -#include <unistd.h> -#include <signal.h> -#include <err.h> -#include <stdlib.h> - - -size_t readBackend(int fd, char * buf, size_t maxlen) -{ - int len = read(fd, buf, maxlen); - if (len < 0) { - len = 0; - } - - return len; -} - -int stopBackend(int pid, int pipefd) -{ - close(pipefd); - kill(pid, SIGTERM); - int status; - wait(&status); - return status; -} - -int startBackend(const char * backend, int * pipefd) -{ - /* Create a pipe */ - int pipe_fds[2]; - if (pipe(pipe_fds)) { - warn("Failed to open pipe, cannot start backend!"); - return -1; - } - - int pid = fork(); - if (!pid) { - /* Child closes read end of pipe */ - close(pipe_fds[0]); - - write(pipe_fds[1], "From child", 11); - /* dup write end of pipe to stdout (FD 1), closing old stdout */ - //dup2(pipe_fds[1], 1); - //dup2(pipe_fds[1], 2); - - write(2, "Child stderr\n", 13); - printf("Child stdout\n"); - - /* Don't need whatever FD is in pipe_fds[1] anymore, since it is stdout now */ - close(pipe_fds[1]); - - execl(backend, "BackEnd", NULL); - exit(0); - } - - /* Return the read end of the pipe in pipefd pointer */ - *pipefd = pipe_fds[0]; - - - /* Parent closes write end of the pipe */ - close(pipe_fds[1]); - - - return pid; -} diff --git a/groundStation/gui/MicroCART/wrappers.h b/groundStation/gui/MicroCART/wrappers.h deleted file mode 100644 index 6a29ecf90a9b59c71a3595242fa5fb31c68899e8..0000000000000000000000000000000000000000 --- a/groundStation/gui/MicroCART/wrappers.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef WRAPPERS_H -#define WRAPPERS_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include <stdio.h> - -int startBackend(const char * backend, int * pipefd); -int stopBackend(int pid, int pipefd); -size_t readBackend(int fd, char * buf, size_t maxlen); - -#ifdef __cplusplus -} -#endif - -#endif // WRAPPERS_H