James Kuszmaul | 313e9ce | 2024-02-11 17:47:33 -0800 | [diff] [blame^] | 1 | #include "gflags/gflags.h" |
| 2 | |
| 3 | #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" |
| 10 | #include "aos/util/simulation_logger.h" |
| 11 | #include "y2024/control_loops/drivetrain/drivetrain_base.h" |
| 12 | #include "y2024/localizer/localizer.h" |
| 13 | |
| 14 | DEFINE_string(config, "y2024/aos_config.json", |
| 15 | "Name of the config file to replay using."); |
| 16 | DEFINE_int32(team, 9971, "Team number to use for logfile replay."); |
| 17 | DEFINE_string(output_folder, "/tmp/replayed", |
| 18 | "Name of the folder to write replayed logs to."); |
| 19 | |
| 20 | int 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 | // sort logfiles |
| 29 | const std::vector<aos::logger::LogFile> logfiles = |
| 30 | aos::logger::SortParts(aos::logger::FindLogs(argc, argv)); |
| 31 | |
| 32 | // open logfiles |
| 33 | aos::logger::LogReader reader(logfiles, &config.message()); |
| 34 | |
| 35 | reader.RemapLoggedChannel("/localizer", "y2024.localizer.Status"); |
| 36 | for (const auto orin : {"orin1", "orin2"}) { |
| 37 | for (const auto camera : {"camera0", "camera1"}) { |
| 38 | reader.RemapLoggedChannel(absl::StrCat("/", orin, "/", camera), |
| 39 | "y2024.localizer.Visualization"); |
| 40 | } |
| 41 | } |
| 42 | reader.RemapLoggedChannel("/localizer", "frc971.controls.LocalizerOutput"); |
| 43 | |
| 44 | auto factory = |
| 45 | std::make_unique<aos::SimulatedEventLoopFactory>(reader.configuration()); |
| 46 | |
| 47 | reader.RegisterWithoutStarting(factory.get()); |
| 48 | |
| 49 | const aos::Node *node = nullptr; |
| 50 | if (aos::configuration::MultiNode(reader.configuration())) { |
| 51 | node = aos::configuration::GetNode(reader.configuration(), "imu"); |
| 52 | } |
| 53 | std::vector<std::unique_ptr<aos::util::LoggerState>> loggers; |
| 54 | |
| 55 | reader.OnStart(node, [&factory, node, &loggers]() { |
| 56 | aos::NodeEventLoopFactory *node_factory = |
| 57 | factory->GetNodeEventLoopFactory(node); |
| 58 | node_factory->AlwaysStart<y2024::localizer::Localizer>("localizer"); |
| 59 | loggers.push_back(std::make_unique<aos::util::LoggerState>( |
| 60 | factory.get(), node, FLAGS_output_folder)); |
| 61 | }); |
| 62 | |
| 63 | reader.event_loop_factory()->Run(); |
| 64 | |
| 65 | reader.Deregister(); |
| 66 | |
| 67 | return 0; |
| 68 | } |