blob: 15b29b2a40448dbae8beebca697719d8ac067e14 [file] [log] [blame]
Maxwell Henderson7643e4c2024-03-11 20:43:18 -07001#include <fstream>
2
Austin Schuh99f7c6a2024-06-25 22:07:44 -07003#include "absl/flags/flag.h"
4#include "absl/log/check.h"
5#include "absl/log/log.h"
Maxwell Henderson7643e4c2024-03-11 20:43:18 -07006
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 Schuh99f7c6a2024-06-25 22:07:44 -070012ABSL_FLAG(std::string, output_path, "/tmp/pdp_values.csv", "");
Maxwell Henderson7643e4c2024-03-11 20:43:18 -070013
14int 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 Schuh99f7c6a2024-06-25 22:07:44 -070031 file_stream.open(absl::GetFlag(FLAGS_output_path));
Maxwell Henderson7643e4c2024-03-11 20:43:18 -070032 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}