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