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