-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheulerplot.cpp
81 lines (72 loc) · 2.63 KB
/
eulerplot.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "eulerplot.h"
#include "ui_eulerplot.h"
#include "globals.h"
EulerPlot::EulerPlot(QWidget *parent) :
QDialog(parent),
ui(new Ui::EulerPlot)
{
ui->setupUi(this);
EulerPlot::MakePlot();
}
EulerPlot::~EulerPlot()
{
delete ui;
}
//Draw - read data from txt files and plot
void EulerPlot::MakePlot()
{
QVector<double> t;
QVector<double> phi,the,psi;
QString file_name = "./outputs/" + QString::fromStdString(currentTime) + "angles.txt";
QFile textFile(file_name);
//Read Data From File
if(textFile.open(QIODevice::ReadOnly))
{
int i = 0;
QTextStream textStream(&textFile);
while (!textStream.atEnd()) {
QString line = textStream.readLine();
if(textStream.status() == QTextStream::Ok){
QStringList lstLine = line.split(QRegExp("\\s+"));
phi.append(lstLine.at(0).toDouble());
the.append(lstLine.at(1).toDouble());
psi.append(lstLine.at(2).toDouble());
t.append(i);
i++;
}
else
break;
}
//Phi plot
ui->customEulerPlot->addGraph();
ui->customEulerPlot->graph(0)->setData(t,phi);
ui->customEulerPlot->graph(0)->setPen(QPen(Qt::blue));
ui->customEulerPlot->graph(0)->setName("pitch - " + QString::fromUtf8("\u03B8"));
//Theta plot
ui->customEulerPlot->addGraph();
ui->customEulerPlot->graph(1)->setData(t,the);
ui->customEulerPlot->graph(1)->setPen(QPen(Qt::red));
ui->customEulerPlot->graph(1)->setName("roll - " + QString::fromUtf8("\u03C6"));
//Psi plot
ui->customEulerPlot->addGraph();
ui->customEulerPlot->graph(2)->setData(t,psi);
ui->customEulerPlot->graph(2)->setPen(QPen(Qt::green));
ui->customEulerPlot->graph(2)->setName("yaw - " + QString::fromUtf8("\u03C8"));
//Set labels, ranges, legend
ui->customEulerPlot->xAxis->setLabel("Time (Sec)");
ui->customEulerPlot->yAxis->setLabel("Angle (Degrees)");
ui->customEulerPlot->rescaleAxes();
ui->customEulerPlot->yAxis->setRange(-180, 180);
ui->customEulerPlot->legend->setVisible(true);
ui->customEulerPlot->legend->setFont(QFont("Helvetica", 9));
//Draw
ui->customEulerPlot->replot();
}
}
//Save and Close
void EulerPlot::on_pushButton_clicked()
{
QString file_name = "./outputs/" + QString::fromStdString(currentTime) + "angles.png";
ui->customEulerPlot->savePng(file_name);
this->close();
}