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. |
| 7 | #include "aos/events/logging/log_reader.h" |
| 8 | #include "aos/events/simulated_event_loop.h" |
| 9 | #include "aos/init.h" |
| 10 | #include "aos/json_to_flatbuffer.h" |
| 11 | #include "aos/logging/log_message_generated.h" |
| 12 | #include "aos/network/team_number.h" |
| 13 | #include "gflags/gflags.h" |
| 14 | #include "y2020/constants.h" |
| 15 | #include "y2020/control_loops/superstructure/superstructure.h" |
| 16 | |
| 17 | DEFINE_int32(team, 971, "Team number to use for logfile replay."); |
| 18 | |
| 19 | int main(int argc, char **argv) { |
| 20 | aos::InitGoogle(&argc, &argv); |
| 21 | |
| 22 | aos::network::OverrideTeamNumber(FLAGS_team); |
| 23 | y2020::constants::InitValues(); |
| 24 | |
| 25 | // open logfiles |
| 26 | aos::logger::LogReader reader( |
| 27 | aos::logger::SortParts(aos::logger::FindLogs(argc, argv))); |
| 28 | // TODO(james): Actually enforce not sending on the same buses as the logfile |
| 29 | // spews out. |
| 30 | reader.RemapLoggedChannel("/superstructure", |
| 31 | "y2020.control_loops.superstructure.Status"); |
| 32 | reader.RemapLoggedChannel("/superstructure", |
| 33 | "y2020.control_loops.superstructure.Output"); |
| 34 | |
| 35 | aos::SimulatedEventLoopFactory factory(reader.configuration()); |
| 36 | reader.Register(&factory); |
| 37 | |
| 38 | aos::NodeEventLoopFactory *roborio = |
| 39 | factory.GetNodeEventLoopFactory("roborio"); |
| 40 | |
| 41 | roborio->OnStartup([roborio]() { |
| 42 | roborio->AlwaysStart<y2020::control_loops::superstructure::Superstructure>( |
| 43 | "superstructure"); |
| 44 | }); |
| 45 | |
| 46 | std::unique_ptr<aos::EventLoop> print_loop = roborio->MakeEventLoop("print"); |
| 47 | print_loop->SkipAosLog(); |
| 48 | print_loop->MakeWatcher( |
| 49 | "/aos", [&print_loop](const aos::logging::LogMessageFbs &msg) { |
| 50 | LOG(INFO) << print_loop->context().monotonic_event_time << " " |
| 51 | << aos::FlatbufferToJson(&msg); |
| 52 | }); |
| 53 | print_loop->MakeWatcher( |
| 54 | "/superstructure", |
| 55 | [&print_loop]( |
| 56 | const y2020::control_loops::superstructure::Position &position) { |
| 57 | LOG(INFO) << print_loop->context().monotonic_event_time << " " |
| 58 | << aos::FlatbufferToJson(position.hood()); |
| 59 | }); |
| 60 | print_loop->MakeWatcher( |
| 61 | "/superstructure", |
| 62 | [&print_loop]( |
| 63 | const y2020::control_loops::superstructure::Status &status) { |
| 64 | if (status.estopped()) { |
| 65 | LOG(INFO) << "Estopped"; |
| 66 | } |
| 67 | LOG(INFO) << print_loop->context().monotonic_event_time << " " |
| 68 | << aos::FlatbufferToJson(status.hood()); |
| 69 | }); |
| 70 | |
| 71 | factory.Run(); |
| 72 | |
| 73 | reader.Deregister(); |
| 74 | |
| 75 | return 0; |
| 76 | } |