James Kuszmaul | 313e9ce | 2024-02-11 17:47:33 -0800 | [diff] [blame] | 1 | #include "gflags/gflags.h" |
| 2 | |
| 3 | #include "aos/configuration.h" |
| 4 | #include "aos/events/logging/log_reader.h" |
| 5 | #include "aos/events/logging/log_writer.h" |
| 6 | #include "aos/events/simulated_event_loop.h" |
| 7 | #include "aos/init.h" |
| 8 | #include "aos/json_to_flatbuffer.h" |
| 9 | #include "aos/network/team_number.h" |
| 10 | #include "aos/util/simulation_logger.h" |
James Kuszmaul | 86116c2 | 2024-03-15 22:50:34 -0700 | [diff] [blame^] | 11 | #include "frc971/constants/constants_sender_lib.h" |
| 12 | #include "frc971/imu_fdcan/dual_imu_blender_lib.h" |
| 13 | #include "y2024/constants/simulated_constants_sender.h" |
James Kuszmaul | 313e9ce | 2024-02-11 17:47:33 -0800 | [diff] [blame] | 14 | #include "y2024/control_loops/drivetrain/drivetrain_base.h" |
| 15 | #include "y2024/localizer/localizer.h" |
| 16 | |
| 17 | DEFINE_string(config, "y2024/aos_config.json", |
| 18 | "Name of the config file to replay using."); |
James Kuszmaul | 86116c2 | 2024-03-15 22:50:34 -0700 | [diff] [blame^] | 19 | DEFINE_bool(override_config, false, |
| 20 | "If set, override the logged config with --config."); |
| 21 | DEFINE_int32(team, 971, "Team number to use for logfile replay."); |
James Kuszmaul | 313e9ce | 2024-02-11 17:47:33 -0800 | [diff] [blame] | 22 | DEFINE_string(output_folder, "/tmp/replayed", |
| 23 | "Name of the folder to write replayed logs to."); |
James Kuszmaul | 86116c2 | 2024-03-15 22:50:34 -0700 | [diff] [blame^] | 24 | DEFINE_string(constants_path, "y2024/constants/constants.json", |
| 25 | "Path to the constant file"); |
James Kuszmaul | 313e9ce | 2024-02-11 17:47:33 -0800 | [diff] [blame] | 26 | |
| 27 | int main(int argc, char **argv) { |
| 28 | aos::InitGoogle(&argc, &argv); |
| 29 | |
| 30 | aos::network::OverrideTeamNumber(FLAGS_team); |
| 31 | |
| 32 | const aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 33 | aos::configuration::ReadConfig(FLAGS_config); |
| 34 | |
| 35 | // sort logfiles |
| 36 | const std::vector<aos::logger::LogFile> logfiles = |
| 37 | aos::logger::SortParts(aos::logger::FindLogs(argc, argv)); |
| 38 | |
| 39 | // open logfiles |
James Kuszmaul | 86116c2 | 2024-03-15 22:50:34 -0700 | [diff] [blame^] | 40 | aos::logger::LogReader reader( |
| 41 | logfiles, FLAGS_override_config ? &config.message() : nullptr); |
James Kuszmaul | 313e9ce | 2024-02-11 17:47:33 -0800 | [diff] [blame] | 42 | |
| 43 | reader.RemapLoggedChannel("/localizer", "y2024.localizer.Status"); |
Maxwell Henderson | 3279bc5 | 2024-03-01 09:50:53 -0800 | [diff] [blame] | 44 | for (const auto orin : {"orin1", "imu"}) { |
James Kuszmaul | 313e9ce | 2024-02-11 17:47:33 -0800 | [diff] [blame] | 45 | for (const auto camera : {"camera0", "camera1"}) { |
| 46 | reader.RemapLoggedChannel(absl::StrCat("/", orin, "/", camera), |
| 47 | "y2024.localizer.Visualization"); |
| 48 | } |
| 49 | } |
| 50 | reader.RemapLoggedChannel("/localizer", "frc971.controls.LocalizerOutput"); |
James Kuszmaul | 86116c2 | 2024-03-15 22:50:34 -0700 | [diff] [blame^] | 51 | reader.RemapLoggedChannel("/localizer", "frc971.IMUValuesBatch"); |
| 52 | reader.RemapLoggedChannel("/imu", "frc971.imu.DualImuBlenderStatus"); |
| 53 | reader.RemapLoggedChannel("/imu/constants", "y2024.Constants"); |
| 54 | reader.RemapLoggedChannel("/roborio/constants", "y2024.Constants"); |
| 55 | reader.RemapLoggedChannel("/orin1/constants", "y2024.Constants"); |
James Kuszmaul | 313e9ce | 2024-02-11 17:47:33 -0800 | [diff] [blame] | 56 | |
| 57 | auto factory = |
| 58 | std::make_unique<aos::SimulatedEventLoopFactory>(reader.configuration()); |
| 59 | |
| 60 | reader.RegisterWithoutStarting(factory.get()); |
| 61 | |
James Kuszmaul | 86116c2 | 2024-03-15 22:50:34 -0700 | [diff] [blame^] | 62 | y2024::SendSimulationConstants(reader.event_loop_factory(), FLAGS_team, |
| 63 | FLAGS_constants_path); |
| 64 | |
James Kuszmaul | 313e9ce | 2024-02-11 17:47:33 -0800 | [diff] [blame] | 65 | const aos::Node *node = nullptr; |
| 66 | if (aos::configuration::MultiNode(reader.configuration())) { |
| 67 | node = aos::configuration::GetNode(reader.configuration(), "imu"); |
| 68 | } |
| 69 | std::vector<std::unique_ptr<aos::util::LoggerState>> loggers; |
| 70 | |
| 71 | reader.OnStart(node, [&factory, node, &loggers]() { |
| 72 | aos::NodeEventLoopFactory *node_factory = |
| 73 | factory->GetNodeEventLoopFactory(node); |
| 74 | node_factory->AlwaysStart<y2024::localizer::Localizer>("localizer"); |
James Kuszmaul | 86116c2 | 2024-03-15 22:50:34 -0700 | [diff] [blame^] | 75 | node_factory->AlwaysStart<frc971::imu_fdcan::DualImuBlender>( |
| 76 | "dual_imu_blender"); |
James Kuszmaul | 313e9ce | 2024-02-11 17:47:33 -0800 | [diff] [blame] | 77 | loggers.push_back(std::make_unique<aos::util::LoggerState>( |
| 78 | factory.get(), node, FLAGS_output_folder)); |
| 79 | }); |
| 80 | |
| 81 | reader.event_loop_factory()->Run(); |
| 82 | |
| 83 | reader.Deregister(); |
| 84 | |
| 85 | return 0; |
| 86 | } |