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