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