Maxwell Henderson | 7643e4c | 2024-03-11 20:43:18 -0700 | [diff] [blame] | 1 | #include <fstream> |
| 2 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 3 | #include "absl/flags/flag.h" |
| 4 | #include "absl/log/check.h" |
| 5 | #include "absl/log/log.h" |
Maxwell Henderson | 7643e4c | 2024-03-11 20:43:18 -0700 | [diff] [blame] | 6 | |
| 7 | #include "aos/events/logging/log_reader.h" |
| 8 | #include "aos/events/simulated_event_loop.h" |
| 9 | #include "aos/init.h" |
| 10 | #include "frc971/wpilib/pdp_values_generated.h" |
| 11 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 12 | ABSL_FLAG(std::string, output_path, "/tmp/pdp_values.csv", ""); |
Maxwell Henderson | 7643e4c | 2024-03-11 20:43:18 -0700 | [diff] [blame] | 13 | |
| 14 | int main(int argc, char **argv) { |
| 15 | aos::InitGoogle(&argc, &argv); |
| 16 | |
| 17 | aos::logger::LogReader reader( |
| 18 | aos::logger::SortParts(aos::logger::FindLogs(argc, argv))); |
| 19 | |
| 20 | aos::SimulatedEventLoopFactory event_loop_factory(reader.configuration()); |
| 21 | |
| 22 | reader.RegisterWithoutStarting(&event_loop_factory); |
| 23 | |
| 24 | const aos::Node *roborio = |
| 25 | aos::configuration::GetNode(reader.configuration(), "roborio"); |
| 26 | |
| 27 | std::unique_ptr<aos::EventLoop> event_loop = |
| 28 | event_loop_factory.MakeEventLoop("roborio", roborio); |
| 29 | |
| 30 | std::ofstream file_stream; |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 31 | file_stream.open(absl::GetFlag(FLAGS_output_path)); |
Maxwell Henderson | 7643e4c | 2024-03-11 20:43:18 -0700 | [diff] [blame] | 32 | file_stream << "timestamp,currents,voltage\n"; |
| 33 | |
| 34 | event_loop->SkipAosLog(); |
| 35 | event_loop->MakeWatcher( |
| 36 | "/roborio/aos", |
| 37 | [&file_stream, &event_loop](const frc971::PDPValues &pdp_values) { |
| 38 | file_stream << event_loop->context().monotonic_event_time << "," |
| 39 | << "["; |
| 40 | |
| 41 | for (uint i = 0; i < pdp_values.currents()->size(); i++) { |
| 42 | file_stream << pdp_values.currents()->Get(i); |
| 43 | if (i != pdp_values.currents()->size() - 1) { |
| 44 | file_stream << ", "; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | file_stream << "]," << pdp_values.voltage() << "\n"; |
| 49 | }); |
| 50 | |
| 51 | event_loop_factory.Run(); |
| 52 | |
| 53 | reader.Deregister(); |
| 54 | |
| 55 | file_stream.close(); |
| 56 | |
| 57 | return 0; |
| 58 | } |