blob: 27fdd85561c02be3643634b47a64991edc28c380 [file] [log] [blame]
Philipp Schrader790cb542023-07-05 21:06:52 -07001#include "gflags/gflags.h"
2
James Kuszmaul6e0d8652023-03-12 14:02:26 -07003#include "aos/configuration.h"
4#include "aos/events/logging/log_reader.h"
5#include "aos/events/logging/log_writer.h"
6#include "aos/events/simulated_event_loop.h"
7#include "aos/init.h"
8#include "aos/json_to_flatbuffer.h"
9#include "aos/network/team_number.h"
James Kuszmaule4853542023-05-15 20:35:48 -070010#include "aos/util/simulation_logger.h"
James Kuszmaul6e0d8652023-03-12 14:02:26 -070011#include "y2023/control_loops/drivetrain/drivetrain_base.h"
James Kuszmaule4853542023-05-15 20:35:48 -070012#include "y2023/localizer/localizer.h"
James Kuszmaul6e0d8652023-03-12 14:02:26 -070013
14DEFINE_string(config, "y2023/aos_config.json",
15 "Name of the config file to replay using.");
16DEFINE_int32(team, 9971, "Team number to use for logfile replay.");
17DEFINE_string(output_folder, "/tmp/replayed",
18 "Name of the folder to write replayed logs to.");
19
James Kuszmaul6e0d8652023-03-12 14:02:26 -070020int main(int argc, char **argv) {
21 aos::InitGoogle(&argc, &argv);
22
23 aos::network::OverrideTeamNumber(FLAGS_team);
24
25 const aos::FlatbufferDetachedBuffer<aos::Configuration> config =
26 aos::configuration::ReadConfig(FLAGS_config);
27
28 // find logfiles
29 std::vector<std::string> unsorted_logfiles =
30 aos::logger::FindLogs(argc, argv);
31
32 // sort logfiles
33 const std::vector<aos::logger::LogFile> logfiles =
34 aos::logger::SortParts(unsorted_logfiles);
35
36 // open logfiles
37 aos::logger::LogReader reader(logfiles, &config.message());
38
Philipp Schrader790cb542023-07-05 21:06:52 -070039 reader.RemapLoggedChannel("/localizer", "y2023.localizer.Status");
James Kuszmaul6e0d8652023-03-12 14:02:26 -070040 for (const auto pi : {"pi1", "pi2", "pi3", "pi4"}) {
41 reader.RemapLoggedChannel(absl::StrCat("/", pi, "/camera"),
42 "y2023.localizer.Visualization");
43 }
Philipp Schrader790cb542023-07-05 21:06:52 -070044 reader.RemapLoggedChannel("/localizer", "frc971.controls.LocalizerOutput");
James Kuszmaul6e0d8652023-03-12 14:02:26 -070045
46 auto factory =
47 std::make_unique<aos::SimulatedEventLoopFactory>(reader.configuration());
48
49 reader.Register(factory.get());
50
James Kuszmaul6e0d8652023-03-12 14:02:26 -070051 // List of nodes to create loggers for (note: currently just roborio; this
52 // code was refactored to allow easily adding new loggers to accommodate
53 // debugging and potential future changes).
54 const std::vector<std::string> nodes_to_log = {"imu"};
James Kuszmaule4853542023-05-15 20:35:48 -070055 std::vector<std::unique_ptr<aos::util::LoggerState>> loggers =
56 aos::util::MakeLoggersForNodes(reader.event_loop_factory(), nodes_to_log,
57 FLAGS_output_folder);
James Kuszmaul6e0d8652023-03-12 14:02:26 -070058
59 const aos::Node *node = nullptr;
60 if (aos::configuration::MultiNode(reader.configuration())) {
61 node = aos::configuration::GetNode(reader.configuration(), "imu");
62 }
63
64 std::unique_ptr<aos::EventLoop> localizer_event_loop =
65 reader.event_loop_factory()->MakeEventLoop("localizer", node);
66 localizer_event_loop->SkipTimingReport();
67
68 y2023::localizer::Localizer localizer(
69 localizer_event_loop.get(),
70 y2023::control_loops::drivetrain::GetDrivetrainConfig());
71
72 reader.event_loop_factory()->Run();
73
74 reader.Deregister();
75
76 return 0;
77}