Austin Schuh | f213a07 | 2021-10-17 23:42:50 -0700 | [diff] [blame] | 1 | // This binary allows us to replay the drivetrain code over existing logfile, |
| 2 | // primarily for use in testing changes to the localizer code. |
| 3 | // When you run this code, it generates a new logfile with the data all |
| 4 | // replayed, so that it can then be run through the plotting tool or analyzed |
| 5 | // in some other way. The original drivetrain status data will be on the |
| 6 | // /original/drivetrain channel. |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame^] | 7 | #include "absl/flags/flag.h" |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 8 | |
Austin Schuh | f213a07 | 2021-10-17 23:42:50 -0700 | [diff] [blame] | 9 | #include "aos/events/logging/log_reader.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" |
Austin Schuh | f213a07 | 2021-10-17 23:42:50 -0700 | [diff] [blame] | 15 | #include "y2020/constants.h" |
| 16 | #include "y2020/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."); |
Austin Schuh | f213a07 | 2021-10-17 23:42:50 -0700 | [diff] [blame] | 19 | |
| 20 | int main(int argc, char **argv) { |
| 21 | aos::InitGoogle(&argc, &argv); |
| 22 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame^] | 23 | aos::network::OverrideTeamNumber(absl::GetFlag(FLAGS_team)); |
Austin Schuh | f213a07 | 2021-10-17 23:42:50 -0700 | [diff] [blame] | 24 | y2020::constants::InitValues(); |
| 25 | |
| 26 | // open logfiles |
| 27 | aos::logger::LogReader reader( |
| 28 | aos::logger::SortParts(aos::logger::FindLogs(argc, argv))); |
| 29 | // TODO(james): Actually enforce not sending on the same buses as the logfile |
| 30 | // spews out. |
| 31 | reader.RemapLoggedChannel("/superstructure", |
| 32 | "y2020.control_loops.superstructure.Status"); |
| 33 | reader.RemapLoggedChannel("/superstructure", |
| 34 | "y2020.control_loops.superstructure.Output"); |
| 35 | |
| 36 | aos::SimulatedEventLoopFactory factory(reader.configuration()); |
| 37 | reader.Register(&factory); |
| 38 | |
| 39 | aos::NodeEventLoopFactory *roborio = |
| 40 | factory.GetNodeEventLoopFactory("roborio"); |
| 41 | |
| 42 | roborio->OnStartup([roborio]() { |
| 43 | roborio->AlwaysStart<y2020::control_loops::superstructure::Superstructure>( |
| 44 | "superstructure"); |
| 45 | }); |
| 46 | |
| 47 | std::unique_ptr<aos::EventLoop> print_loop = roborio->MakeEventLoop("print"); |
| 48 | print_loop->SkipAosLog(); |
| 49 | print_loop->MakeWatcher( |
| 50 | "/aos", [&print_loop](const aos::logging::LogMessageFbs &msg) { |
| 51 | LOG(INFO) << print_loop->context().monotonic_event_time << " " |
| 52 | << aos::FlatbufferToJson(&msg); |
| 53 | }); |
| 54 | print_loop->MakeWatcher( |
| 55 | "/superstructure", |
| 56 | [&print_loop]( |
| 57 | const y2020::control_loops::superstructure::Position &position) { |
| 58 | LOG(INFO) << print_loop->context().monotonic_event_time << " " |
| 59 | << aos::FlatbufferToJson(position.hood()); |
| 60 | }); |
| 61 | print_loop->MakeWatcher( |
| 62 | "/superstructure", |
| 63 | [&print_loop]( |
| 64 | const y2020::control_loops::superstructure::Status &status) { |
| 65 | if (status.estopped()) { |
| 66 | LOG(INFO) << "Estopped"; |
| 67 | } |
| 68 | LOG(INFO) << print_loop->context().monotonic_event_time << " " |
| 69 | << aos::FlatbufferToJson(status.hood()); |
| 70 | }); |
| 71 | |
| 72 | factory.Run(); |
| 73 | |
| 74 | reader.Deregister(); |
| 75 | |
| 76 | return 0; |
| 77 | } |