blob: 52fd917f56529ce4c390b263d3e829131a64cc10 [file] [log] [blame]
Austin Schuh99f7c6a2024-06-25 22:07:44 -07001#include "absl/flags/flag.h"
James Kuszmaul313e9ce2024-02-11 17:47:33 -08002
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 Kuszmaul86116c22024-03-15 22:50:34 -070011#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 Kuszmaul313e9ce2024-02-11 17:47:33 -080014#include "y2024/control_loops/drivetrain/drivetrain_base.h"
15#include "y2024/localizer/localizer.h"
16
Austin Schuh99f7c6a2024-06-25 22:07:44 -070017ABSL_FLAG(std::string, config, "y2024/aos_config.json",
18 "Name of the config file to replay using.");
19ABSL_FLAG(bool, override_config, false,
20 "If set, override the logged config with --config.");
21ABSL_FLAG(int32_t, team, 971, "Team number to use for logfile replay.");
22ABSL_FLAG(std::string, output_folder, "/tmp/replayed",
23 "Name of the folder to write replayed logs to.");
24ABSL_FLAG(std::string, constants_path, "y2024/constants/constants.json",
25 "Path to the constant file");
James Kuszmaul313e9ce2024-02-11 17:47:33 -080026
27int main(int argc, char **argv) {
28 aos::InitGoogle(&argc, &argv);
29
Austin Schuh99f7c6a2024-06-25 22:07:44 -070030 aos::network::OverrideTeamNumber(absl::GetFlag(FLAGS_team));
James Kuszmaul313e9ce2024-02-11 17:47:33 -080031
32 const aos::FlatbufferDetachedBuffer<aos::Configuration> config =
Austin Schuh99f7c6a2024-06-25 22:07:44 -070033 aos::configuration::ReadConfig(absl::GetFlag(FLAGS_config));
James Kuszmaul313e9ce2024-02-11 17:47:33 -080034
35 // sort logfiles
36 const std::vector<aos::logger::LogFile> logfiles =
37 aos::logger::SortParts(aos::logger::FindLogs(argc, argv));
38
39 // open logfiles
Austin Schuh99f7c6a2024-06-25 22:07:44 -070040 aos::logger::LogReader reader(logfiles, absl::GetFlag(FLAGS_override_config)
41 ? &config.message()
42 : nullptr);
James Kuszmaul313e9ce2024-02-11 17:47:33 -080043
44 reader.RemapLoggedChannel("/localizer", "y2024.localizer.Status");
Maxwell Henderson3279bc52024-03-01 09:50:53 -080045 for (const auto orin : {"orin1", "imu"}) {
James Kuszmaul313e9ce2024-02-11 17:47:33 -080046 for (const auto camera : {"camera0", "camera1"}) {
47 reader.RemapLoggedChannel(absl::StrCat("/", orin, "/", camera),
48 "y2024.localizer.Visualization");
49 }
50 }
51 reader.RemapLoggedChannel("/localizer", "frc971.controls.LocalizerOutput");
James Kuszmaul86116c22024-03-15 22:50:34 -070052 reader.RemapLoggedChannel("/localizer", "frc971.IMUValuesBatch");
53 reader.RemapLoggedChannel("/imu", "frc971.imu.DualImuBlenderStatus");
54 reader.RemapLoggedChannel("/imu/constants", "y2024.Constants");
55 reader.RemapLoggedChannel("/roborio/constants", "y2024.Constants");
56 reader.RemapLoggedChannel("/orin1/constants", "y2024.Constants");
James Kuszmaul313e9ce2024-02-11 17:47:33 -080057
58 auto factory =
59 std::make_unique<aos::SimulatedEventLoopFactory>(reader.configuration());
60
61 reader.RegisterWithoutStarting(factory.get());
62
Austin Schuh99f7c6a2024-06-25 22:07:44 -070063 y2024::SendSimulationConstants(reader.event_loop_factory(),
64 absl::GetFlag(FLAGS_team),
65 absl::GetFlag(FLAGS_constants_path));
James Kuszmaul86116c22024-03-15 22:50:34 -070066
James Kuszmaul313e9ce2024-02-11 17:47:33 -080067 const aos::Node *node = nullptr;
68 if (aos::configuration::MultiNode(reader.configuration())) {
69 node = aos::configuration::GetNode(reader.configuration(), "imu");
70 }
71 std::vector<std::unique_ptr<aos::util::LoggerState>> loggers;
72
73 reader.OnStart(node, [&factory, node, &loggers]() {
74 aos::NodeEventLoopFactory *node_factory =
75 factory->GetNodeEventLoopFactory(node);
76 node_factory->AlwaysStart<y2024::localizer::Localizer>("localizer");
James Kuszmaul86116c22024-03-15 22:50:34 -070077 node_factory->AlwaysStart<frc971::imu_fdcan::DualImuBlender>(
78 "dual_imu_blender");
James Kuszmaul313e9ce2024-02-11 17:47:33 -080079 loggers.push_back(std::make_unique<aos::util::LoggerState>(
Austin Schuh99f7c6a2024-06-25 22:07:44 -070080 factory.get(), node, absl::GetFlag(FLAGS_output_folder)));
James Kuszmaul313e9ce2024-02-11 17:47:33 -080081 });
82
83 reader.event_loop_factory()->Run();
84
85 reader.Deregister();
86
87 return 0;
88}