James Kuszmaul | 022d40e | 2020-02-11 17:06:18 -0800 | [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/configuration.h" |
| 8 | #include "aos/events/logging/logger.h" |
| 9 | #include "aos/events/simulated_event_loop.h" |
| 10 | #include "aos/init.h" |
| 11 | #include "aos/json_to_flatbuffer.h" |
| 12 | #include "aos/network/team_number.h" |
| 13 | #include "frc971/control_loops/drivetrain/drivetrain.h" |
| 14 | #include "gflags/gflags.h" |
| 15 | #include "y2020/control_loops/drivetrain/drivetrain_base.h" |
James Kuszmaul | 68f7d27 | 2020-02-22 20:55:02 -0800 | [diff] [blame] | 16 | #include "y2020/control_loops/drivetrain/localizer.h" |
James Kuszmaul | 022d40e | 2020-02-11 17:06:18 -0800 | [diff] [blame] | 17 | |
| 18 | DEFINE_string(logfile, "/tmp/logfile.bfbs", |
| 19 | "Name of the logfile to read from."); |
| 20 | DEFINE_string(config, "y2020/config.json", |
| 21 | "Name of the config file to replay using."); |
| 22 | DEFINE_string(output_file, "/tmp/replayed.bfbs", |
| 23 | "Name of the logfile to write replayed data to."); |
| 24 | DEFINE_int32(team, 971, "Team number to use for logfile replay."); |
| 25 | int main(int argc, char **argv) { |
| 26 | aos::InitGoogle(&argc, &argv); |
| 27 | |
| 28 | aos::network::OverrideTeamNumber(FLAGS_team); |
| 29 | |
| 30 | aos::InitCreate(); |
| 31 | |
| 32 | const aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 33 | aos::configuration::ReadConfig(FLAGS_config); |
| 34 | |
| 35 | aos::logger::LogReader reader(FLAGS_logfile, &config.message()); |
| 36 | // TODO(james): Actually enforce not sending on the same buses as the logfile |
| 37 | // spews out. |
| 38 | reader.RemapLoggedChannel("/drivetrain", |
| 39 | "frc971.control_loops.drivetrain.Status"); |
| 40 | reader.RemapLoggedChannel("/drivetrain", |
| 41 | "frc971.control_loops.drivetrain.Output"); |
| 42 | reader.Register(); |
| 43 | |
James Kuszmaul | 5f6d1d4 | 2020-03-01 18:10:07 -0800 | [diff] [blame] | 44 | const aos::Node *node = nullptr; |
| 45 | if (aos::configuration::MultiNode(reader.configuration())) { |
| 46 | node = aos::configuration::GetNode(reader.configuration(), "roborio"); |
| 47 | } |
| 48 | |
James Kuszmaul | 022d40e | 2020-02-11 17:06:18 -0800 | [diff] [blame] | 49 | aos::logger::DetachedBufferWriter file_writer(FLAGS_output_file); |
| 50 | std::unique_ptr<aos::EventLoop> log_writer_event_loop = |
James Kuszmaul | 5f6d1d4 | 2020-03-01 18:10:07 -0800 | [diff] [blame] | 51 | reader.event_loop_factory()->MakeEventLoop("log_writer", node); |
James Kuszmaul | 022d40e | 2020-02-11 17:06:18 -0800 | [diff] [blame] | 52 | log_writer_event_loop->SkipTimingReport(); |
James Kuszmaul | 022d40e | 2020-02-11 17:06:18 -0800 | [diff] [blame] | 53 | aos::logger::Logger writer(&file_writer, log_writer_event_loop.get()); |
| 54 | |
| 55 | std::unique_ptr<aos::EventLoop> drivetrain_event_loop = |
James Kuszmaul | 5f6d1d4 | 2020-03-01 18:10:07 -0800 | [diff] [blame] | 56 | reader.event_loop_factory()->MakeEventLoop("drivetrain", node); |
James Kuszmaul | 022d40e | 2020-02-11 17:06:18 -0800 | [diff] [blame] | 57 | drivetrain_event_loop->SkipTimingReport(); |
| 58 | |
James Kuszmaul | 68f7d27 | 2020-02-22 20:55:02 -0800 | [diff] [blame] | 59 | y2020::control_loops::drivetrain::Localizer localizer( |
James Kuszmaul | 022d40e | 2020-02-11 17:06:18 -0800 | [diff] [blame] | 60 | drivetrain_event_loop.get(), |
| 61 | y2020::control_loops::drivetrain::GetDrivetrainConfig()); |
| 62 | frc971::control_loops::drivetrain::DrivetrainLoop drivetrain( |
| 63 | y2020::control_loops::drivetrain::GetDrivetrainConfig(), |
| 64 | drivetrain_event_loop.get(), &localizer); |
| 65 | |
| 66 | reader.event_loop_factory()->Run(); |
| 67 | |
| 68 | aos::Cleanup(); |
| 69 | return 0; |
| 70 | } |