-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththree_line_ieee_example.cpp
More file actions
73 lines (61 loc) · 2.03 KB
/
three_line_ieee_example.cpp
File metadata and controls
73 lines (61 loc) · 2.03 KB
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
#include "example_common.hpp"
#include "gnuplotpp/plot.hpp"
#include "gnuplotpp/presets.hpp"
#include <algorithm>
#include <filesystem>
#include <string>
#include <vector>
int main(int argc, char** argv) {
using namespace gnuplotpp;
const std::filesystem::path out_dir =
example_common::parse_out_dir(argc, argv, "out/three_line_ieee_example");
FigureSpec fs;
fs.preset = Preset::IEEE_SingleColumn;
apply_preset_defaults(fs);
fs.rows = 1;
fs.cols = 1;
fs.formats = {OutputFormat::Pdf, OutputFormat::Svg, OutputFormat::Eps};
fs.title = "Three-Method Comparison";
fs.style.line_width_pt = 1.5;
Figure fig(fs);
AxesSpec ax;
ax.title = "Position Error Norm";
ax.xlabel = "t [s]";
ax.ylabel = "||e_p|| [m]";
ax.legend = true;
ax.grid = true;
ax.ylog = true;
std::vector<double> t;
std::vector<double> srif;
std::vector<double> ukf;
std::vector<double> ekf;
for (int i = 0; i < 200; ++i) {
const double x = static_cast<double>(i) * 0.5;
t.push_back(x);
srif.push_back(16.0 / (1.0 + 0.20 * x));
ukf.push_back(11.0 / (1.0 + 0.080 * x));
ekf.push_back(7.8 / (1.0 + 0.035 * x));
}
double y_max_data = 0.0;
for (const double v : srif) {
y_max_data = std::max(y_max_data, v);
}
for (const double v : ukf) {
y_max_data = std::max(y_max_data, v);
}
for (const double v : ekf) {
y_max_data = std::max(y_max_data, v);
}
const double y_max_plot = y_max_data * 1.05;
const double y_min_plot = std::max(1.0e-3, srif.back() * 0.8);
ax.has_ylim = true;
ax.ymin = y_min_plot;
ax.ymax = y_max_plot;
ax.gnuplot_commands = {
"set label 1 'e_p(t)=e_0 e^{-{/Symbol l} t}' at graph 0.06,0.10 font 'Times,8' front"};
fig.axes(0).set(ax);
fig.axes(0).add_series(SeriesSpec{.type = SeriesType::Line, .label = "SRIF"}, t, srif);
fig.axes(0).add_series(SeriesSpec{.type = SeriesType::Line, .label = "UKF"}, t, ukf);
fig.axes(0).add_series(SeriesSpec{.type = SeriesType::Line, .label = "EKF"}, t, ekf);
return example_common::render_figure(fig, out_dir / "figures");
}