Skip to content
Snippets Groups Projects
Commit 35d5728a authored by Jake Drahos's avatar Jake Drahos
Browse files

Created stuff for the tracker data

parent 17aa6c16
No related branches found
No related tags found
No related merge requests found
...@@ -14,9 +14,11 @@ TEMPLATE = app ...@@ -14,9 +14,11 @@ TEMPLATE = app
SOURCES += main.cpp\ SOURCES += main.cpp\
mainwindow.cpp \ mainwindow.cpp \
wrappers.c wrappers.c \
trackerworker.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
wrappers.h wrappers.h \
trackerworker.h
FORMS += mainwindow.ui FORMS += mainwindow.ui
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.2.2, 2017-02-23T15:17:30. --> <!-- Written by QtCreator 3.2.2, 2017-03-05T17:14:24. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.ActiveTarget</variable> <variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="int">0</value> <value type="int">-1</value>
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.EditorSettings</variable> <variable>ProjectExplorer.Project.EditorSettings</variable>
......
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include <QFileDialog>
#include <QThread>
#include <QTimer>
#include "wrappers.h" #include "wrappers.h"
#include "trackerworker.h"
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::MainWindow) ui(new Ui::MainWindow)
{ {
ui->setupUi(this); ui->setupUi(this);
/* Create a thread for workers */
QThread* workerThread = new QThread(this);
/* Create a worker to update the tracker */
TrackerWorker * trackerWorker = new TrackerWorker();
/* Move it to the worker thread. This means that slots of this worker
* will run in the worker thread, and not block the UI */
trackerWorker->moveToThread(workerThread);
/* Connect tracker worker */
connect(trackerWorker, SIGNAL (finished(float, float, float, float, float, float)),
this, SLOT (updateTracker(float, float, float, float, float, float)));
connect(findChild<QPushButton *>("pbStart"), SIGNAL (clicked()), trackerWorker, SLOT (connectBackend()));
connect(findChild<QPushButton *>("pbConnect"), SIGNAL (clicked()), trackerWorker, SLOT (connectBackend()));
/* Create other workers and add them to the worker thread, then connect them */
/* Now we can activate the slots of the workers with impunity and not block the UI thread */
/* Connect refresh button and refresh timer to tracker worker */
QTimer * trackerTimer = new QTimer(this);
connect(trackerTimer, SIGNAL(timeout()), trackerWorker, SLOT(process()));
connect(findChild<QPushButton *>("pbRefresh"), SIGNAL (clicked()), trackerWorker, SLOT (process()));
/* Start the things */
trackerTimer->start(300);
workerThread->start();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
...@@ -15,26 +48,45 @@ MainWindow::~MainWindow() ...@@ -15,26 +48,45 @@ MainWindow::~MainWindow()
delete ui; delete ui;
} }
void MainWindow::updateTracker(float x, float y, float z, float p, float r, float yaw)
{
findChild<QLineEdit *>("xLineEdit")->setText(QString::number(x));
findChild<QLineEdit *>("yLineEdit")->setText(QString::number(y));
findChild<QLineEdit *>("zLineEdit")->setText(QString::number(z));
findChild<QLineEdit *>("pLineEdit")->setText(QString::number(p));
findChild<QLineEdit *>("rLineEdit")->setText(QString::number(r));
findChild<QLineEdit *>("yLineEdit_2")->setText(QString::number(yaw));
}
void MainWindow::on_pbStart_clicked() void MainWindow::on_pbStart_clicked()
{ {
this->backendPid = startBackend(); this->backendPid = startBackend(findChild<QLineEdit *>("backendPath")->text().toStdString().c_str());
findChild<QPushButton *>("pbStart")->setEnabled(false); findChild<QPushButton *>("pbStart")->setEnabled(false);
findChild<QPushButton *>("pbConnect")->setEnabled(false); findChild<QPushButton *>("pbConnect")->setEnabled(false);
findChild<QPushButton *>("pbStop")->setEnabled(true); findChild<QPushButton *>("pbStop")->setEnabled(true);
backendState = 1;
} }
void MainWindow::on_pbConnect_clicked() void MainWindow::on_pbConnect_clicked()
{ {
// TODO: Connect to existing backend (what is connected?)
findChild<QPushButton *>("pbStart")->setEnabled(false); findChild<QPushButton *>("pbStart")->setEnabled(false);
findChild<QPushButton *>("pbConnect")->setEnabled(false); findChild<QPushButton *>("pbConnect")->setEnabled(false);
findChild<QPushButton *>("pbStop")->setEnabled(true); findChild<QPushButton *>("pbStop")->setEnabled(true);
backendState = 1;
} }
void MainWindow::on_pbStop_clicked() void MainWindow::on_pbStop_clicked()
{ {
stopBackend(backendPid); stopBackend(backendPid);
findChild<QPushButton *>("pbStart")->setEnabled(true); findChild<QPushButton *>("pbStart")->setEnabled(true);
//findChild<QPushButton *>("pbConnect")->setEnabled(true); findChild<QPushButton *>("pbConnect")->setEnabled(true);
findChild<QPushButton *>("pbStop")->setEnabled(false); findChild<QPushButton *>("pbStop")->setEnabled(false);
backendState = 0;
}
void MainWindow::on_chooseBackend_clicked()
{
QString backendPath = QFileDialog::getOpenFileName(this,
tr("Path to Backend Executable"));
findChild<QLineEdit *>("backendPath")->setText(backendPath);
} }
...@@ -22,6 +22,10 @@ private slots: ...@@ -22,6 +22,10 @@ private slots:
void on_pbStop_clicked(); void on_pbStop_clicked();
void on_chooseBackend_clicked();
void updateTracker(float x, float y, float z, float p, float r, float yaw);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
pid_t backendPid; pid_t backendPid;
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>481</width> <width>569</width>
<height>347</height> <height>427</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
<rect> <rect>
<x>10</x> <x>10</x>
<y>10</y> <y>10</y>
<width>461</width> <width>531</width>
<height>271</height> <height>281</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
...@@ -29,6 +29,9 @@ ...@@ -29,6 +29,9 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="backend"> <widget class="QWidget" name="backend">
<attribute name="title"> <attribute name="title">
<string>Connection</string> <string>Connection</string>
...@@ -55,7 +58,7 @@ ...@@ -55,7 +58,7 @@
<item> <item>
<widget class="QPushButton" name="pbConnect"> <widget class="QPushButton" name="pbConnect">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>true</bool>
</property> </property>
<property name="text"> <property name="text">
<string>Connect</string> <string>Connect</string>
...@@ -74,6 +77,20 @@ ...@@ -74,6 +77,20 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="chooseBackend">
<property name="text">
<string>Choose Backend</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="backendPath"/>
</item>
</layout>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
...@@ -100,19 +117,138 @@ ...@@ -100,19 +117,138 @@
</layout> </layout>
</widget> </widget>
</widget> </widget>
<widget class="QWidget" name="tab_2"> <widget class="QWidget" name="status">
<attribute name="title"> <attribute name="title">
<string>Tab 2</string> <string>Quad Status</string>
</attribute> </attribute>
<widget class="QWidget" name="horizontalLayoutWidget_2">
<property name="geometry">
<rect>
<x>-1</x>
<y>9</y>
<width>451</width>
<height>226</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="xLabel">
<property name="text">
<string>X</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="xLineEdit">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="yLabel">
<property name="text">
<string>Y</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="yLineEdit">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="zLabel">
<property name="text">
<string>Z</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="zLineEdit">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="pLabel">
<property name="text">
<string>P</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="pLineEdit">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="rLabel">
<property name="text">
<string>R</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="rLineEdit">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="yLabel_2">
<property name="text">
<string>Y</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="yLineEdit_2">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QFormLayout" name="formLayout_2"/>
</item>
</layout>
</widget>
</widget> </widget>
</widget> </widget>
<widget class="QPushButton" name="pbRefresh">
<property name="geometry">
<rect>
<x>10</x>
<y>290</y>
<width>88</width>
<height>34</height>
</rect>
</property>
<property name="text">
<string>Refresh</string>
</property>
</widget>
</widget> </widget>
<widget class="QMenuBar" name="menuBar"> <widget class="QMenuBar" name="menuBar">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>481</width> <width>569</width>
<height>30</height> <height>30</height>
</rect> </rect>
</property> </property>
......
#include "trackerworker.h"
#include <QThread>
TrackerWorker::TrackerWorker() :
QObject(), run(true)
{
}
TrackerWorker::~TrackerWorker()
{
}
void TrackerWorker::connectBackend()
{
}
void TrackerWorker::disconnectBackend()
{
}
void TrackerWorker::process()
{
/* Fake data. SAD! */
static float x = 1.0f, y = 2.0f, z = 3.0f, p = 4.0f, r = 5.0f, yaw = 6.0f;
x += 1.0;
y += 2.0;
z += 3.0;
p += 4.0;
r += 5.0;
yaw += 6.0;
emit finished(x, y, z, p, r, yaw);
}
#ifndef TRACKERWORKER_H
#define TRACKERWORKER_H
#include <QObject>
class TrackerWorker : public QObject
{
Q_OBJECT
public:
TrackerWorker();
~TrackerWorker();
signals:
void finished(float, float, float, float, float, float);
public slots:
void process();
void connectBackend();
void disconnectBackend();
private:
bool run;
};
#endif // TRACKERWORKER_H
...@@ -13,13 +13,11 @@ int stopBackend(int pid) ...@@ -13,13 +13,11 @@ int stopBackend(int pid)
return status; return status;
} }
int startBackend() int startBackend(const char * backend)
{ {
int pid = fork(); int pid = fork();
if (!pid) { if (!pid) {
// TODO: Make dynamic execl(backend, "backEnd", NULL);
// TODO: Redirect stdout to pipe to GUI
execl("backEnd", "backEnd", NULL);
exit(0); exit(0);
} }
return pid; return pid;
......
...@@ -6,7 +6,7 @@ extern "C" ...@@ -6,7 +6,7 @@ extern "C"
{ {
#endif #endif
int startBackend(void); int startBackend(const char * backend);
int stopBackend(int pid); int stopBackend(int pid);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
#include "frontend_common.h" #include "frontend_common.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Struct containing pos/att data */ /* Struct containing pos/att data */
struct frontend_tracker_data { struct frontend_tracker_data {
double height; double height;
...@@ -24,4 +28,8 @@ struct frontend_tracker_data { ...@@ -24,4 +28,8 @@ struct frontend_tracker_data {
int frontend_track(struct backend_conn * conn, int frontend_track(struct backend_conn * conn,
struct frontend_tracker_data *data); struct frontend_tracker_data *data);
#endif /* __FRONTEND_TRACKER_H */ #ifdef __cplusplus
\ No newline at end of file }
#endif
#endif /* __FRONTEND_TRACKER_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment