blob: 492ddfa84587655b2aef6e3f80a7ea22b85ab5ff [file] [log] [blame]
James Kuszmaul48671362020-12-24 13:54:16 -08001#include "frc971/analysis/in_process_plotter.h"
2
3#include "aos/init.h"
4
5// To run this example, do:
6// bazel run -c opt //frc971/analysis:in_process_plotter_demo
7// And then open localhost:8080, select "C++ Plotter" from the drop-down, and
8// then select "TITLE!" or "Trig Functions" from the second drop-down to see
9// each plot.
10int main(int argc, char *argv[]) {
11 aos::InitGoogle(&argc, &argv);
12 frc971::analysis::Plotter plotter;
13 plotter.Title("TITLE!");
14 plotter.AddFigure("Fig Foo");
15 plotter.ShareXAxis(true);
16 plotter.AddLine({1, 2, 3, 4, 5}, {1, 2, 3, 4, 5}, "y = x");
17 plotter.AddLine({5, 4, 3, 2, 1}, {1, 2, 3, 4, 5}, "y = -x");
18 plotter.YLabel("Y Axis");
19 plotter.AddFigure("Fig Bar");
20 plotter.ShareXAxis(true);
21 plotter.AddLine({1, 2, 3}, {3, 4, 5}, "y = x + 2");
22 plotter.XLabel("X Axis (Linked to both above plots)");
23 plotter.Publish();
24
25 plotter.Title("Trig Functions");
26
27 plotter.AddFigure("Sin & Cos");
28 std::vector<double> x;
29 std::vector<double> sinx;
30 std::vector<double> cosx;
31 constexpr int kNumPoints = 100000;
32 for (int ii = 0; ii < kNumPoints; ++ii) {
33 x.push_back(ii * 2 * M_PI / kNumPoints);
34 sinx.push_back(std::sin(x.back()));
35 cosx.push_back(std::cos(x.back()));
36 }
37 plotter.AddLine(x, sinx, "sin(x)");
38 plotter.AddLine(x, cosx, "cos(x)");
39 plotter.Publish();
40
41 plotter.Spin();
42}