Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 1 | // This binary allows us to replay the superstructure code over existing |
| 2 | // logfile. When you run this code, it generates a new logfile with the data all |
| 3 | // replayed, so that it can then be run through the plotting tool or analyzed |
| 4 | // in some other way. The original superstructure status data will be on the |
| 5 | // /original/superstructure channel. |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 6 | #include "absl/flags/flag.h" |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 7 | |
| 8 | #include "aos/events/logging/log_reader.h" |
| 9 | #include "aos/events/logging/log_writer.h" |
| 10 | #include "aos/events/simulated_event_loop.h" |
| 11 | #include "aos/init.h" |
| 12 | #include "aos/json_to_flatbuffer.h" |
| 13 | #include "aos/logging/log_message_generated.h" |
| 14 | #include "aos/network/team_number.h" |
| 15 | #include "y2024/constants.h" |
| 16 | #include "y2024/control_loops/superstructure/superstructure.h" |
| 17 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 18 | ABSL_FLAG(int32_t, team, 971, "Team number to use for logfile replay."); |
| 19 | ABSL_FLAG(std::string, output_folder, "/tmp/superstructure_replay/", |
| 20 | "Logs all channels to the provided logfile."); |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 21 | |
| 22 | int main(int argc, char **argv) { |
| 23 | aos::InitGoogle(&argc, &argv); |
| 24 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 25 | aos::network::OverrideTeamNumber(absl::GetFlag(FLAGS_team)); |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 26 | |
| 27 | // open logfiles |
| 28 | aos::logger::LogReader reader( |
| 29 | aos::logger::SortParts(aos::logger::FindLogs(argc, argv))); |
| 30 | // TODO(james): Actually enforce not sending on the same buses as the logfile |
| 31 | // spews out. |
| 32 | reader.RemapLoggedChannel("/superstructure", |
| 33 | "y2024.control_loops.superstructure.Status"); |
| 34 | reader.RemapLoggedChannel("/superstructure", |
| 35 | "y2024.control_loops.superstructure.Output"); |
| 36 | |
| 37 | aos::SimulatedEventLoopFactory factory(reader.configuration()); |
| 38 | reader.Register(&factory); |
| 39 | |
| 40 | aos::NodeEventLoopFactory *roborio = |
| 41 | factory.GetNodeEventLoopFactory("roborio"); |
| 42 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 43 | unlink(absl::GetFlag(FLAGS_output_folder).c_str()); |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 44 | std::unique_ptr<aos::EventLoop> logger_event_loop = |
| 45 | roborio->MakeEventLoop("logger"); |
| 46 | auto logger = std::make_unique<aos::logger::Logger>(logger_event_loop.get()); |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 47 | logger->StartLoggingOnRun(absl::GetFlag(FLAGS_output_folder)); |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 48 | |
| 49 | roborio->OnStartup([roborio]() { |
| 50 | roborio->AlwaysStart<y2024::control_loops::superstructure::Superstructure>( |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 51 | "superstructure"); |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 52 | }); |
| 53 | |
| 54 | std::unique_ptr<aos::EventLoop> print_loop = roborio->MakeEventLoop("print"); |
| 55 | print_loop->SkipAosLog(); |
| 56 | print_loop->MakeWatcher( |
| 57 | "/aos", [&print_loop](const aos::logging::LogMessageFbs &msg) { |
| 58 | LOG(INFO) << print_loop->context().monotonic_event_time << " " |
| 59 | << aos::FlatbufferToJson(&msg); |
| 60 | }); |
| 61 | print_loop->MakeWatcher( |
| 62 | "/superstructure", |
| 63 | [&](const y2024::control_loops::superstructure::Status &status) { |
| 64 | if (status.estopped()) { |
| 65 | LOG(ERROR) << "Estopped"; |
| 66 | } |
| 67 | }); |
| 68 | |
| 69 | factory.Run(); |
| 70 | |
| 71 | reader.Deregister(); |
| 72 | |
| 73 | return 0; |
| 74 | } |