Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [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 |
Milind Upadhyay | 9d68b13 | 2022-04-01 10:58:18 -0700 | [diff] [blame] | 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" |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 7 | |
Milind Upadhyay | 9d68b13 | 2022-04-01 10:58:18 -0700 | [diff] [blame] | 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" |
Milind Upadhyay | 9d68b13 | 2022-04-01 10:58:18 -0700 | [diff] [blame] | 15 | #include "y2022/constants.h" |
| 16 | #include "y2022/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."); |
Milind Upadhyay | 9d68b13 | 2022-04-01 10:58:18 -0700 | [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)); |
Milind Upadhyay | 9d68b13 | 2022-04-01 10:58:18 -0700 | [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 | "y2022.control_loops.superstructure.Status"); |
| 34 | reader.RemapLoggedChannel("/superstructure", |
| 35 | "y2022.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()); |
Milind Upadhyay | 9d68b13 | 2022-04-01 10:58:18 -0700 | [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)); |
Milind Upadhyay | 9d68b13 | 2022-04-01 10:58:18 -0700 | [diff] [blame] | 48 | |
| 49 | roborio->OnStartup([roborio]() { |
| 50 | roborio->AlwaysStart<y2022::control_loops::superstructure::Superstructure>( |
| 51 | "superstructure", std::make_shared<y2022::constants::Values>( |
| 52 | y2022::constants::MakeValues())); |
| 53 | }); |
| 54 | |
| 55 | std::unique_ptr<aos::EventLoop> print_loop = roborio->MakeEventLoop("print"); |
| 56 | print_loop->SkipAosLog(); |
| 57 | print_loop->MakeWatcher( |
| 58 | "/aos", [&print_loop](const aos::logging::LogMessageFbs &msg) { |
| 59 | LOG(INFO) << print_loop->context().monotonic_event_time << " " |
| 60 | << aos::FlatbufferToJson(&msg); |
| 61 | }); |
| 62 | print_loop->MakeWatcher( |
| 63 | "/superstructure", |
| 64 | [&](const y2022::control_loops::superstructure::Status &status) { |
| 65 | if (status.estopped()) { |
| 66 | LOG(ERROR) << "Estopped"; |
| 67 | } |
| 68 | }); |
| 69 | |
| 70 | factory.Run(); |
| 71 | |
| 72 | reader.Deregister(); |
| 73 | |
| 74 | return 0; |
| 75 | } |